|
4 | 4 | import numpy as np |
5 | 5 | import pytest |
6 | 6 |
|
7 | | -from kwave.utils.conversion import db2neper, neper2db |
| 7 | +from kwave.kgrid import kWaveGrid |
| 8 | +from kwave.utils.conversion import db2neper, grid2cart, neper2db |
8 | 9 | from kwave.utils.filters import apply_filter, extract_amp_phase, spect |
9 | 10 | from kwave.utils.interp import get_bli |
10 | 11 | from kwave.utils.mapgen import fit_power_law_params, power_law_kramers_kronig |
|
13 | 14 | from tests.matlab_test_data_collectors.python_testers.utils.record_reader import TestRecordReader |
14 | 15 |
|
15 | 16 |
|
| 17 | +def test_grid2cart(): |
| 18 | + kgrid = kWaveGrid( |
| 19 | + [1000, 100, 10], |
| 20 | + [1, 1, 1], |
| 21 | + ) |
| 22 | + binary_sensor_mask = np.zeros((1000, 100, 10)) |
| 23 | + binary_sensor_mask[50, 50, 4] = 1 |
| 24 | + binary_sensor_mask[99, 99, 9] = 1 |
| 25 | + |
| 26 | + cart_bsm, order_index = grid2cart(kgrid, binary_sensor_mask) |
| 27 | + assert cart_bsm.shape == (3, 2), f"grid2cart did not return a 3x2 array. Shape is {cart_bsm.shape}" |
| 28 | + print(cart_bsm) |
| 29 | + expected_cart_bsm = np.array([[-450, 0, -1], [-401, 49, 4]]).T |
| 30 | + print(expected_cart_bsm) |
| 31 | + assert np.all(cart_bsm == expected_cart_bsm) |
| 32 | + |
| 33 | + |
| 34 | +def test_grid2cart_origin(): |
| 35 | + kgrid = kWaveGrid( |
| 36 | + [1000, 100, 10], |
| 37 | + [1, 1, 1], |
| 38 | + ) |
| 39 | + binary_sensor_mask = np.zeros((1000, 100, 10)) |
| 40 | + binary_sensor_mask[500, 50, 5] = 1 # equivalent index in matlab is [501, 51, 6] for mask origin |
| 41 | + cart_bsm, order_index = grid2cart(kgrid, binary_sensor_mask) |
| 42 | + print(cart_bsm) |
| 43 | + print(order_index) |
| 44 | + assert np.all(cart_bsm == 0), "origin location was incorrect" |
| 45 | + |
| 46 | + |
16 | 47 | def test_nepers2db(): |
17 | 48 | expected_scalar = 8.186258123051049e05 |
18 | 49 | expected_matrix = expected_scalar * np.ones((10, 10)) |
|
0 commit comments