mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 03:23:34 +01:00
Pulse: Waveform figure: show SNR levels
This commit is contained in:
parent
de92e25b75
commit
4e96342342
1 changed files with 37 additions and 18 deletions
|
@ -235,6 +235,8 @@ def get_time_residuals_for_template(
|
|||
|
||||
true_time_offset = antenna.peak_time - template.peak_time
|
||||
|
||||
antenna.signal_level = np.max(antenna.signal)
|
||||
|
||||
if False: # flip polarisation
|
||||
antenna.signal *= -1
|
||||
|
||||
|
@ -245,26 +247,43 @@ def get_time_residuals_for_template(
|
|||
|
||||
antenna.signal += filtered_noise
|
||||
|
||||
antenna.noise_level = np.sqrt(np.mean(filtered_noise**2))
|
||||
|
||||
antenna.signal_to_noise = antenna.signal_level/antenna.noise_level
|
||||
|
||||
# Show signals
|
||||
if do_plots:
|
||||
fig, axs = plt.subplots(2, sharex=True)
|
||||
if not hasattr(axs, '__len__'):
|
||||
axs = [axs]
|
||||
|
||||
axs[0].set_title("Antenna Waveform")
|
||||
axs[-1].set_xlabel("Time [ns]")
|
||||
axs[0].set_ylabel("Amplitude")
|
||||
axs[0].plot(antenna.t, antenna.signal, label='bandpassed w/ noise', alpha=0.9)
|
||||
axs[0].plot(antenna.t, antenna.signal - filtered_noise, label='bandpassed w/o noise', alpha=0.9)
|
||||
axs[0].legend()
|
||||
l1 = axs[0].plot(antenna.t, antenna.signal, label='Filtered w/ noise', alpha=0.7)
|
||||
l2 = axs[0].plot(antenna.t, antenna.signal - filtered_noise, label='Filtered w/o noise', alpha=0.7)
|
||||
l3 = axs[0].plot(antenna.t, filtered_noise, label='Noise', alpha=0.7)
|
||||
|
||||
axs[1].set_title("Template")
|
||||
axs[1].set_ylabel("Amplitude")
|
||||
axs[1].plot(template.t, template.signal, label='orig')
|
||||
axs[1].plot(template.t + true_time_offset, template.signal, label='true moved orig')
|
||||
axs[1].legend()
|
||||
if True: # indicate signal and noise levels
|
||||
level_kwargs = dict(ls='dashed', alpha=0.4)
|
||||
|
||||
axs[0].axhline(antenna.signal_level, color=l2[0].get_color(), **level_kwargs, label='Signal Level')
|
||||
axs[0].axhline(antenna.noise_level, color=l3[0].get_color(), **level_kwargs, label='Noise Level')
|
||||
|
||||
|
||||
axs[0].legend(title=f'SNR = {antenna.signal_to_noise:.1g}')
|
||||
axs[0].grid()
|
||||
axs[1].grid()
|
||||
|
||||
fig.savefig('figures/11_antenna_signals.pdf')
|
||||
if len(axs) > 1:
|
||||
axs[1].set_title("Template")
|
||||
axs[1].set_ylabel("Amplitude")
|
||||
axs[1].plot(template.t, template.signal, label='orig')
|
||||
axs[1].plot(template.t + true_time_offset, template.signal, label='true moved orig')
|
||||
axs[1].legend()
|
||||
axs[1].grid()
|
||||
|
||||
fig.tight_layout()
|
||||
fig.savefig(f'figures/11_antenna_signals_tdt{template.dt:.1g}.pdf')
|
||||
|
||||
if True: # zoom
|
||||
wx = 100
|
||||
|
@ -272,7 +291,7 @@ def get_time_residuals_for_template(
|
|||
|
||||
old_xlims = axs[0].get_xlim()
|
||||
axs[0].set_xlim( x0-wx, x0+wx)
|
||||
fig.savefig('figures/11_antenna_signals_zoom.pdf')
|
||||
fig.savefig(f'figures/11_antenna_signals_tdt{template.dt:.1g}_zoom.pdf')
|
||||
|
||||
# restore
|
||||
axs[0].set_xlim(*old_xlims)
|
||||
|
@ -294,12 +313,12 @@ def get_time_residuals_for_template(
|
|||
axs2[0].plot(upsampled_t, upsampled_trace, label='upsampled')
|
||||
axs2[0].legend(loc='upper right')
|
||||
|
||||
fig2.savefig('figures/11_upsampled.pdf')
|
||||
fig2.savefig(f'figures/11_upsampled_tdt{template.dt:.1g}.pdf')
|
||||
|
||||
wx = 1e2
|
||||
x0 = upsampled_t[0] + wx - 5
|
||||
axs2[0].set_xlim(x0-wx, x0+wx)
|
||||
fig2.savefig('figures/11_upsampled_zoom.pdf')
|
||||
fig2.savefig(f'figures/11_upsampled_tdt{template.dt:.1g}_zoom.pdf')
|
||||
|
||||
if True:
|
||||
plt.close(fig2)
|
||||
|
@ -345,7 +364,7 @@ def get_time_residuals_for_template(
|
|||
|
||||
offset_list = [
|
||||
[best_time_lag, dict(label=template.name, color='orange')],
|
||||
[true_time_offset, dict(label='True offset', color='green')],
|
||||
[true_time_offset, dict(label='True offset', ls='dashed', color='green')],
|
||||
]
|
||||
|
||||
# Signal
|
||||
|
@ -379,18 +398,18 @@ def get_time_residuals_for_template(
|
|||
|
||||
|
||||
if True: # zoom
|
||||
wx = len(template.signal) * (template.dt)/2
|
||||
t0 = best_time_lag
|
||||
wx = len(template.signal) * (min(1,template.dt))/4
|
||||
t0 = true_time_offset
|
||||
|
||||
old_xlims = axs[0].get_xlim()
|
||||
axs[i].set_xlim( x0-wx, x0+3*wx)
|
||||
fig.savefig('figures/11_corrs_zoom.pdf')
|
||||
fig.savefig(f'figures/11_corrs_tdt{template.dt:.1g}_zoom.pdf')
|
||||
|
||||
# restore
|
||||
axs[i].set_xlim(*old_xlims)
|
||||
|
||||
fig.tight_layout()
|
||||
fig.savefig('figures/11_corrs.pdf')
|
||||
fig.savefig(f'figures/11_corrs_tdt{template.dt:.1g}.pdf')
|
||||
|
||||
if True:
|
||||
plt.close(fig)
|
||||
|
|
Loading…
Reference in a new issue