ZH: rework beacon info in hdf5 file

This commit is contained in:
Eric Teunis de Boone 2022-11-22 11:40:00 +01:00
parent dd9630f346
commit fe20ee3d39
2 changed files with 39 additions and 11 deletions

View file

@ -55,10 +55,13 @@ def read_beacon_hdf5(fname, **h5ant_kwargs):
return f_beacon, tx, antennas return f_beacon, tx, antennas
def Antenna_from_h5ant(h5ant, traces_key='traces', raise_exception=True, read_AxB=True): def Antenna_from_h5ant(h5ant, traces_key='traces', raise_exception=True, read_AxB=True, read_beacon_info=True):
mydict = { k:h5ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] } mydict = { k:h5ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] }
ant = Antenna(**mydict) ant = Antenna(**mydict)
if h5ant.attrs:
ant.attrs = {**h5ant.attrs}
# Traces
if traces_key is None: if traces_key is None:
pass pass
elif traces_key not in h5ant: elif traces_key not in h5ant:
@ -72,12 +75,20 @@ def Antenna_from_h5ant(h5ant, traces_key='traces', raise_exception=True, read_Ax
if len(h5ant[traces_key]) > 4: if len(h5ant[traces_key]) > 4:
ant.beacon = h5ant[traces_key][4] ant.beacon = h5ant[traces_key][4]
# E_AxB
if read_AxB and 'E_AxB' in h5ant: if read_AxB and 'E_AxB' in h5ant:
ant.t_AxB = h5ant['E_AxB'][0] ant.t_AxB = h5ant['E_AxB'][0]
ant.E_AxB = h5ant['E_AxB'][1] ant.E_AxB = h5ant['E_AxB'][1]
if h5ant.attrs: # Beacons
ant.attrs = {**h5ant.attrs} if read_beacon_info and 'beacon' in h5ant:
h5beacon = h5ant['beacon']
beacon_info = {}
for name in h5beacon.keys():
beacon_info[name] = h5beacon[name].attrs
ant.beacon_info = beacon_info
return ant return ant

View file

@ -124,6 +124,9 @@ if __name__ == "__main__":
amplitude = amps[idx] amplitude = amps[idx]
orientation = orients[idx] orientation = orients[idx]
# for reporting using plots
found_data[i] = frequency, phase, amplitude
if show_plots and (i == 60 or i == 72): if show_plots and (i == 60 or i == 72):
fig, ax = plt.subplots() fig, ax = plt.subplots()
trace_amp = max(traces[-1]) - min(traces[-1]) trace_amp = max(traces[-1]) - min(traces[-1])
@ -134,12 +137,26 @@ if __name__ == "__main__":
ax.set_title(f"Beacon at antenna {h5ant}\nF:{frequency}, P:{phase}, A:{amplitude}") ax.set_title(f"Beacon at antenna {h5ant}\nF:{frequency}, P:{phase}, A:{amplitude}")
ax.legend() ax.legend()
h5ant_group.attrs['beacon_freq'] = frequency # save to file
h5ant_group.attrs['beacon_phase_measured'] = phase h5beacon = h5ant.require_group('beacon')
h5ant_group.attrs['beacon_amplitude'] = amplitude
h5ant_group.attrs['beacon_orientation'] = orientation
found_data[i] = frequency, phase, amplitude # only take n_sig significant digits into account
# for naming in hdf5 file
n_sig = 4
decimal = int(np.floor(np.log10(abs(frequency))))
freq_name = str(np.around(frequency, n_sig-decimal))
# delete previous values
if freq_name in h5beacon:
del h5beacon[freq_name]
h5beacon_freq = h5beacon.create_group(freq_name)
h5attrs = h5beacon_freq.attrs
h5attrs['freq'] = frequency
h5attrs['phase'] = phase
h5attrs['amplitude'] = amplitude
h5attrs['orientation'] = orientation
print("Beacon Phases, Amplitudes and Frequencies written to", antennas_fname) print("Beacon Phases, Amplitudes and Frequencies written to", antennas_fname)