示例#1
0
def plot_ts(ts, fname="ts.png"):
    plot = TimeSeriesPlot()
    ax = plot.gca()
    ax.plot(TimeSeries(ts, sample_rate=1.0 / ts.delta_t, epoch=ts.start_time))
    ax.set_xlim(ts.start_time, ts.end_time)
    pyplot.savefig(fname, dpi=300)
    pyplot.close()
示例#2
0
文件: plots.py 项目: Yuzhe98/Yu0702
def plot_ts(ts, fname="ts.png"):
    '''
    Plot time series data
    '''
    plot = TimeSeriesPlot()
    ax = plot.gca()
    ax.plot(TimeSeries(ts, sample_rate=1.0 / ts.delta_t, epoch=ts.start_time))
    ax.set_xlim(ts.start_time, ts.end_time)
    plt.savefig(fname, transparent=True)
    plt.close()
def plot_ts(ts, fname="ts.png"):
    import matplotlib
    matplotlib.use("agg")
    from matplotlib import pyplot

    from gwpy.plotter import TimeSeriesPlot
    from gwpy.timeseries import TimeSeries
    plot = TimeSeriesPlot()
    ax = plot.gca()
    ax.plot(TimeSeries(ts, sample_rate=1.0/ts.delta_t, epoch=ts.start_time))
    pyplot.savefig(fname)
    pyplot.close()
示例#4
0
 def plot_line_chart(self, label, users, userID=None):
     plot = TimeSeriesPlot()
     for user, classifications in self.items():
         if user in users:
             matrices = []
             for cid in sorted(classifications.keys()):
                 matrices.append(classifications[cid])
                 timeseries_confusion_matrix = TimeSeries(
                     numpy.vstack(matrices)[:, label])
                 plot.add_timeseries(timeseries_confusion_matrix)
         else:
             continue
     return plot
示例#5
0
文件: plots.py 项目: Yuzhe98/Yu0702
def plot_tiles_ts(tdb, ndof, df, sample_rate, t0, t1, fname="tiles.png"):
    '''
    Plot time series for several channels
    '''
    fig = TimeSeriesPlot(figsize=(12, 12))
    fig.suptitle('%i channels, %i Hz bandwidth, %i DOF' % (len(tdb), df, ndof))
    plt.subplots_adjust(left=0.03,
                        right=0.97,
                        bottom=0.07,
                        top=0.95,
                        hspace=0,
                        wspace=0)
    for i, tdf in enumerate(tdb):
        ts_data = TimeSeries(tdf, epoch=float(t0), sample_rate=sample_rate)
        ax = fig.add_subplot(len(tdb), 1, len(tdb) - i)
        ax.plot(ts_data)
        ax.set_xlim(t0, t1)
        if i > 0:
            ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)
    plt.savefig(fname, transparent=True)
    plt.close()
示例#6
0
文件: plots.py 项目: Yuzhe98/Yu0702
def plot_time_series(data,
                     station='station-name',
                     t0=None,
                     t1=None,
                     seglist=None,
                     burst=None,
                     fname='time_series'):
    """
    Generate a plot of the whole data time series
    """
    if type(data[0]) == numpy.float64:
        data = [
            TimeSeries(data,
                       sample_rate=data.sample_rate,
                       epoch=data.start_time)
        ]
    plot = TimeSeriesPlot(frameon=False)
    ax = plot.gca()
    # Loop over all the time series
    for ts in data:
        # Plot time series for each segment
        ax.plot(ts)
    # Display title
    ax.set_title('$\mathrm{' + station + '}$')
    ax.set_ylabel('Magnetic Field')
    # Plot fake signal
    if burst is not None:
        ax.plot(burst, color='red')
    # Plot activity segments
    if seglist != None:
        activity = SegmentList(seglist[station].active)
        plotargs = {
            'label': 'data present',
            'facecolor': 'g',
            'edgecolor': 'k'
        }
        plot.add_state_segments(activity, plotargs=plotargs)
    # Set limits
    if t0 is not None and t1 is not None:
        plot.axes[0].set_epoch(t0)
        plot.axes[1].set_epoch(t0)
        ax.set_xlim(t0, t1)
    # Fix exceeded cell block limit error
    plt.rcParams['agg.path.chunksize'] = 20000
    # Save figure
    plt.show() if fname == None else plot.savefig('%s.png' % fname)
    plt.close()
