def getTimeDelaysFromTrack(track): ''' Given a trajectory (each row specified x,y,z,t in ENU), this will determine the expected set of time delays based on the current saved antenna positions. ''' antennas_physical, antennas_phase_hpol, antennas_phase_vpol = info.loadAntennaLocationsENU()# MAKE SURE TO PUT THE DEPLOY INDEX CORRECTLY cable_delays = info.loadCableDelays() pairs = list(itertools.combinations((0,1,2,3), 2)) labels = ['Physical','Hpol Phase Center','Vpol Phase Center'] print_prefixs = { 'Physical':'expected_time_differences_physical' , 'Hpol Phase Center':'expected_time_differences_hpol' , 'Vpol Phase Center':'expected_time_differences_vpol'} tof = {} dof = {} dt = {} for index, antennas in enumerate([antennas_physical,antennas_phase_hpol,antennas_phase_vpol]): tof[labels[index]] = {} dof[labels[index]] = {} dt[labels[index]] = {} #print('\nCalculating expected time delays from %s location'%labels[index]) for antenna, location in antennas.items(): tof[labels[index]][antenna] = [] dof[labels[index]][antenna] = [] for plane_location in track: distance = numpy.sqrt((plane_location[0] - location[0])**2 + (plane_location[1] - location[1])**2 + (plane_location[2] - location[2])**2) time = (distance / c)*1e9 #ns if index == 0: time += 0 #Physical, assuming no cable delay elif index == 1: time += cable_delays['hpol'][antenna] elif index == 2: time += cable_delays['vpol'][antenna] tof[labels[index]][antenna].append(time) dof[labels[index]][antenna].append(distance) tof[labels[index]][antenna] = numpy.array(tof[labels[index]][antenna]) dof[labels[index]][antenna] = numpy.array(dof[labels[index]][antenna]) dt[labels[index]] = {} for pair in pairs: dt[labels[index]][pair] = tof[labels[index]][pair[0]] - tof[labels[index]][pair[1]] return tof, dof, dt
((1, 3), 115.57550659269941), ((2, 3), -83.00271992904541)] expected_time_differences_vpol = [((0, 1), -39.7774564691897), ((0, 2), 103.04747677383648), ((0, 3), 33.348616734485404), ((1, 2), 142.82493324302618), ((1, 3), 73.1260732036751), ((2, 3), -69.69886003935108)] max_time_differences_vpol = [((0, 1), -116.30631267571034), ((0, 2), 167.91381462435598), ((0, 3), 173.23375803172078), ((1, 2), 148.37193587533608), ((1, 3), 107.24435568878336), ((2, 3), -78.60480502528327)] antennas_physical, antennas_phase_hpol, antennas_phase_vpol = info.loadAntennaLocationsENU( deploy_index=1) pulser_location = info.loadPulserLocationsENU()['run1507'] #ENU elif site == 2: waveform_index_range = ( 2000, 3000 ) #Looking at the later bit of the waveform only, 10000 will cap off. run = 1509 cfd_thresh = 0.8 expected_time_differences_physical = [((0, 1), -96.21228508039667), ((0, 2), 21.36317970746586), ((0, 3), -56.5419782996255), ((1, 2), 117.57546478786253), ((1, 3), 39.67030678077117), ((2, 3), -77.90515800709136)]
def getTimeDelaysFromTrack(track, adjusted_antennas_physical=None, adjusted_antennas_phase_hpol=None, adjusted_antennas_phase_vpol=None, adjusted_cable_delays=None): ''' Given a trajectory (each row specified x,y,z,t in ENU), this will determine the expected set of time delays based on the current saved antenna positions. If you want to test a new location for the antennas you can pass dictionaries the new locations as kwargs. They are expected to be the same format as from loadAntennaLocationsENU. Same for cable delays. ''' try: antennas_physical, antennas_phase_hpol, antennas_phase_vpol = info.loadAntennaLocationsENU( ) # MAKE SURE TO PUT THE DEPLOY INDEX CORRECTLY if adjusted_antennas_physical is not None: print( 'Using adjusted_antennas_physical rather than antennas_physical.' ) antennas_physical = adjusted_antennas_physical if adjusted_antennas_phase_hpol is not None: print( 'Using adjusted_antennas_phase_hpol rather than antennas_phase_hpol.' ) antennas_phase_hpol = adjusted_antennas_phase_hpol if adjusted_antennas_phase_vpol is not None: print( 'Using adjusted_antennas_phase_vpol rather than antennas_phase_vpol.' ) antennas_phase_vpol = adjusted_antennas_phase_vpol if adjusted_cable_delays is not None: print( 'Using given values of cable delays rather than the currently saved values.' ) cable_delays = adjusted_cable_delays.copy() else: cable_delays = info.loadCableDelays() pprint(cable_delays) pairs = list(itertools.combinations((0, 1, 2, 3), 2)) labels = ['Physical', 'Hpol Phase Center', 'Vpol Phase Center'] print_prefixs = { 'Physical': 'expected_time_differences_physical', 'Hpol Phase Center': 'expected_time_differences_hpol', 'Vpol Phase Center': 'expected_time_differences_vpol' } tof = {} dof = {} dt = {} for index, antennas in enumerate( [antennas_physical, antennas_phase_hpol, antennas_phase_vpol]): tof[print_prefixs[labels[index]]] = {} dof[print_prefixs[labels[index]]] = {} dt[print_prefixs[labels[index]]] = {} #print('\nCalculating expected time delays from %s location'%print_prefixs[labels[index]]) for antenna, location in antennas.items(): tof[print_prefixs[labels[index]]][antenna] = [] dof[print_prefixs[labels[index]]][antenna] = [] for plane_location in track: distance = numpy.sqrt( (plane_location[0] - location[0])**2 + (plane_location[1] - location[1])**2 + (plane_location[2] - location[2])**2) time = (distance / c) * 1e9 #ns if index == 0: time += 0 #Physical, assuming no cable delay elif index == 1: time += cable_delays['hpol'][antenna] elif index == 2: time += cable_delays['vpol'][antenna] tof[print_prefixs[labels[index]]][antenna].append(time) dof[print_prefixs[labels[index]]][antenna].append( distance) #Does not include cable delays tof[print_prefixs[labels[index]]][antenna] = numpy.array( tof[print_prefixs[labels[index]]][antenna]) dof[print_prefixs[labels[index]]][antenna] = numpy.array( dof[print_prefixs[labels[index]]][antenna]) dt[print_prefixs[labels[index]]] = {} for pair in pairs: dt[print_prefixs[ labels[index]]][pair] = tof[print_prefixs[labels[index]]][ pair[0]] - tof[print_prefixs[labels[index]]][pair[1]] return tof, dof, dt except Exception as e: print('Error in getTimeDelaysFromTrack.') print(e) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
freq_classications = ['PLF', 'LF', 'HF', 'PHF', 'BB'] freq_colors_cm = plt.cm.get_cmap('Set3', len(freq_classications)) freq_colors = freq_colors_cm(numpy.linspace(0, 1, len(freq_classications))) freq_color_dict = {} for i, key in enumerate(freq_classications): freq_color_dict[key] = {} freq_color_dict[key]['c'] = numpy.array([freq_colors[i]]) freq_color_dict[key]['labeled_yet'] = False # freq_colors = plt.cm.get_cmap('plasma',len(freq_classications)-1)#-1 because BB will be black known_planes, calibrated_trigtime, output_tracks = pt.getKnownPlaneTracks() origin = info.loadAntennaZeroLocation( deploy_index=1) #This is what ENU is with respect to. antennas_physical, antennas_phase_hpol, antennas_phase_vpol = info.loadAntennaLocationsENU( ) antennas_phase_start = antennas_phase_hpol print('Loading in cable delays.') cable_delays = info.loadCableDelays()[mode] if plot_planes == True: plane_fig = plt.figure() plane_fig.canvas.set_window_title('3D Plane Tracks') plane_ax = plane_fig.add_subplot(111, projection='3d') plane_ax.scatter(0, 0, 0, label='Antenna 0', c='k') plane_polys = {} interpolated_plane_locations = {} measured_plane_time_delays = {} measured_plane_time_delays_weights = {}
from pprint import pprint import pymap3d as pm import itertools pairs = list(itertools.combinations((0, 1, 2, 3), 2)) plt.ion() c = 2.99700e8 #m/s if __name__ == '__main__': try: if len(sys.argv) == 2: run_label = 'run%i' % int(sys.argv[1]) else: print('No run number given. Defaulting to 1507') run_label = 'run1507' antennas_physical, antennas_phase_hpol, antennas_phase_vpol = info.loadAntennaLocationsENU( ) # MAKE SURE TO PUT THE DEPLOY INDEX CORRECTLY pulser_phase_location = info.loadPulserPhaseLocationsENU() #ENU try: pulser_location = [ pulser_phase_location['physical'][run_label], pulser_phase_location['hpol'][run_label], pulser_phase_location['vpol'][run_label] ] except: pulser_location = [ pulser_phase_location['physical'][run_label], pulser_phase_location['physical'][run_label], pulser_phase_location['physical'][run_label] ]
final_corr_length = 2**17 crit_freq_low_pass_MHz = [ 80, 70, 70, 70, 70, 70, 60, 70 ] #Filters here are attempting to correct for differences in signals from pulsers. low_pass_filter_order = [0, 8, 8, 8, 10, 8, 3, 8] crit_freq_high_pass_MHz = 65 high_pass_filter_order = 12 apply_phase_response = True hilbert = False #Load antenna position information from the info.py script origin = info.loadAntennaZeroLocation() #Assuming default_deploy antennas_physical, antennas_phase_hpol, antennas_phase_vpol = info.loadAntennaLocationsENU( ) #Assuming default_deploy #Create a Reader object for the specific run. reader = Reader(datapath, run) print('The run associated with this reader is:') print(reader.run) print('This run has %i events' % (reader.N())) #Create a TimeDelayCalculator object for the specified run. Note that if the above parameters haven't been change tdc_raw = TimeDelayCalculator(reader, final_corr_length=final_corr_length, crit_freq_low_pass_MHz=None, crit_freq_high_pass_MHz=None, low_pass_filter_order=None, high_pass_filter_order=None, plot_filters=False,