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)
from numpy import (random, testing as nptest) from gwpy.table import EventTable from gwpy.timeseries import (TimeSeries, StateVector) from gwpy.spectrogram import Spectrogram from gwpy.segments import (Segment, SegmentList) from gwsumm import (archive, data, globalv, channels, triggers) __author__ = 'Duncan Macleod <*****@*****.**>' TEST_DATA = TimeSeries([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], epoch=100, unit='meter', sample_rate=1, channel='X1:TEST-CHANNEL', name='TEST DATA') TEST_DATA.channel = channels.get_channel(TEST_DATA.channel) # -- utilities ---------------------------------------------------------------- def empty_globalv(): globalv.DATA = type(globalv.DATA)() globalv.SPECTROGRAMS = type(globalv.SPECTROGRAMS)() globalv.SEGMENTS = type(globalv.SEGMENTS)() globalv.TRIGGERS = type(globalv.TRIGGERS)() def create(data, **metadata): SeriesClass = metadata.pop('series_class', TimeSeries) d = SeriesClass(data, **metadata) d.channel = channels.get_channel(d.channel)
from gwpy.table import EventTable from gwpy.timeseries import (TimeSeries, StateVector) from gwpy.spectrogram import Spectrogram from gwpy.segments import (Segment, SegmentList) from .. import (archive, data, globalv, channels, triggers) __author__ = 'Duncan Macleod <*****@*****.**>' TEST_DATA = TimeSeries([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], epoch=100, unit='meter', sample_rate=1, channel='X1:TEST-CHANNEL', name='TEST DATA') TEST_DATA.channel = channels.get_channel(TEST_DATA.channel) # -- utilities ---------------------------------------------------------------- def empty_globalv(): globalv.DATA = type(globalv.DATA)() globalv.SPECTROGRAMS = type(globalv.SPECTROGRAMS)() globalv.SEGMENTS = type(globalv.SEGMENTS)() globalv.TRIGGERS = type(globalv.TRIGGERS)() def create(data, **metadata): SeriesClass = metadata.pop('series_class', TimeSeries) d = SeriesClass(data, **metadata) d.channel = channels.get_channel(d.channel)