open, mode='rs', **kwargs) [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.


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.


Additional arguments when opening the file as a stream.

— For both reading and writing of streams
rawstr 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_rateQuantity, 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_frameint, optional

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

payload_nbytesint, optional

Number of bytes per payload (in each raw file separately). If both samples_per_frame and payload_nbytes are None, payload_nbytes is set to 2**22 (4 MiB).

nchanint, optional

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

bpsint, optional

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

complex_databool, optional

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

squeezebool, 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)
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 (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.

verifybool, 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)

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


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

— Header keywords(see fromvalues())

Start time of the file.

header_mode‘rawdump’ or ‘phased’, optional

Used to explicitly set the mode of the GSB stream. Default: ‘rawdump’ if only a single raw file is present, or ‘phased’ otherwise.

seq_nrint, optional

Frame number, only used for phased (default: 0).


GSBTimeStampIO (timestamp), or GSBFileReader or GSBFileWriter (binary), or GSBStreamReader or GSBStreamWriter (stream)