ZH: move true_phase_diff function to lib

This commit is contained in:
Eric Teunis de Boone 2022-12-15 12:28:43 +01:00
parent 14a9fdb957
commit ae66d4ff1d
2 changed files with 32 additions and 30 deletions

View file

@ -9,30 +9,6 @@ import numpy as np
import aa_generate_beacon as beacon
import lib
def antenna_true_phases(tx, antennas, freq_name, c_light=3e8):
"""
Determine true phases from the antenna phases.
This removes the geometrical phase from the antenna phase.
"""
if not hasattr(antennas, '__len__'):
single_ant = True
antennas = [antennas]
true_phases = np.empty( (len(antennas)) )
for i, ant in enumerate(antennas):
beacon_info = ant.beacon_info[freq_name]
measured_phase = ant.beacon_info[freq_name]['phase']
f_beacon = ant.beacon_info[freq_name]['freq']
geom_time = lib.geometry_time(tx, ant, c_light=c_light)
geom_phase = geom_time * 2*np.pi*f_beacon
true_phases[i] = lib.phase_mod(lib.phase_mod(measured_phase) - lib.phase_mod(geom_phase) )
return true_phases
if __name__ == "__main__":
from os import path
import sys
@ -71,18 +47,18 @@ if __name__ == "__main__":
N_beacon_freqs = len(antennas[0].beacon_info)
for freq_name in antennas[0].beacon_info.keys():
true_phases = antenna_true_phases(tx, antennas, freq_name, c_light=c_light)
true_phases = lib.antenna_true_phase_diff(tx, antennas, freq_name, c_light=c_light)
# Remove the phase from one antenna
# this is a free parameter
# (only required for absolute timing)
if remove_absolute_phase_offset_first_antenna or remove_absolute_phase_offset_minimum:
if remove_absolute_phase_offset_first_antenna: # just take the first phase
minimum_phase = -1*true_phases[0]
minimum_phase = true_phases[0]
else: # take the minimum
minimum_phase = -1*np.min(true_phases, axis=-1)
minimum_phase = np.min(true_phases, axis=-1)
true_phases += minimum_phase
true_phases -= minimum_phase
true_phases = lib.phase_mod(true_phases)
# Save to antennas in file
@ -99,7 +75,7 @@ if __name__ == "__main__":
if show_plots or fig_dir:
fig, ax = plt.subplots()
spatial_unit=None
fig.suptitle('True phases\nf_beacon= {:2.0f}MHz'.format(f_beacon*1e3))
fig.suptitle('Clock phases\nf_beacon= {:2.0f}MHz'.format(f_beacon*1e3))
antenna_locs = list(zip(*[(ant.x, ant.y) for ant in antennas]))
ax.set_xlabel('x' if spatial_unit is None else 'x [{}]'.format(spatial_unit))
@ -108,7 +84,7 @@ if __name__ == "__main__":
scatter_kwargs['cmap'] = 'inferno'
scatter_kwargs['vmin'] = -np.pi
scatter_kwargs['vmax'] = +np.pi
color_label='$\\varphi$'
color_label='$\\varphi(\\sigma_t)$ [rad]'
sc = ax.scatter(*antenna_locs, c=true_phases, **scatter_kwargs)
fig.colorbar(sc, ax=ax, label=color_label)

View file

@ -53,6 +53,32 @@ def beacon_from(tx, rx, f, t=0, t0=0, c_light=3e8, radiate_rsq=True, amplitude=1
return sine_beacon(f, t, t0=t0, amplitude=amplitude,**kwargs)
def antenna_true_phase_diff(tx, antennas, freq_name, c_light=3e8):
"""
Determine true phases from the antenna phases.
This removes the geometrical phase from the antenna phase.
"""
if not hasattr(antennas, '__len__'):
single_ant = True
antennas = [antennas]
true_phases = np.empty( (len(antennas)) )
for i, ant in enumerate(antennas):
beacon_info = ant.beacon_info[freq_name]
measured_phase = beacon_info['phase']
f_beacon = beacon_info['freq']
geom_time = geometry_time(tx, ant, c_light=c_light)
geom_phase = geom_time * 2*np.pi*f_beacon
print(ant.name, measured_phase, geom_phase, phase_mod(geom_phase))
true_phases[i] = phase_mod(phase_mod(measured_phase) - phase_mod(geom_phase) )
return true_phases
""" Fourier """
def ft_corr_vectors(freqs, time):
"""