with h5py.File(args.h5_file, "r") as f: # load the fixed dataset if exists if "data" in f: scatterers_data = f["data"].value print("Configuring %d fixed scatterers" % scatterers_data.shape[0]) sim_cpu.add_fixed_scatterers(scatterers_data) sim_gpu.add_fixed_scatterers(scatterers_data) # load the spline dataset if exists if "spline_degree" in f: amplitudes = f["amplitudes"].value control_points = f["control_points"].value knot_vector = f["knot_vector"].value spline_degree = f["spline_degree"].value print("Configuring %d spline scatterers" % control_points.shape[0]) sim_cpu.add_spline_scatterers(spline_degree, knot_vector, control_points, amplitudes) sim_gpu.add_spline_scatterers(spline_degree, knot_vector, control_points, amplitudes) # configure simulation parameters sim_cpu.set_parameter("verbose", "0"); sim_gpu.set_parameter("verbose", "0") sim_cpu.set_parameter("sound_speed", "1540.0"); sim_gpu.set_parameter("sound_speed", "1540.0") sim_cpu.set_parameter("radial_decimation", "10"); sim_gpu.set_parameter("radial_decimation", "10") sim_cpu.set_parameter("phase_delay", "on"); sim_gpu.set_parameter("phase_delay", "on") # configure the RF excitation fs = 50e6 ts = 1.0/fs fc = 2.5e6 tc = 1.0/fc t_vector = np.arange(-16*tc, 16*tc, ts) bw = 0.2
lateral_dirs = np.empty((args.num_beams_total, 3), dtype="float32") y_axis = np.array([0.0, 1.0, 0.0]) lateral_dir = np.cross(y_axis, direction) for beam_no in range(args.num_beams_total): origins[beam_no, :] = origin directions[beam_no, :] = direction lateral_dirs[beam_no, :] = lateral_dir # set the beam profile sim_fixed.set_analytical_beam_profile(args.sigma_lateral, args.sigma_elevational) sim_spline.set_analytical_beam_profile(args.sigma_lateral, args.sigma_elevational) # configure spline simulator sim_spline.add_spline_scatterers(int(spline_degree), knot_vector, control_points, amplitudes) sim_spline.set_scan_sequence(origins, directions, args.line_length, lateral_dirs, timestamps) # fixed iq_lines_fixed, sim_time_fixed = run_fixed_simulation( sim_fixed, origin, direction, lateral_dir, args.line_length, timestamps, fixed_scatterers) if args.only_save_png: import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt plt.figure(1) make_mmode_image(iq_lines_fixed) plt.title("M-Mode produced with the fixed algorithm : %f sec" %
origins = np.empty((args.num_beams_total, 3), dtype="float32") directions = np.empty((args.num_beams_total, 3), dtype="float32") lateral_dirs = np.empty((args.num_beams_total, 3), dtype="float32") y_axis = np.array([0.0, 1.0, 0.0]) lateral_dir = np.cross(y_axis, direction) for beam_no in range(args.num_beams_total): origins[beam_no, :] = origin directions[beam_no, :] = direction lateral_dirs[beam_no, :] = lateral_dir # set the beam profile sim_fixed.set_analytical_beam_profile(args.sigma_lateral, args.sigma_elevational) sim_spline.set_analytical_beam_profile(args.sigma_lateral, args.sigma_elevational) # configure spline simulator sim_spline.add_spline_scatterers(spline_degree, knot_vector, control_points, amplitudes) sim_spline.set_scan_sequence(origins, directions, args.line_length, lateral_dirs, timestamps) # fixed iq_lines_fixed, sim_time_fixed = run_fixed_simulation(sim_fixed, origin, direction, lateral_dir, args.line_length, timestamps, fixed_scatterers) if args.only_save_png: import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt plt.figure(1) make_mmode_image(iq_lines_fixed) plt.title("M-Mode produced with the fixed algorithm : %f sec" % sim_time_fixed) if args.only_save_png: plt.savefig("mmode_fixed_alg.png")