示例#7
0
def plot_time_series(station,
                     ts_list,
                     start_time,
                     end_time,
                     seglist=None,
                     hp=None):
    """
    Generate a plot of the whole data time series
    """
    plot = TimeSeriesPlot()
    ax = plot.gca()
    # Loop over all the time series
    for ts in ts_list:
        # Plot time series for each segment
        ax.plot(ts, color='black')
    # Display title
    ax.set_title('$\mathrm{' + station + '}$')
    # Plot fake signal
    if hp != None:
        ax.plot(hp, color='red')
    # Plot activity segments
    if seglist != None:
        plot.add_state_segments(SegmentList(seglist[station].active),
                                plotargs={
                                    'label': 'data present',
                                    'facecolor': 'g',
                                    'edgecolor': 'k'
                                })
    # Set limits
    plot.axes[0].set_epoch(start_time)
    plot.axes[1].set_epoch(start_time)
    ax.set_xlim(start_time, end_time)
    # Fix exceeded cell block limit error
    matplotlib.pyplot.rcParams['agg.path.chunksize'] = 20000
    # Save figure
    plot.savefig('time_series.png', dpi=300)
示例#8
0
from gwpy.plotter import TimeSeriesPlot
plot = TimeSeriesPlot(l1hoft, h1hoft)
plot.show()
示例#9
0
文件: gw150914.py 项目: Phatom/gwpy
b = data.filter(zpk, filtfilt=True)

# .. note::
#
#    The :mod:`~gwpy.signal.filter_design` methods return digital filters
#    by default, so we apply them using `TimeSeries.filter`. If we had
#    analogue filters (perhaps by passing `analog=True` to the filter design
#    method), the easiest application would be `TimeSeries.zpk`

# Finally, we can :meth:`~TimeSeries.plot` the original and filtered data,
# adding some code to prettify the figure:

from gwpy.plotter import TimeSeriesPlot
plot = TimeSeriesPlot(data.crop(*data.span.contract(1)),
                      b.crop(*b.span.contract(1)),
                      figsize=[12, 8],
                      sep=True,
                      sharex=True,
                      color='gwpy:ligo-hanford')
plot.axes[0].set_title('LIGO-Hanford strain data around GW150914')
plot.axes[0].text(1.0,
                  1.0,
                  'Unfiltered data',
                  transform=plot.axes[0].transAxes,
                  ha='right')
plot.axes[0].set_ylabel('Amplitude [strain]', y=-0.2)
plot.axes[1].text(1.0,
                  1.0,
                  '50-250\,Hz bandpass, notches at 60, 120, 180 Hz',
                  transform=plot.axes[1].transAxes,
                  ha='right')
plot.show()
示例#10
0
# To see the effect of the Planck-taper window, we can taper a
# sinusoidal `TimeSeries` at both ends:

import numpy
from gwpy.timeseries import TimeSeries
t = numpy.linspace(0, 1, 2048)
series = TimeSeries(numpy.cos(10.5 * numpy.pi * t), times=t)
tapered = series.taper()

# We can plot it to see how the ends now vary smoothly from 0 to 1:

from gwpy.plotter import TimeSeriesPlot
plot = TimeSeriesPlot(series, tapered, sep=True, sharex=True)
plot.show()
示例#11
0
from gwpy.timeseries import TimeSeries
from gwpy.plotter import TimeSeriesPlot
h1 = TimeSeries.fetch_open_data('H1', 1126259457, 1126259467)
h1b = h1.bandpass(50, 250).notch(60).notch(120)
l1 = TimeSeries.fetch_open_data('L1', 1126259457, 1126259467)
l1b = l1.bandpass(50, 250).notch(60).notch(120)
plot = TimeSeriesPlot()
ax = plot.gca()
ax.plot(h1b, color='gwpy:ligo-hanford', label='LIGO-Hanford')
ax.plot(l1b, color='gwpy:ligo-livingston', label='LIGO-Livingston')
ax.set_epoch(1126259462.427)
ax.set_xlim(1126259462, 1126259462.6)
ax.set_ylim(-1e-21, 1e-21)
ax.set_ylabel('Strain noise')
ax.legend()
plot.show()
示例#12
0
]

