ZH: new function read_clock_offsets

This is moved out from the scripts that already have to modify timing
This commit is contained in:
Eric Teunis de Boone 2023-01-16 19:42:21 +01:00
parent 7c570c462e
commit daf2209c73
3 changed files with 35 additions and 9 deletions

View file

@ -20,6 +20,35 @@ tx_fname = 'tx.json'
antennas_fname = 'antennas.hdf5' antennas_fname = 'antennas.hdf5'
c_light = lib.c_light c_light = lib.c_light
def read_antenna_clock_repair_offsets(antennas, mode='all', freq_name=None):
valid_modes = ['orig', 'ks', 'phases', 'all']
time_offsets = []
for i, ant in enumerate(antennas):
_clock_delta = 0
# original timing
if mode == 'orig':
_clock_delta = ant.attrs['clock_offset']
# phase
if mode in ['all', 'phases']:
clock_phase = ant.beacon_info[freq_name]['sigma_phase_mean']
f_beacon = ant.beacon_info[freq_name]['freq']
clock_phase_time = clock_phase/(2*np.pi*f_beacon)
_clock_delta += clock_phase_time
# ks
if mode in ['all', 'ks']:
best_k_time = ant.beacon_info[freq_name]['best_k_time']
_clock_delta += best_k_time
time_offsets.append(_clock_delta)
return time_offsets
def write_tx_file(fname, tx, f_beacon, **kwargs): def write_tx_file(fname, tx, f_beacon, **kwargs):
with open(fname, 'w') as fp: with open(fname, 'w') as fp:
return json.dump( return json.dump(

View file

@ -201,14 +201,13 @@ if __name__ == "__main__":
# Remove time due to true phase # Remove time due to true phase
# and optionally remove the beacon # and optionally remove the beacon
measured_repair_offsets = beacon.read_antenna_clock_repair_offsets(ev.antennas, mode='phases', freq_name=freq_name)
for i, ant in enumerate(ev.antennas): for i, ant in enumerate(ev.antennas):
clock_phase = ant.beacon_info[freq_name]['sigma_phase_mean']
clock_phase_time = clock_phase/(2*np.pi*f_beacon)
ev.antennas[i].orig_t = ev.antennas[i].t_AxB ev.antennas[i].orig_t = ev.antennas[i].t_AxB
ev.antennas[i].t_AxB += clock_phase_time ev.antennas[i].t_AxB += measured_repair_offsets[i]
if remove_beacon_from_trace: if remove_beacon_from_trace:
clock_phase = measured_repair_offsets[i]*2*np.pi*f_beacon
meas_phase = ant.beacon_info[freq_name]['phase'] meas_phase = ant.beacon_info[freq_name]['phase']
f = ant.beacon_info[freq_name]['freq'] f = ant.beacon_info[freq_name]['freq']
ampl = ant.beacon_info[freq_name]['amplitude'] ampl = ant.beacon_info[freq_name]['amplitude']

View file

@ -66,12 +66,10 @@ if __name__ == "__main__":
f_beacon = ev.antennas[0].beacon_info[freq_name]['freq'] f_beacon = ev.antennas[0].beacon_info[freq_name]['freq']
# Repair clock offsets with the measured offsets # Repair clock offsets with the measured offsets
measured_repair_offsets = beacon.read_antenna_clock_repair_offsets(ev.antennas, mode='all', freq_name=freq_name)
for i, ant in enumerate(ev.antennas): for i, ant in enumerate(ev.antennas):
clock_phase_time = ant.beacon_info[freq_name]['sigma_phase_mean']/(2*np.pi*f_beacon) # t_AxB will be set by the rit.set_pol_and_bp function
best_k_time = ant.beacon_info[freq_name]['best_k_time'] ev.antennas[i].t += measured_repair_offsets[i]
total_clock_time = best_k_time + clock_phase_time
ev.antennas[i].t += total_clock_time
N_X, Xlow, Xhigh = 23, 100, 1200 N_X, Xlow, Xhigh = 23, 100, 1200
with joblib.parallel_backend("loky"): with joblib.parallel_backend("loky"):