# open¶

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

Open VDIF 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.

sample_rateQuantity, optional

Number of complete samples per second, i.e. the rate at which each channel in each thread is sampled. If None (default), will be inferred from the header or by scanning one second of the file.

squeezebool, optional

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

subsetindexing object or tuple of objects, optional

Specific components of the complete sample to decode (after possible squeezing). If a single indexing object is passed, it selects threads. If a tuple is passed, the first selects threads and the second selects channels. If the tuple is empty (default), all components are read.

fill_valuefloat or complex, optional

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

verifybool, optional

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

— For writing a stream
header0VDIFHeader

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 in each thread is sampled. For EDV 1 and 3, can alternatively set sample_rate within the header.

Number of threads (e.g., 2 for 2 polarisations). Default: 1.

squeezebool, optional

If True (default), writer accepts squeezed arrays as input, and adds any dimensions of 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, this would include the following.

timeTime

Start time of the file. Can instead pass on ref_epoch and seconds.

nchanint, optional

Number of channels (default: 1). Note: different numbers of channels per thread is not supported.

complex_databool, optional

Whether data are complex. Default: False.

bpsint, optional

Bits per elementary sample, i.e. per real or imaginary component for complex data. Default: 1.

samples_per_frameint

Number of complete samples per frame. Can alternatively use frame_length, the number of 8-byte words for header plus payload. For some EDV, this number is fixed (e.g., frame_length=629 for edv=3, which corresponds to 20000 real 2-bit samples per frame).

station2 characters, optional

Station ID. Can also be an unsigned 2-byte integer. Default: 0.

edv{False, 0, 1, 2, 3, 4, 0xab}

Extended Data Version.

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.