sigpyproc.readers#
Classes for reading filterbank and PSRFITS data.
This module contains the FilReader and PFITSReader classes for reading filterbank and PSRFITS data.
Classes
A class to handle the reading of sigproc format filterbank files. |
|
Reads a filterbank file from a FITS file. |
|
Extracts a data block from a filterbank file centered on a pulse. |
- class sigpyproc.readers.FilReader(filenames, *, check_contiguity=True)[source]#
Bases:
FilterbankA class to handle the reading of sigproc format filterbank files.
- Parameters:
- Attributes:
bitsinfoBitsInfo: Bits info of input file data.chan_strideint: Channel byte stride in input data.
filenamestr: Name of the input file (first file in case of multiple input files).
headerHeader metadata of input file.
samp_strideint: Sample byte stride in input data.
Methods
read_block(start, nsamps[, fch1, nchans])Read a data block from the filterbank file stream.
read_dedisp_block(start, nsamps, dm)Read a block of dedispersed filterbank data.
read_plan([gulp, start, nsamps, skipback, ...])Read sequential filterbank in gulps and yield.
- Returns:
FilterbankBase container of filterbank data with observational metadata.
Notes
To be considered as a Sigproc format filterbank file the header must only contain keywords found in the
SIGPROC_SCHEMAdictionary.- property header#
Header metadata of input file.
- Returns:
HeaderHeader object containing metadata of the input file.
- property filename#
str: Name of the input file (first file in case of multiple input files).
- property chan_stride#
int: Channel byte stride in input data.
- property samp_stride#
int: Sample byte stride in input data.
- read_block(start, nsamps, fch1=None, nchans=None)[source]#
Read a data block from the filterbank file stream.
- 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).
- fch1
float, optional Frequency of the first channel, by default None (header value).
- nchans
int, optional Number of channels in the block, by default None (header value).
- start
- Returns:
FilterbankBlock2-D array of filterbank data with observational metadata.
- Raises:
ValueErrorif requested
nsampsornchansare out of range.
- read_dedisp_block(start, nsamps, dm)[source]#
Read a block of dedispersed filterbank data.
Best used in cases where I/O time dominates reading a block of data.
- Parameters:
- Returns:
FilterbankBlock2-D array of filterbank data with observational metadata.
- Raises:
ValueErrorif requested dedispersed
nsampsare out of range.
- read_plan(gulp=16384, start=0, nsamps=None, skipback=0, description=None, *, quiet=False, allocator=None)[source]#
Read sequential filterbank in gulps and yield.
- Parameters:
- gulp
int, optional Number of time samples in each read, by default 16384.
- start
int, optional Starting sample to read from, 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 Annotation for progress bar (rich), by default Calling Stack.
- quiet
bool, optional Disable progress bar and logging, by default False.
- allocator
Callable[[int],Buffer], optional An allocator callback that returns an object implementing the Python Buffer Protocol interface (PEP 3118) for the data to be read into, by default None.
- gulp
- Yields:
- Raises:
ValueErrorIf read samples <
skipback.
Notes
For each read, the generator yields a tuple
x, where:x[0]is the number of samples readx[1]is the index of the read (i.e.x[1]=0is 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_r, ii, data in self.read_plan(**plan_kwargs): # do something where data always has contains ``nchans*nsamps`` points.
- class sigpyproc.readers.PFITSReader(filename)[source]#
Bases:
FilterbankReads a filterbank file from a FITS file.
- Parameters:
- filename
str Name of the input file.
- filename
- Attributes:
Methods
read_block(start, nsamps[, fch1, nchans])Read a data block from the filterbank file stream.
read_dedisp_block(start, nsamps, dm)Read a block of dedispersed filterbank data.
read_plan([gulp, start, nsamps, skipback, ...])Read sequential filterbank in gulps and yield.
- property pri_hdr#
PrimaryHdr: Primary header of input file.
- property header#
Header metadata of input file.
- Returns:
HeaderHeader object containing metadata of the input file.
- property filename#
str: Name of the input file (first file in case of multiple input files).
- read_block(start, nsamps, fch1=None, nchans=None)[source]#
Read a data block from the filterbank file stream.
- 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).
- fch1
float, optional Frequency of the first channel, by default None (header value).
- nchans
int, optional Number of channels in the block, by default None (header value).
- start
- Returns:
FilterbankBlock2-D array of filterbank data with observational metadata.
- Raises:
ValueErrorif requested
nsampsornchansare out of range.
- read_dedisp_block(start, nsamps, dm)[source]#
Read a block of dedispersed filterbank data.
Best used in cases where I/O time dominates reading a block of data.
- Parameters:
- Returns:
FilterbankBlock2-D array of filterbank data with observational metadata.
- Raises:
ValueErrorif requested dedispersed
nsampsare out of range.
- read_plan(gulp=16384, start=0, nsamps=None, skipback=0, description=None, *, quiet=False, allocator=None)[source]#
Read sequential filterbank in gulps and yield.
- Parameters:
- gulp
int, optional Number of time samples in each read, by default 16384.
- start
int, optional Starting sample to read from, 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 Annotation for progress bar (rich), by default Calling Stack.
- quiet
bool, optional Disable progress bar and logging, by default False.
- allocator
Callable[[int],Buffer], optional An allocator callback that returns an object implementing the Python Buffer Protocol interface (PEP 3118) for the data to be read into, by default None.
- gulp
- Yields:
- Raises:
ValueErrorIf read samples <
skipback.
Notes
For each read, the generator yields a tuple
x, where:x[0]is the number of samples readx[1]is the index of the read (i.e.x[1]=0is 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_r, 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=attr_dict['min_nsamps'].default, toa_freq=attr_dict['toa_freq'].default, nchans=attr_dict['nchans'].default)[source]#
Bases:
objectExtracts a data block from a filterbank file centered on a pulse.
The extracted block is centered on the given pulse toa at the desired 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 toa_freq.
- pulse_width
int Width of the pulse in samples.
- pulse_dm
float Dispersion measure of the pulse.
- toa_freq
float, optional Frequency at which the pulse toa is given, by default None (highest frequency)
- nchans
int, optional Number of channels to extract, by default None (all channels)
- 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
- filfile
- Attributes:
block_delayint: Dispersion Block size in samples.
disp_delayint: Dispersion delay in samples.
- filfile
- min_nsamps
- nchans
nsampsint: Number of samples in the output block.
nsamps_fileint: Number of samples to read in the file.
nstartint: Start sample of the output block.
nstart_fileint: Start sample to read in the file.
- pulse_dm
- pulse_toa
pulse_toa_blockint: Time of arrival of the pulse in the output block.
- pulse_width
- sub_hdr
t_decimateint: Decimation factor to consider.
- toa_freq
Methods
get_data([pad_mode])Extract the filterbank block centered on the pulse.
- filfile#
- pulse_toa#
- pulse_width#
- pulse_dm#
- min_nsamps#
- toa_freq#
- nchans#
- sub_hdr#
- property t_decimate#
int: Decimation factor to consider.
- property disp_delay#
int: Dispersion delay in samples.
- property block_delay#
int: Dispersion Block size in samples.
- property nsamps#
int: Number of samples in the output block.
- property nstart#
int: Start sample of the output block.
- property nstart_file#
int: Start sample to read in the file.
- property nsamps_file#
int: Number of samples to read in the file.
- property pulse_toa_block#
int: Time of arrival of the pulse in the output block.
- get_data(pad_mode='median')[source]#
Extract the filterbank block centered on the pulse.
- Parameters:
- pad_mode{‘median’, ‘mean’}, optional
Mode for padding the data, by default “median”
- Returns:
FilterbankBlockData block.