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_plot_oxz_many(show_plots): grid = arim.Grid(-5e-3, 5e-3, 0, 0, 0, 15e-3, 0.1e-3) k = 0.01e-3 data = np.exp(-grid.x**2 / k - (grid.z - 5e-3)**2 / (2 * k)) nrows = 2 ncols = 3 data_list = [data * (i + 1) for i in range(nrows * ncols)] title_list = ["Plot {}".format(i + 1) for i in range(nrows * ncols)] figsize = (12, 8) ax_list, im_list = aplt.plot_oxz_many(data_list, grid, nrows, ncols, figsize=figsize) plt.close("all") ax_list, im_list = aplt.plot_oxz_many( data_list, grid, nrows, ncols, title_list=title_list, suptitle="Many plots", figsize=figsize, y_suptitle=0.98, ) if show_plots: plt.show() else: plt.close("all")
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 make_grid_tfm(conf, extra=5e-3): grid_conf = conf["grid"].copy() pixel_size = grid_conf["pixel_size"] if grid_conf.get("zmin", None) is None: grid_conf["zmin"] = conf["frontwall"]["z"] + pixel_size if grid_conf.get("zmax", None) is None: grid_conf["zmax"] = conf["backwall"]["z"] - pixel_size + extra return arim.Grid(**grid_conf, ymin=0.0, ymax=0.0)
def test_plot_interfaces(show_plots, plot_interfaces_kwargs): # setup interfaces numinterface = 200 numinterface2 = 200 xmin = -5e-3 xmax = 60e-3 z_backwall = 20e-3 points, orientations = arim.geometry.points_1d_wall_z(0, 12e-3, z=0.0, numpoints=64, name="Probe") rot = g.rotation_matrix_y(np.deg2rad((12))) points = points.rotate(rot) points = points.translate((0, 0, -10e-3)) orientations = orientations.rotate(rot) probe = arim.geometry.OrientedPoints(points, orientations) assert probe.orientations[0, 2, 0] > 0 assert probe.orientations[0, 2, 2] > 0 points, orientations = arim.geometry.points_1d_wall_z( xmin, xmax, z=0.0, numpoints=numinterface, name="Frontwall") frontwall = arim.geometry.OrientedPoints(points, orientations) points, orientations = arim.geometry.points_1d_wall_z( xmin, xmax, z=z_backwall, numpoints=numinterface2, name="Backwall") backwall = arim.geometry.OrientedPoints(points, orientations) grid_obj = arim.Grid(xmin, xmax, 0, 0, 0, z_backwall, 1e-3) grid = grid_obj.to_oriented_points() interfaces = [probe, frontwall, backwall, grid] # end setup interfaces aplt.plot_interfaces(interfaces, **plot_interfaces_kwargs) if show_plots: plt.show() else: plt.close("all")
def test_plot_oxz(show_plots): grid = arim.Grid(-5e-3, 5e-3, 0, 0, 0, 15e-3, 0.1e-3) k = 2 * np.pi / 10e-3 data = (np.cos(grid.x * 2 * k) * np.sin(grid.z * k)) * (grid.z**2) # check it works without error ax, im = aplt.plot_oxz(data, grid) plt.close("all") ax, im = aplt.plot_oxz( data.reshape((grid.numx, grid.numz)), grid, scale="linear", title="some linear stuff", ) if show_plots: plt.show() else: plt.close("all") with tempfile.TemporaryDirectory() as dirname: out_file = Path(dirname) / Path("toto.png") ax, im = aplt.plot_oxz( data, grid, title="some db stuff", scale="db", clim=[-12, 0], savefig=True, filename=str(out_file), ) if show_plots: plt.show() else: plt.close("all") assert out_file.exists()