def reference_psds_for_filename(filename): xmldoc = ligolw_utils.load_filename( filename, contenthandler=lal.series.PSDContentHandler) psds = lal.series.read_psd_xmldoc(xmldoc) return dict( (key, timing.InterpolatedPSD(filter.abscissa(psd), psd.data.data)) for key, psd in psds.iteritems() if psd is not None)
def generate_psd(S): psd = lal.CreateREAL8FrequencySeries(None, lal.LIGOTimeGPS(0), 0, 1 / data_duration, filter.unitInverseHertz, data_length // 2 + 1) psd.data.data = S(filter.abscissa(psd)) return psd
def reference_psds_for_filename(filename): xmldoc = ligolw_utils.load_filename( filename, contenthandler=lal.series.PSDContentHandler) psds = lal.series.read_psd_xmldoc(xmldoc, root_name=None) return { key: timing.InterpolatedPSD(filter.abscissa(psd), psd.data.data, f_high_truncate=opts.f_high_truncate) for key, psd in psds.items() if psd is not None}
def psd(self, freq_min, freq_resolution, length): """ Compute PSD from noise model """ power_spec_density = CreateREAL8FrequencySeries("spectrum", 0.0, freq_min, freq_resolution, DimensionlessUnit, length); # SimNoisePSD(power_spec_density, freq_min, DETECTOR_NOISES[self.name]) data = numpy.loadtxt(DETECTOR_PSD_FILES[self.name],dtype={'names':('freq','psd'), 'formats':('f8','f8')}) model = timing.InterpolatedPSD(data['freq'], data['psd']) power_spec_density.data.data = model(filter.abscissa(power_spec_density)) return power_spec_density
def psd(self, freq_min, freq_resolution, length): """ Compute PSD from noise model """ power_spec_density = CreateREAL8FrequencySeries( "spectrum", 0.0, freq_min, freq_resolution, DimensionlessUnit, length) # SimNoisePSD(power_spec_density, freq_min, DETECTOR_NOISES[self.name]) data = numpy.loadtxt(DETECTOR_PSD_FILES[self.name], dtype={ 'names': ('freq', 'psd'), 'formats': ('f8', 'f8') }) model = timing.InterpolatedPSD(data['freq'], data['psd']) power_spec_density.data.data = model( filter.abscissa(power_spec_density)) return power_spec_density
def reference_psd_for_sngl(sngl): psd = psdseglistdict[sngl.ifo] try: psd = psd[psd.find(sngl.get_end())].psd except ValueError: raise ValueError( 'No PSD found for detector {0} at GPS time {1}'.format( sngl.ifo, sngl.get_end())) flow = psd.file.attrs['low_frequency_cutoff'] df = psd.attrs['delta_f'] kmin = int(flow / df) fseries = lal.CreateREAL8FrequencySeries( 'psd', psd.attrs['epoch'], kmin * df, df, lal.StrainUnit**2 / lal.HertzUnit, len(psd.value) - kmin) fseries.data.data = psd.value[kmin:] / np.square(DYN_RANGE_FAC) return timing.InterpolatedPSD( filter.abscissa(fseries), fseries.data.data, f_high_truncate=opts.f_high_truncate)
# Create a CoincEvent table. coinc_table = lsctables.New(lsctables.CoincTable) out_xmldoc.childNodes[0].appendChild(coinc_table) # Create a CoincInspiral table. coinc_inspiral_table = lsctables.New(lsctables.CoincInspiralTable) out_xmldoc.childNodes[0].appendChild(coinc_inspiral_table) # Read PSD file. progress.update(-1, 'reading ' + opts.reference_psd.name) xmldoc, _ = ligolw_utils.load_fileobj( opts.reference_psd, contenthandler=lal.series.PSDContentHandler) psds = lal.series.read_psd_xmldoc(xmldoc) psds = dict( (key, timing.InterpolatedPSD(filter.abscissa(psd), psd.data.data)) for key, psd in psds.items() if psd is not None) # Detector noise PSD model class psdfunc(object): def __init__(self, func): self.func = func def __call__(self, f): _f = np.atleast_1d(f) ret = np.empty(_f.shape, dtype=float) cond = (5 <= _f) & (_f <= 1800) ret[cond] = self.func(_f[cond]) ret[~cond] = 0. if np.isscalar(f):
[glue.lal.LIGOTimeGPS(0), glue.lal.LIGOTimeGPS(2e9)]) search_summary_table = lsctables.New(lsctables.SearchSummaryTable) out_xmldoc.childNodes[0].appendChild(search_summary_table) summary = ligolw_search_summary.append_search_summary(out_xmldoc, process, inseg=all_time, outseg=all_time) # Read PSDs. progress.update(-1, 'reading ' + opts.reference_psd.name) xmldoc, _ = ligolw_utils.load_fileobj( opts.reference_psd, contenthandler=lal.series.PSDContentHandler) psds = lal.series.read_psd_xmldoc(xmldoc, root_name=None) psds = { key: timing.InterpolatedPSD(filter.abscissa(psd), psd.data.data) for key, psd in psds.items() if psd is not None } # Read injection file. progress.update(-1, 'reading ' + opts.input.name) xmldoc, _ = ligolw_utils.load_fileobj( opts.input, contenthandler=ligolw_bayestar.LSCTablesContentHandler) # Extract simulation table from injection file. sim_inspiral_table = ligolw_table.get_table( xmldoc, lsctables.SimInspiralTable.tableName) # Create a SnglInspiral table and initialize its row ID counter. sngl_inspiral_table = lsctables.New(lsctables.SnglInspiralTable) out_xmldoc.childNodes[0].appendChild(sngl_inspiral_table)
# [2000, 9e-46, 1.4e-44]]) data_adv = numpy.loadtxt("Adv_Virgo_20Mpc_PSD.txt",dtype={'names':('f','psd'), 'formats':('f8','f8')}) data_aligo = numpy.loadtxt("aLIGO_80Mpc_PSD.txt",dtype={'names':('f','psd'), 'formats':('f8','f8')}) data_O1 = numpy.loadtxt("O1-H1-GDS-CALIB_STRAIN.txt",dtype={'names':('f','asd'), 'formats':('f8','f8')}) #filename = "psds_2016-17.xml" filename = "psd.xml" duration = 32 # sec sample_rate = 1024 # Hz xmldoc = ligolw_utils.load_filename( filename, contenthandler=lal.series.PSDContentHandler) input_psds = lal.series.read_psd_xmldoc(xmldoc) psd_models = dict( (key, timing.InterpolatedPSD(filter.abscissa(psd), psd.data.data)) for key, psd in input_psds.iteritems() if psd is not None) for detector, model in psd_models.iteritems(): psd = lal.CreateREAL8FrequencySeries(None, lal.LIGOTimeGPS(0), 0, 1./duration, filter.unitInverseHertz, int((duration * sample_rate) / 2 + 1)) psd.data.data = model(filter.abscissa(psd)) plot.loglog(filter.abscissa(psd), psd.data.data, label=detector) # plot.loglog(data[:,0],data[:,1]) # plot.loglog(data[:,0],data[:,2]) plot.loglog(data_adv['f'],data_adv['psd'], label="V1 from Prospects paper") plot.loglog(data_aligo['f'],data_aligo['psd'], label="H1 and L1 from Prospects paper") plot.loglog(data_O1['f'],data_O1['asd']**2, label="H1 -- O1") plot.legend(loc=1)