def test_multiview_tfm(use_real_grid): # make probe probe = arim.Probe.make_matrix_probe(5, 0.5e-3, 1, np.nan, 1e6) probe.set_reference_element("first") probe.reset_position() probe.translate([0.0, 0.0, -1e-3]) # make frame tx_arr, rx_arr = arim.ut.fmc(probe.numelements) time = arim.Time(0.5e-6, 1 / 20e6, 100) # use random data but ensure reciprocity scanlines = np.zeros((len(tx_arr), len(time))) for i, (tx, rx) in enumerate(zip(tx_arr, rx_arr)): np.random.seed((tx * rx)**2) # symmetric in tx and rx scanlines[i] = np.random.rand(len(time)) block = arim.Material(6300, 3100) frame = arim.Frame(scanlines, time, tx_arr, rx_arr, probe, arim.ExaminationObject(block)) # prepare view LL-T in contact if use_real_grid: grid = arim.Grid(0.0, 0.0, 0.0, 0.0, 5e-3, 5e-3, np.nan) grid_interface = arim.Interface(*grid.to_oriented_points()) else: grid = arim.Points(np.array([0.0, 0.0, 5e-3]), name="Grid") grid_interface = arim.Interface( *arim.geometry.default_oriented_points(grid.to_1d_points())) backwall = arim.geometry.points_1d_wall_z(-1e-3, 1e-3, 10e-3, 200) backwall_interface = arim.Interface(*backwall) probe_interface = arim.Interface(*probe.to_oriented_points()) path_LL = arim.Path( [probe_interface, backwall_interface, grid_interface], [block, block], ["L", "L"], ) path_T = arim.Path([probe_interface, grid_interface], [block], ["T"]) view = arim.View(path_LL, path_T, "LL-T") arim.ray.ray_tracing([view], convert_to_fortran_order=True) # make TFM tfm = im.tfm.tfm_for_view(frame, grid, view, fillvalue=np.nan) # Check this value is unchanged over time! expected_val = 12.745499105785953 assert tfm.res.shape == grid.shape if use_real_grid: np.testing.assert_array_almost_equal(tfm.res, [[[expected_val]]]) else: np.testing.assert_allclose(tfm.res, expected_val) # Reverse view view_rev = arim.View(path_LL, path_T, "T-LL") tfm_rev = im.tfm.tfm_for_view(frame, grid, view_rev, fillvalue=np.nan) assert tfm.res.shape == grid.shape if use_real_grid: np.testing.assert_array_almost_equal(tfm_rev.res, [[[expected_val]]]) else: np.testing.assert_allclose(tfm_rev.res, expected_val)
def test_make_views(): xmin = -5e-3 xmax = 5e-3 zmin = 0.0 zmax = 7e-3 grid = arim.Grid(xmin, xmax, 0.0, 0.0, zmin, zmax, pixel_size=1e-3) grid_p = grid.to_oriented_points() probe = arim.probes["ima_50_MHz_128_1d"] probe_p = probe.to_oriented_points() frontwall = arim.geometry.points_1d_wall_z(xmin, xmax, zmin, 11) backwall = arim.geometry.points_1d_wall_z(xmin, xmax, zmax, 10) block_material = arim.Material(6300.0, 3120.0) # General ExaminationObject examination_object = arim.ExaminationObject(block_material) views = bic.make_views( examination_object, probe_p, grid_p, max_number_of_reflection=0, tfm_unique_only=False, ) assert len(views) == 4 with pytest.raises(ValueError): # Undefined backwall views = bic.make_views(examination_object, probe_p, grid_p, max_number_of_reflection=2) # BlockInContact with a backwall examination_object = arim.BlockInContact(block_material, backwall=backwall) views = bic.make_views( examination_object, probe_p, grid_p, max_number_of_reflection=1, tfm_unique_only=False, ) assert len(views) == 36 with pytest.raises(ValueError): # Undefined frontwall views = bic.make_views(examination_object, probe_p, grid_p, max_number_of_reflection=2) # BlockInContact with a backwall and a frontwall examination_object = arim.BlockInContact(block_material, frontwall, backwall) views = bic.make_views( examination_object, probe_p, grid_p, max_number_of_reflection=2, tfm_unique_only=False, ) assert len(views) == 196
def test_contact_tfm(use_hmc): # make probe probe = arim.Probe.make_matrix_probe(5, 0.5e-3, 1, np.nan, 1e6) probe.set_reference_element("first") probe.reset_position() probe.translate([0.0, 0.0, -1e-3]) # make frame if use_hmc: tx_arr, rx_arr = arim.ut.hmc(probe.numelements) else: tx_arr, rx_arr = arim.ut.fmc(probe.numelements) time = arim.Time(0.5e-6, 1 / 20e6, 100) # use random data but ensure reciprocity scanlines = np.zeros((len(tx_arr), len(time))) for i, (tx, rx) in enumerate(zip(tx_arr, rx_arr)): np.random.seed((tx * rx)**2) # symmetric in tx and rx scanlines[i] = np.random.rand(len(time)) # check reciprocity if not use_hmc: for i, (tx, rx) in enumerate(zip(tx_arr, rx_arr)): scanline_1 = scanlines[i] scanline_2 = scanlines[np.logical_and(tx_arr == rx, rx_arr == tx)][0] np.testing.assert_allclose(scanline_1, scanline_2, err_msg="fmc data not symmetric") block = arim.Material(6300, 3100) frame = arim.Frame(scanlines, time, tx_arr, rx_arr, probe, arim.ExaminationObject(block)) # prepare view LL-T in contact grid = arim.Points(np.array([0.0, 0.0, 5e-3]), name="Grid") tfm = im.tfm.contact_tfm(frame, grid, block.longitudinal_vel, fillvalue=np.nan) # Check this value is unchanged over time! expected_val = 12.49925772283528 assert tfm.res.shape == grid.shape np.testing.assert_allclose(tfm.res, expected_val)