StreamWriterBase¶
- class baseband.base.base.StreamWriterBase(fh_raw, header0, *, squeeze=True, **kwargs)[source] [edit on github]¶
Bases:
StreamBase
Base for all stream writers, providing a standard write method.
- Parameters:
- fh_rawfilehandle
Should be opened in binary mode for writer, and usually wrapped in a given format’s
FileWriter
.- header0header instance
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
Information that supplements that of the header. In particular, any format should define
bps
,complex_data
,samples_per_frame
,sample_shape
(on file), andsample_rate
.
Notes
Accessing frames happens via a number of private methods, which can be overridden by subclasses to deal with their peculiarities.
The process starts in
write
with_get_frame(offset)
, which determines theindex
of the frame a given offset falls in, and then either uses_make_frame(index)
to create it, or returns a possibly cached frame, together with thesample_offset
at whichoffset
falls within the frame. Then, data is inserted as needed until the frame is exhausted, at which point the frame is written to disk using_fh_raw_write_frame
and the process repeats.Various formats override various steps. For instance, for DADA and GUPPI,
_make_frame()
and_fh_raw_write_frame()
are overridden to work with memory mapped files. For GSB,_fh_raw_write_frame()
is overridden to take into account that header and data are read from different files.Attributes Summary
Bits per elementary sample.
Whether the data are complex.
First header of the file.
Number of complete samples per second.
Shape of a complete sample (possibly subset or squeezed).
Number of complete samples per frame.
Whether data arrays have dimensions with length unity removed.
Start time of the file.
Time of the sample pointer's current offset in file.
Methods Summary
close
()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.
- time¶
Time of the sample pointer’s current offset in file.
See also
start_time
for the start time of the file.
Methods Documentation
- close()[source] [edit on github]¶
- tell(unit=None) [edit on github]¶
Current offset in the file.
- Parameters:
- unit
Unit
or str, optional Time 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.
- unit
- Returns:
- write(data, valid=True)[source] [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.- validbool, optional
Whether the current data are valid. Default:
True
.
- data