Skip to content
Snippets Groups Projects
Commit 3e1ae2a1 authored by ChiWai Chan's avatar ChiWai Chan
Browse files

svd_bank_snr.py & gstlal_inspiral_calc_snr:

Fixing sanity checking & remove unuse option
parent 79fe4e13
No related branches found
No related tags found
No related merge requests found
Pipeline #70877 passed with warnings
......@@ -119,7 +119,6 @@ def parse_command_line():
group.add_option("--row-number", type = "int", help = "The row number of the template (optional). All the SNRs will be outputed if it is not given.")
group.add_option("--table", metavar = "filename", help = "A LIGO light-weight xml.gz file containing SnglInspiral Table. Expecting one template for each instrument only.")
group.add_option("--approximant", metavar = "name", type = "str", help = "Name of the Waveform model (require).")
group.add_option("--template-duration", metavar = "seconds", type = "float", help = "Duration of the template")
group.add_option("--sample-rate", metavar = "Hz", default = 2048, type = "int", help = "Sampling rate of the template and SNR for mode 1")
group.add_option("--f-low", metavar = "Hz", default = 10, type = "float", help = "The minimum frequency of GW signal")
group.add_option("--f-high", metavar = "Hz", type = "float", help = "The maximum frequency of GW signal")
......@@ -147,18 +146,22 @@ def parse_command_line():
options, args = parser.parse_args()
# Check SNR series output
if options.start is None or options.end is None:
raise ValueError("Must have --start and --end.")
else:
if options.start >= options.end:
raise ValueError("--start must less than --end.")
# Setting up GW data
gw_data_source_info = datasource.GWDataSourceInfo(options)
if options.instrument not in gw_data_source_info.channel_dict.keys():
raise ValueError("No such instrument: %s in GWDataSourceInfo: (%s)"% (options.instrument, ", ".join(gw_data_source_info.channel_dict.keys())))
# Check SNRs series output
if options.start is None or options.end is None:
raise ValueError("Must have --start and --end.")
elif options.start >= options.end:
raise ValueError("--start must less than --end.")
# Extra handle for SNRs output because SNRs are not stable initially and have padding at the end
# FIXME: the 650s is hardcoded (~BNS waveforms duration) and only used as a lower bound to avoid having a frame file that is too short
if options.start - gw_data_source_info.seg[0] <= 650 or gw_data_source_info.seg[1] - options.end <= 650:
raise ValueError("Check your inputted --start / --end or your frame file. You should have a long enough data such that, the --start/--end is larger/less than the start/end of your data at least 650s. ")
# Setting up PSD
if options.reference_psd:
psd = lal.series.read_psd_xmldoc(ligolw_utils.load_url(options.reference_psd, contenthandler = lal.series.PSDContentHandler))
......
......@@ -55,6 +55,8 @@ class SNR_Pipeline(object):
"deltaT": None,
"data": [],
}
if self.start >= self.end:
raise ValueError("Start time must be less than end time.")
def run(self, segments):
if self.verbose:
......@@ -101,27 +103,18 @@ class SNR_Pipeline(object):
return tseries
def get_snr_series(self, COMPLEX = False):
assert snr_info["epoch"] is not None, "No SNRs are obtained, check your start time."
gps_start = self.snr_info["epoch"].gpsSeconds + self.snr_info["epoch"].gpsNanoSeconds * 10.**-9
gps = gps_start + numpy.arange(len(self.snr_info["data"])) * self.snr_info["deltaT"]
if self.start and self.end:
if self.start >= self.end:
raise ValueError("Start time must be less than end time.")
if self.start - gps[0] >= 0 and self.start - gps[-1] <= 0:
s = abs(gps - self.start).argmin()
else:
raise ValueError("Invalid choice of start time %f." % self.start)
if self.end - gps[0] >= 0 and self.end - gps[-1] <= 0:
e = abs(gps - self.end).argmin()
else:
raise ValueError("Invalid choice of end time %f." % self.end)
if self.start - gps[0] < 0 or self.end - gps[-1] > 0:
raise ValueError("Invalid choice of start time or end time. The data spans from %f to %f." % (gps[0], gps[-1]))
else:
s = abs(gps - self.start).argmin()
e = abs(gps - self.end).argmin()
self.snr_info["epoch"] = gps[s]
self.snr_info["data"] = self.snr_info["data"][s:e].T
else:
self.snr_info["epoch"] = gps[0]
self.snr_info["data"] = self.snr_info["data"].T
self.snr_info["epoch"] = gps[s]
self.snr_info["data"] = self.snr_info["data"][s:e].T
if self.row_number is None:
temp = []
......@@ -185,11 +178,6 @@ class LLOID_SNR(SNR_Pipeline):
SNR_Pipeline.__init__(self, row_number, start, end, name = "gstlal_inspiral_lloid_snr", verbose = verbose)
self.snr_info["instrument"] = instrument
# sanity check
if psd is not None:
if not (instrument in set(psd)):
raise ValueError("No psd for instrument %s." % instrument)
if self.verbose:
sys.stderr.write("Building pipeline to calculate SNR...\n")
......@@ -241,11 +229,6 @@ class FIR_SNR(SNR_Pipeline):
SNR_Pipeline.__init__(self, 0, start, end, name = "gstlal_inspiral_fir_snr", verbose = verbose)
self.snr_info["instrument"] = instrument
# sanity check
if psd is not None:
if not (instrument in set(psd)):
raise ValueError("No psd for instrument %s." % instrument)
if self.verbose:
sys.stderr.write("Building pipeline to calculate SNR\n")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment