GSBStreamReader

class baseband.gsb.base.GSBStreamReader(fh_ts, fh_raw, sample_rate=None, samples_per_frame=None, payload_nbytes=None, nchan=None, bps=None, complex_data=None, squeeze=True, subset=(), verify=True)[source] [edit on github]

Bases: GSBStreamBase, StreamReaderBase

GSB format reader.

Allows access to GSB files as a continuous series of samples. Requires both a timestamp and one or more corresponding raw data files.

Parameters:
fh_tsfilehandle

For reading timestamps.

fh_rawfilehandle, or nested tuple of filehandles

Raw binary data filehandle(s). A single file is needed for rawdump, and a tuple for phased. For a nested tuple, the outer tuple determines the number of polarizations, and the inner tuple(s) the number of streams per polarization. E.g., ((polL1, polL2), (polR1, polR2)) for two streams per polarization. A single tuple is interpreted as streams of a single polarization.

sample_rateQuantity, optional

Number of complete samples per second, i.e. the rate at which each channel of each polarization is sampled. If None, will be inferred assuming the frame rate is exactly 0.25165824 s.

samples_per_frameint, optional

Number of complete samples per frame (possibly combining two files). Can give payload_nbytes instead.

payload_nbytesint, optional

Number of bytes per payload (in each raw file separately). If both samples_per_frame and payload_nbytes are None, payload_nbytes is set to 2**22 (4 MiB).

nchanint, optional

Number of channels. Default: 1 for rawdump, 512 for phased.

bpsint, optional

Bits per elementary sample, i.e. per real or imaginary component for complex data. Default: 4 for rawdump, 8 for phased.

complex_databool, optional

Whether data are complex. Default: False for rawdump, True for phased.

squeezebool, optional

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

subsetindexing object or tuple of objects, optional

Specific components of the complete sample to decode (after possibly squeezing). If a single indexing object is passed, it selects (available) polarizations. If a tuple is passed, the first selects polarizations and the second selects channels. If the tuple is empty (default), all components are read.

verifybool, optional

Whether to do basic checks of frame integrity when reading. The first frame of the stream is always checked. Default: True.

Attributes Summary

bps

Bits per elementary sample.

complex_data

Whether the data are complex.

dtype

fill_value

Value to use for invalid or missing data.

header0

First header of the file.

info

ndim

Number of dimensions of the (squeezed/subset) stream data.

payload_nbytes

Number of bytes per payload, divided by the number of raw files.

sample_rate

Number of complete samples per second.

sample_shape

Shape of a complete sample (possibly subset or squeezed).

samples_per_frame

Number of complete samples per frame.

shape

Shape of the (squeezed/subset) stream data.

size

Total number of component samples in the (squeezed/subset) stream data.

squeeze

Whether data arrays have dimensions with length unity removed.

start_time

Start time of the file.

stop_time

Time at the end of the file, just after the last sample.

subset

Specific components of the complete sample to decode.

time

Time of the sample pointer's current offset in file.

verify

Whether to do consistency checks on frames being read.

Methods Summary

close()

read([count, out])

Read a number of complete samples.

readable()

Whether the file can be read and decoded.

seek(offset[, whence])

Change the sample pointer position.

tell([unit])

Current offset in the file.

Attributes Documentation

bps

Bits per elementary sample.

complex_data

Whether the data are complex.

dtype
fill_value

Value to use for invalid or missing data. Default: 0.

header0

First header of the file.

info
ndim

Number of dimensions of the (squeezed/subset) stream data.

payload_nbytes

Number of bytes per payload, divided by the number of raw files.

sample_rate
sample_shape

Shape of a complete sample (possibly subset or squeezed).

samples_per_frame

Number of complete samples per frame.

shape

Shape of the (squeezed/subset) stream data.

size

Total number of component samples in the (squeezed/subset) stream data.

squeeze

Whether data arrays have dimensions with length unity removed.

If True, data read out has such dimensions removed, and data passed in for writing has them inserted.

start_time

Start time of the file.

See also time for the time of the sample pointer’s current offset, and (if available) stop_time for the time at the end of the file.

stop_time

Time at the end of the file, just after the last sample.

See also start_time for the start time of the file, and time for the time of the sample pointer’s current offset.

subset

Specific components of the complete sample to decode.

The order of dimensions is the same as for sample_shape. Set by the class initializer.

time

Time of the sample pointer’s current offset in file.

See also start_time for the start time, and (if available) stop_time for the end time, of the file.

verify

Whether to do consistency checks on frames being read.

Methods Documentation

close() [edit on github]
read(count=None, out=None) [edit on github]

Read a number of complete samples.

Parameters:
countint or None, optional

Number of complete samples to read. If None (default) or negative, the number of samples left. Ignored if out is given.

outNone or array, optional

Array to store the samples in. If given, count will be inferred from the first dimension; the remaining dimensions should equal sample_shape.

Returns:
outndarray of float or complex

The first dimension is sample-time, and the remaining ones are as given by sample_shape.

readable()[source] [edit on github]

Whether the file can be read and decoded.

seek(offset, whence=0) [edit on github]

Change the sample pointer position.

This works like a normal filehandle seek, but the offset is in samples (or a relative or absolute time).

Parameters:
offsetint, Quantity, or Time

Offset to move to. Can be an (integer) number of samples, an offset in time units, or an absolute time. For the latter two, the pointer will be moved to the nearest integer sample.

whence{0, 1, 2, ‘start’, ‘current’, or ‘end’}, optional

Like regular seek, the offset is taken to be from the start if whence=0 (default), from the current position if 1, and from the end if 2. One can alternativey use ‘start’, ‘current’, or ‘end’ for 0, 1, or 2, respectively. Ignored if offset is a time.

tell(unit=None) [edit on github]

Current offset in the file.

Parameters:
unitUnit or str, optional

Time unit the offset should be returned in. By default, no unit is used, i.e., an integer enumerating samples is returned. For the special string ‘time’, the absolute time is calculated.

Returns:
offsetint, Quantity, or Time

Offset in current file (or time at current position).