def prepInterpFunc(self): ''' When called this will generate the interpolation functions used by interpolateTimeGrid. Should be called if positions change (or similar). This will return arrival times (at board, including cable delays) for antennas 1,2,3 relative to antenna 0. So if ant 1 signal arrives later than ant 0 it will arive at a positive number of that many ns. ''' try: cable_delays = info.loadCableDelays()['hpol'] cable_delays = cable_delays - cable_delays[ 0] #Relative to antenna 0, how long it takes for the signal to arrive. #cable_delays = numpy.zeros(4)# THIS WILL IGNORE CABLE DELAYS AND SHOULD BE DONE FOR TESTING PURPOSES ONLY. self.t_hpol_0subtract1_interp = scipy.interpolate.RectBivariateSpline( self.thetas_rad, self.phis_rad, -self.t_hpol_0subtract1 + cable_delays[1]) self.t_hpol_0subtract2_interp = scipy.interpolate.RectBivariateSpline( self.thetas_rad, self.phis_rad, -self.t_hpol_0subtract2 + cable_delays[2]) self.t_hpol_0subtract3_interp = scipy.interpolate.RectBivariateSpline( self.thetas_rad, self.phis_rad, -self.t_hpol_0subtract3 + cable_delays[3]) cable_delays = info.loadCableDelays()['vpol'] cable_delays = cable_delays - cable_delays[ 0] #Relative to antenna 0, how long it takes for the signal to arrive. #cable_delays = numpy.zeros(4)# THIS WILL IGNORE CABLE DELAYS AND SHOULD BE DONE FOR TESTING PURPOSES ONLY. self.t_vpol_0subtract1_interp = scipy.interpolate.RectBivariateSpline( self.thetas_rad, self.phis_rad, -self.t_vpol_0subtract1 + cable_delays[1]) self.t_vpol_0subtract2_interp = scipy.interpolate.RectBivariateSpline( self.thetas_rad, self.phis_rad, -self.t_vpol_0subtract2 + cable_delays[2]) self.t_vpol_0subtract3_interp = scipy.interpolate.RectBivariateSpline( self.thetas_rad, self.phis_rad, -self.t_vpol_0subtract3 + cable_delays[3]) except Exception as e: print('\nError in %s' % inspect.stack()[0][3]) 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)
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
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)
import pprint import itertools import warnings import h5py import pandas as pd import tools.get_plane_tracks as pt warnings.simplefilter(action='ignore', category=FutureWarning) plt.ion() n = 1.0003 #Index of refraction of air #Should use https://www.itu.int/dms_pubrec/itu-r/rec/p/R-REC-P.453-11-201507-S!!PDF-E.pdf c = 299792458 / n #m/s datapath = os.environ['BEACON_DATA'] cable_delays = info.loadCableDelays() #The below are not ALL pulser points, but a set that has been precalculated and can be used #if you wish to skip the calculation finding them. known_pulser_ids = info.loadPulserEventids(remove_ignored=True) ignorable_pulser_ids = info.loadIgnorableEventids() cm = plt.cm.get_cmap('plasma') rescm = plt.cm.get_cmap('viridis') # all_candidates = {\ # '1651-49':{ 'eventids':numpy.array([[1651,49],[1651,6817],[1651,12761]]),\ # 'known_flight':None},\ # '1661-34206':{ 'eventids':numpy.array([[1661,34206],[1661,35542],[1661,36609]]),\ # 'known_flight':None},\ # '1662-58427':{ 'eventids':numpy.array([[1662,58427],[1662,58647]]),\
pulser_phase_location['physical'][run_label], pulser_phase_location['physical'][run_label], pulser_phase_location['physical'][run_label] ] print('Locations used:') print('Pulser Physical Location:') print(pulser_location[0], '\n') print('Pulser Hpol Location:') print(pulser_location[1], '\n') print('Pulser Vpol Location:') print(pulser_location[2], '\n') ''' NEED TO ACCOUNT FOR CABLE DELAYS! ''' cable_delays = info.loadCableDelays() 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' } for index, antennas in enumerate( [antennas_physical, antennas_phase_hpol, antennas_phase_vpol]): #print('\nCalculating expected time delays from %s location'%labels[index]) tof = {} dof = {} for antenna, location in antennas.items(): distance = numpy.sqrt( (pulser_location[index][0] - location[0])**2 +