sigpyproc.timeseries#

Classes for handling 1D time series data.

This module contains the TimeSeries class for handling 1D time series data.

Classes

TimeSeries

Container for 1-D time series data.

class sigpyproc.timeseries.TimeSeries(data, header)[source]#

Bases: object

Container for 1-D time series data.

Parameters:
dataArrayLike

1-D time series array.

headerHeader

Header object containing metadata.

Attributes:
data

Time series data array.

header

Metadata header object.

nsamples

Number of samples.

Methods

apply_boxcar(width)

Apply a square-normalized boxcar filter to the time series.

correlate(other)

Perform cross correlation with another time series using FFTs.

deredden([method, window, fast])

Remove low-frequency red noise using a moving filter.

downsample(factor[, filter_method])

Downsample the time series.

fold(period[, accel, nbins, nints])

Fold time series into discrete phase and sub-integration bins.

from_dat(datfile[, inffile])

Read a Presto format .dat file.

from_tim(timfile)

Read a sigproc format .tim file.

normalise([loc_method, scale_method])

Normalise/standardise the time series.

pad(npad[, mode])

Pad a time series with mean valued data.

resample(accel)

Perform time domain resampling to remove acceleration.

rfft([fftn])

Perform 1-D real to complex forward FFT.

to_dat([basename])

Write time series in presto .dat format.

to_tim([filename])

Write time series in sigproc format.

property data#

Time series data array.

Returns:
NDArray[float32]

1-D time series array.

property header#

Metadata header object.

Returns:
Header

Header object containing metadata.

property nsamples#

Number of samples.

Returns:
int

Number of samples in the time series.

normalise(loc_method='mean', scale_method='std')[source]#

Normalise/standardise the time series.

Normalisation is performed by subtracting the loc estimate, and dividing by the scale estimate of the data.

Parameters:
loc_method{“mean”, “median”}, optional

Method to estimate location to subtract, by default “mean”.

scale_method{“std”, “iqr”, “mad”}, optional

Method to estimate scale to divide by, by default “std”.

Returns:
TimeSeries

Normalised time series.

downsample(factor, filter_method='mean')[source]#

Downsample the time series.

Returned time series is of size nsamples // factor.

Parameters:
factorint

Factor by which to downsample the time series.

filter_method{“mean”, “median”}, optional

Method to downsample, by default ‘mean’.

Returns:
TimeSeries

Downsampled time series.

pad(npad, mode='mean', **pad_kwargs)[source]#

Pad a time series with mean valued data.

Parameters:
npadint

Number of bins to add at the end of the time series.

modestr, optional

Padding mode (as used by numpy.pad), by default ‘mean’.

**pad_kwargsdict

Keyword arguments for numpy.pad.

Returns:
TimeSeries

Padded time series.

deredden(method='mean', window=0.5, *, fast=False)[source]#

Remove low-frequency red noise using a moving filter.

Parameters:
method{‘mean’, ‘median’}, optional

Moving filter function to use, by default ‘mean’.

windowint, optional

Width of moving filter window in seconds, by default 0.5 seconds.

fastbool, optional

Use a faster but less accurate method, by default False.

Returns:
TimeSeries

De-reddened time series.

Raises:
ValueError

If window < 0.

fold(period, accel=0, nbins=50, nints=32)[source]#

Fold time series into discrete phase and sub-integration bins.

Parameters:
periodfloat

Period to fold (in seconds).

accelfloat, optional

Acceleration to fold, by default 0.

nbinsint, optional

Number of phase bins in output, by default 50.

nintsint, optional

Number of sub-integrations in output, by default 32.

Returns:
FoldedData

Data cube containing the folded data.

Raises:
ValueError

If nbins * nints is too large for length of the data.

rfft(fftn=None)[source]#

Perform 1-D real to complex forward FFT.

Time series is zero-padded to the next good size for the FFT.

Parameters:
fftnCallable[[np.ndarray], np.ndarray], optional

The fft function to use. Own fft implementations can be used, e.g, pyfftw.interfaces.numpy_fft.rfft, or mkl_fft.interfaces.numpy_fft.rfft, by default None.

Returns:
FourierSeries

Fourier transform of the time series.

apply_boxcar(width)[source]#

Apply a square-normalized boxcar filter to the time series.

Parameters:
widthint

Width of boxcar to apply in bins.

Returns:
TimeSeries

Filtered time series.

Raises:
ValueError

If width < 1.

Notes

Time series returned is normalized in units of S/N.

resample(accel)[source]#

Perform time domain resampling to remove acceleration.

Parameters:
accelfloat

Acceleration to remove from the time series.

Returns:
TimeSeries

Resampled time series.

correlate(other)[source]#

Perform cross correlation with another time series using FFTs.

This method implements correlation equivalent to scipy.signal.correlate with mode='full' and method='fft'. Correlation lags will be np.arange(-len(other) + 1, nsamples).

Parameters:
otherTimeSeries | np.ndarray

Array to correlate with.

Returns:
TimeSeries

Time series containing the full correlation.

Raises:
OSError

If input array other is not TimeSeries or ndarray.

to_dat(basename=None)[source]#

Write time series in presto .dat format.

Parameters:
basenamestr, optional

File basename for output .dat and .inf files, by default None.

Returns:
str

Output .dat file name.

Notes

Method also writes a corresponding .inf file from the header data.

to_tim(filename=None)[source]#

Write time series in sigproc format.

Parameters:
filenamestr, optional

Name of file to write to, by default basename.tim.

Returns:
str

Output .tim file name.

classmethod from_dat(datfile, inffile=None)[source]#

Read a Presto format .dat file.

Parameters:
datfilestr | Path

Name of the .dat file to read.

inffilestr | Path, optional

Name of the corresponding .inf file, by default None.

Returns:
TimeSeries

TimeSeries object.

Notes

If inffile is None, then the associated .inf file must be in the same directory.

classmethod from_tim(timfile)[source]#

Read a sigproc format .tim file.

Parameters:
timfilestr | Path

Name of the .tim file to read.

Returns:
TimeSeries

TimeSeries object.