GSBStreamWriter¶
-
class
baseband.gsb.base.
GSBStreamWriter
(fh_ts, fh_raw, header0=None, sample_rate=None, samples_per_frame=None, payload_nbytes=None, nchan=None, bps=None, complex_data=None, squeeze=True, **kwargs)[source] [edit on github]¶ Bases:
baseband.gsb.base.GSBStreamBase
,baseband.vlbi_base.base.VLBIStreamWriterBase
GSB format writer.
Encodes and writes sequences of samples to file.
Parameters: fh_ts :
GSBTimeStampIO
For writing headers to storage.
fh_raw : filehandle, or nested tuple of filehandles
For writing raw binary data to storage. 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.header0 :
GSBHeader
Header for the first frame, holding time information, etc. Can instead give keyword arguments to construct a header (see
**kwargs
).sample_rate :
Quantity
, optionalNumber of complete samples per second, i.e. the rate at which each channel of each polarization is sampled. If not given, will be inferred assuming the frame rate is exactly 0.25165824 s.
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
andpayload_nbytes
areNone
,payload_nbytes
is set to2**22
(4 MB) for rawdump, and2**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
squeeze : bool, optional
**kwargs
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()
)time :
Time
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_nr : int, optional
Frame number, only used for phased (default: 0).
Attributes Summary
bps
Bits per elementary sample. complex_data
Whether the data are complex. header0
First header of the file. sample_rate
Number of complete samples per second. sample_shape
Shape of a complete sample (possibly subset or squeezed). samples_per_frame
Number of complete samples per frame. squeeze
Whether data arrays have dimensions with length unity removed. start_time
Start time of the file. subset
Specific components of the complete sample to decode. time
Time of the sample pointer’s current offset in file. verify
Whether to do consistency checks on frames being read. Methods Summary
close
()flush
()tell
([unit])Current offset in the file. write
(data[, valid])Write data, buffering by frames as needed. Attributes Documentation
-
bps
¶ Bits per elementary sample.
-
complex_data
¶ Whether the data are complex.
-
header0
¶ First header of the file.
-
sample_rate
¶ Number of complete samples per second.
-
sample_shape
¶ Shape of a complete sample (possibly subset or squeezed).
-
samples_per_frame
¶ Number of complete samples per frame.
-
squeeze
¶ Whether data arrays have dimensions with length unity removed.
If
True
, data read out has such dimensions removed, and data passed in for writing has them inserted.
-
start_time
¶ Start time of the file.
See also
time
for the time of the sample pointer’s current offset, and (if available)stop_time
for the time at the end of the file.
-
subset
¶ Specific components of the complete sample to decode.
The order of dimensions is the same as for
sample_shape
. Set by the class initializer.
-
time
¶ Time of the sample pointer’s current offset in file.
See also
start_time
for the start time, and (if available)stop_time
for the end time, of the file.
-
verify
¶ Whether to do consistency checks on frames being read.
Methods Documentation
-
close
() [edit on github]¶
-
flush
()[source] [edit on github]¶
-
tell
(unit=None) [edit on github]¶ Current offset in the file.
Parameters: unit :
Unit
or str, optionalTime unit the offset should be returned in. By default, no unit is used, i.e., an integer enumerating samples is returned. For the special string ‘time’, the absolute time is calculated.
Returns: offset : int,
Quantity
, orTime
Offset in current file (or time at current position).
-
write
(data, valid=True) [edit on github]¶ Write data, buffering by frames as needed.
Parameters: data :
ndarray
Piece of data to be written, with sample dimensions as given by
sample_shape
. This should be properly scaled to make best use of the dynamic range delivered by the encoding.valid : bool, optional
Whether the current data are valid. Default:
True
.
-