open

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

Open GUPPI 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 GUPPIStreamReader)

squeeze : bool, optional

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

subset : indexing 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 : (see GUPPIStreamWriter)

header0 : GUPPIHeader

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

squeeze : bool, optional

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

frames_per_file : int, optional

When writing to a sequence of files, sets the number of frames within each file. Default: 128.

**kwargs

If the header is not given, an attempt will be made to construct one with any further keyword arguments.

— Header keywords : (see fromvalues())

time : Time

Start time of the file. Must have an integer number of seconds.

sample_rate : Quantity

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

samples_per_frame : int

Number of complete samples per frame. Can alternatively give payload_nbytes.

payload_nbytes : int

Number of bytes per payload. Can alternatively give samples_per_frame.

offset : Quantity or TimeDelta, optional

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

npol : int, optional

Number of polarizations (default: 1).

nchan : int, optional

Number of channels (default: 1). For GUPPI, complex data is only allowed when nchan > 1.

bps : int, optional

Bits per elementary sample, i.e. per real or imaginary component for complex data (default: 8).

Returns:

Filehandle

Notes

For streams, one can also pass in a list of files, or equivalently a sequentialfile object (opened in ‘rb’ mode for reading or ‘w+b’ for writing).