# At last we can :meth:`~TimeSeriesDict.get` 12 hours of data for each
# interferometer:
lho = TimeSeriesDict.get([c % 'H1' for c in channels],
                         'Feb 13 2015 16:00',
                         'Feb 14 2015 04:00',
                         verbose=True)
llo = TimeSeriesDict.get([c % 'L1' for c in channels],
                         'Feb 13 2015 16:00',
                         'Feb 14 2015 04:00',
                         verbose=True)

# Next we can plot the data, with a separate `~gwpy.plotter.Axes` for each
# instrument:
plot = TimeSeriesPlot(lho, llo)
for ifo, ax in zip(['H1', 'L1'], plot.axes):
    ax.legend(['X', 'Y', 'Z'])
    ax.yaxis.set_label_position('right')
    ax.set_ylabel(ifo, rotation=0, va='center', ha='left')
    ax.set_yscale('log')
plot.text(0.1,
          0.5,
          '$1-3$\,Hz motion [nm/s]',
          rotation=90,
          fontsize=24,
          ha='center',
          va='center')
plot.axes[0].set_title('Magnitude 7.1 earthquake impact on LIGO', fontsize=24)
plot.show()
示例#13
0
data2 = TimeSeries.fetch('L1:LDAS-STRAIN', 968654552, 968654562)
from gwpy.plotter import TimeSeriesPlot
plot2 = TimeSeriesPlot()
ax2 = plot2.gca()
ax2.plot(data, color='k', linestyle='--')
ax2.plot(data2, color='r', linestyle=':')
plot2.show()
示例#14
0
from matplotlib.ticker import MultipleLocator, FormatStrFormatter

start = Time('2014-11-27 21:00:00', format='iso', scale='utc')
end = Time('2014-12-01 21:00:00', format='iso', scale='utc')
print start.iso, start.gps
print end.iso, end.gps

