sigpyproc.io module#
sigpyproc.io.sigproc#
- sigpyproc.io.sigproc.edit_header(filename, key, value)#
Edit a sigproc style header directly in place for the given file.
- Parameters:
- Raises:
ValueError – if the new header to be written to file is longer or shorter than the header that was previously in the file.
Notes
It is up to the user to be responsible with this function, as it will directly change the file on which it is being operated.
- sigpyproc.io.sigproc.parse_header_multi(filenames, check_contiguity=True)#
Parse the metadata from Sigproc-style file/sequential files.
- sigpyproc.io.sigproc.parse_header(filename)#
Parse the metadata from a single Sigproc-style file.
- sigpyproc.io.sigproc.match_header(header1, header2)#
Match header keywords between two parsed sigproc headers.
- Parameters:
- Raises:
ValueError – if key values do not match.
- sigpyproc.io.sigproc.ensure_contiguity(header)#
Check if list of sigproc files are contiguous/sequential.
- Parameters:
header (
dict) – parsed header of sigproc files- Raises:
ValueError – if files are not contiguous
- sigpyproc.io.sigproc.encode_header(header)#
Get sigproc format header in binary format.
- Returns:
header in binary format
- Return type:
- sigpyproc.io.sigproc.encode_key(key, value=None, value_type='str')#
Encode given header key to a bytes string.
sigpyproc.io.bits#
- sigpyproc.io.bits.unpack(array, nbits)#
Unpack 1, 2 and 4 bit array. Only unpacks in big endian bit ordering.
- Parameters:
array (
numpy.ndarray) – Array to unpack.nbits (
int) – Number of bits to unpack.
- Returns:
Unpacked array.
- Return type:
- Raises:
ValueError – if nbits is not 1, 2, or 4
- sigpyproc.io.bits.pack(array, nbits)#
Pack 1, 2 and 4 bit array. Only packs in big endian bit ordering.
- Parameters:
array (
numpy.ndarray) – Array to pack.nbits (
int) – Number of bits to pack.
- Returns:
Packed array.
- Return type:
- Raises:
ValueError – if nbits is not 1, 2, or 4
- class sigpyproc.io.bits.BitsInfo(nbits, digi_sigma=_Nothing.NOTHING)#
Bases:
objectClass to handle bits info.
- Raises:
ValueError – if input nbits not in [1, 2, 4, 8, 16, 32]
- nbits#
- digi_sigma#
- default_sigma = {1: 0.5, 2: 1.5, 4: 6, 8: 6, 16: 6, 32: 6}#
- property dtype#
Type of the data (np.dtype, read-only).
- property itemsize#
Element size of this data-type object (int, read-only).
- property unpack#
Whether to unpack bits (bool, read-only).
- property bitfact#
Bit factor to unpack/pack bits (int, read-only).
- property digi_min#
Minimum value used to quantize data (int, read-only).
- property digi_max#
Maximum value used to quantize data (int, read-only).
- property digi_mean#
Mean used to quantize data (float, read-only).
- property digi_scale#
Scale used to quantize data (float, read-only).
sigpyproc.io.fileio#
- class sigpyproc.io.fileio.FileReader(files, hdrlens, datalens, mode='r', nbits=8)#
Bases:
_FileBaseA file reader class that can read from multiple files.
Files should have format similar to
sigproc.- Parameters:
files (
list[str]) – list of files to be read fromhdrlens (
list[int]) – list of header lengths for each filedatalens (
list[int]) – list of data lengths for each filemode (
str, optional) – file opening mode, by default “r”nbits (
int, optional) – number of bits per sample in the files, by default 8
- cread(nunits)#
Read nunits (nbytes) of data from the file.
- seek(offset, whence=0)#
Change the multifile stream position to the given data offset.
offset is always interpreted for a headerless file and is relative to start of the first file.
- Parameters:
- Raises:
ValueError – if whence is not 0 or 1.
- class sigpyproc.io.fileio.FileWriter(file, tsamp, nchans, mode='w', nbits=8, quantize=False, interval_seconds=10, constant_offset_scale=False, **digi_kwargs)#
Bases:
_FileBaseA file writer class that can write to a
sigprocformat file.- Parameters:
file (
str) – file to be written tomode (
str, optional) – file writing mode, by default “w”nbits (
int, optional) – number of bits per sample in the file, by default 8quantize (
bool, optional) – whether to quantize the data, by default Falsetsamp (
float, optional) – sampling time, by default Nonenchans (
int, optional) – number of channels, by default Noneinterval_seconds (
float, optional) – sample interval used for quantization in seconds, by default 10constant_offset_scale (
bool, optional) – whether to use constant offset and scale, by default False**digi_kwargs (
dict) – keyword arguments for the digitizer:digi_mean,digi_scale,digi_min,digi_max
- Raises:
ValueError – if quantize is True and outut
nbitsis 32.
- cwrite(ar)#
Write an array to file.
- Parameters:
ar (
ndarray) – a 1-D numpy array
Notes
Regardless of the dtype of the array argument, the data will be packed with a bitsize determined by the nbits attribute of the File instance. To change this attribute, use the _setNbits methods. It is the responsibility of the user to ensure that values in the array do not go beyond the maximum and minimum values allowed by the nbits attribute.
- write(bo)#
Write the given bytes-like object, bo to the file stream.
Wrapper for
io.RawIOBase.write().- Parameters:
bo (
bytes) – bytes-like object
- close()#
Close the currently open file object.
- class sigpyproc.io.fileio.Transform(tsamp, nchans, digi_mean, digi_scale, digi_min, digi_max, interval_seconds=10, constant_offset_scale=False)#
Bases:
objectA class to transform data to the quantized format.
- Parameters:
tsamp (
float) – sampling time, by default Nonenchans (
int) – number of channels, by default Nonedigi_mean (
float) – mean of the quantized datadigi_scale (
float) – scale of the quantized datadigi_min (
float) – minimum value of the quantized datadigi_max (
float) – maximum value of the quantized datainterval_seconds (
float, optional) – sample interval used for quantization in seconds, by default 10constant_offset_scale (
bool, optional) – whether to use constant offset and scale, by default False
- property interval_samples#
- rescale(data)#
- quantize(data)#
sigpyproc.io.pfits#
- class sigpyproc.io.pfits.Receiver(*, name, nrcvr, basis, hand, sa, rph, tracking_mode, tracking_angle)#
Bases:
objectReceiver information.
- Variables:
name (
str) – Name of the receiver.nrcvr (
int) – Number of receptors.basis (
str) – Basis of receptors.hand (
int) – Hand of receptor basis.sa (
float) – Symmetry angle of receptor basis.rph (
float) – Reference source phase.tracking_mode (
str) – Tracking mode of the receiver platform.tracking_angle (
float) – Position angle tracked by the receiver.
- name#
- nrcvr#
- basis#
- hand#
- sa#
- rph#
- tracking_mode#
- tracking_angle#
- class sigpyproc.io.pfits.Backend(*, name, phase, dcc, delay, tcycle, configfile)#
Bases:
objectBackend information.
- Variables:
name (
str) – Name of the backend instrument.phase (
float) – Phase convention of backend.dcc (
float) – Downconversion conjugation corrected.delay (
float) – Backend propn delay from digi. input.tcycle (
float) – Native cycle time of correlation system.configfile (
str) – Name of a configuration file used to set up the backend system.
- name#
- phase#
- dcc#
- delay#
- tcycle#
- configfile#
- class sigpyproc.io.pfits.PrimaryHdr(filename)#
Bases:
object- property header#
Primary header.
- Type:
- property location#
Antenna location.
- property receiver#
Receiver information.
- Type:
Receiver
- property backend#
Backend information.
- Type:
Backend
- property date_obs#
Observation start date.
- Type:
- property freqs#
Frequency channels.
- Type:
- property chan_dm#
Dispersion measure value used for on-line (normally coherent) dedispersion.
- Type:
- property coord#
Source coordinates.
- property tstart#
Observation start time.
- Type:
- class sigpyproc.io.pfits.SubintHdr(filename)#
Bases:
object- property header#
SUBINT header.
- Type:
- property subint_shape#
- property sub_hdr#
- property offs_sub#
Time since the observation start at the centre of first sub-integration (seconds).
- Type:
- property azimuth#
Azimuth (degrees).
- property zenith#
Zenith (degrees).
- property freqs#
Frequency channels for first subint.
- class sigpyproc.io.pfits.PFITSFile(filename)#
Bases:
objectHandle a PSRFITS file.
- Parameters:
filename (
str) – Filename of the PSRFITS file.
- property pri_hdr#
Primary header.
- Type:
- read_subints(startsub, nsubs, poln_select=1, scloffs=True, weights=True)#
Read the digitised data in a given polarization format from a range of PSRFITS SUBINT table.
- Parameters:
startsub (
int) – index of start row (subint) to read from the SUBINT tablensubs (
int) – number of subints to read from the SUBINT tablepoln_select (
int, optional) – 1=PP+QQ, 2=PP,QQ, 3=(PP+QQ)^2 4=PP,QQ,PQ,QP, by default 1scloffs (
bool, optional) – apply scales and offsets when unpacking data, by default Falseweights (
bool, optional) – apply weights when unpacking data, by default False
- Returns:
subint (row) data in float32 if scloffs or weights applied, otherwise in uint8 with shape (nsamps, nchan).
- Return type:
- read_subint_pol(isub, poln_select=1, scloffs=True, weights=True)#
Read the digitised data in a given polarization format from the PSRFITS SUBINT table.
- Parameters:
isub (
int) – index of row (subint) to read from the SUBINT tablepoln_select (
int, optional) – 1=PP+QQ, 2=PP,QQ, 3=(PP+QQ)^2 4=PP,QQ,PQ,QP, by default 1scloffs (
bool, optional) – apply scales and offsets when unpacking data, by default Trueweights (
bool, optional) – apply weights when unpacking data, by default True
- Returns:
subint (row) data in float32 if scloffs or weights applied, otherwise in uint8 with shape (nsamps, nchan).
- Return type:
- read_subint(isub, scloffs=True, weights=True)#
Read the digitised data from the PSRFITS SUBINT table.
- Parameters:
- Returns:
subint (row) data in float32 if scale_and_offset or weights applied, otherwise in uint8 with shape (nsamps, npol, nchan).
- Return type:
- read_freqs(isub)#
Read the Channel centre frequency from the PSRFITS SUBINT table.
- Parameters:
isub (
int) – index of row (subint) to read from the SUBINT table- Returns:
Centre frequency for each channel in MHz (NCHAN)
- Return type:
FrequencyChannels
- read_weights(isub)#
Read channel weight (DAT_WTS) column from the SUBINT table.
- Parameters:
isub (
int) – index of row (subint) to read from the SUBINT table- Returns:
Weights for each channel in the range 0-1 (NCHAN)
- Return type:
- read_scales(isub)#
Read channel data scale factor (DAT_SCL) column from the SUBINT table.
- Parameters:
isub (
int) – index of row (subint) to read from the SUBINT table- Returns:
Data scale factor for each channel (NCHAN*NPOL)
- Return type: