open

baseband_tasks.io.hdf5.base.open(filename, mode='r', **kwargs)[source] [edit on github]

Open an HDF5 file as a stream.

This yields a filehandle wrapped around an HDF file that has methods for reading and writing to the file as if it were a stream of samples.

Parameters
namestr, File, of Group

File name, filehandle, or group containing header and payload.

mode{‘r’, ‘w’}, optional

Whether to open for reading (default) or writing.

**kwargs

Additional arguments when opening the file for writing.

— For reading(see HDF5StreamReader)
squeezebool, optional

If True (default), remove any dimensions of length unity from decoded data.

subsetindexing object, optional

Specific components of the complete sample to decode (after possibly squeezing).

— For writing(see HDF5StreamWriter)
header0HDF5Header

Header for the first frame, holding time information, etc. Can instead give a template or keyword arguments to construct a header from.

squeezebool, optional

If True, writer accepts squeezed arrays as input, and adds any dimensions of length unity. Default: True unless a template is given.

templateheader or stream template, optional

Must have attributes defining the required header keywords (see below).

wholebool, optional

If True, assume a header for the complete stream is wanted, and use ‘start_time’ for the ‘time’ and the total number of samples for ‘samples_per_frame’. Default: True if the template has both ‘start_time’ and ‘shape’ (i.e., for streams). Ignored if template is not given.

verifybool, optional

Whether to do basic verification. Default: True.

**kwargs

Any additional values for constructing a header. If template is given, these will override its values.

— Header keywords(see baseband_tasks.io.hdf5.HDF5Header.fromvalues())
sample_shapetuple

Shape of the individual samples.

samples_per_frameint

Number of complete samples per frame. Typically, only one frame is used, so this is the total number of samples to be stored.

sample_rateQuantity

Number of complete samples per second, i.e. the rate at which each channel of each polarization is sampled.

dtypestr or dtype

Data type of the raw data. Should only be given if bps and complex_data are not given.

encoded_dtypestr or dtype, optional

Data type of the encoded data. By default, equal to dtype, but can be used to reduce the precision, e.g., to half-precision with ‘f2’ for real-valued data or the custom ‘c4’ dtype for complex. Should only be given if bps and complex_data are not given.

complex_databool, optional

Whether encoded data are complex (default: False). Should only be given if dtype is not given.

bpsint, optional

Bits per elementary sample, i.e. per real or imaginary component for complex data (default: 8). Should only be given if dtype is not given.

Returns
Filehandle

HDF5StreamReader or HDF5StreamWriter (stream).