SR2 = TimeSeries.fetch('L1:SUS-SR2_M1_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True)
SR3 = TimeSeries.fetch('L1:SUS-SR3_M1_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True)
SRM = TimeSeries.fetch('L1:SUS-SRM_M1_DAMP_V_IN1_DQ.mean,m-trend', start, end, verbose=True)
TCS_HAM4 = TimeSeries.fetch('L1:TCS-ITMY_HWS_CHAMBERTEMPERATURESENSORA.mean,m-trend', start, end, verbose=True)
TCS_HAM5 = TimeSeries.fetch('L1:TCS-ITMX_HWS_CHAMBERTEMPERATURESENSORA.mean,m-trend', start, end, verbose=True)

print 'data fetched'

plot_HAM4 = TimeSeriesPlot(TCS_HAM4, SR2, sep=True)
ax1 = plot_HAM4.axes[0]  #plot TCS_HAM4
ax1.plot(TCS_HAM5, label='L1:TCS-ITMX\_HWS\_CHAMBERTEMPERATURESENSORA.mean') #plot TCS_HAM5
#ax1.lines[0].set_color('red')
ax1.set_ylim(18,18.6)
ax1.set_ylabel('C')
ax1.set_title('(HWS) Temperature vs. SRC (4 days)')
ax1.legend(loc='upper right',  ncol=1, fancybox=True, shadow=True) 
ax1.grid(True, which='both', axis='both') # add more grid   
#mj  = MultipleLocator(1)
ml1 = MultipleLocator(0.1)
#ax1.yaxis.set_major_locator(mj)
ax1.yaxis.set_minor_locator(ml1)

ax2 = plot_HAM4.axes[1]  #plotSR2
ax2.plot(SR3, label = 'L1:SUS-SR3\_M1\_DAMP\_V\_IN1\_DQ.mean')
示例#15
0
from gwpy.signal import filter_design
bp = filter_design.bandpass(50, 250, 2048)

notches = [filter_design.notch(line, 2048) for
           line in (60, 120, 180)]

zpk = filter_design.concatenate_zpks(bp, *notches)

hfilt = hdata.filter(zpk, filtfilt=True)

hdata = hdata.crop(*hdata.span.contract(1))
hfilt = hfilt.crop(*hfilt.span.contract(1))

from gwpy.plotter import TimeSeriesPlot
plot = TimeSeriesPlot(hdata, hfilt, figsize=[12, 8], sep=True, sharex=True,
                      color='gwpy:ligo-hanford')
ax1, ax2 = plot.axes
ax1.set_title('Strain Data')
ax1.text(1.0, 1.0, 'Unfiltered data', transform=ax1.transAxes, ha='right')
ax1.set_ylabel('Amplitude [strain]', y=-0.2)
ax2.set_ylabel('')
ax2.text(1.0, 1.0, '50-250\,Hz bandpass, notches at 60, 120, 180 Hz',
         transform=ax2.transAxes, ha='right')
plot.show()


priors = tupak.gw.prior.BBHPriorSet()

priors['luminosity_distance'] = tupak.core.prior.Uniform(
    minimum=injection_parameters['luminosity_distance'] - 100,
    maximum=injection_parameters['luminosity_distance'] + 100,
# Demodulation is useful when trying to examine steady sinusoidal
# signals we know to be contained within data. For instance,
# we can download some data from LOSC to look at trends of the
# amplitude and phase of Livingston's calibration line at 331.3 Hz:

from gwpy.timeseries import TimeSeries
data = TimeSeries.fetch_open_data('L1', 1131350417, 1131357617)

# We can demodulate the `TimeSeries` at 331.3 Hz with a stride of once
# per minute:

amp, phase = data.demodulate(331.3, stride=60)

# We can then plot these trends to visualize changes in the amplitude
# and phase of the calibration line:

from gwpy.plotter import TimeSeriesPlot
plot = TimeSeriesPlot(amp, phase, sep=True)
plot.show()
示例#17
0
channels = [
    '%s:ISI-BS_ST1_SENSCOR_GND_STS_X_BLRMS_30M_100M.mean,s-trend',
    '%s:ISI-BS_ST1_SENSCOR_GND_STS_Y_BLRMS_30M_100M.mean,s-trend',
    '%s:ISI-BS_ST1_SENSCOR_GND_STS_Z_BLRMS_30M_100M.mean,s-trend',
]

# At last we can fetch 12 hours of data for each interferometer using the
# `TimeSeriesDict.fetch` method:
lho = TimeSeriesDict.fetch([c % 'H1' for c in channels],
                           'Feb 13 2015 16:00', 'Feb 14 2015 04:00')
llo = TimeSeriesDict.fetch([c % 'L1' for c in channels],
                           'Feb 13 2015 16:00', 'Feb 14 2015 04:00')

# Next we can plot the data, with a separate `~gwpy.plotter.Axes` for each
# instrument:
plot = TimeSeriesPlot(lho, llo)
for ifo, ax in zip(['H1', 'L1'], plot.axes):
   ax.legend(['X', 'Y', 'Z'])
   ax.yaxis.set_label_position('right')
   ax.set_ylabel(ifo, rotation=0, va='center', ha='left')
   ax.set_yscale('log')
plot.text(0.1, 0.5, '$1-3$\,Hz motion [nm/s]', rotation=90, fontsize=24,
          ha='center', va='center')
plot.axes[0].set_title('Magnitude 7.1 earthquake impact on LIGO', fontsize=24)
plot.show()

# Here we have also customised the output by manually setting the legend
# entries, putting the interferometer label on the right-hand side, setting
# a logarithmic y-axis scale, adding a shared y-axis label on the left-hand
# side, and setting a title.
示例#18
0
from gwpy.plotter import TimeSeriesPlot
plot = TimeSeriesPlot(data.crop(*data.span.contract(1)),
                      b.crop(*b.span.contract(1)),
                      figsize=[12, 8],
                      sep=True,
                      sharex=True,
                      color='gwpy:ligo-hanford')
plot.axes[0].set_title('LIGO-Hanford strain data around GW150914')
plot.axes[0].text(1.0,
                  1.0,
                  'Unfiltered data',
                  transform=plot.axes[0].transAxes,
                  ha='right')
plot.axes[0].set_ylabel('Amplitude [strain]', y=-0.2)
plot.axes[1].text(1.0,
                  1.0,
                  '50-250\,Hz bandpass, notches at 60, 120, 180 Hz',
                  transform=plot.axes[1].transAxes,
                  ha='right')
plot.show()
示例#19
0
from gwpy.plotter import TimeSeriesPlot
plot = TimeSeriesPlot(
    data.crop(*data.span.contract(1)),
    b.crop(*b.span.contract(1)),
    figsize=[12, 8], sep=True, sharex=True)
plot.axes[0].set_title('LIGO-Hanford strain data around GW150914')
plot.axes[0].text(
    1.0, 1.0, 'Unfiltered data',
    transform=plot.axes[0].transAxes, ha='right')
plot.axes[0].set_ylabel('Amplitude [strain]', y=-0.2)
plot.axes[1].text(
    1.0, 1.0, '50-250\,Hz bandpass, notches at 60, 120, 180 Hz',
    transform=plot.axes[1].transAxes, ha='right')
plot.show()
示例#20
0
channels = [
    '%s:ISI-BS_ST1_SENSCOR_GND_STS_X_BLRMS_30M_100M.mean,s-trend',
    '%s:ISI-BS_ST1_SENSCOR_GND_STS_Y_BLRMS_30M_100M.mean,s-trend',
    '%s:ISI-BS_ST1_SENSCOR_GND_STS_Z_BLRMS_30M_100M.mean,s-trend',
]

# At last we can :meth:`~TimeSeriesDict.get` 12 hours of data for each
# interferometer:
lho = TimeSeriesDict.get([c % 'H1' for c in channels], 'Feb 13 2015 16:00',
                         'Feb 14 2015 04:00')
llo = TimeSeriesDict.get([c % 'L1' for c in channels], 'Feb 13 2015 16:00',
                         'Feb 14 2015 04:00')

# Next we can plot the data, with a separate `~gwpy.plotter.Axes` for each
# instrument:
plot = TimeSeriesPlot(lho, llo)
ax1, ax2 = plot.axes
for ifo, ax in zip(('Hanford', 'Livingston'), (ax1, ax2)):
    ax.legend(['X', 'Y', 'Z'])
    ax.set_yscale('log')
    ax.text(1.01,
            0.5,
            ifo,
            ha='left',
            va='center',
            transform=ax.transAxes,
            fontsize=18)
ax1.set_ylabel('$1-3$\,Hz motion [nm/s]', y=-0.1)
ax2.set_ylabel('')
ax1.set_title('Magnitude 7.1 earthquake impact on LIGO')
plot.show()
示例#21
0
from gwpy.plotter import TimeSeriesPlot
inj = injfd.ifft()
plot = TimeSeriesPlot(noise, inj, sep=True, sharex=True, sharey=True)
plot.show()
示例#22
0
# We can design an arbitrarily complicated filter using
# :mod:`gwpy.signal.filter_design`

from gwpy.signal import filter_design
bp = filter_design.bandpass(50, 250, 4096.)
notches = [filter_design.notch(f, 4096.) for f in (60, 120, 180)]
zpk = filter_design.concatenate_zpks(bp, *notches)

# And then can download some data from LOSC to apply it using
# `TimeSeries.filter`:

from gwpy.timeseries import TimeSeries
data = TimeSeries.fetch_open_data('H1', 1126259446, 1126259478)
filtered = data.filter(zpk, filtfilt=True)

# We can plot the original signal, and the filtered version, cutting
# off either end of the filtered data to remove filter-edge artefacts

from gwpy.plotter import TimeSeriesPlot
plot = TimeSeriesPlot(data, filtered[128:-128], sep=True)
plot.show()
示例#23
0
# 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.plotter import TimeSeriesPlot
plot = TimeSeriesPlot(noise, signal, data, sep=True, sharex=True, sharey=True)
plot.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.