From fe20ee3d396451bba85ac0cfbf8af4c501323f8a Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Tue, 22 Nov 2022 11:40:00 +0100 Subject: [PATCH] ZH: rework beacon info in hdf5 file --- .../aa_generate_beacon.py | 23 +++++++++++----- .../ba_beacon_phases.py | 27 +++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/simulations/airshower_beacon_simulation/aa_generate_beacon.py b/simulations/airshower_beacon_simulation/aa_generate_beacon.py index b7ee39b..e0861e1 100755 --- a/simulations/airshower_beacon_simulation/aa_generate_beacon.py +++ b/simulations/airshower_beacon_simulation/aa_generate_beacon.py @@ -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 diff --git a/simulations/airshower_beacon_simulation/ba_beacon_phases.py b/simulations/airshower_beacon_simulation/ba_beacon_phases.py index fa15176..24cd60e 100755 --- a/simulations/airshower_beacon_simulation/ba_beacon_phases.py +++ b/simulations/airshower_beacon_simulation/ba_beacon_phases.py @@ -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)