# open¶

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

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.

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 possibly squeezing). If a single indexing object is passed, it selects polarizations. With a tuple, the first selects polarizations and the second selects channels. If the tuple is empty (default), all components are read.

— For writing a stream
header0DADAHeader

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

squeezebool, optional

If True (default), writer accepts squeezed arrays as input, and adds any dimensions of length unity.

**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.

samples_per_frameint,

Number of complete samples per frame.

sample_rateQuantity

Number of complete samples per second, i.e. the rate at which each channel of each polarization is sampled.

offsetQuantity or TimeDelta, optional

Time offset from the start of the whole observation (default: 0).

npolint, optional

Number of polarizations (default: 1).

nchanint, optional

Number of channels (default: 1).

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: 8).

Returns
Filehandle

DADAFileReader or DADAFileWriter (binary), or DADAStreamReader or DADAStreamWriter (stream).

Notes

For streams, one can also pass to name a list of files, or a template string that can be formatted using ‘frame_nr’, ‘obs_offset’, and other header keywords (by DADAFileNameSequencer).

For writing, one can mimic what is done at quite a few telescopes by using the template ‘{utc_start}_{obs_offset:016d}.000000.dada’. Unlike for most openers, file_size is set to the size of one frame as given by the header.

For reading, to read series such as the above, use something like ‘2013-07-02-01:37:40_{obs_offset:016d}.000000.dada’. Note that here we have to pass in the date explicitly, since the template is used to get the first file name, before any header is read, and therefore the only keywords available are ‘frame_nr’, ‘file_nr’, and ‘obs_offset’, all of which are assumed to be zero for the first file. To avoid this restriction, pass in keyword arguments with values appropriate for the first file.

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.