How to use the gwpy.timeseries.TimeSeries function in gwpy

To help you get started, we’ve selected a few gwpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gwpy / gwpy / examples / frequencyseries / inject.py View on Github external
the time of a glitch. In LIGO data analysis, this procedure is referred
to as an _injection_.

In the example below we will create a stream of random, white Gaussian
noise, then inject a loud, steady sinuosoid. We will do this in the
frequency domain because it is much easier to model a sinusoid there.
"""

__author__ = "Alex Urban "
__currentmodule__ = 'gwpy.timeseries'

# First, we prepare one second of Gaussian noise:

from numpy import random
from gwpy.timeseries import TimeSeries
noise = TimeSeries(random.normal(scale=.1, size=1024), sample_rate=1024)

# To inject a signal in the frequency domain, we need to take an FFT:

noisefd = noise.fft()

# We can now easily inject a loud sinusoid of unit amplitude at, say,
# 30 Hz. To do this, we use :meth:`~gwpy.types.series.Series.inject`.

import numpy
from gwpy.frequencyseries import FrequencySeries
signal = FrequencySeries(numpy.array([1.]), f0=30, df=noisefd.df)
injfd = noisefd.inject(signal)

# We can then visualize the data before and after injection in the frequency
# domain:
github gwpy / gwpy / gwpy / timeseries / io / lalframe.py View on Github external
def read_timeseriesdict(source, channels, start=None, end=None, dtype=None,
                        resample=None, gap=None, pad=None, nproc=1,
                        series_class=TimeSeries):
    """Read the data for a list of channels from a GWF data source.

    Parameters
    ----------
    source : `str`, :class:`glue.lal.Cache`, `list`
        data source object, one of:

        - `str` : frame file path
        - :class:`glue.lal.Cache`, `list` : contiguous list of frame paths

    channels : `list`
        list of channel names (or `Channel` objects) to read from frame.

    start : `Time`, :lalsuite:`LIGOTimeGPS`, optional
        start GPS time of desired data.
github lscsoft / lalsuite-archive / pylal / pylal / pylal_seismon_wiener.py View on Github external
# Subtracts the filtered SS from S using FIR filter coefficients W.
    # Routine written by Jan Harms. Routine modified by Michael Coughlin.
    # Modified: August 17, 2012
    # Contact: michael.coughlin@ligo.org

    N = len(W)-1
    ns = len(S)

    FF = np.zeros([ns-N,])

    for k in xrange(N,ns):
        tmp = SS[k-N:k+1,:] * W
        FF[k-N] = np.sum(tmp)

    cutoff = 10.0
    dataFF = gwpy.timeseries.TimeSeries(FF, sample_rate=samplef)
    dataFFLowpass = dataFF.lowpass(cutoff, amplitude=0.9, order=12, method='scipy')
    FF = np.array(dataFFLowpass)
    FF = np.array(dataFF)

    residual = S[range(ns-N)]-FF
    residual = residual - np.mean(residual)

    return residual, FF
github gwpy / gwpy / gwpy / table / rate.py View on Github external
bins2.append((bin_, bins[i+1]))
        bins = bins2
    elif isinstance(operator, (unicode, str)):
        op = OPERATORS[operator]
    else:
        op = operator
    coldata = get_table_column(self, column)
    colstr = get_column_string(column)
    # generate one TimeSeries per bin
    out = TimeSeriesDict()
    for bin_ in bins:
        if isinstance(bin_, tuple):
            bintimes = times[(coldata >= bin_[0]) & (coldata < bin_[1])]
        else:
            bintimes = times[op(coldata, bin_)]
        out[bin_] = TimeSeries(
            numpy.histogram(bintimes, bins=timebins)[0] / float(stride),
            epoch=start, sample_rate=1/float(stride), unit='Hz',
            name='%s $%s$ %s' % (colstr, operator, bin_), channel=channel)
    return out
github gwpy / gwpy / docs / spectrogram / spectrogram_plot.py View on Github external
from gwpy.timeseries import TimeSeries
gwdata = TimeSeries.fetch('H1:LDAS-STRAIN', 'September 16 2010 06:40',
                          'September 16 2010 06:50')
