sigpyproc.base#
- class sigpyproc.base.Filterbank#
Bases:
ABCBase 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.
- abstract read_block(start, nsamps)#
Read a block of filterbank data.
- Parameters:
- Returns:
2-D array of filterbank data with observational metadata
- Return type:
- Raises:
ValueError – if requested samples are out of range
- abstract 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:
- Returns:
2-D array of filterbank data with observational metadata
- Return type:
- Raises:
ValueError – if requested dedispersed samples are out of range
- abstract 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 16384start (
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 0description (
str, optional) – description of task show next to progress bar (rich), by default Calling Stackquiet (
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 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, ii, data in self.read_plan(**plan_kwargs): # do something where data always has contains ``nchans*nsamps`` points.
- property chan_stats#
Channel statistics of input data.
- Type:
- compute_stats(**plan_kwargs)#
Compute channelwise statistics of data (upto kurtosis).
- Parameters:
**plan_kwargs (
dict) – Keyword arguments forread_plan().
- compute_stats_basic(**plan_kwargs)#
Compute channelwise statistics of data (only mean and rms).
- Parameters:
**plan_kwargs (
dict) – Keyword arguments forread_plan().
- collapse(gulp=16384, start=0, nsamps=None, **plan_kwargs)#
Sum across all frequencies for each time sample.
- Parameters:
gulp (
int, optional) – number of samples in each read, by default 16384start (
int, optional) – start sample, by default 0nsamps (
int, optional) – number of samples to read, by default all**plan_kwargs (
dict) – Additional Keyword arguments forread_plan().
- Returns:
A zero-DM time series
- Return type:
- bandpass(**plan_kwargs)#
Average across each time sample for all frequencies.
- Parameters:
**plan_kwargs (
dict) – Keyword arguments forread_plan().- Returns:
the bandpass of the data
- Return type:
- dedisperse(dm, gulp=16384, **plan_kwargs)#
Dedisperse the data and collapse to a time series.
- Parameters:
dm (
float) – dispersion measure to dedisperse togulp (
int, optional) – number of samples in each read, by default 16384**plan_kwargs (
dict) – Additional keyword arguments forread_plan().
- Returns:
a dedispersed time series
- Return type:
Notes
If gulp < maximum dispersion delay, gulp is taken to be twice the maximum dispersion delay.
- read_chan(chan, gulp=16384, **plan_kwargs)#
Read a single frequency channel from the data as a time series.
- Parameters:
chan (
int) – channel to retrieve (0 is the highest frequency channel)gulp (
int, optional) – number of samples in each read, by default 16384**plan_kwargs (
dict) – Additional keyword arguments forread_plan().
- Returns:
selected channel as a time series
- Return type:
- Raises:
ValueError – If chan is out of range (chan < 0 or chan > total channels).
- invert_freq(filename=None, **plan_kwargs)#
Invert the frequency ordering of the data and write to a new file.
- Parameters:
filename (
str, optional) – name of output file, by defaultbasename_inverted.fil**plan_kwargs (
dict) – Additional keyword arguments forread_plan().
- Returns:
name of output file
- Return type:
- apply_channel_mask(chanmask, maskvalue=0, filename=None, **plan_kwargs)#
Apply a channel mask to the data and write to a new file.
- Parameters:
chanmask (
ArrayLike) – boolean array of channel mask (1 or True for bad channel)maskvalue (
intorfloat, optional) – value to set the masked data to, by default 0filename (
str, optional) – name of the output filterbank file, by defaultbasename_masked.fil**plan_kwargs (
dict) – Additional keyword arguments forread_plan().
- Returns:
name of output file
- Return type:
- downsample(tfactor=1, ffactor=1, gulp=16384, filename=None, **plan_kwargs)#
Downsample data in time and/or frequency and write to file.
- Parameters:
tfactor (
int, optional) – factor by which to downsample in time, by default 1ffactor (
int, optional) – factor by which to downsample in frequency, by default 1gulp (
int, optional) – number of samples in each read, by default 16384filename (
str, optional) – name of file to write to, by defaultbasename_tfactor_ffactor.fil**plan_kwargs (
dict) – Additional keyword arguments forread_plan().
- Returns:
output file name
- Return type:
- Raises:
ValueError – If number of channels is not divisible by ffactor.
- extract_samps(start, nsamps, filename=None, **plan_kwargs)#
Extract a subset of time samples from the data and write to file.
- Parameters:
start (
int) – start sample to extractnsamps (
int) – number of samples to extractfilename (
str, optional) – name of output file, by defaultbasename_samps_start_start+nsamps.fil**plan_kwargs (
dict) – Additional keyword arguments forread_plan().
- Returns:
name of new file
- Return type:
- Raises:
ValueError – If start or nsamps are out of bounds.
- extract_chans(chans=None, **plan_kwargs)#
Extract a subset of channels from the data and write each to file.
- Parameters:
chans (
ArrayLike, optional) – channel numbers to extract, by default all channels**plan_kwargs (
dict) – Keyword arguments forread_plan().
- Returns:
names of all files written to disk
- Return type:
- Raises:
ValueError – If chans are out of range (chan < 0 or chan > total channels).
Notes
Time series are written to disk with names based on channel number.
- extract_bands(chanstart, nchans, chanpersub=None, **plan_kwargs)#
Extract a subset of Sub-bands from the data and write each to file.
- Parameters:
chanstart (
int) – start channel to extractnchans (
int) – number of channel to extractchanpersub (
int, optional) – number of channels in each sub-band, by defaultnchans**plan_kwargs (
dict) – Keyword arguments forread_plan().
- Returns:
names of all files written to disk
- Return type:
- Raises:
ValueError – If
chanpersubis less than 1 or greater thannchans.ValueError – If
nchansis not divisible bychanpersub.ValueError – If
chanstartis out of range (chanstart< 0 orchanstart> total channels).
Notes
Filterbanks are written to disk with names based on sub-band number.
- requantize(nbits_out, remove_bandpass=False, filename=None, **plan_kwargs)#
Eequantize the data and write to a new file.
- Parameters:
nbits_out (
int) – number of bits into requantize the dataremove_bandpass (
bool, optional) – remove the bandpass from the data, by default Falsefilename (
str, optional) – name of output file, by defaultbasename_digi.fil**plan_kwargs (
dict) – Keyword arguments forread_plan().
- Returns:
name of output file
- Return type:
- Raises:
ValueError – If
nbits_outis less than 1 or greater than 32.
- remove_zerodm(filename=None, **plan_kwargs)#
Remove the channel-weighted zero-DM from the data and write to disk.
- Parameters:
filename (
str, optional) – name of output file , by defaultbasename_noZeroDM.fil**plan_kwargs (
dict) – Keyword arguments forread_plan().
- Returns:
name of output file
- Return type:
Notes
Based on Presto implementation of Eatough, Keane & Lyne 2009 [1].
References
- subband(dm, nsub, filename=None, gulp=16384, **plan_kwargs)#
Produce a set of dedispersed subbands from the data.
- Parameters:
dm (
float) – the DM of the subbandsnsub (
int) – the number of subbands to producefilename (
str, optional) – output file name of subbands, by defaultbasename_DM.subbandsgulp (
int, optional) – number of samples in each read, by default 16384**plan_kwargs (
dict) – Additional keyword arguments forread_plan().
- Returns:
name of output subbands file
- Return type:
- fold(period, dm, accel=0, nbins=50, nints=32, nbands=32, gulp=16384, **plan_kwargs)#
Fold data into discrete phase, subintegration and subband bins.
- Parameters:
period (
float) – period in seconds to fold withdm (
float) – dispersion measure to dedisperse toaccel (
float, optional) – acceleration in m/s/s to fold with, by default 0nbins (
int, optional) – number of phase bins in output, by default 50nints (
int, optional) – number of subintegrations in output, by default 32nbands (
int, optional) – number of subbands in output, by default 32gulp (
int, optional) – number of samples in each read, by default 16384**plan_kwargs (
dict) – Additional keyword arguments forread_plan().
- Returns:
3 dimensional data cube
- Return type:
- 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.
- clean_rfi(method='mad', threshold=3, chanmask=None, custom_funcn=None, filename=None, **plan_kwargs)#
Clean RFI from the data.
- Parameters:
method (
str, optional) – method to use for cleaning (“mad”, “iqrm”), by default “mad”threshold (
float, optional) – threshold for cleaning, by default 3chanmask (
ArrayLike, optional) – User channel mask to use (1 or True for bad channels), by default Nonecustom_funcn (
Callable, optional) – Custom function to apply to the mask, by default Nonefilename (
str, optional) – output file name, by default None**plan_kwargs (
dict) – Additional keyword arguments forread_plan().
- Returns:
Filename and mask of cleaned data
- Return type:
tuple(str,RFIMask)- Raises:
ValueError – If method is not “mad” or “iqrm”