2023-01-09 16:40:32 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# vim: fdm=indent ts=4
|
|
|
|
|
|
|
|
"""
|
|
|
|
Do a reconstruction of airshower after correcting for the
|
|
|
|
clock offsets.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import matplotlib.pyplot as plt
|
2023-01-11 02:59:04 +01:00
|
|
|
from mpl_toolkits.mplot3d import Axes3D # required for projection='3d' on old matplotliblib versions
|
2023-01-09 16:40:32 +01:00
|
|
|
import numpy as np
|
|
|
|
from os import path
|
2023-01-11 02:59:04 +01:00
|
|
|
import pickle
|
2023-01-12 13:39:06 +01:00
|
|
|
import joblib
|
2023-01-09 16:40:32 +01:00
|
|
|
|
|
|
|
from earsim import REvent
|
|
|
|
from atmocal import AtmoCal
|
|
|
|
import aa_generate_beacon as beacon
|
|
|
|
import lib
|
|
|
|
from lib import rit
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import matplotlib
|
|
|
|
if os.name == 'posix' and "DISPLAY" not in os.environ:
|
|
|
|
matplotlib.use('Agg')
|
|
|
|
|
|
|
|
atm = AtmoCal()
|
|
|
|
|
2023-01-12 14:31:21 +01:00
|
|
|
from scriptlib import MyArgumentParser
|
|
|
|
parser = MyArgumentParser()
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-01-09 16:40:32 +01:00
|
|
|
fname = "ZH_airshower/mysim.sry"
|
|
|
|
|
2023-01-12 14:49:54 +01:00
|
|
|
fig_dir = args.fig_dir
|
2023-01-09 16:40:32 +01:00
|
|
|
fig_subdir = path.join(fig_dir, 'reconstruction')
|
2023-01-12 14:31:21 +01:00
|
|
|
show_plots = args.show_plots
|
2023-01-09 16:40:32 +01:00
|
|
|
|
|
|
|
####
|
|
|
|
fname_dir = path.dirname(fname)
|
|
|
|
antennas_fname = path.join(fname_dir, beacon.antennas_fname)
|
2023-01-11 18:33:56 +01:00
|
|
|
pickle_fname = path.join(fname_dir, 'res.pkl')
|
2023-01-09 16:40:32 +01:00
|
|
|
|
2023-01-11 02:59:04 +01:00
|
|
|
# create fig_dir
|
|
|
|
if fig_dir:
|
|
|
|
os.makedirs(fig_dir, exist_ok=True)
|
|
|
|
if fig_subdir:
|
|
|
|
os.makedirs(fig_subdir, exist_ok=True)
|
|
|
|
|
2023-01-09 16:40:32 +01:00
|
|
|
# Read in antennas from file
|
|
|
|
_, tx, antennas = beacon.read_beacon_hdf5(antennas_fname)
|
|
|
|
# Read original REvent
|
|
|
|
ev = REvent(fname)
|
|
|
|
# .. patch in our antennas
|
|
|
|
ev.antennas = antennas
|
|
|
|
|
2023-01-11 02:59:04 +01:00
|
|
|
# For now only implement using one freq_name
|
|
|
|
freq_names = antennas[0].beacon_info.keys()
|
|
|
|
if len(freq_names) > 1:
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
freq_name = next(iter(freq_names))
|
|
|
|
f_beacon = ev.antennas[0].beacon_info[freq_name]['freq']
|
|
|
|
|
2023-01-09 16:40:32 +01:00
|
|
|
# Repair clock offsets with the measured offsets
|
2023-01-16 19:42:21 +01:00
|
|
|
measured_repair_offsets = beacon.read_antenna_clock_repair_offsets(ev.antennas, mode='all', freq_name=freq_name)
|
2023-01-09 16:40:32 +01:00
|
|
|
for i, ant in enumerate(ev.antennas):
|
2023-01-16 19:42:21 +01:00
|
|
|
# t_AxB will be set by the rit.set_pol_and_bp function
|
|
|
|
ev.antennas[i].t += measured_repair_offsets[i]
|
2023-01-09 16:40:32 +01:00
|
|
|
|
2023-01-11 02:59:04 +01:00
|
|
|
N_X, Xlow, Xhigh = 23, 100, 1200
|
2023-01-12 13:39:06 +01:00
|
|
|
with joblib.parallel_backend("loky"):
|
|
|
|
res = rit.reconstruction(ev, outfile=fig_subdir+'/fig.pdf', slice_outdir=fig_subdir+'/', Xlow=Xlow, N_X=N_X, Xhigh=Xhigh)
|
2023-01-09 16:40:32 +01:00
|
|
|
|
2023-01-11 02:59:04 +01:00
|
|
|
## Save a pickle
|
|
|
|
with open(pickle_fname, 'wb') as fp:
|
2023-01-09 16:40:32 +01:00
|
|
|
pickle.dump(res,fp)
|
|
|
|
|
2023-01-11 02:59:04 +01:00
|
|
|
if show_plots:
|
2023-01-09 16:40:32 +01:00
|
|
|
plt.show()
|