specgram = gwdata.spectrogram(20, fftlength=8, overlap=4) ** (1/2.)
plot = specgram.plot(norm='log', vmin=1e-23, vmax=1e-19)
ax = plot.gca()
ax.set_ylim(40, 4000)
ax.set_yscale('log')
plot.add_colorbar(label='GW strain ASD [strain/$\sqrt{\mathrm{Hz}}$]')
plot.show()
github gwpy / gwpy / gwpy / spectrogram / spectrogram.py View on Github external
# parse y-axis params
        if f0 is not None:
            kwargs['y0'] = f0
        if df is not None:
            kwargs['dy'] = df
        if frequencies is not None:
            kwargs['yindex'] = frequencies

        # generate Spectrogram
        return super(Spectrogram, cls).__new__(cls, data, unit=unit, name=name,
                                               channel=channel, **kwargs)

    # -- Spectrogram properties -----------------

    epoch = property(TimeSeries.epoch.__get__, TimeSeries.epoch.__set__,
                     TimeSeries.epoch.__delete__,
                     """Starting GPS epoch for this `Spectrogram`

                     :type: `~gwpy.segments.Segment`
                     """)

    t0 = property(TimeSeries.t0.__get__, TimeSeries.t0.__set__,
                  TimeSeries.t0.__delete__,
                  """GPS time of first time bin

                  :type: `~astropy.units.Quantity` in seconds
                  """)

    dt = property(TimeSeries.dt.__get__, TimeSeries.dt.__set__,
                  TimeSeries.dt.__delete__,
                  """Time-spacing for this `Spectrogram`
github lscsoft / lalsuite-archive / pylal / pylal / pylal_seismon_utils.py View on Github external
dataFull.resample(channel.samplef)

    else:

        #for frame in params["frame"]:
        #    print frame.path
        #    frame_data,data_start,_,dt,_,_ = Fr.frgetvect1d(frame.path,channel.station)

        #print params["frame"]
        #dataFull = gwpy.timeseries.TimeSeries.read(params["frame"], channel.station, epoch=gpsStart, duration=duration)
        #print "done"

        # make timeseries
        try:
            dataFull = gwpy.timeseries.TimeSeries.read(params["frame"], channel.station, start=gpsStart, end=gpsEnd)
        except:
            print "data read from frames failed... continuing\n"
            return dataFull

    return dataFull
github gwpy / gwpy / gwpy / timeseries / io / gwf / lalframe.py View on Github external
def read(source, channels, start=None, end=None, series_class=TimeSeries,
         scaled=None):
    """Read data from one or more GWF files using the LALFrame API
    """
    # scaled must be provided to provide a consistent API with frameCPP
    if scaled is not None:
        warnings.warn(
            "the `scaled` keyword argument is not supported by lalframe, "
            "if you require ADC scaling, please install "
            "python-ldas-tools-framecpp",
        )

    stream = open_data_source(source)

    # parse times and restrict to available data
    epoch = lal.LIGOTimeGPS(stream.epoch.gpsSeconds,
                            stream.epoch.gpsNanoSeconds)
github gwpy / gwpy / examples / timeseries / filter.py View on Github external
"""Filtering a `TimeSeries` with a ZPK filter

Several data streams read from the LIGO detectors are whitened before being
recorded to prevent numerical errors when using single-precision data
storage.
In this example we read such `channel ` and undo the
whitening to show the physical content of these data.

"""

__author__ = "Duncan Macleod "
__currentmodule__ = 'gwpy.timeseries'

# First, we import the `TimeSeries` and :meth:`~TimeSeries.get` the data:
from gwpy.timeseries import TimeSeries
white = TimeSeries.get(
    'L1:OAF-CAL_DARM_DQ', 'March 2 2015 12:00', 'March 2 2015 12:30')

# Now, we can re-calibrate these data into displacement units by first applying
# a `highpass ` filter to remove the low-frequency noise,
# and then applying our de-whitening filter in `ZPK ` format
# with five zeros at 100 Hz and five poles at 1 Hz (giving an overall DC
# gain of 10 :sup:`-10`:
hp = white.highpass(4)
displacement = hp.zpk([100]*5, [1]*5, 1e-10)

# We can visualise the impact of the whitening by calculating the ASD
# `~gwpy.frequencyseries.FrequencySeries` before and after the filter,

whiteasd = white.asd(8, 4)
dispasd = displacement.asd(8, 4)