ZH: denote Xref in figure names

This commit is contained in:
Eric Teunis de Boone 2023-06-29 11:09:20 +02:00
parent 14ab836a6d
commit f50b5cb308
2 changed files with 15 additions and 14 deletions

View file

@ -187,6 +187,7 @@ if __name__ == "__main__":
from scriptlib import MyArgumentParser from scriptlib import MyArgumentParser
parser = MyArgumentParser(default_fig_dir="./figures/periods_from_shower_figures/") parser = MyArgumentParser(default_fig_dir="./figures/periods_from_shower_figures/")
parser.add_argument('--quick_run', action='store_true', help='Use a very coarse grid (6x6)') parser.add_argument('--quick_run', action='store_true', help='Use a very coarse grid (6x6)')
parser.add_argument('-X', type=int, default=400, help='Atmospheric depth to start the initial grid.')
parser.add_argument('--max-k', type=float, default=2, help='Maximum abs(k) allowed to be shifted. (Default: %(default)d)') parser.add_argument('--max-k', type=float, default=2, help='Maximum abs(k) allowed to be shifted. (Default: %(default)d)')
parser.add_argument('-N', '--N_runs', type=int, default=5, help='Maximum amount of iterations to grid search. (Default: %(default)d)') parser.add_argument('-N', '--N_runs', type=int, default=5, help='Maximum amount of iterations to grid search. (Default: %(default)d)')
@ -211,7 +212,7 @@ if __name__ == "__main__":
max_k = int(args.max_k) max_k = int(args.max_k)
allowed_ks = np.arange(-max_k, max_k+1, dtype=int) allowed_ks = np.arange(-max_k, max_k+1, dtype=int)
Xref = 400 Xref = args.X
N_runs = args.N_runs N_runs = args.N_runs
remove_beacon_from_trace = True remove_beacon_from_trace = True
@ -424,7 +425,7 @@ if __name__ == "__main__":
x /= 4 x /= 4
y /= 4 y /= 4
print(f"Testing grid run {r} centered on ({xoff}, {yoff})") print(f"Testing grid run {r} centered on ({xoff}, {yoff}) at X={Xref}.")
ks_per_loc = np.zeros( (len(x)*len(y), len(ev.antennas)) , dtype=int) ks_per_loc = np.zeros( (len(x)*len(y), len(ev.antennas)) , dtype=int)
maxima_per_loc = np.zeros( (len(x)*len(y))) maxima_per_loc = np.zeros( (len(x)*len(y)))
@ -441,22 +442,21 @@ if __name__ == "__main__":
print(f"Testing location {i} out of {N_loc}") print(f"Testing location {i} out of {N_loc}")
tmp_fig_subdir = fig_subdir tmp_fig_subdir = fig_subdir
test_loc = (x_+xoff)* ev.uAxB + (y_+yoff)*ev.uAxAxB + dXref *ev.uA test_loc = loc[0]* ev.uAxB + loc[1]*ev.uAxAxB + dXref *ev.uA
xx.append(x_+xoff)
yy.append(y_+yoff)
# Find best k for each antenna # Find best k for each antenna
ks_per_loc[i], maxima_per_loc[i] = find_best_period_shifts_summing_at_location(test_loc, ev.antennas, allowed_ks, period=1/f_beacon, dt=dt, ks_per_loc[i], maxima_per_loc[i] = find_best_period_shifts_summing_at_location(test_loc, ev.antennas, allowed_ks, period=1/f_beacon, dt=dt,
plot_iteration_with_shifted_trace=[ 5, len(ev.antennas)-1], plot_iteration_with_shifted_trace=[ 5, len(ev.antennas)-1],
fig_dir=tmp_fig_subdir, fig_distinguish=f"run{r}.", fig_dir=tmp_fig_subdir, fig_distinguish=f"X{Xref}. run{r}.",
snr_str=snr_str,shower_plane_loc=((x_+xoff)/1e3, (y_+yoff)/1e3, dXref)) snr_str=snr_str,shower_plane_loc=(loc[0]/1e3, loc[1]/1e3, dXref),
)
xx = np.array(xx) xx = np.array(xx)
yy = np.array(yy) yy = np.array(yy)
locs = list(zip(xx, yy)) locs = list(zip(xx, yy))
## Save maxima to file ## Save maxima to file
np.savetxt(path.join(fig_dir, path.basename(__file__)+f'.maxima.run{r}.txt'), np.column_stack((locs, maxima_per_loc, ks_per_loc)) ) np.savetxt(path.join(fig_dir, path.basename(__file__)+f'.maxima.X{Xref}.run{r}.txt'), np.column_stack((locs, maxima_per_loc, ks_per_loc)) )
if True: #plot maximum at test locations if True: #plot maximum at test locations
fig, axs = plt.subplots(figsize=figsize) fig, axs = plt.subplots(figsize=figsize)
@ -477,11 +477,11 @@ if __name__ == "__main__":
old_xlims = axs.get_xlim() old_xlims = axs.get_xlim()
old_ylims = axs.get_ylim() old_ylims = axs.get_ylim()
fig.tight_layout() fig.tight_layout()
fig.savefig(path.join(fig_dir, path.basename(__file__)+f'.maxima.run{r}.pdf')) fig.savefig(path.join(fig_dir, path.basename(__file__)+f'.maxima.X{Xref}.run{r}.pdf'))
if False: if False:
axs.plot(tx.x/1e3, tx.y/1e3, marker='X', color='k') axs.plot(tx.x/1e3, tx.y/1e3, marker='X', color='k')
fig.tight_layout() fig.tight_layout()
fig.savefig(path.join(fig_dir, path.basename(__file__)+f'.maxima.run{r}.with_tx.pdf')) fig.savefig(path.join(fig_dir, path.basename(__file__)+f'.maxima.X{Xref}.run{r}.with_tx.pdf'))
axs.set_xlim(*old_xlims) axs.set_xlim(*old_xlims)
axs.set_ylim(*old_ylims) axs.set_ylim(*old_ylims)
fig.tight_layout() fig.tight_layout()
@ -494,7 +494,7 @@ if __name__ == "__main__":
print('Best k:', best_k) print('Best k:', best_k)
## Save best ks to file ## Save best ks to file
np.savetxt(path.join(fig_dir, path.basename(__file__)+f'.bestk.run{r}.txt'), best_k ) np.savetxt(path.join(fig_dir, path.basename(__file__)+f'.bestk.X{Xref}.run{r}.txt'), best_k )
## Do a small reconstruction of the shower for best ks ## Do a small reconstruction of the shower for best ks
if True: if True:
@ -544,7 +544,7 @@ if __name__ == "__main__":
fname_extra = "max_amp" fname_extra = "max_amp"
fig.tight_layout() fig.tight_layout()
fig.savefig(path.join(fig_dir, path.basename(__file__)+f'.reconstruction.run{r}.{fname_extra}.pdf')) fig.savefig(path.join(fig_dir, path.basename(__file__)+f'.reconstruction.X{Xref}.run{r}.{fname_extra}.pdf'))
# Abort if no improvement # Abort if no improvement
if ( r!= 0 and (old_ks_per_loc == ks_per_loc[best_idx]).all() ): if ( r!= 0 and (old_ks_per_loc == ks_per_loc[best_idx]).all() ):

