Create home/comp_snr_ts authored by Kentaro Mogushi's avatar Kentaro Mogushi
```
# calculate the optimal snr in raw scale
y_inj_pycbc = scaled_projected_wf_dict['L1_y_inj_pycbc']
y_inj_pycbc = scaled_projected_wf_dict['L1_y_inj_pycbc']
snr_ts_pycbc = scaled_projected_wf_dict['L1_snr_ts']
psd = asd.to_pycbc() ** 2
psd = pycbc_interpolate(psd, y_inj_pycbc.delta_f)
opt_snr_inj = pycbc.filter.matchedfilter.sigma(y_inj_pycbc, psd=psd, low_frequency_cutoff=10,
high_frequency_cutoff=1024)
print('optimal SNR of the injection: {:.2f}'.format(opt_snr_inj))
# calculate the optimal snr in whiten scale
whitened_y_inj_pycbc = whitened_scaled_projected_wf_dict['L1_y_inj_pycbc']
whitened_y_inj_pycbc_dummy = whitened_scaled_projected_wf_dict['L1_y_inj_pycbc_dummy']
whitened_gwpy = d_gwpy.whiten(asd=asd, fduration=2, method='median')
asd_whitened = calcualte_asd(whitened_gwpy)
psd_whitened = asd_whitened.to_pycbc() ** 2
psd_whitened = pycbc_interpolate(psd_whitened, y_inj_pycbc.delta_f)
opt_snr_inj = pycbc.filter.matchedfilter.sigma(whitened_y_inj_pycbc, psd=psd_whitened, low_frequency_cutoff=10, high_frequency_cutoff=1024)
print('optimal SNR of the injection: {:.2f}'.format(opt_snr_inj))
snr_timeseries_inj = pycbc.filter.matchedfilter.matched_filter(whitened_y_inj_pycbc_dummy, whitened_y_inj_pycbc, psd=psd_whitened,
low_frequency_cutoff=10,
high_frequency_cutoff=1024)
plt.plot(snr_timeseries_inj.sample_times, np.abs(snr_timeseries_inj.data) , label='whitened scale')
plt.plot(snr_ts_pycbc.sample_times, np.abs(snr_ts_pycbc.data), label='raw scale')
plt.legend()
plt.savefig('test.png')
plt.close()
```
- optimal SNR in whitened space is smaller than the SNR in raw scale by a factor of 2.
![Screen_Shot_2021-03-11_at_12.46.39_PM](uploads/1be82f43e25524fa5081c74e79770a55/Screen_Shot_2021-03-11_at_12.46.39_PM.png)
\ No newline at end of file