mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 03:23:34 +01:00
Pulse: snr plot: indicate masking
This commit is contained in:
parent
279ea46550
commit
fd9119ad89
1 changed files with 88 additions and 52 deletions
|
@ -5,7 +5,7 @@ from lib import util
|
|||
from scipy import signal, interpolate, stats
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from itertools import zip_longest
|
||||
from itertools import zip_longest, pairwise
|
||||
import h5py
|
||||
from copy import deepcopy
|
||||
|
||||
|
@ -232,6 +232,7 @@ if __name__ == "__main__":
|
|||
h5_cache_fname = f'11_pulsed_timing.hdf5'
|
||||
|
||||
time_accuracies = np.zeros(len(snr_factors))
|
||||
mask_counts = np.zeros(len(snr_factors))
|
||||
for k, snr_sigma_factor in tqdm(enumerate(snr_factors)):
|
||||
# Read in cached time residuals
|
||||
if True:
|
||||
|
@ -448,15 +449,37 @@ if __name__ == "__main__":
|
|||
|
||||
# Make a plot of the time residuals
|
||||
if N_residuals > 1:
|
||||
time_accuracies[k] = np.std(time_residuals[:N_residuals])
|
||||
time_residuals = time_residuals[:N_residuals]
|
||||
|
||||
for i in range(1 + cut_wrong_peak_matches):
|
||||
mask_count = 0
|
||||
|
||||
if i==1: # if cut_wrong_peak_matches:
|
||||
wrong_peak_condition = lambda t_res: abs(t_res) > antenna_dt*4
|
||||
|
||||
mask = wrong_peak_condition(time_residuals)
|
||||
|
||||
mask_count = np.count_nonzero(mask)
|
||||
|
||||
print("Masking {} residuals".format(mask_count))
|
||||
time_residuals = time_residuals[~mask]
|
||||
|
||||
if not mask_count:
|
||||
print("Continuing")
|
||||
continue
|
||||
|
||||
time_accuracies[k] = np.std(time_residuals)
|
||||
mask_counts[k] = mask_count
|
||||
|
||||
hist_kwargs = dict(bins='sqrt', density=False, alpha=0.8, histtype='step')
|
||||
fig, ax = plt.subplots()
|
||||
ax.set_title(
|
||||
"Template Correlation Lag finding"
|
||||
+ f"\n template dt: {template_dt*1e3: .1e}ps"
|
||||
+ f"\n template dt: {template_dt: .1e}ns"
|
||||
+ f"; antenna dt: {antenna_dt: .1e}ns"
|
||||
+ f"; noise_factor: {noise_sigma_factor: .1e}"
|
||||
+ ";" if not mask_count else "\n"
|
||||
+ f"snr_factor: {snr_sigma_factor: .1e}"
|
||||
+ "" if not mask_count else f"; N_masked: {mask_count}"
|
||||
)
|
||||
ax.set_xlabel("Time Residual [ns]")
|
||||
ax.set_ylabel("#")
|
||||
|
@ -503,7 +526,10 @@ if __name__ == "__main__":
|
|||
|
||||
ax.text( *(0.02, 0.95), text_str, fontsize=12, ha='left', va='top', transform=ax.transAxes)
|
||||
|
||||
fig.savefig(f"figures/11_time_residual_hist_tdt{template_dt:0.1e}_n{noise_sigma_factor: .1e}.pdf")
|
||||
if mask_count:
|
||||
fig.savefig(f"figures/11_time_residual_hist_tdt{template_dt:0.1e}_n{snr_sigma_factor:.1e}_masked.pdf")
|
||||
else:
|
||||
fig.savefig(f"figures/11_time_residual_hist_tdt{template_dt:0.1e}_n{snr_sigma_factor:.1e}.pdf")
|
||||
|
||||
if True:
|
||||
plt.close(fig)
|
||||
|
@ -526,7 +552,17 @@ if __name__ == "__main__":
|
|||
ax.set_yscale('log')
|
||||
|
||||
# plot the values
|
||||
ax.plot(np.asarray(snr_factors), time_accuracies, ls='none', marker='o')
|
||||
l = None
|
||||
for j, mask_threshold in enumerate(pairwise([np.inf, 250, 50, 1, 0])):
|
||||
kwargs = dict(
|
||||
ls='none',
|
||||
marker=['^', 'v','8', 'o',][j],
|
||||
color=None if l is None else l[0].get_color(),
|
||||
)
|
||||
mask = mask_counts >= mask_threshold[1]
|
||||
mask &= mask_counts < mask_threshold[0]
|
||||
|
||||
l = ax.plot(snr_factors[mask], time_accuracies[mask], **kwargs)
|
||||
|
||||
if True: # limit y-axis to 1e0
|
||||
ax.set_ylim([None, 1e1])
|
||||
|
|
Loading…
Reference in a new issue