diff --git a/simulations/airshower_beacon_simulation/aa_generate_beacon.py b/simulations/airshower_beacon_simulation/aa_generate_beacon.py index 8fb41a6..3551e51 100755 --- a/simulations/airshower_beacon_simulation/aa_generate_beacon.py +++ b/simulations/airshower_beacon_simulation/aa_generate_beacon.py @@ -18,6 +18,7 @@ import lib # {{{ vim marker tx_fname = 'tx.json' antennas_fname = 'antennas.hdf5' +snr_fname = 'snr.json' c_light = lib.c_light def read_antenna_clock_repair_offsets(antennas, mode='all', freq_name=None): @@ -49,6 +50,17 @@ def read_antenna_clock_repair_offsets(antennas, mode='all', freq_name=None): return time_offsets +def write_snr_file(fname, snrs): + with open(fname, 'w') as fp: + return json.dump( + {'mean': np.mean(snrs), 'std': np.std(snrs), 'values': snrs}, + fp + ) + +def read_snr_file(fname): + with open(fname, 'r') as fp: + return json.load(fp) + def write_tx_file(fname, tx, f_beacon, **kwargs): with open(fname, 'w') as fp: return json.dump( diff --git a/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py b/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py index d945bb5..d813a9d 100755 --- a/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py +++ b/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py @@ -42,6 +42,7 @@ if __name__ == "__main__": fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) tx_fname = path.join(fname_dir, beacon.tx_fname) + snr_fname = path.join(fname_dir, beacon.snr_fname) # create fig_dir if fig_dir: @@ -92,9 +93,8 @@ if __name__ == "__main__": N_samples = len(antennas[0].beacon) beacon_snrs = [ lib.signal_to_noise(myfilter(beacon_amp*ant.beacon), myfilter(ant.noise), samplerate=1/dt, signal_band=beacon_pb, noise_band=noise_pb) for i, ant in enumerate(antennas) ] - with open(path.join(fname_dir, 'snr.txt'), 'w') as f: - f.write('mean='+str(np.mean(beacon_snrs))+'\n') - f.write('std='+str(np.std(beacon_snrs))+'\n') + # write mean and std to file + beacon.write_snr_file(snr_fname, beacon_snrs) fig, ax = plt.subplots(figsize=figsize) ax.set_title(f"Maximum Beacon/Noise SNR (N_samples:{N_samples:.1e})")