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
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
info
()Standardized information on file readers.
Methods Summary
close
(self)find_header
(self, *args, **kwargs)Find the nearest header from the current position.
get_frame_rate
(self)Determine the number of frames per second.
locate_frames
(self[, pattern])Use a pattern to locate frame starts near the current position.
read_frame
(self[, verify])Read a single frame (header plus payload).
read_header
(self)Read a single header from the file.
temporary_offset
(self[, offset, whence])Context manager for temporarily seeking to another file position.
Attributes Documentation
-
fh_raw
= None¶
-
info
¶ Standardized information on file readers.
The
info
descriptor has a number of standard attributes, which are determined from arguments passed in opening the file, from the first header (info.header0
) and from possibly scanning the file to determine the duration of frames.Examples
The most common use is simply to print information:
>>> from baseband.data import SAMPLE_MARK5B >>> from baseband import mark5b >>> fh = mark5b.open(SAMPLE_MARK5B, 'rb') >>> fh.info File information: format = mark5b number_of_frames = 4 frame_rate = 6400.0 Hz bps = 2 complex_data = False readable = False missing: nchan: needed to determine sample shape, frame rate, ... kday, ref_time: needed to infer full times. >>> fh.close() >>> fh = mark5b.open(SAMPLE_MARK5B, 'rb', kday=56000, nchan=8) >>> fh.info File information: format = mark5b number_of_frames = 4 frame_rate = 6400.0 Hz sample_rate = 32.0 MHz samples_per_frame = 5000 sample_shape = (8,) bps = 2 complex_data = False start_time = 2014-06-13T05:30:01.000000000 readable = True checks: decodable: True >>> fh.close()
- Attributes
- formatstr or
None
File format, or
None
if the underlying file cannot be parsed.- number_of_framesint
Number of frames in the file.
- frame_rate
Quantity
Number of data frames per unit of time.
- sample_rate
Quantity
Complete samples per unit of time.
- samples_per_frameint
Number of complete samples in each frame.
- sample_shapetuple
Dimensions of each complete sample (e.g.,
(nchan,)
).- bpsint
Number of bits used to encode each elementary sample.
- complex_databool
Whether the data are complex.
- start_time
Time
Time of the first complete sample.
- readablebool
Whether the first sample could be read and decoded.
- missingdict
Entries are keyed by names of arguments that should be passed to the file reader to obtain full information. The associated entries explain why these arguments are needed.
- checksdict
Checks that were done to determine whether the file was readable (normally the only entry is ‘decodable’).
- errorsdict
Any exceptions raised while trying to determine attributes or doing checks. Keyed by the attributes/checks.
- warningsdict
Any warnings about the attributes or about the checks. Keyed by the attributes/checks.
- formatstr or
Methods Documentation
-
close
(self) [edit on github]¶
-
find_header
(self, *args, **kwargs) [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.vlbi_base.base.HeaderNotFoundError
If no header could be located.
- AssertionError
If the header did not pass verification.
-
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_rate
Quantity
Frames per second.
- frame_rate
-
locate_frames
(self, 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.vlbi_base.base.VLBIFileReaderBase.locate_frames
except that by default the Mark 5B sync pattern is used.
-
read_frame
(self, 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
(self)[source] [edit on github]¶ Read a single header from the file.
- Returns
- header
Mark5BHeader
- header
-
temporary_offset
(self, 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()
.