sigpyproc.io.fileio#
File I/O base class and readers/writers.
This module contains the FileBase class and the FileReader and FileWriter classes for reading and writing filterbank files.
Classes
File I/O base class. |
|
A file reader class that can read from multiple files. |
|
A file writer class that can write to a |
Functions
Allocate a buffer of the given size safely using the given allocator. |
- class sigpyproc.io.fileio.FileBase(files, mode)[source]#
Bases:
objectFile I/O base class.
- Parameters:
- Attributes:
file_curstr: Name of the currently open file.
Methods
- property file_cur#
str: Name of the currently open file.
- class sigpyproc.io.fileio.FileReader(sinfo, mode='r', nbits=8)[source]#
Bases:
FileBaseA file reader class that can read from multiple files.
Files should have format similar to
sigproc.- Parameters:
- sinfo
StreamInfo stream information object containing header and data lengths
- mode
str, optional file opening mode, by default “r”
- nbits
int, optional number of bits per sample in the files, by default 8
- sinfo
- Attributes:
cur_data_pos_fileint: Current data position in the current file.
cur_data_pos_streamint: Current data position in the data stream.
Methods
cread(nunits)Read nunits data of the given number of bits from the file stream.
creadinto(read_buffer[, unpack_buffer])Read from file stream into a buffer of pre-defined length.
seek(offset[, whence])Change the file stream position to the given offset relative to the whence.
- property cur_data_pos_file#
int: Current data position in the current file.
- property cur_data_pos_stream#
int: Current data position in the data stream.
- creadinto(read_buffer, unpack_buffer=None)[source]#
Read from file stream into a buffer of pre-defined length.
- Parameters:
- Returns:
intNumber of bytes readinto the buffer
- Raises:
OSErrorif no file is open for reading
Notes
It is the responsibility of the caller to handle the case than fewer bytes than requested are read into the buffer. When at the end of the file stream the number of bytes returned will be zero.
- seek(offset, whence=0)[source]#
Change the file stream position to the given offset relative to the whence.
- Parameters:
- Raises:
ValueErrorif whence is not 0 or 1.
- class sigpyproc.io.fileio.FileWriter(file, *, mode='w', nbits=8, rescale=False)[source]#
Bases:
FileBaseA file writer class that can write to a
sigprocformat file.- Parameters:
- file
str file name to write to
- mode
str, optional file writing mode, by default “w”
- nbits
int, optional number of bits per sample in the file, by default 8
- scale_fac
float, optional Additional scale factor to apply to data, by default 1.0
- rescale
bool, optional whether to rescale the data using the nbit-dependent values, by default True
- file
Methods
cwrite(arr)Write an array to file.
write(bo)Write the given bytes-like object, bo to the file stream.
- Raises:
ValueErrorif quantize is True and outut
nbitsis 32.
- cwrite(arr)[source]#
Write an array to file.
- Parameters:
- ar
ndarray a 1-D numpy array containing the data
- ar
Notes
Input data will be packed with a bitsize determined by the nbits
- write(bo)[source]#
Write the given bytes-like object, bo to the file stream.
Wrapper for
io.RawIOBase.write.- Parameters:
- bo
bytes bytes-like object
- bo
- sigpyproc.io.fileio.allocate_buffer(allocator, nbytes)[source]#
Allocate a buffer of the given size safely using the given allocator.
- Parameters:
- Returns:
BufferA buffer object of the given size. collections.abc.Buffer (PEP 688).
- Raises:
ValueErrorif nbytes is less than or equal to zero.
RuntimeErrorif the buffer allocation fails.
TypeErrorif the allocator does not return a buffer object.
ValueErrorif the allocated buffer is not of the expected size.