DADAFileReader¶
- class baseband.dada.base.DADAFileReader(fh_raw)[source] [edit on github]¶
Bases:
FileBase
Simple reader for DADA files.
Wraps a binary filehandle, providing methods to help interpret the data, such as
read_frame
andget_frame_rate
. By default, frame payloads are mapped rather than fully read into physical memory.- Parameters:
- fh_rawfilehandle
Filehandle of the raw binary data file.
Attributes Summary
Standardized information on file readers.
Methods Summary
close
()Determine the number of frames per second.
read_frame
([memmap, verify])Read the frame header and read or map the corresponding 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¶
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 Mark5BFile 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 Mark5BFile 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()
Methods Documentation
- close() [edit on github]¶
- get_frame_rate()[source] [edit on github]¶
Determine the number of frames per second.
The routine uses the sample rate and number of samples per frame from the first header in the file.
- Returns:
- frame_rate
Quantity
Frames per second.
- frame_rate
- read_frame(memmap=True, verify=True)[source] [edit on github]¶
Read the frame header and read or map the corresponding payload.
- Parameters:
- Returns:
- frame
DADAFrame
With
.header
and.payload
properties. The.data
property returns all data encoded in the frame. Since this may be too large to fit in memory, it may be better to access the parts of interest by slicing the frame.
- frame
- read_header()[source] [edit on github]¶
Read a single header from the file.
- Returns:
- header
DADAHeader
- 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()
.