def find_echo_location(file): """A wrapper for find_half_height.""" data = read_ultrasound_new.read_ultrasound(file, 1) trimmed_data = trim_leading_edge(data) crossing_depth = find_half_height(trimmed_data['depth'], trimmed_data['echo'][5]) return crossing_depth
def __init__(self, shot, channel_num): '''Initialize a ChannelData object. Note that shot is a Shot object, which must be created before. Ideally, this function is only run from Shot.add_channel_data().''' if(not(shot.channels_used.__contains__(channel_num))): raise ValueError("Shot %d does not use channel %d" % (shot.number, channel_num)) #Get a pointer back to our parent Shot. self.shot = shot #Read in the data from the UDV file if(not(os.path.exists(shot.filename))): raise ValueError('Data file %s does not exist.' % self.filename) data = rudv.read_ultrasound(shot.filename, channel_num, verbose=0) self.velocity = data['velocity'] self.echo = data['echo'] self.energy = data['energy'] self.depth = data['depth'] self.time = data['time'] self.channel = data['channel'] self.maxvelocity = data['maxvelocity'] #Now grab the shot parameters from the database. params = sp.shot_params[shot.number] if(params.__contains__('trouble_flag')): print "Shot %d has trouble_flag set. Check notebook." % shot.number #Pick out the transducer mounting parameters to correspond to this #channel channel_idx = params['channels'].index(channel_num) self.A = params['As'][channel_idx] self.B = params['Bs'][channel_idx] self.offset = params['offsets'][channel_idx] self.port = params['ports'][channel_idx] self.time_points = self.time.size self.spatial_points = self.depth.size #Now run some routines to unwrap the aliased velocity, and to find #the location of each measurement. self.calculate_radius() self.calculate_azimuth() self.calculate_height() self.unwrap_velocity()
def extract_spiral_modes(filename, channel, omega2, start_time, end_time, desiredcells=200, rin=udvh.r1, filter_threshold=1000, background_subtract=0, derotate=0, maxv=10000, minv=-10000, max_diff_mean=10000, levels=0, smoothradial=0): if(rudv.read_ultrasound("960.BDD", 1)): has_radial=1 else: has_radial=0 #I use the novr option to generate v_t, so that it is less susceptible #to noise on the radial transducer, and then run again to get the v_r #data separately. #If we don't have radial data, just use data_vt for the radial dataset, #so v_r will just be 0. data_vt = udvh.generate_profiles_alltime_novr(filename, channel, omega2) if(has_radial): data_vr = udvh.generate_profiles_alltime(filename, channel, omega2) else: data_vr = data_vt phase = linspace(-pi, pi, 100) time = data_vt['time'] vt = data_vt['vt'] vr = data_vr['vr'] r = data_vt['r'] if (derotate != 0): derotate_angle = start_time*2.0*pi/(end_time-start_time) derotate_angle = fmod(derotate_angle, 2.0*pi) for i in range(0, time.size): if (time[i] > start_time) & (time[i-1] <= start_time): start_pos = i elif (time[i] > end_time) & (time[i-1] <= end_time): end_pos = i-1 #Trim the arrays time = time[start_pos-10:end_pos+10] vt = vt[start_pos-10:end_pos+10,:] vr = vr[start_pos-10:end_pos+10,:] #Now convert time to phase time = time - start_time measured_phase = time*2.0*pi/(end_time-start_time) - pi resampled_vt = zeros([phase.size, r.size]) resampled_vr = zeros([phase.size, r.size]) #Now resample for each element of r for i in range(0, r.size): #Filter the data to remove spurious measurements for k in range (0, 5): if (vt[k,i] > maxv): vt[k,i] = maxv if (vt[k,i] < minv): vt[k,i] = minv for k in range (5, vt[:,i].size): if abs(vt[k,i] - vt[k-5:k-1,i].mean()) > filter_threshold: vt[k,i] = vt[k-5:k-1,i].mean() if (vt[k,i] > maxv): vt[k,i] = maxv if (vt[k,i] < minv): vt[k,i] = minv #Need to offset theta to account for the angular extent of the #the measurement chord. #Note that there is some weirdness because of the branchcuts of asin. vt_theta_offset = pi - udvh.tan_probe_angle*pi/180 - (pi - math.asin(udvh.r2*math.sin(udvh.tan_probe_angle*pi/180)/r[i])) vt_temp_measured_phase = measured_phase - vt_theta_offset #This is just set by the port plugs where the transducers are #installed. The radial transducer leads the azimuthal transducer #by 90 degrees vr_theta_offset = -pi/2 vr_temp_measured_phase = measured_phase - vr_theta_offset #Now resample. Array is reversed, since measurements in experiment #are made from larger phase down to smaller phase #(features flowing past transducer) tck_vt = scipy.interpolate.splrep(vt_temp_measured_phase, vt[:,i], s=0) resampled_vt[:,i] = (scipy.interpolate.splev(phase, tck_vt, der=0))[::-1] tck_vr = scipy.interpolate.splrep(vr_temp_measured_phase, vr[:,i], s=0) resampled_vr[:,i] = (scipy.interpolate.splev(phase, tck_vr, der=0))[::-1] if(background_subtract == 1): resampled_vt[:,i] = resampled_vt[:,i]-resampled_vt[:,i].mean() if(smoothradial == 1): for i in range(0, phase.size): tck_sr = scipy.interpolate.splrep(r, resampled_vr[i,:], s=100) resampled_vr[i,:] = (scipy.interpolate.splev(r, tck_sr, der=0)) #r and phase contain the and theta coordinates #vr and vt are arrays, with the first index the phase, #and the second index r data = {'r': r, 'phase': phase, 'vr': resampled_vr, 'vt': resampled_vt} return data
def extract_spiral_modes_good(filename, channel, omega2, start_time, end_time, desiredcells=200, rin=udvh.r1, filter_threshold=1000, background_subtract=0, derotate=0, maxv=10000, minv=-10000, max_diff_mean=10000, levels=0, smoothradial=0, smoothingfactor=100): oscillation_time = end_time-start_time #I use the novr option to generate v_t, so that it is less susceptible #to noise on the radial transducer, and then run again to get the v_r #data separately. r_data = rudv.read_ultrasound(filename, 1) t_data = rudv.read_ultrasound(filename, channel) r, v_r, v_t = udvh.reconstruct_avg_velocities_nonaxisymmetric(r_data, t_data, 100, omega2, oscillation_time) vt = zeros([r_data['time'].size, r.size]) vr = zeros([r_data['time'].size, r.size]) #Because of the resampling interval that I do in #reconstruct_avg_velocities_nonaxisymmetric, I can't go all the way to the #ends of the time interval. boundary = int(oscillation_time/(t_data['time'][5]-t_data['time'][4]))/2 + 2 for i in range(boundary, r_data['time'].size-boundary): r, v_r, v_t = udvh.reconstruct_avg_velocities_nonaxisymmetric(r_data, t_data, i, omega2, oscillation_time) vt[i,:] = v_t vr[i,:] = v_r phase = linspace(-pi, pi, 100) time = r_data['time'] if (derotate != 0): derotate_angle = start_time*2.0*pi/(end_time-start_time) derotate_angle = fmod(derotate_angle, 2.0*pi) for i in range(0, time.size): if (time[i] > start_time) & (time[i-1] <= start_time): start_pos = i elif (time[i] > end_time) & (time[i-1] <= end_time): end_pos = i-1 #Trim the arrays time = time[start_pos-10:end_pos+10] vt = vt[start_pos-10:end_pos+10,:] vr = vr[start_pos-10:end_pos+10,:] #Now convert time to phase time = time - start_time measured_phase = time*2.0*pi/(end_time-start_time) - pi resampled_vt = zeros([phase.size, r.size]) resampled_vr = zeros([phase.size, r.size]) #Now resample for each element of r for i in range(0, r.size): #Filter the data to remove spurious measurements for k in range (0, 5): if (vt[k,i] > maxv): vt[k,i] = maxv if (vt[k,i] < minv): vt[k,i] = minv for k in range (5, vt[:,i].size): if abs(vt[k,i] - vt[k-5:k-1,i].mean()) > filter_threshold: vt[k,i] = vt[k-5:k-1,i].mean() if (vt[k,i] > maxv): vt[k,i] = maxv if (vt[k,i] < minv): vt[k,i] = minv #Now resample. Array is reversed, since measurements in experiment #are made from larger phase down to smaller phase #(features flowing past transducer) tck_vt = scipy.interpolate.splrep(measured_phase, vt[:,i], s=0) resampled_vt[:,i] = (scipy.interpolate.splev(phase, tck_vt, der=0))[::-1] tck_vr = scipy.interpolate.splrep(measured_phase, vr[:,i], s=0) resampled_vr[:,i] = (scipy.interpolate.splev(phase, tck_vr, der=0))[::-1] if(background_subtract == 1): resampled_vt[:,i] = resampled_vt[:,i]-resampled_vt[:,i].mean() if(smoothradial == 1): for i in range(0, phase.size): tck_sr = scipy.interpolate.splrep(r, resampled_vr[i,:], s=smoothingfactor) resampled_vr[i,:] = (scipy.interpolate.splev(r, tck_sr, der=0)) #r and phase contain the and theta coordinates #vr and vt are arrays, with the first index the phase, #and the second index r data = {'r': r, 'phase': phase, 'vr': resampled_vr, 'vt': resampled_vt} return data