mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 03:23:34 +01:00
ZH: rework beacon info in hdf5 file
This commit is contained in:
parent
dd9630f346
commit
fe20ee3d39
2 changed files with 39 additions and 11 deletions
|
@ -55,10 +55,13 @@ def read_beacon_hdf5(fname, **h5ant_kwargs):
|
|||
|
||||
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'] }
|
||||
ant = Antenna(**mydict)
|
||||
if h5ant.attrs:
|
||||
ant.attrs = {**h5ant.attrs}
|
||||
|
||||
# Traces
|
||||
if traces_key is None:
|
||||
pass
|
||||
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:
|
||||
ant.beacon = h5ant[traces_key][4]
|
||||
|
||||
if read_AxB and 'E_AxB' in h5ant:
|
||||
ant.t_AxB = h5ant['E_AxB'][0]
|
||||
ant.E_AxB = h5ant['E_AxB'][1]
|
||||
# E_AxB
|
||||
if read_AxB and 'E_AxB' in h5ant:
|
||||
ant.t_AxB = h5ant['E_AxB'][0]
|
||||
ant.E_AxB = h5ant['E_AxB'][1]
|
||||
|
||||
if h5ant.attrs:
|
||||
ant.attrs = {**h5ant.attrs}
|
||||
# Beacons
|
||||
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
|
||||
|
||||
|
|
|
@ -124,6 +124,9 @@ if __name__ == "__main__":
|
|||
amplitude = amps[idx]
|
||||
orientation = orients[idx]
|
||||
|
||||
# for reporting using plots
|
||||
found_data[i] = frequency, phase, amplitude
|
||||
|
||||
if show_plots and (i == 60 or i == 72):
|
||||
fig, ax = plt.subplots()
|
||||
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.legend()
|
||||
|
||||
h5ant_group.attrs['beacon_freq'] = frequency
|
||||
h5ant_group.attrs['beacon_phase_measured'] = phase
|
||||
h5ant_group.attrs['beacon_amplitude'] = amplitude
|
||||
h5ant_group.attrs['beacon_orientation'] = orientation
|
||||
# save to file
|
||||
h5beacon = h5ant.require_group('beacon')
|
||||
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue