GSBFrame

class baseband.gsb.GSBFrame(header, payload, valid=None, verify=True)[source] [edit on github]

Bases: FrameBase

Frame encapsulating GSB rawdump or phased data.

For rawdump data, lines in the timestamp file are associated with single blocks of raw data. For phased data, the lines are associated with one or two polarisations, each consisting of two blocks of raw data. Hence, the raw data come from two or four files.

Parameters:
headerGSBHeader

Based on line from rawdump or phased timestamp file.

payloadGSBPayload

Based on a single block of rawdump data, or the combined blocks for phased data.

validbool, optional

Whether the data are valid. Default: True.

verifybool, optional

Whether to verify consistency of the frame parts. Default: True.

Notes

GSB files do not support storing whether data are valid or not on disk. Hence, this has to be determined independently. If valid=False, any decoded data are set to cls.fill_value (by default, 0).

The Frame can also be read instantiated using class methods:

fromfile : read header and payload from their respective filehandles

fromdata : encode data as payload

Of course, one can also do the opposite:

tofilemethod to write header and payload to filehandles (splitting

payload in the appropriate files).

data : property that yields full decoded payload

A number of properties are defined: shape, dtype and size are the shape, type and number of complete samples of the data array, and nbytes the frame size in bytes. Furthermore, the frame acts as a dictionary, with keys those of the header. Any attribute that is not defined on the frame itself, such as .time will be looked up on the header as well.

Attributes Summary

data

Full decoded frame.

dtype

Numeric type of the frame data.

fill_value

Value to replace invalid data in the frame.

nbytes

Size of the encoded frame in the raw data file in bytes.

ndim

Number of dimensions of the frame data.

sample_shape

Shape of a sample in the frame (nchan,).

shape

Shape of the frame data.

size

Total number of component samples in the frame data.

valid

Whether frame contains valid data.

Methods Summary

fromdata(data[, header, bps, valid, verify])

Construct frame from data and header.

fromfile(fh_ts, fh_raw[, payload_nbytes, ...])

Read a frame from timestamp and raw data filehandles.

keys()

tofile(fh_ts, fh_raw)

Write encoded frame to timestamp and raw data filehandles.

verify()

Simple verification.

Attributes Documentation

data

Full decoded frame.

dtype

Numeric type of the frame data.

fill_value

Value to replace invalid data in the frame.

nbytes

Size of the encoded frame in the raw data file in bytes.

ndim

Number of dimensions of the frame data.

sample_shape

Shape of a sample in the frame (nchan,).

shape

Shape of the frame data.

size

Total number of component samples in the frame data.

valid

Whether frame contains valid data.

Methods Documentation

classmethod fromdata(data, header=None, *, bps=4, valid=True, verify=True, **kwargs)[source] [edit on github]

Construct frame from data and header.

Parameters:
datandarray

Array holding data to be encoded.

headercls._header_class

Header for the frame.

bpsint, optional

Bits per elementary sample. Default: 4.

validbool, optional

Whether this payload contains valid data.

verifybool, optional

Whether to verify the header and frame correctness.

**kwargs

Used to intialize the header, if not given.

classmethod fromfile(fh_ts, fh_raw, payload_nbytes=4194304, sample_shape=(1,), bps=4, complex_data=False, valid=True, verify=True)[source] [edit on github]

Read a frame from timestamp and raw data filehandles.

Any arguments beyond the filehandle are used to help initialize the payload, except for valid and verify, which are passed on to the header and class initializers.

Parameters:
fh_tsfilehandle

To the timestamp file. The next line will be read.

fh_rawfile_handle or tuple

Should be a single handle for a rawdump data frame, or a tuple containing tuples with pairs of handles for a phased one. E.g., ((L1, L2), (R1, R2)) for left and right polarisations.

payload_nbytesint, optional

Size of the individual payloads in bytes. Default: 2**22 (4 MB).

sample_shapetuple, optional

Shape of the samples (e.g., (nchan,)). Default: (1,).

bpsint, optional

Bits per elementary sample. Default: 4.

complex_databool, optional

Whether data are complex. Default: False.

validbool, optional

Whether the data are valid (default: True). Note that this cannot be inferred from the header or payload itself. If False, any data read will be set to cls.fill_value.

verifybool, optional

Whether to verify consistency of the frame parts. Default: True.

keys() [edit on github]
tofile(fh_ts, fh_raw)[source] [edit on github]

Write encoded frame to timestamp and raw data filehandles.

Parameters:
fh_tsfilehandle

To the timestamp file. A line will be added to it.

fh_rawfile_handle or tuple

Should be a single handle for a rawdump data frame, or a tuple containing tuples with pairs of handles for a phased one. E.g., ((L1, L2), (R1, R2)) for left and right polarisations.

verify() [edit on github]

Simple verification. To be added to by subclasses.