FrequencySeries#
- class gwpy.frequencyseries.FrequencySeries(
- data: ArrayLike1D,
- unit: UnitLike = None,
- f0: Quantity | float | None = None,
- df: Quantity | float | None = None,
- frequencies: ArrayLike1D | None = None,
- name: str | None = None,
- epoch: SupportsToGps | None = None,
- channel: Channel | str | None = None,
- **kwargs,
Bases:
SeriesA data array holding some metadata to represent a frequency series.
- Parameters:
- valuearray_like
Input data array.
- unit
Unit, optional Physical unit of these data.
- f0
float,Quantity, optional, default:0 Starting frequency for these data.
- df
float,Quantity, optional, default:1 Frequency resolution for these data.
- frequencies
array-like The complete array of frequencies indexing the data. This argument takes precedence over
f0anddfso should be given in place of these if relevant, not alongside.- epoch
LIGOTimeGPS,float,str, optional GPS epoch associated with these data, any input parsable by
to_gpsis fine.- name
str, optional Descriptive title for this array.
- channel
Channel,str, optional Source data stream for these data.
- dtype
dtype, optional Input data type.
- copy
bool, optional, default:False Choose to copy the input data to new memory.
- subok
bool, optional, default:True Allow passing of sub-classes by the array generator.
Notes
Key methods:
Read data into a
FrequencySeries.Write this
FrequencySeriesto a file.plot([method, xscale])Plot the data for this
FrequencySeries.zpk(zeros, poles, gain, *[, analog, ...])Filter this
FrequencySeriesby applying a zero-pole-gain filter.Attributes Summary
Frequency spacing of this
FrequencySeriesStarting frequency for this
FrequencySeriesSeries of frequencies for each sample
Read data into a
FrequencySeries.Write this
FrequencySeriesto a file.Methods Summary
filter(filt, *[, analog, sample_rate, unit, ...])Apply a filter to this
FrequencySeries.from_lal(lalfs, *[, copy])Generate a new
FrequencySeriesfrom a LALFrequencySeries.from_pycbc(fs, *[, copy])Convert a
pycbc.types.frequencyseries.FrequencySeries.ifft()Compute the one-dimensional discrete inverse Fourier transform.
interpolate(df)Interpolate this
FrequencySeriesto a new resolution.plot([method, xscale])Plot the data for this
FrequencySeries.to_lal()Convert this
FrequencySeriesinto a LAL FrequencySeries.to_pycbc(*[, copy])Convert this
FrequencySeriesinto a PyCBC FrequencySeries.zpk(zeros, poles, gain, *[, analog, ...])Filter this
FrequencySeriesby applying a zero-pole-gain filter.Attributes Documentation
- df[source]#
Frequency spacing of this
FrequencySeries
- f0[source]#
Starting frequency for this
FrequencySeries
- read#
Read data into a
FrequencySeries.Arguments and keywords depend on the output format, see the online documentation for full details for each format, the parameters below are common to most formats.
- Parameters:
- source
str,os.PathLike,file, orlistofthese Source of data, any of the following:
Path of a single data file
List of data file paths
Path of LAL-format cache file
- args
Other arguments are (in general) specific to the given
format.- format
str, optional Source format identifier. If not given, the format will be detected if possible. See below for list of acceptable formats.
- kwargs
Other keywords are (in general) specific to the given
format.
- source
- Raises:
IndexErrorIf
sourceis an empty list.
- write#
Write this
FrequencySeriesto a file.Arguments and keywords depend on the output format, see the online documentation for full details for each format, the parameters below are common to most formats.
Methods Documentation
- filter(
- filt: FilterCompatible,
- *,
- analog: bool = False,
- sample_rate: QuantityLike | None = None,
- unit: str = 'rad/s',
- normalize_gain: bool = False,
- inplace: bool = False,
Apply a filter to this
FrequencySeries.The input filter argument is designed to accept any filter created by the
scipy.signalfilter design functions, and operates on the conventions of that module.- Parameters:
- filt
numpy.ndarrayortuple The filter to be applied. This can be specified in any of the following forms, with the appropriate number of elements in the tuple:
numpy.ndarray- 1D array of FIR filter coefficients.tuple[numpy.ndarray, numpy.ndarray]- numerator/demoinator polynomials of the transfer function.numpy.ndarray- 2D array of SOS coefficients.tuple[numpy.ndarray, numpy.ndarray, float]- zero-pole-gain representation.
- analog
bool, optional Type of ZPK being applied, if
analog=Trueall parameters will be converted in the Z-domain for digital filtering via the bilinear transform.- sample_rate
float,Quantity, optional Sample rate of data (in Hertz), used to apply a digital filter. Defaults to the last frequency value of this
FrequencySeries(i.e. the Nyquist frequency).- unit
str, optional For analogue ZPK filters, the units in which the zeros and poles are specified. Either
'Hz'or'rad/s'(default).- normalize_gain
bool, optional Whether to normalize the gain when converting from Hz to rad/s.
False(default): Multiply zeros/poles by -2π but leave gain unchanged. This matches the LIGO GDS ‘f’ plane convention (plane='f'ins2z()).True: Normalize gain to preserve frequency response magnitude. Gain is scaled by \(|∏p_i/∏z_i| · (2π)^{(n_p - n_z)}\). Use this when your filter was designed with the transfer function \(H(f) = k·∏(f-z_i)/∏(f-p_i)\) in Hz. This matches the LIGO GDS ‘n’ plane convention (plane='n'ins2z()).
Only used for analogue filters in Hz (
analog=True, unit="Hz").- inplacebool, optional
If
True, this array will be overwritten with the filtered version.
- filt
- Returns:
- result
FrequencySeries The filtered version of the input
FrequencySeries, ifinplace=Truewas given, this is just a reference to the modified input array.
- result
- Raises:
ValueErrorIf
filtarguments cannot be interpreted properly.
See also
FrequencySeries.zpkFor applying a zero-pole-gain filter, including in other units (e.g. poles and zeros specified in Hertz).
- classmethod from_lal(
- lalfs: LALFrequencySeriesType,
- *,
- copy: bool = True,
Generate a new
FrequencySeriesfrom a LALFrequencySeries.Any type of LAL FrequencySeries is supported.
- classmethod from_pycbc(
- fs: pycbc.types.TimeSeries,
- *,
- copy: bool = True,
Convert a
pycbc.types.frequencyseries.FrequencySeries.- Parameters:
- fs
pycbc.types.frequencyseries.FrequencySeries The input PyCBC
FrequencySeriesarray.- copy
bool, optional If
True, copy these data to a new array.
- fs
- Returns:
- spectrum
FrequencySeries A GWpy version of the input frequency series.
- spectrum
- ifft() TimeSeries[source]#
Compute the one-dimensional discrete inverse Fourier transform.
- Returns:
- out
TimeSeries The normalised, real-valued
TimeSeries.
- out
See also
numpy.fft.irfftThe inverse (real) FFT function.
Notes
This method applies the necessary normalisation such that the condition holds:
>>> timeseries = TimeSeries([1.0, 0.0, -1.0, 0.0], sample_rate=1.0) >>> timeseries.fft().ifft() == timeseries
- interpolate(df: float) Self[source]#
Interpolate this
FrequencySeriesto a new resolution.- Parameters:
- df
float Desired frequency resolution of the interpolated
FrequencySeries, in Hz.
- df
- Returns:
- out
FrequencySeries The interpolated version of the input
FrequencySeries.
- out
See also
numpy.interpFor the underlying 1-D linear interpolation scheme.
- plot( ) Plot[source]#
Plot the data for this
FrequencySeries.
- to_lal() LALFrequencySeriesType[source]#
Convert this
FrequencySeriesinto a LAL FrequencySeries.- Returns:
- lalspec
FrequencySeries An XLAL-format FrequencySeries of a given type, e.g.
REAL8FrequencySeries.
- lalspec
- to_pycbc(*, copy: bool = True) pycbc.types.FrequencySeries[source]#
Convert this
FrequencySeriesinto a PyCBC FrequencySeries.- Parameters:
- Returns:
- frequencyseries
pycbc.types.frequencyseries.FrequencySeries A PyCBC representation of this
FrequencySeries.
- frequencyseries
- zpk(
- zeros: ArrayLike1D,
- poles: ArrayLike1D,
- gain: float,
- *,
- analog: bool = True,
- sample_rate: QuantityLike | None = None,
- unit: str = 'rad/s',
- normalize_gain: bool = False,
Filter this
FrequencySeriesby applying a zero-pole-gain filter.- Parameters:
- zeros
array-like List of zero frequencies (in Hertz).
- poles
array-like List of pole frequencies (in Hertz).
- gain
float DC gain of filter.
- analog
bool, optional Type of ZPK being applied, if
analog=Trueall parameters will be converted in the Z-domain for digital filtering via the bilinear transform.- sample_rate
float,Quantity, optional Sample rate of data (in Hertz), used to apply a digital filter. Defaults to the last frequency value of this
FrequencySeries(i.e. the Nyquist frequency).- unit
str, optional For analogue ZPK filters, the units in which the zeros and poles are specified. Either
'Hz'or'rad/s'(default).- normalize_gain
bool, optional Whether to normalize the gain when converting from Hz to rad/s.
False(default): Multiply zeros/poles by -2π but leave gain unchanged. This matches the LIGO GDS ‘f’ plane convention (plane='f'ins2z()).True: Normalize gain to preserve frequency response magnitude. Gain is scaled by \(|∏p_i/∏z_i| · (2π)^{(n_p - n_z)}\). Use this when your filter was designed with the transfer function \(H(f) = k·∏(f-z_i)/∏(f-p_i)\) in Hz. This matches the LIGO GDS ‘n’ plane convention (plane='n'ins2z()).
Only used for analogue filters in Hz (
analog=True, unit="Hz").
- zeros
- Returns:
- spectrum
FrequencySeries The frequency-domain filtered version of the input data.
- spectrum
See also
FrequencySeries.filterFor details on how a digital ZPK-format filter is applied.
Examples
To apply a zpk filter with file poles at 100 Hz, and five zeros at 1 Hz (giving an overall DC gain of 1e-10):
>>> data2 = data.zpk([100]*5, [1]*5, 1e-10)