Pulse: snr plot: indicate masking

This commit is contained in:
Eric Teunis de Boone 2023-04-26 14:51:01 +02:00
parent 279ea46550
commit fd9119ad89

View file

@ -5,7 +5,7 @@ from lib import util
from scipy import signal, interpolate, stats from scipy import signal, interpolate, stats
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from itertools import zip_longest from itertools import zip_longest, pairwise
import h5py import h5py
from copy import deepcopy from copy import deepcopy
@ -232,6 +232,7 @@ if __name__ == "__main__":
h5_cache_fname = f'11_pulsed_timing.hdf5' h5_cache_fname = f'11_pulsed_timing.hdf5'
time_accuracies = np.zeros(len(snr_factors)) time_accuracies = np.zeros(len(snr_factors))
mask_counts = np.zeros(len(snr_factors))
for k, snr_sigma_factor in tqdm(enumerate(snr_factors)): for k, snr_sigma_factor in tqdm(enumerate(snr_factors)):
# Read in cached time residuals # Read in cached time residuals
if True: if True:
@ -448,15 +449,37 @@ if __name__ == "__main__":
# Make a plot of the time residuals # Make a plot of the time residuals
if N_residuals > 1: 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') hist_kwargs = dict(bins='sqrt', density=False, alpha=0.8, histtype='step')
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.set_title( ax.set_title(
"Template Correlation Lag finding" "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"; 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_xlabel("Time Residual [ns]")
ax.set_ylabel("#") 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) 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: if True:
plt.close(fig) plt.close(fig)
@ -526,7 +552,17 @@ if __name__ == "__main__":
ax.set_yscale('log') ax.set_yscale('log')
# plot the values # 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 if True: # limit y-axis to 1e0
ax.set_ylim([None, 1e1]) ax.set_ylim([None, 1e1])