Mark5BFileReader¶
- class baseband.mark5b.base.Mark5BFileReader(fh_raw, kday=None, ref_time=None, nchan=None, bps=2)[source] [edit on github]¶
Bases:
VLBIFileReaderBase
Simple reader for Mark 5B files.
Wraps a binary filehandle, providing methods to help interpret the data, such as
read_frame
andget_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_time
Time
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
Methods Summary
close
()find_header
(*args, **kwargs)Find the nearest header from the current position.
Determine the number of frames per second.
locate_frames
([pattern])Use a pattern to locate frame starts near the current position.
read_frame
([verify])Read a single frame (header plus payload).
Read a single header from the file.
temporary_offset
([offset, whence])Context manager for temporarily seeking to another file position.
Attributes Documentation
- fh_raw = None¶
- info¶
Methods Documentation
- close() [edit on github]¶
- find_header(*args, **kwargs)[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 are as for
locate_frames
.- Returns:
- header
Retrieved header.
- Raises:
- ~baseband.base.base.HeaderNotFoundError
If no header could be located.
- AssertionError
If the header did not pass verification.
- 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 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_rate
Quantity
Frames per second.
- frame_rate
- locate_frames(pattern=None, **kwargs)[source] [edit on github]¶
Use a pattern to locate frame starts near the current position.
Note that the current position is always included.
Parameters are as for
baseband.base.base.VLBIFileReaderBase.locate_frames
except that by default the Mark 5B sync pattern is used.
- read_frame(verify=True)[source] [edit on github]¶
Read a single frame (header plus payload).
- Returns:
- frame
Mark5BFrame
With
header
anddata
properties that return theMark5BHeader
and data encoded in the frame, respectively.- verifybool, optional
Whether to do basic checks of frame integrity. Default:
True
.
- frame
- read_header()[source] [edit on github]¶
Read a single header from the file.
- Returns:
- header
Mark5BHeader
- header
- temporary_offset(offset=None, whence=0) [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. As a convenience, one can pass on the offset to seek to when entering the context manager. Parameters are as forio.IOBase.seek()
.