open

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

Open Mark5B file(s) 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:
namestr or filehandle, or sequence of str

File name, filehandle, sequence of file names, or template (file name(s) can be Path but template has to be str).

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_rateQuantity, 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.

kdayint 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_timeTime 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.

nchanint, optional

Number of channels. Default: 1.

bpsint, optional

Bits per elementary sample. Default: 2.

squeezebool, optional

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

subsetindexing object, optional

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

fill_valuefloat or complex

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

verifybool or ‘fix’, optional

Whether to do basic checks of frame integrity when reading. Default: ‘fix’, which implies basic verification and replacement of gaps with zeros.

— For writing a stream(see Mark5BStreamWriter)
header0Mark5BHeader

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

sample_rateQuantity

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

nchanint, optional

Number of channels. Default: 1.

bpsint, optional

Bits per elementary sample. Default: 2.

squeezebool, optional

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

file_sizeint or None, optional

When writing to a sequence of files, the maximum size of one file in bytes. If None (default), the file size is unlimited, and only the first file will be written to.

**kwargs

If no header is given, an attempt is made to construct one from these. For a standard header, the following suffices.

— Header kwargs(see fromvalues())
timeTime

Start time of the file. Sets bcd-encoded unit day, hour, minute, second, and fraction, as well as the frame number, in the header.

Returns:
Filehandle

Mark5BFileReader or Mark5BFileWriter (binary), or Mark5BStreamReader or Mark5BStreamWriter (stream).

Notes

One can also pass to name a list, tuple, or subclass of FileNameSequencer. For writing to multiple files, the file_size keyword must be passed or only the first file will be written to. One may also pass in a sequentialfile object (opened in ‘rb’ mode for reading or ‘w+b’ for writing), though for typical use cases it is practically identical to passing in a list or template.