sigpyproc.readers#

class sigpyproc.readers.FilReader(filenames, check_contiguity=True)#

Bases: Filterbank

A class to handle the reading of sigproc format filterbank files.

Parameters:
  • filenames (str or list of str) – filterbank file or list of filterbank files

  • check_contiguity (bool, optional) – whether to check if files are contiguous, by default True

Returns:

Base container of filterbank data with observational metadata

Return type:

Filterbank

Notes

To be considered as a Sigproc format filterbank file the header must only contain keywords found in the header_keys dictionary.

property header#

Header metadata of input file.

Type:

Header

property filename#

Name of the input file (first file in case of multiple input files).

Type:

str

property bitsinfo#

Bits info of input file data.

Type:

BitsInfo

property sampsize#

Sample byte stride in input data.

Type:

int

read_block(start, nsamps)#

Read a block of filterbank data.

Parameters:
  • start (int) – first time sample of the block to be read

  • nsamps (int) – number of samples in the block (i.e. block will be nsamps*nchans in size)

Returns:

2-D array of filterbank data with observational metadata

Return type:

FilterbankBlock

Raises:

ValueError – if requested samples are out of range

read_dedisp_block(start, nsamps, dm)#

Read a block of dedispersed filterbank data.

Best used in cases where I/O time dominates reading a block of data.

Parameters:
  • start (int) – first time sample of the block to be read

  • nsamps (int) – number of samples in the block (i.e. block will be nsamps*nchans in size)

  • dm (float) – dispersion measure to dedisperse at

Returns:

2-D array of filterbank data with observational metadata

Return type:

FilterbankBlock

Raises:

ValueError – if requested dedispersed samples are out of range

read_plan(gulp=16384, start=0, nsamps=None, skipback=0, description=None, quiet=False)#

A generator used to perform filterbank reading.

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

  • start (int, optional) – first sample to read from filterbank, by default 0 (start of file)

  • nsamps (int, optional) – total number of samples to read, by default None (end of the file)

  • skipback (int, optional) – number of samples to skip back after each read, by default 0

  • description (str, optional) – description of task show next to progress bar (rich), by default Calling Stack

  • quiet (bool, optional) – suppress progress bar and logging, by default False

Yields:

Iterator (tuple(int, int, ndarray)) – An iterable of the values in the sequence.

Raises:

ValueError – If read samples < skipback.

Notes

For each read, the generator yields a tuple x, where:

  • x[0] is the number of samples read

  • x[1] is the index of the read (i.e. x[1]=0 is the first read)

  • x[2] is a 1-D numpy array containing the data that was read

Examples

The normal calling syntax for this is function is:

>>> for nsamps, ii, data in self.read_plan(**plan_kwargs):
        # do something
where data always has contains ``nchans*nsamps`` points.
class sigpyproc.readers.PFITSReader(filename)#

Bases: Filterbank

Reads a filterbank file from a FITS file.

Parameters:

filename (str) – Name of the input file.

property pri_hdr#

Primary header of input file.

Type:

PrimaryHdr

property sub_hdr#

Subint header of input file.

Type:

SubintHdr

property header#

Header metadata of input file.

Type:

Header

property filename#

Name of the input file (first file in case of multiple input files).

Type:

str

property bitsinfo#

Bits info of input file data.

Type:

BitsInfo

property sampsize#

Sample byte stride in input data.

Type:

int

read_block(start, nsamps)#

Read a block of filterbank data.

Parameters:
  • start (int) – first time sample of the block to be read

  • nsamps (int) – number of samples in the block (i.e. block will be nsamps*nchans in size)

Returns:

2-D array of filterbank data with observational metadata

Return type:

FilterbankBlock

Raises:

ValueError – if requested samples are out of range

read_dedisp_block(start, nsamps, dm)#

Read a block of dedispersed filterbank data.

Best used in cases where I/O time dominates reading a block of data.

Parameters:
  • start (int) – first time sample of the block to be read

  • nsamps (int) – number of samples in the block (i.e. block will be nsamps*nchans in size)

  • dm (float) – dispersion measure to dedisperse at

Returns:

2-D array of filterbank data with observational metadata

Return type:

FilterbankBlock

Raises:

ValueError – if requested dedispersed samples are out of range

read_plan(gulp=16384, start=0, nsamps=None, skipback=0, description=None, quiet=False)#

A generator used to perform filterbank reading.

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

  • start (int, optional) – first sample to read from filterbank, by default 0 (start of file)

  • nsamps (int, optional) – total number of samples to read, by default None (end of the file)

  • skipback (int, optional) – number of samples to skip back after each read, by default 0

  • description (str, optional) – description of task show next to progress bar (rich), by default Calling Stack

  • quiet (bool, optional) – suppress progress bar and logging, by default False

Yields:

Iterator (tuple(int, int, ndarray)) – An iterable of the values in the sequence.

Raises:

ValueError – If read samples < skipback.

Notes

For each read, the generator yields a tuple x, where:

  • x[0] is the number of samples read

  • x[1] is the index of the read (i.e. x[1]=0 is the first read)

  • x[2] is a 1-D numpy array containing the data that was read

Examples

The normal calling syntax for this is function is:

>>> for nsamps, ii, data in self.read_plan(**plan_kwargs):
        # do something
where data always has contains ``nchans*nsamps`` points.
class sigpyproc.readers.PulseExtractor(filfile, pulse_toa, pulse_width, pulse_dm, min_nsamps=256, quiet=False)#

Bases: object

Extracts a data block from a filterbank file centered on a pulse.

The extracted block is centered on the given pulse toa at the highest frequency in the band. The block is padded if the pulse is too close to the edge of the filterbank file.

Parameters:
  • filfile (str) – Name of the filterbank file.

  • pulse_toa (int) – Time of arrival of the pulse in samples at the highest frequency.

  • pulse_width (int) – Width of the pulse in samples.

  • pulse_dm (float) – Dispersion measure of the pulse.

  • min_nsamps (int, optional) – Minimum number of samples in the extracted block, by default 256

  • quiet (bool, optional) – If True, suppresses logging messages, by default False

property decimation_factor#

Decimation factor to consider.

Type:

int

property disp_delay#

Dispersion delay in samples.

Type:

int

property block_delay#

Dispersion Block size in samples.

Type:

int

property nsamps#

Number of samples in the output block.

Type:

int

property nstart#

Start sample of the output block.

Type:

int

property nstart_file#

Start sample to read in the file.

Type:

int

property nsamps_file#

Number of samples to read in the file.

Type:

int

property pulse_toa_block#

Time of arrival of the pulse in the output block.

Type:

int

get_data(pad_mode='median')#

Extracts the data block from the filterbank file.

Parameters:

pad_mode (str, optional) – Mode for padding the data, by default “median”

Returns:

Data block.

Return type:

FilterbankBlock