def compute(self, raw: TimeSeries) -> TimeSeriesDict: out = TimeSeriesDict() times = unique([60 * (t.value // 60) for t in raw.times]) raw.name = raw.name + '.mean' out[raw.name] = TimeSeries( [raw.crop(t - 60, t).mean().value for t in times[1:]], times=times) out[raw.name].__metadata_finalize__(raw) return out
def test_read_frame_file(self): start_time = 0 end_time = 10 channel = "H1:GDS-CALIB_STRAIN" N = 100 times = np.linspace(start_time, end_time, N) data = np.random.normal(0, 1, N) ts = TimeSeries(data=data, times=times, t0=0) ts.channel = Channel(channel) ts.name = channel filename = os.path.join(self.outdir, "test.gwf") ts.write(filename, format="gwf") # Check reading without time limits strain = gwutils.read_frame_file( filename, start_time=None, end_time=None, channel=channel ) self.assertEqual(strain.channel.name, channel) self.assertTrue(np.all(strain.value == data[:-1])) # Check reading with time limits start_cut = 2 end_cut = 8 strain = gwutils.read_frame_file( filename, start_time=start_cut, end_time=end_cut, channel=channel ) idxs = (times > start_cut) & (times < end_cut) # Dropping the last element - for some reason gwpy drops the last element when reading in data self.assertTrue(np.all(strain.value == data[idxs][:-1])) # Check reading with unknown channels strain = gwutils.read_frame_file(filename, start_time=None, end_time=None) self.assertTrue(np.all(strain.value == data[:-1])) # Check reading with incorrect channel strain = gwutils.read_frame_file( filename, start_time=None, end_time=None, channel="WRONG" ) self.assertTrue(np.all(strain.value == data[:-1])) ts = TimeSeries(data=data, times=times, t0=0) ts.name = "NOT-A-KNOWN-CHANNEL" ts.write(filename, format="gwf") strain = gwutils.read_frame_file(filename, start_time=None, end_time=None) self.assertEqual(strain, None)
def _get_tf_path(self, approximant='SEOBNRv4_opt', sample_rate=4096 * 4): """ Get frequency track of an event based on GraceDb parameters. Parameters ---------- approximant : str, optional f_lower : int, optional sample_rate : int, optional Returns ------- tf_path : gwpy.timeseries.TimeSeries object Time series of frequency. """ if not all( hasattr(self, x) for x in ['graceid', 'm1', 'm2', 's1z', 's2z', 'start_time', 'end_time']): return None hp, hc = get_td_waveform(approximant='SEOBNRv4_opt', mass1=self.m1, mass2=self.m2, spin1z=self.s1z, spin2z=self.s2z, delta_t=1.0 / sample_rate, f_lower=30, frame_axis=SIM_INSPIRAL_FRAME_AXIS_ORBITAL_L) foft = frequency_from_polarizations(hp, hc) try: foft = utils.trim_foft(foft) except: pass tf_path = TimeSeries(foft, t0=self.end_time + float(foft.start_time), dt=foft.delta_t) tf_path = tf_path.crop(self.start_time, self.end_time) tf_path.name = self.graceid + '_path' return tf_path
def compute(self, raw: TimeSeries) -> TimeSeriesDict: out = TimeSeriesDict() if self.channel.endswith(',m-trend'): raw.name = raw.name.replace(',m-trend', '') out[raw.name] = raw return out