sigpyproc.Utils

class sigpyproc.Utils.File(filename, mode, nbits=8)[source]

Bases: _io.FileIO

A class to handle writing of arbitrary bit size data to file.

Parameters
  • filename (str()) – name of file to open

  • mode (str()) – file access mode, can be either “r”, “r+”, “w” or “a”.

  • nbits – the bit size of units to be read from or written to file

Note

The File class handles all packing and unpacking of sub-byte size data under the hood, so all calls can be made requesting numbers of units rather than numbers of bits or bytes.

cread(nunits)[source]

Read nunits of data from the file.

Parameters

nunits (int) – number of units to be read from file

Returns

an array containing the read data

Return type

numpy.ndarray

cwrite(ar)[source]

Write an array to file.

Parameters

ar (numpy.ndarray) – a numpy array

Note

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.

sigpyproc.Utils.editInplace(inst, key, value)[source]

Edit a sigproc style header in place

Parameters
  • inst (Header) – a header instance with a .filename attribute

  • key (str()) – name of parameter to change (must be a valid sigproc key)

  • value – new value to enter into header

Note

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. The only fail contition of editInplace comes when the new header to be written to file is longer or shorter than the header that was previously in the file.

sigpyproc.Utils.nearestFactor(n, val)[source]

Find nearest factor.

Parameters
  • n (int) – number that we wish to factor

  • val (int) – number that we wish to find nearest factor to

Returns

nearest factor

Return type

int

sigpyproc.Utils.rollArray(y, shift, axis)[source]

Roll the elements in the array by ‘shift’ positions along the given axis.

Args: y – array to roll shift – number of bins to shift by axis – axis to roll along

Returns: shifted Ndarray

sigpyproc.Utils.stackRecarrays(arrays)[source]

Wrapper for stacking numpy.recarrays