open

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

Open GSB file(s) for reading or writing.

A GSB data set contains a text header file and one or more raw data files. When the file is opened as text, one gets a standard filehandle, but with methods to read/write timestamps. When it is opened as a binary, one similarly gets methods to read/write frames. Opened as a stream, the file is interpreted as a timestamp file, but raw files need to be given too. This allows access to the stream(s) as series of samples.

Parameters:

name : str

Filename of timestamp or raw data file.

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

Whether to open for reading or writing, and as a regular text or binary file (for timestamps and data, respectively) or as a stream. Default: ‘rs’, for reading a stream.

**kwargs

Additional arguments when opening the file as a stream.

— For both reading and writing of streams :

raw : str or (tuple of) tuple of str

Name of files holding payload data. A single file is needed for rawdump, and a tuple for phased. For a nested tuple, the outer tuple determines the number of polarizations, and the inner tuple(s) the number of streams per polarization. E.g., ((polL1, polL2), (polR1, polR2)) for two streams per polarization. A single tuple is interpreted as streams of a single polarization.

sample_rate : Quantity, optional

Number of complete samples per second, i.e. the rate at which each channel of each polarization is sampled. If None, will be inferred assuming the frame rate is exactly 251.658240 ms.

samples_per_frame : int, optional

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

payload_nbytes : int, optional

Number of bytes per payload, divided by the number of raw files. If both samples_per_frame and payload_nbytes are None, payload_nbytes is set to 2**22 (4 MB) for rawdump, and 2**23 (8 MB) divided by the number of streams per polarization for phased.

nchan : int, optional

Number of channels. Default: 1 for rawdump, 512 for phased.

bps : int, optional

Bits per elementary sample, i.e. per real or imaginary component for complex data. Default: 4 for rawdump, 8 for phased.

complex_data : bool, optional

Whether data are complex. Default: False for rawdump, True for phased.

squeeze : bool, optional

If True (default) and reading, remove any dimensions of length unity from decoded data. If True and writing, accept squeezed arrays as input, and adds any dimensions of length unity.

— For reading only : (see GSBStreamReader)

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 (available) polarizations. If a tuple is passed, the first selects polarizations and the second selects channels. If the tuple is empty (default), all components are read.

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 only : (see GSBStreamWriter)

header0 : GSBHeader

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

**kwargs

If the header is not given, an attempt will be made to construct one with any further keyword arguments. If one requires to explicitly set the mode of the GSB stream, use header_mode. If not given, it will be ‘rawdump’ if only a single raw file is present, or ‘phased’ otherwise. See GSBStreamWriter.

Returns:

Filehandle