c = 1540 # Speed of sound [m/s] lambd = c / f0 # Wavelength [m] width = lambd # Width of element height = 5 / 1000 # Height of element [m] kerf = 0.05 / 1000 # Kerf (gap between elements) [m] pitch = kerf + width # Pitch (center-to-center distance between elements) [m] N_elements = 192 # Number of physical elements no_sub_x = 1 # Number of sub-divisions in x-direction of elements no_sub_y = 10 # Number of sub-divisions in y-direction of elements # Create and configure GPU simulator from pyrfsim import RfSimulator sim = RfSimulator('gpu') sim.set_print_debug(True) sim.set_parameter('sound_speed', str(c)) sim.set_parameter('radial_decimation', '1') # depth-direction downsampling factor sim.set_parameter('phase_delay', 'on') # improves subsample accuracy sim.set_parameter('use_elev_hack', 'off') def subdivide(length, num): delta = length * 1 / num divisions = np.arange((-num // 2 + 1) * delta, (num // 2 + 1) * delta, delta) return divisions
timestamps.append(cur_time) cur_time += prt if cur_time >= args.end_time: cur_time = args.start_time timestamps = np.array(timestamps, dtype="float32") # precompute fixed-scatterer datasets fixed_scatterers = create_fixed_datasets(args, control_points, amplitudes, spline_degree, knot_vector, timestamps) # create two simulator instances - one for spline-only and one fixed-only sim_fixed = RfSimulator("gpu") sim_spline = RfSimulator("gpu") sim_fixed.set_parameter("verbose", "0") sim_spline.set_parameter("verbose", "0") sim_fixed.set_print_debug(False) sim_spline.set_print_debug(False) sim_fixed.set_parameter("sound_speed", "%f" % c0) sim_spline.set_parameter("sound_speed", "%f" % c0) sim_fixed.set_parameter("phase_delay", "on") sim_spline.set_parameter("phase_delay", "on") sim_fixed.set_parameter("radial_decimation", "5") sim_spline.set_parameter("radial_decimation", "5") num_gpus = int(sim_fixed.get_parameter("num_cuda_devices")) print("System has %d CUDA devices" % num_gpus) sim_fixed.set_parameter("gpu_device", "%d" % args.gpu_device_no) sim_spline.set_parameter("gpu_device", "%d" % args.gpu_device_no) print("Fixed simulator uses %s" % sim_fixed.get_parameter("cur_device_name")) print("Spline simulator uses %s" %
cur_time = args.start_time timestamps = [] for i in range(args.num_beams_total): timestamps.append(cur_time) cur_time += prt if cur_time >= args.end_time: cur_time = args.start_time timestamps = np.array(timestamps, dtype="float32") # precompute fixed-scatterer datasets fixed_scatterers = create_fixed_datasets(args, control_points, amplitudes, spline_degree, knot_vector, timestamps) # create two simulator instances - one for spline-only and one fixed-only sim_fixed = RfSimulator("gpu") sim_spline = RfSimulator("gpu") sim_fixed.set_parameter("verbose", "0"); sim_spline.set_parameter("verbose", "0") sim_fixed.set_print_debug(False); sim_spline.set_print_debug(False) sim_fixed.set_parameter("sound_speed", "%f" % c0); sim_spline.set_parameter("sound_speed", "%f" % c0) sim_fixed.set_parameter("phase_delay", "on"); sim_spline.set_parameter("phase_delay", "on") sim_fixed.set_parameter("radial_decimation", "5"); sim_spline.set_parameter("radial_decimation", "5") num_gpus = int(sim_fixed.get_parameter("num_cuda_devices")) print "System has %d CUDA devices" % num_gpus sim_fixed.set_parameter("gpu_device", "%d" % args.gpu_device_no) sim_spline.set_parameter("gpu_device", "%d" % args.gpu_device_no) print "Fixed simulator uses %s" % sim_fixed.get_parameter("cur_device_name") print "Spline simulator uses %s" % sim_spline.get_parameter("cur_device_name") # define excitation signal t_vector = np.arange(-16/args.fc, 16/args.fc, 1.0/args.fs) samples = np.array(gausspulse(t_vector, bw=args.bw, fc=args.fc), dtype="float32") center_index = int(len(t_vector)/2)
type=int, default=128) parser.add_argument("--x0", help="Scanseq width in meters (left end)", type=float, default=-0.03) parser.add_argument("--x1", help="Scanseq width in meters (right end)", type=float, default=0.03) args = parser.parse_args() # create and configure simulator sim = RfSimulator("gpu") sim.set_parameter("verbose", "0") sim.set_print_debug(False) sim.set_parameter("sound_speed", "1540.0") sim.set_parameter("radial_decimation", "15") sim.set_parameter("phase_delay", "on") # define excitation signal t_vector = np.arange(-16 / args.fc, 16 / args.fc, 1.0 / args.fs) samples = np.array(gausspulse(t_vector, bw=args.bw, fc=args.fc), dtype="float32") center_index = int(len(t_vector) / 2) demod_freq = args.fc sim.set_excitation(samples, center_index, args.fs, demod_freq) # create linear scan sequence origins = np.empty((args.num_lines, 3), dtype="float32") directions = np.empty((args.num_lines, 3), dtype="float32")
parser.add_argument("--save_pdf", help="Save pdf figures", action="store_true") parser.add_argument("--visualize", help="Interactive figures", action="store_true") args = parser.parse_args() c0 = 1540.0 # Create and configure if args.use_gpu: print "Using GPU" sim = RfSimulator("gpu") else: print "Using CPU" sim = RfSimulator("cpu") sim.set_parameter("num_cpu_cores", "all") sim.set_parameter("verbose", "0") sim.set_print_debug(False) sim.set_parameter("sound_speed", "%f" % c0) sim.set_parameter("radial_decimation", "30") # Enable phase-delays for smooth curves sim.set_parameter("phase_delay", "on") # Set spline scatterers with h5py.File(args.scatterer_file, "r") as f: control_points = np.array(f["control_points"].value, dtype="float32") amplitudes = np.array(f["amplitudes"].value, dtype="float32") knot_vector = np.array(f["knot_vector"].value, dtype="float32") spline_degree = int(f["spline_degree"].value) sim.add_spline_scatterers(spline_degree, knot_vector, control_points, amplitudes) print "Number of scatterers: %d" % control_points.shape[0]
# DEMO 1 # Linear scan with three scatterers. # Using a Gaussian analytic beam profile. import sys sys.path.append(".") from pyrfsim import RfSimulator import matplotlib.pyplot as plt import matplotlib.cm as cm from scipy.signal import gausspulse import numpy as np # Create and configure CPU simulator sim = RfSimulator("cpu") sim.set_parameter("verbose", "1") sim.set_print_debug(True) # Set general simulation parameters sim.set_parameter("sound_speed", "1540.0") sim.set_parameter("num_cpu_cores", "all") sim.set_parameter("radial_decimation", "20") # Set scatterers num_scatterers = 16 scatterers_data = np.zeros((num_scatterers, 4), dtype="float32") scatterers_data[:,2] = np.linspace(0.01, 0.16, num_scatterers) scatterers_data[:,3] = np.ones((num_scatterers,)) sim.add_fixed_scatterers(scatterers_data) # Define excitation signal fs = 50e6 ts = 1.0/fs