mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 03:23:34 +01:00
ZH: findks:: sum-maxima figure + shower_plane location in titling
This commit is contained in:
parent
82a33bd84c
commit
d0320298c2
1 changed files with 30 additions and 4 deletions
|
@ -20,7 +20,7 @@ import aa_generate_beacon as beacon
|
|||
import lib
|
||||
from lib import rit
|
||||
|
||||
def find_best_period_shifts_summing_at_location(test_loc, antennas, allowed_ks, period=1, dt=None, period_shift_first_trace=0, plot_iteration_with_shifted_trace=None, fig_dir=None, fig_distinguish=None,snr_str=None):
|
||||
def find_best_period_shifts_summing_at_location(test_loc, antennas, allowed_ks, period=1, dt=None, period_shift_first_trace=0, plot_iteration_with_shifted_trace=None, fig_dir=None, fig_distinguish=None,snr_str=None, shower_plane_loc=None):
|
||||
"""
|
||||
Find the best sample_shift for each antenna by summing the antenna traces
|
||||
and seeing how to get the best alignment.
|
||||
|
@ -81,11 +81,21 @@ def find_best_period_shifts_summing_at_location(test_loc, antennas, allowed_ks,
|
|||
# init figure
|
||||
if i in plot_iteration_with_shifted_trace:
|
||||
fig, ax = plt.subplots(figsize=figsize)
|
||||
ax.set_title("Traces at ({:.1g},{:.1g},{:.1g}); i={i}/{tot}".format(*test_loc, i=i, tot=N_ant))
|
||||
if shower_plane_loc is not None:
|
||||
title_location = "s({:.1g},{:.1g},{:.1g})".format(*shower_plane_loc)
|
||||
else:
|
||||
title_location = "({.1g},{:.1g},{:.1g})".format(*test_loc)
|
||||
ax.set_title("Traces at {}; i={i}/{tot}".format(title_location, i=i, tot=N_ant))
|
||||
ax.set_xlabel("Time [ns]")
|
||||
ax.set_ylabel("Amplitude")
|
||||
ax.plot(t_sum, a_sum)
|
||||
|
||||
fig2, ax2 = plt.subplots(figsize=figsize)
|
||||
ax2.set_title("Maxima at {}; i={i}/{tot}".format(title_location, i=i, tot=N_ant))
|
||||
ax2.set_xlabel("$k$th Period")
|
||||
ax2.set_ylabel("Summed Amplitude")
|
||||
ax2.plot(0, np.max(a_sum), marker='*', label='trace_sum', ls='none', ms=20)
|
||||
|
||||
# find the maxima for each period shift k
|
||||
shift_maxima = np.zeros( len(allowed_ks) )
|
||||
for j, k in enumerate(allowed_ks):
|
||||
|
@ -95,6 +105,7 @@ def find_best_period_shifts_summing_at_location(test_loc, antennas, allowed_ks,
|
|||
|
||||
if i in plot_iteration_with_shifted_trace and abs(k) <= 3:
|
||||
ax.plot(t_sum, augmented_a, alpha=0.7, ls='dashed', label=f'{k:g}')
|
||||
ax2.plot(k, shift_maxima[j], marker='o', ls='none', ms=20)
|
||||
|
||||
# transform maximum into best_sample_shift
|
||||
best_idx = np.argmax(shift_maxima)
|
||||
|
@ -105,13 +116,26 @@ def find_best_period_shifts_summing_at_location(test_loc, antennas, allowed_ks,
|
|||
|
||||
# cleanup figure
|
||||
if i in plot_iteration_with_shifted_trace:
|
||||
# plot the traces
|
||||
if True: # plot best k again
|
||||
ax.plot(t_sum, best_augmented_a, alpha=0.8, label=f'best $k$={best_period_shifts[i]:g}', lw=2)
|
||||
|
||||
if True: # plot best shift
|
||||
ax2.plot(allowed_ks[best_idx], shift_maxima[best_idx], marker='*', ls='none', ms=20, label=f'best $k$={best_period_shifts[i]:g}')
|
||||
|
||||
|
||||
ax.legend(title='period shift $k$; '+snr_str, ncol=5 )
|
||||
ax2.legend(title=snr_str)
|
||||
if fig_dir:
|
||||
fig.tight_layout()
|
||||
fname = path.join(fig_dir, path.basename(__file__) + f'.{fig_distinguish}i{i}' + '.loc{:.1f}-{:.1f}-{:.1f}'.format(*test_loc))
|
||||
fig2.tight_layout()
|
||||
|
||||
if shower_plane_loc is not None:
|
||||
fname_location = '.sloc{:.1g}-{:.1g}-{:.1g}'.format(*shower_plane_loc)
|
||||
else:
|
||||
fname_location = '.loc{:.1f}-{:.1f}-{:.1f}'.format(*test_loc)
|
||||
|
||||
fname = path.join(fig_dir, path.basename(__file__) + f'.{fig_distinguish}i{i}' + fname_location)
|
||||
if True:
|
||||
old_xlim = ax.get_xlim()
|
||||
|
||||
|
@ -130,7 +154,9 @@ def find_best_period_shifts_summing_at_location(test_loc, antennas, allowed_ks,
|
|||
ax.set_xlim(*old_xlim)
|
||||
|
||||
fig.savefig(fname + ".pdf")
|
||||
fig2.savefig(fname + ".maxima.pdf")
|
||||
plt.close(fig)
|
||||
plt.close(fig2)
|
||||
|
||||
# sort by antenna (undo sorting by maximum)
|
||||
undo_sort_idx = np.argsort(sort_idx)
|
||||
|
@ -413,7 +439,7 @@ if __name__ == "__main__":
|
|||
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],
|
||||
fig_dir=tmp_fig_subdir, fig_distinguish=f"run{r}.",
|
||||
snr_str=snr_str)
|
||||
snr_str=snr_str,shower_plane_loc=((x_+xoff)/1e3, (y_+yoff)/1e3, dXref))
|
||||
|
||||
xx = np.array(xx)
|
||||
yy = np.array(yy)
|
||||
|
|
Loading…
Reference in a new issue