open

baseband.mark5b.open(name, mode=u'rs', **kwargs) [edit on github]

Open Mark5B file for reading or writing.

Opened as a binary file, one gets a wrapped filehandle that adds methods to read/write a frame. Opened as a stream, the handle is wrapped further, with methods such as reading and writing to the file as if it were a stream of samples.

Parameters:

name : str or filehandle

File name or handle.

mode : {‘rb’, ‘wb’, ‘rs’, or ‘ws’}, optional

Whether to open for reading or writing, and as a regular binary file or as a stream. Default: ‘rs’, for reading a stream.

**kwargs

Additional arguments when opening the file as a stream.

— For reading a stream : (see Mark5BStreamReader)

sample_rate : Quantity, optional

Number of complete samples per second, i.e. the rate at which each channel is sampled. If None (default), will be inferred from scanning one second of the file or, failing that, using the time difference between two consecutive frames.

kday : int or None

Explicit thousands of MJD of the observation start time (eg. 57000 for MJD 57999), used to infer the full MJD from the header’s time information. Can instead pass an approximate ref_time.

ref_time : Time or None

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

nchan : int, optional

Number of channels. Default: 1.

bps : int, optional

Bits per elementary sample. Default: 2.

squeeze : bool, optional

If True (default), remove any dimensions of length unity from decoded data.

subset : indexing object, optional

Specific channels of the complete sample to decode (after possible squeezing). If an empty tuple (default), all channels are read.

fill_value : float or complex

Value to use for invalid or missing data. Default: 0.

verify : bool, optional

Whether to do basic checks of frame integrity when reading. The first frame of the stream is always checked. Default: True.

— For writing a stream : (see Mark5BStreamWriter)

header0 : Mark5BHeader

Header for the first frame, holding time information, etc. Can instead give keyword arguments to construct a header (see **kwargs).

sample_rate : Quantity

Number of complete samples per second, i.e. the rate at which each channel is sampled. Needed to calculate header timestamps.

nchan : int, optional

Number of channels. Default: 1.

bps : int, optional

Bits per elementary sample. Default: 2.

squeeze : bool, optional

If True (default), writer accepts squeezed arrays as input, and adds channel and thread dimensions if they have length unity.

**kwargs

If no header is given, an attempt is made to construct one with any further keyword arguments. See Mark5BStreamWriter.

Returns:

Filehandle