Mark5BFileReader

class baseband.mark5b.base.Mark5BFileReader(fh_raw, kday=None, ref_time=None, nchan=None, bps=2)[source] [edit on github]

Bases: baseband.vlbi_base.base.VLBIFileReaderBase

Simple reader for Mark 5B files.

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

Parameters
fh_rawfilehandle

Filehandle of the raw binary data file.

kdayint or None

Explicit thousands of MJD of the observation time. Can instead pass an approximate ref_time.

ref_timeTime or None

Reference time within 500 days of the observation time, used to infer the full MJD. Used only if kday is not given.

nchanint, optional

Number of channels. Default: 1.

bpsint, optional

Bits per elementary sample. Default: 2.

Attributes Summary

info()

Methods Summary

close(self)

find_header(self[, forward, maximum])

Find the nearest header from the current position.

get_frame_rate(self)

Determine the number of frames per second.

read_frame(self[, verify])

Read a single frame (header plus payload).

read_header(self)

Read a single header from the file.

temporary_offset(self)

Context manager for temporarily seeking to another file position.

Attributes Documentation

info

Methods Documentation

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

Find the nearest header from the current position.

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

Parameters
forwardbool, optional

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

maximumint, optional

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

Returns
headerMark5BHeader or None

Retrieved Mark 5B header, or None if nothing found.

get_frame_rate(self)[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 uses the time difference between two consecutive frames. This can fail if the headers do not store fractional seconds, or if the data rate is above 512 Mbps.

Returns
frame_rateQuantity

Frames per second.

read_frame(self, verify=True)[source] [edit on github]

Read a single frame (header plus payload).

Returns
frameMark5BFrame

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

verifybool, optional

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

read_header(self)[source] [edit on github]

Read a single header from the file.

Returns
headerMark5BHeader
temporary_offset(self) [edit on github]

Context manager for temporarily seeking to another file position.

To be used as part of a with statement:

with fh_raw.temporary_offset() [as fh_raw]:
    with-block

On exiting the with-block, the file pointer is moved back to its original position.