View file

@ -103,6 +103,7 @@ if __name__ == "__main__":
from scriptlib import MyArgumentParser from scriptlib import MyArgumentParser
parser = MyArgumentParser() parser = MyArgumentParser()
parser.add_argument('--input-fname', type=str, default=None, help='Path to mysim.sry, either directory or path. If empty it takes DATA_DIR and appends mysim.sry. (Default: %(default)s)') parser.add_argument('--input-fname', type=str, default=None, help='Path to mysim.sry, either directory or path. If empty it takes DATA_DIR and appends mysim.sry. (Default: %(default)s)')
parser.add_argument('-X', type=int, default=400, help='Atmospheric depth to start the initial grid.')
group = parser.add_argument_group('figures') group = parser.add_argument_group('figures')
for case in valid_cases: for case in valid_cases:
@ -154,9 +155,9 @@ if __name__ == "__main__":
## ##
## Setup grid ## Setup grid
## ##
X = 400 X = args.X
zgr = 0 #not exact zgr = 0 #not exact
dXref = atm.distance_to_slant_depth(np.deg2rad(ev.zenith),750,zgr+ev.core[2]) dXref = atm.distance_to_slant_depth(np.deg2rad(ev.zenith),X,zgr+ev.core[2])
scale2d = dXref*np.tan(np.deg2rad(2.)) scale2d = dXref*np.tan(np.deg2rad(2.))
scale4d = dXref*np.tan(np.deg2rad(4.)) scale4d = dXref*np.tan(np.deg2rad(4.))
scale02d = dXref*np.tan(np.deg2rad(0.2)) scale02d = dXref*np.tan(np.deg2rad(0.2))