VDIFFileReader

class baseband.vdif.base.VDIFFileReader(fh_raw)[source] [edit on github]

Bases: baseband.vlbi_base.base.VLBIFileReaderBase

Simple reader for VDIF files.

Wraps a binary filehandle, providing methods to help interpret the data, such as read_frame, read_frameset and get_frame_rate.

Parameters:

fh_raw : filehandle

Filehandle of the raw binary data file.

Attributes Summary

info

Methods Summary

close()
find_header([template_header, frame_nbytes, …]) Find the nearest header from the current position.
get_frame_rate() Determine the number of frames per second.
read_frame() Read a single frame (header plus payload).
read_frameset([thread_ids, edv, verify]) Read a single frame (header plus payload).
read_header() Read a single header from the file.

Attributes Documentation

info

Methods Documentation

close() [edit on github]
find_header(template_header=None, frame_nbytes=None, edv=None, maximum=None, forward=True)[source] [edit on github]

Find the nearest header from the current position.

Search for a valid header at a given position which is consistent with template_header or with a header a frame size ahead. Note that the latter turns out to be an unexpectedly weak check on real data!

If successful, the file pointer is left at the start of the header.

Parameters:

template_header : VDIFHeader

If given, used to infer the frame size and EDV.

frame_nbytes : int

Frame size in bytes, used if template_header is not given.

edv : int

EDV of the header, used if template_header is not given.

maximum : int, optional

Maximum number of bytes forward to search through. Default: twice the frame size.

forward : bool, optional

Seek forward if True (default), backward if False.

Returns:

header : VDIFHeader or None

Retrieved VDIF header, or None if nothing found.

get_frame_rate()[source] [edit on github]

Determine the number of frames per second.

This method first tries to determine the frame rate by looking for the highest frame number in the first second of data. If that fails, it attempts to extract the sample rate from the header.

Returns:

frame_rate : Quantity

Frames per second.

read_frame()[source] [edit on github]

Read a single frame (header plus payload).

Returns:

frame : VDIFFrame

With .header and .data properties that return the VDIFHeader and data encoded in the frame, respectively.

read_frameset(thread_ids=None, edv=None, verify=True)[source] [edit on github]

Read a single frame (header plus payload).

Parameters:

thread_ids : list, optional

The thread ids that should be read. If None (default), read all threads.

edv : int, optional

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

verify : bool, optional

Whether to do basic checks of frame integrity. Default: True.

Returns:

frameset : VDIFFrameSet

With .headers and .data properties that return a list of VDIFHeaders and the data encoded in the frame set, respectively.

read_header()[source] [edit on github]

Read a single header from the file.

Returns:header : VDIFHeader