VDIFFrameSet

class baseband.vdif.VDIFFrameSet(frames, header0=None)[source] [edit on github]

Bases: object

Representation of a set of VDIF frames, combining different threads.

Parameters:
frameslist of VDIFFrame

Should all cover the same time span.

header0VDIFHeader

First header of the frame set. If None (default), is extracted from frames[0].

Notes

The FrameSet can also be read instantiated using class methods:

fromfile : read frames from a filehandle, optionally selecting threads

fromdata : encode data as a set of frames

Of course, one can also do the opposite:

tofile : write frames to filehandle

data : property that yields full decoded frame payloads

One can decode part of the payload by indexing or slicing the frame. If the frame does not contain valid data, all values returned are set to self.fill_value.

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. Like a VDIFFrame, the frame set acts as a dictionary, with keys those of the header of the first frame (available via .header0). Any attribute that is not defined on the frame set itself, such as .time will also be looked up on the header.

Attributes Summary

data

Full decoded frame.

dtype

Numeric type of the frameset data.

fill_value

Value to replace invalid data in the frameset.

nbytes

Size of the encoded frame in bytes.

ndim

Number of dimensions of the frameset data.

sample_shape

Shape of a sample in the frameset (nthread, nchan).

shape

Shape of the frameset data.

size

Total number of component samples in the frameset data.

valid

Whether frameset contains valid data.

Methods Summary

fromdata(data[, headers, verify])

Construct a set of frames from data and headers.

fromfile(fh[, thread_ids, edv, verify])

Read a frame set from a file, starting at the current location.

keys()

tofile(fh)

Write all encoded frames to filehandle.

Attributes Documentation

data

Full decoded frame.

dtype

Numeric type of the frameset data.

fill_value

Value to replace invalid data in the frameset.

nbytes

Size of the encoded frame in bytes.

ndim

Number of dimensions of the frameset data.

sample_shape

Shape of a sample in the frameset (nthread, nchan).

shape

Shape of the frameset data.

size

Total number of component samples in the frameset data.

valid

Whether frameset contains valid data.

Methods Documentation

classmethod fromdata(data, headers=None, verify=True, **kwargs)[source] [edit on github]

Construct a set of frames from data and headers.

Parameters:
datandarray

Array holding complex or real data to be encoded. Dimensions should be (samples_per_frame, nthread, nchan).

headersVDIFHeader, list of same, or None

If a single header, a list with increasing thread_id is generated. If not given, will attempt to generate a header from the keyword arguments.

verifybool

Whether or not to do basic assertions that check the integrety (e.g., that channel information and whether or not data are complex are consistent between header and data). Default: True.

**kwargs

If header is not given, these are used to initialize one.

Returns:
framesetVDIFFrameSet
classmethod fromfile(fh, thread_ids=None, edv=None, verify=True)[source] [edit on github]

Read a frame set from a file, starting at the current location.

Parameters:
fhfilehandle

Handle to the VDIF file. Should be at the location where the frames are read from.

thread_idslist or None, optional

The thread ids that should be read. If None (default), continue reading threads as long as the frame number does not increase.

edvint or None, optional

The expected extended data version for the VDIF Header. If None (default), use that of the first frame. (Passing it in slightly improves file integrity checking.)

verifybool, optional

Whether to do (light) sanity checks on the header. Default: True.

Returns:
framesetVDIFFrameSet

Its frames property holds a list of frames (in order of either their thread_id or following the input thread_ids list). Use the data attribute to convert to an array.

keys()[source] [edit on github]
tofile(fh)[source] [edit on github]

Write all encoded frames to filehandle.