sigpyproc.io module
Contents
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)¶
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:
sigpyproc.io.fileio._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:
sigpyproc.io.fileio._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)¶