sigpyproc.Filterbank

class sigpyproc.Filterbank.Filterbank[source]

Bases: object

New Class exporting methods for the manipulation of frequency-major order pulsar data.

Notes

The Filterbank class should never be instantiated directly. Instead it should be inherited by data reading classes.

applyChannelMask(chanmask, outfilename=None, gulp=512, back_compatible=True, **kwargs)[source]

Set the data in the given channels to zero.

Parameters
  • chanmask (list) – binary channel mask (0 for bad channel, 1 for good)

  • outfilename (str, optional) – name of the output filterbank file, by default basename_masked.fil

  • gulp (int, optional) – number of samples in each read, by default 512

  • back_compatible (bool, optional) – sigproc compatibility flag, by default True

Returns

name of output file

Return type

str

bandpass(gulp=512, **kwargs)[source]

Average across each time sample for all frequencies.

Parameters

gulp (int, optional) – number of samples in each read, by default 512

Returns

the bandpass of the data

Return type

TimeSeries

collapse(gulp=512, start=0, nsamps=None, **kwargs)[source]

Sum across all frequencies for each time sample.

Parameters
  • gulp (int, optional) – number of samples in each read, by default 512

  • start (int, optional) – start sample, by default 0

  • nsamps (int, optional) – number of samples to read, by default all

Returns

A zero-DM time series

Return type

TimeSeries

dedisperse(dm, gulp=10000, **kwargs)[source]

Dedisperse the data to a time series.

Parameters
  • dm (float) – dispersion measure to dedisperse to

  • gulp (int, optional) – number of samples in each read, by default 10000

Returns

a dedispersed time series

Return type

TimeSeries

Notes

If gulp < maximum dispersion delay, gulp is taken to be twice the maximum dispersion delay.

downsample(tfactor=1, ffactor=1, gulp=512, filename=None, back_compatible=True, **kwargs)[source]

Downsample data in time and/or frequency and write to file.

Parameters
  • tfactor (int, optional) – factor by which to downsample in time, by default 1

  • ffactor (int, optional) – factor by which to downsample in frequency, by default 1

  • gulp (int, optional) – number of samples in each read, by default 512

  • filename (str, optional) – name of file to write to, by default basename_tfactor_ffactor.fil

  • back_compatible (bool, optional) – sigproc compatibility flag (legacy code), by default True

Returns

output file name

Return type

str

Raises

ValueError – If number of channels is not divisible by ffactor.

fold(period, dm, accel=0, nbins=50, nints=32, nbands=32, gulp=10000, **kwargs)[source]

Fold data into discrete phase, subintegration and subband bins.

Parameters
  • period (float) – period in seconds to fold with

  • dm (float) – dispersion measure to dedisperse to

  • accel (float, optional) – acceleration in m/s/s to fold with, by default 0

  • nbins (int, optional) – number of phase bins in output, by default 50

  • nints (int, optional) – number of subintegrations in output, by default 32

  • nbands (int, optional) – number of subbands in output, by default 32

  • gulp (int, optional) – number of samples in each read, by default 10000

Returns

3 dimensional data cube

Return type

FoldedData

Raises

ValueError – If nbands * nints * nbins is too large

Notes

If gulp < maximum dispersion delay, gulp is taken to be twice the maximum dispersion delay.

getChan(chan, gulp=512, **kwargs)[source]

Retrieve a single frequency channel from the data.

Parameters
  • chan (int) – channel to retrieve (0 is the highest frequency channel)

  • gulp (int, optional) – number of samples in each read, by default 512

Returns

selected channel as a time series

Return type

TimeSeries

Raises

ValueError – If chan is out of range (chan < 0 or chan > total channels).

getStats(gulp=512, **kwargs)[source]

Retrieve channelwise statistics of data.

Parameters
  • gulp (int, optional) – number of samples in each read, by default 512

  • creates following instance attributes (Function) –

    • chan_means: the mean value of each channel

    • chan_vars: the variance of each channel

    • chan_stdevs: the standard deviation of each channel

    • chan_skews: the skewness of each channel

    • chan_kurts: the kurtosis of each channel

    • chan_max: the maximum value of each channel

    • chan_min: the minimum value of each channel

invertFreq(gulp=512, start=0, nsamps=None, filename=None, back_compatible=True, **kwargs)[source]

Invert the frequency ordering of the data and write new data to a new file.

Parameters
  • gulp (int, optional) – number of samples in each read, by default 512

  • start (int, optional) – start sample, by default 0

  • nsamps (int, optional) – number of samples to read, by default all

  • filename (str, optional) – name of output file, by default basename_inverted.fil

  • back_compatible (bool, optional) – sigproc compatibility flag (legacy code), by default True

Returns

name of output file

Return type

str

removeBandpass(gulp=512, filename=None, back_compatible=True, **kwargs)[source]

Remove the bandpass from the data and write new data to a new file.

Parameters
  • gulp (int, optional) – number of samples in each read, by default 512

  • filename (str, optional) – name of output file, by default basename_bpcorr.fil

  • back_compatible (bool, optional) – sigproc compatibility flag (legacy code), by default True

Returns

name of output file

Return type

str

Raises

TypeError – If nbits of input file is < 8.

removeZeroDM(gulp=512, filename=None, back_compatible=True, **kwargs)[source]

Remove the channel-weighted zero-DM from the data and write to disk.

Parameters
  • gulp (int, optional) – number of samples in each read, by default 512

  • filename (str, optional) – name of output file , by default basename_noZeroDM.fil

  • back_compatible (bool, optional) – sigproc compatibility flag (legacy code), by default True

Returns

name of output file

Return type

str

Notes

Based on Presto implementation of Eatough, Keane & Lyne 2009

setNthreads(nthreads=None)[source]

Set the number of threads available to OpenMP.

Parameters

nthreads (int, optional) – number of threads to use, by default 4

split(start, nsamps, filename=None, gulp=1024, back_compatible=True, **kwargs)[source]

Split data in time.

Parameters
  • start (int) – start sample of split

  • nsamps (int) – number of samples in split

  • filename (str, optional) – name of output file, by default basename_start_start+nsamps.fil

  • gulp (int, optional) – number of samples in each read, by default 1024

  • back_compatible (bool, optional) – sigproc compatibility flag (legacy code), by default True

Returns

name of new file

Return type

str

splitToBands(chanpersub, chanstart=0, gulp=1024, back_compatible=True, **kwargs)[source]

Split the data into component Sub-bands and write to disk.

Parameters
  • chanpersub (int) – number of channels in each sub-band

  • chanstart (int, optional) – start channel of split, by default 0

  • gulp (int, optional) – number of samples in each read, by default 1024

  • back_compatible (bool, optional) – sigproc compatibility flag (legacy code), by default True

Returns

names of all files written to disk

Return type

list of str

Notes

Filterbanks are written to disk with names based on sub-band number.

splitToChans(gulp=1024, back_compatible=True, **kwargs)[source]

Split the data into component channels and write each to file.

Parameters
  • gulp (int, optional) – number of samples in each read, by default 1024

  • back_compatible (bool, optional) – sigproc compatibility flag (legacy code), by default True

Returns

names of all files written to disk

Return type

list of str

Notes

Time series are written to disk with names based on channel number.

subband(dm, nsub, filename=None, gulp=10000, **kwargs)[source]

Produce a set of dedispersed subbands from the data.

Parameters
  • dm (float) – the DM of the subbands

  • nsub (int) – the number of subbands to produce

  • filename (str, optional) – output file name of subbands, by default basename_DM.subbands

  • gulp (int, optional) – number of samples in each read, by default 10000

Returns

name of output subbands file

Return type

str

upTo8bit(filename=None, gulp=512, back_compatible=True, **kwargs)[source]

Convert 1-,2- or 4-bit data to 8-bit data and write to file.

Parameters
  • filename (str, optional) – name of file to write to, by default basename_8bit.fil

  • gulp (int, optional) – number of samples in each read, by default 512

  • back_compatible (bool, optional) – sigproc compatibility flag, by default True

Returns

name of output file

Return type

str

class sigpyproc.Filterbank.FilterbankBlock(input_array, header)[source]

Bases: numpy.ndarray

Class to handle a discrete block of data in time-major order.

Parameters
  • input_array (numpy.ndarray) – 2 dimensional array of shape (nchans, nsamples)

  • header (Header) – observational metadata

Returns

2 dimensional array of shape (nchans, nsamples) with header metadata

Return type

numpy.ndarray

Notes

Data is converted to 32 bits regardless of original type.

dedisperse(dm, only_valid_samples=False)[source]

Dedisperse the block.

Parameters
  • dm (float) – dm to dedisperse to

  • only_valid_samples (bool, optional) – return a FilterbankBlock with only time samples that contain the full bandwidth, by default False

Returns

a dedispersed version of the block

Return type

FilterbankBlock

Raises

ValueError – If there are not enough time samples to dedisperse.

Notes

Frequency dependent delays are applied as rotations to each channel in the block.

downsample(tfactor=1, ffactor=1)[source]

Downsample data block in frequency and/or time.

Parameters
  • tfactor (int, optional) – factor by which to downsample in time, by default 1

  • ffactor (int, optional) – factor by which to downsample in frequency, by default 1

Returns

2 dimensional array of downsampled data

Return type

FilterbankBlock

Raises

ValueError – If number of channels is not divisible by ffactor.

get_bandpass()[source]

Average across each time sample for all frequencies.

Returns

the bandpass of the data

Return type

TimeSeries

get_tim()[source]

Sum across all frequencies for each time sample

Returns

a timeseries

Return type

TimeSeries

normalise()[source]

Divide each frequency channel by its average.

Returns

normalised version of the data

Return type

FilterbankBlock

toFile(filename=None, back_compatible=True)[source]

Write the data to file.

Parameters
  • filename (str, optional) – name of the output file, by default basename_split_start_to_end.fil

  • back_compatible (bool, optional) – sigproc compatibility flag (legacy code), by default True

Returns

name of output file

Return type

str