def test_fcross_project_strain(self): """ Check consistency of project_strain() against antenna_pattern() """ coords = numpy.array([uniform(0,360), uniform(-90,90)]) psi = math.radians(uniform(0,180)) pt_eq = pb.skymaps.Skypoint(*numpy.radians(coords), COORD_SYS_EQUATORIAL) d = pb.detectors.Detector(random.choice(DETECTORS)) antenna_pat = d.antenna_pattern(pt_eq, time=TIME, psi=psi) hplus = TimeSeries(ZEROS_1_SEC, sample_rate=SAMPLING_RATE).to_lal() hcross = TimeSeries(SIN_1_SEC, sample_rate=SAMPLING_RATE).to_lal() hplus.epoch = lal.LIGOTimeGPS(TIME) hcross.epoch = lal.LIGOTimeGPS(TIME) # Project wave onto detector response = d.project_strain(hplus, hcross, pt_eq, psi) # Generate support timeseries data = TimeSeries(ZEROS_5_SEC, \ sample_rate=SAMPLING_RATE, \ t0=TIME-2, unit=response._unit) # Inject signal into timeseries h = data.inject(response) if antenna_pat[1] > 0: estimated_pat = h.max().to_value() else: estimated_pat = h.min().to_value() print("Exact antenna pattern = {} ; Estimated pattern from amplitude = {}".format(antenna_pat[1], estimated_pat)) self.assertAlmostEqual(antenna_pat[1], estimated_pat, places=2)
def test_delay_project_strain(self): """ Check consistency of project_strain() against time_delay_earth_center() """ coords = numpy.array([uniform(0,360), uniform(-90,90)]) pt_eq = pb.skymaps.Skypoint(*numpy.radians(coords), COORD_SYS_EQUATORIAL) d = pb.detectors.Detector(random.choice(DETECTORS)) delay = d.time_delay_from_earth_center(pt_eq, TIME) hplus = TimeSeries(SIN_1_SEC, sample_rate=SAMPLING_RATE).to_lal() hcross = TimeSeries(ZEROS_1_SEC, sample_rate=SAMPLING_RATE).to_lal() hplus.epoch = lal.LIGOTimeGPS(TIME) hcross.epoch = lal.LIGOTimeGPS(TIME) # Project wave onto detector response = d.project_strain(hplus, hcross, pt_eq, 0) # Generate support timeseries data = TimeSeries(ZEROS_5_SEC, \ sample_rate=SAMPLING_RATE, \ t0=TIME-2, unit=response._unit) # Inject signal into timeseries h = data.inject(response) # Find end of the detector response ix, = numpy.where(numpy.abs(h) > numpy.max(h)/10) time_end = h.t0.value + ix[-1]/SAMPLING_RATE estimated_delay = float(time_end - (TIME+1)) print("Exact delay = {} ; Estimated delay = {}".format(delay, estimated_delay)) # Estimate delay from timeseries self.assertAlmostEqual(delay, estimated_delay, places=3)
def test_save_loudest_tile_features(): # prepare input data channel = GW.channels[0] noise = TimeSeries(numpy.random.normal(loc=1, scale=.5, size=16384 * 68), sample_rate=16384, epoch=-34).zpk([], [0], 1) glitch = TimeSeries(signal.gausspulse(numpy.arange(-1, 1, 1. / 16384), bw=100), sample_rate=16384, epoch=-1) * 1e-4 in_ = noise.inject(glitch) _, _, _, qgram, _, _, _ = core.scan(gps=0, channel=channel, xoft=in_, resample=4096, fftlength=8) # test loudest tiles channel.save_loudest_tile_features(qgram, correlate=glitch) assert channel.Q == numpy.around(qgram.plane.q, 1) assert channel.energy == numpy.around(qgram.peak['energy'], 1) assert channel.snr == numpy.around(qgram.peak['snr'], 1) assert channel.t == numpy.around(qgram.peak['time'], 3) assert channel.f == numpy.around(qgram.peak['frequency'], 1) assert channel.corr == numpy.around(glitch.max().value, 1) assert channel.delay == 0.0 assert channel.stdev == glitch.std().value
def test_save_loudest_tile_features(): # prepare input data channel = GW.channels[0] noise = TimeSeries( numpy.random.normal(loc=1, scale=.5, size=16384 * 68), sample_rate=16384, epoch=-34).zpk([], [0], 1) glitch = TimeSeries( signal.gausspulse(numpy.arange(-1, 1, 1./16384), bw=100), sample_rate=16384, epoch=-1) * 1e-4 in_ = noise.inject(glitch) _, _, _, qgram, _, _, _ = core.scan( gps=0, channel=channel, xoft=in_, resample=4096, fftlength=8) # test loudest tiles channel.save_loudest_tile_features(qgram, correlate=glitch) assert channel.Q == numpy.around(qgram.plane.q, 1) assert channel.energy == numpy.around(qgram.peak['energy'], 1) assert channel.snr == numpy.around(qgram.peak['snr'], 1) assert channel.t == numpy.around(qgram.peak['time'], 3) assert channel.f == numpy.around(qgram.peak['frequency'], 1) assert channel.corr == numpy.around(glitch.max().value, 1) assert channel.delay == 0.0 assert channel.stdev == glitch.std().value
# Then we can download a simulation of the GW150914 signal from GWOSC: from astropy.utils.data import get_readable_fileobj url = ("https://www.gw-openscience.org/s/events/GW150914/P150914/" "fig2-unfiltered-waveform-H.txt") with get_readable_fileobj(url) as f: signal = TimeSeries.read(f, format='txt') signal.t0 = .5 # make sure this intersects with noise time samples # Note, since this simulation cuts off before a certain time, it is # important to taper its ends to zero to avoid ringing artifacts. # We can accomplish this using the # :meth:`~gwpy.timeseries.TimeSeries.taper` method. signal = signal.taper() # Since the time samples overlap, we can inject this into our noise data # using :meth:`~gwpy.types.series.Series.inject`: data = noise.inject(signal) # Finally, we can visualize the full process in the time domain: from gwpy.plot import Plot plot = Plot(noise, signal, data, separate=True, sharex=True, sharey=True) plot.gca().set_epoch(0) plot.show() # We can clearly see that the loud GW150914-like signal has been layered # on top of Gaussian noise with the correct amplitude and phase evolution.
# Then we can download a simulation of the GW150914 signal from LOSC: from astropy.utils.data import get_readable_fileobj source = 'https://losc.ligo.org/s/events/GW150914/P150914/' url = '%s/fig2-unfiltered-waveform-H.txt' % source with get_readable_fileobj(url) as f: signal = TimeSeries.read(f, format='txt') signal.t0 = .5 # make sure this intersects with noise time samples # Note, since this simulation cuts off before a certain time, it is # important to taper its ends to zero to avoid ringing artifacts. # We can accomplish this using the # :meth:`~gwpy.timeseries.TimeSeries.taper` method. signal = signal.taper() # Since the time samples overlap, we can inject this into our noise data # using :meth:`~gwpy.types.series.Series.inject`: data = noise.inject(signal) # Finally, we can visualize the full process in the time domain: from gwpy.plot import Plot plot = Plot(noise, signal, data, separate=True, sharex=True, sharey=True) plot.gca().set_epoch(0) plot.show() # We can clearly see that the loud GW150914-like signal has been layered # on top of Gaussian noise with the correct amplitude and phase evolution.
from .. import (config, core, plot) __author__ = 'Alex Urban <*****@*****.**>' # global test objects FFTLENGTH = 8 NOISE = TimeSeries(numpy.random.normal(loc=1, scale=.5, size=16384 * 68), sample_rate=16384, epoch=-34).zpk([], [0], 1) GLITCH = TimeSeries(signal.gausspulse(numpy.arange(-1, 1, 1. / 16384), bw=100), sample_rate=16384, epoch=-1) * 1e-4 INPUT = NOISE.inject(GLITCH) CONFIGURATION = { 'q-range': '3.3166,150', 'frequency-range': '4.0,Inf', 'plot-time-durations': '4', 'always-plot': 'True', } CHANNEL = config.OmegaChannel(channelname='L1:TEST-STRAIN', section='test', **CONFIGURATION) SERIES = core.scan(gps=0, channel=CHANNEL, xoft=INPUT, resample=2048,
from .. import plot __author__ = 'Alex Urban <*****@*****.**>' # global test objects TWOPI = 2 * numpy.pi TIMES = numpy.arange(0, 16384 * 64) NOISE = TimeSeries( numpy.random.normal(loc=1, scale=.5, size=16384 * 64), sample_rate=16384, epoch=-32).zpk([], [0], 1) FRINGE = TimeSeries( numpy.cos(TWOPI * TIMES), sample_rate=16384, epoch=-32) DATA = NOISE.inject(FRINGE) QSPECGRAM = DATA.q_transform(logf=True) # -- make sure plots run end-to-end ------------------------------------------- def test_spectral_comparison(tmpdir): outdir = str(tmpdir) plot1 = os.path.join(outdir, 'test1.png') plot2 = os.path.join(outdir, 'test2.png') # test plotting plot.spectral_comparison(0, QSPECGRAM, FRINGE, plot1) plot.spectral_overlay(0, QSPECGRAM, FRINGE, plot2) # clean up shutil.rmtree(outdir, ignore_errors=True)