def test_save_figure(tmpdir): base = str(tmpdir) series = TimeSeries(numpy.random.normal(loc=0, scale=1, size=24*60), sample_rate=60, unit='Mpc', name='X1:TEST') fig = series.plot() tsplot = plot.save_figure(fig, os.path.join(base, 'test.png')) assert tsplot == os.path.join(base, 'test.png') # no-directory should raise warning with pytest.warns(UserWarning) as record: noneplot = plot.save_figure(fig, os.path.join('tgpflk', 'test.png')) assert noneplot is None assert len(record.list) == 1 assert 'Error saving' in str(record.list[0].message) # remove base directory shutil.rmtree(base, ignore_errors=True)
h1spec = h1.spectrogram(30, fftlength=4) l1spec = l1.spectrogram(30, fftlength=4) # To calculate the inspiral range variation, we need to create a # :class:`~gwpy.timeseries.TimeSeries` in which to store the values, then # loop over each PSD bin in the spectrogram, calculating the # :func:`gwpy.astro.inspiral_range` for each one: import numpy from gwpy.astro import inspiral_range h1range = TimeSeries(numpy.zeros(len(h1spec)), dt=h1spec.dt, t0=h1spec.t0, unit='Mpc') l1range = h1range.copy() for i in range(h1range.size): h1range[i] = inspiral_range(h1spec[i], fmin=10) l1range[i] = inspiral_range(l1spec[i], fmin=10) # We can now easily plot the timeseries to see the variation in LIGO # sensitivity over the hour or so including GW150914: plot = h1range.plot(label='LIGO-Hanford', color='gwpy:ligo-hanford', figsize=(12, 5)) ax = plot.gca() ax.plot(l1range, label='LIGO-Livingston', color='gwpy:ligo-livingston') ax.set_ylabel('Angle-averaged sensitive distance [Mpc]') ax.set_title('LIGO sensitivity to BNS around GW150914') ax.set_epoch(1126259462) # <- set 0 on plot to GW150914 ax.legend() plot.show()
I would like to study the gravitational wave strain time-series around the time of an interesting simulated signal during the last science run (S6). These data are public, so we can load them directly from the web. """ __author__ = "Duncan Macleod <*****@*****.**>" __currentmodule__ = 'gwpy.timeseries' # First: import everything we need (and nothing we don't need) from urllib2 import urlopen from numpy import asarray from gwpy.timeseries import TimeSeries # Next, download the data as a string of text data = urlopen( 'http://www.ligo.org/science/GW100916/L-strain_hp30-968654552-10.txt' ).read() # We can now parse the text as a list of floats, and generate a `TimeSeries` # by supplying the necessary metadata ts = TimeSeries(asarray(data.splitlines(), dtype=float), epoch=968654552, sample_rate=16384, unit='strain') # Finally, we can make a plot: plot = ts.plot() plot.set_title('LIGO Livingston Observatory data for GW100916') plot.set_ylabel('Gravitational-wave strain amplitude') plot.show()
from urllib2 import urlopen from numpy import asarray from gwpy.timeseries import TimeSeries data = urlopen('http://www.ligo.org/science/GW100916/' 'L-strain_hp30-968654552-10.txt').read() ts = TimeSeries(asarray(data.splitlines(), dtype=float), epoch=968654552, sample_rate=16384) plot = ts.plot() plot.set_ylabel('Gravitational-wave strain amplitude') plot.set_title('LIGO Livingston Observatory data for GW100916') plot.show()
l1spec = l1.spectrogram(30, fftlength=4) # To calculate the inspiral range variation, we need to create a # :class:`~gwpy.timeseries.TimeSeries` in which to store the values, then # loop over each PSD bin in the spectrogram, calculating the # :func:`gwpy.astro.inspiral_range` for each one: import numpy from gwpy.astro import inspiral_range h1range = TimeSeries(numpy.zeros(len(h1spec)), dt=h1spec.dt, t0=h1spec.t0, unit='Mpc') l1range = h1range.copy() for i in range(h1range.size): h1range[i] = inspiral_range(h1spec[i], fmin=10) l1range[i] = inspiral_range(l1spec[i], fmin=10) # We can now easily plot the timeseries to see the variation in LIGO # sensitivity over the hour or so including GW150914: from gwpy.plotter.colors import GW_OBSERVATORY_COLORS as GWO_COLORS plot = h1range.plot(label='LIGO-Hanford', color=GWO_COLORS['H1']) ax = plot.gca() ax.plot(l1range, label='LIGO-Livingston', color=GWO_COLORS['L1']) ax.set_ylabel('Angle-averaged sensitive distance [Mpc]') ax.set_title('LIGO sensitivity to BNS around GW150914') ax.set_epoch(1126259462) # <- set 0 on plot to GW150914 ax.legend() plot.show()
from gwpy.timeseries import TimeSeries # To create an array of random numbers, sampled at 100 Hz, in units of # 'metres': from numpy import random series = TimeSeries(random.random(1000), sample_rate=100, unit='m') # which can then be simply visualised via plot = series.plot() plot.show()
h1spec = h1.spectrogram(30, fftlength=4) l1spec = l1.spectrogram(30, fftlength=4) # To calculate the inspiral range variation, we need to create a # :class:`~gwpy.timeseries.TimeSeries` in which to store the values, then # loop over each PSD bin in the spectrogram, calculating the # :func:`gwpy.astro.inspiral_range` for each one: import numpy from gwpy.astro import inspiral_range h1range = TimeSeries(numpy.zeros(len(h1spec)), dt=h1spec.dt, t0=h1spec.t0, unit='Mpc') l1range = h1range.copy() for i in range(h1range.size): h1range[i] = inspiral_range(h1spec[i], fmin=10) l1range[i] = inspiral_range(l1spec[i], fmin=10) # We can now easily plot the timeseries to see the variation in LIGO # sensitivity over the hour or so including GW150914: from gwpy.plotter.colors import GW_OBSERVATORY_COLORS as GWO_COLORS plot = h1range.plot(label='LIGO-Hanford', color=GWO_COLORS['H1']) ax = plot.gca() ax.plot(l1range, label='LIGO-Livingston', color=GWO_COLORS['L1']) ax.set_ylabel('Angle-averaged sensitive distance [Mpc]') ax.set_title('LIGO sensitivity to BNS around GW150914') ax.set_epoch(1126259462) # <- set 0 on plot to GW150914 ax.legend() plot.show()
list(map("%s:%s".__mod__, front_end_channel_list), start=start, end=end)) if plot_additional_hoft: additional_hoft_data = TimeSeriesDict.read( options.additional_hoft_frames_cache, list(map("%s:%s".__mod__, additional_channel_list)), start=start, end=end) print(map("%s:%s".__mod__, front_end_channel_list)) segs = DataQualityFlag.query('%s:DMT-CALIBRATED:1' % ifo, start, end) for n, channel in enumerate(channels): plot = TimeSeries.plot(data["%s:%s" % (ifo, channel)]) ax = plot.gca() if plot_front_end: ax.plot(front_end_data["%s:%s" % (ifo, front_end_channels[n])]) if plot_additional_hoft: ax.plot(additional_hoft_data["%s:%s" % (ifo, additional_channels[n])]) ax.set_ylabel('Correction value') plot.gca().legend() #title = item #title = title.replace('_', '\_') ax.set_title(channel.replace('_', '\_')) if 'F_S_SQUARED' in channel: ax.set_ylim(-100, 100) elif 'SRC_Q_INVERSE' in channel: ax.set_ylim(-2, 2) #plot.add_state_segments(segs, plotargs=dict(label='Calibrated'))