Mark4StreamReader¶
-
class
baseband.mark4.base.
Mark4StreamReader
(fh_raw, sample_rate=None, ntrack=None, decade=None, ref_time=None, squeeze=True, subset=(), fill_value=0.0, verify='fix')[source] [edit on github]¶ Bases:
baseband.mark4.base.Mark4StreamBase
,baseband.vlbi_base.base.VLBIStreamReaderBase
VLBI Mark 4 format reader.
Allows access to a Mark 4 file as a continuous series of samples. Parts of the data stream replaced by header values are filled in.
- Parameters
- fh_rawfilehandle
Filehandle of the raw Mark 4 stream.
- sample_rate
Quantity
, optional Number of complete samples per second, i.e. the rate at which each channel is sampled. If
None
, will be inferred from scanning two frames of the file.- ntrackint or None, optional
Number of Mark 4 bitstreams. If
None
(default), will attempt to automatically detect it by scanning the file.- decadeint or None
Decade of the observation start time (eg.
2010
for 2018), needed to remove ambiguity in the Mark 4 time stamp. Can instead pass an approximateref_time
.- ref_time
Time
or None Reference time within 4 years of the start time of the observations. Used only if
decade
is not given.- squeezebool, optional
If
True
(default), remove any dimensions of length unity from decoded data.- subsetindexing object, optional
Specific channels of the complete sample to decode (after possible squeezing). If an empty tuple (default), all channels are read.
- fill_valuefloat or complex, optional
Value to use for invalid or missing data. Default: 0.
- verifybool or str, optional
Whether to do basic checks of frame integrity when reading. Default: ‘fix’, which implies basic verification and replacement of gaps with zeros.
Attributes Summary
Bits per elementary sample.
Whether the data are complex.
Value to use for invalid or missing data.
First header of the file.
info
()Standardized information on stream readers.
Number of dimensions of the (squeezed/subset) stream data.
Number of complete samples per second.
Shape of a complete sample (possibly subset or squeezed).
Number of complete samples per frame.
Shape of the (squeezed/subset) stream data.
Total number of component samples in the (squeezed/subset) stream data.
Whether data arrays have dimensions with length unity removed.
Start time of the file.
Time at the end of the file, just after the last sample.
Specific components of the complete sample to decode.
Time of the sample pointer’s current offset in file.
Whether to do consistency checks on frames being read.
Methods Summary
close
(self)read
(self[, count, out])Read a number of complete (or subset) samples.
readable
(self)Whether the file can be read and decoded.
seek
(self, offset[, whence])Change the stream position.
tell
(self[, unit])Current offset in the file.
Attributes Documentation
-
bps
¶ Bits per elementary sample.
-
complex_data
¶ Whether the data are complex.
-
dtype
¶
-
fill_value
¶ Value to use for invalid or missing data. Default: 0.
-
header0
¶ First header of the file.
-
info
¶ Standardized information on stream readers.
The
info
descriptor provides a few standard attributes, most of which can also be accessed directly on the stream filehandle, and tests basic readability of the stream. More detailed information on the underlying file is stored in its info, accessible viainfo.file_info
(and shown by__repr__
).- Attributes
- start_time
Time
Time of the first complete sample.
- stop_time
Time
Time of the complete sample just beyond the end of the file.
- sample_rate
Quantity
Complete samples per unit of time.
- shapetuple
Equivalent shape of the whole file, i.e., combining the number of complete samples and the shape of those samples.
- bpsint
Number of bits used to encode each elementary sample.
- complex_databool
Whether the data are complex.
- verifybool or str
The type of verification done by the stream reader.
- readablebool
Whether the first and last samples could be read and decoded.
- checksdict
Checks that were done to determine whether the file was readable (normally ‘continuous’ and ‘decodable’).
- errorsdict
Any exceptions raised while trying to determine attributes or doing checks. Keyed by the attributes/checks.
- warningsdict
Any warnings about the attributes or about the checks. Keyed by the attributes/checks.
- start_time
-
ndim
¶ Number of dimensions of the (squeezed/subset) stream data.
-
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.
-
shape
¶ Shape of the (squeezed/subset) stream data.
-
size
¶ Total number of component samples in the (squeezed/subset) stream data.
-
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.
-
stop_time
¶ Time at the end of the file, just after the last sample.
See also
start_time
for the start time of the file, andtime
for the time of the sample pointer’s current offset.
-
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
(self) [edit on github]¶
-
read
(self, count=None, out=None) [edit on github]¶ Read a number of complete (or subset) samples.
The range retrieved can span multiple frames.
- Parameters
- countint or None, optional
Number of complete/subset samples to read. If
None
(default) or negative, the whole file is read. Ignored ifout
is given.- outNone or array, optional
Array to store the data in. If given,
count
will be inferred from the first dimension; the other dimension should equalsample_shape
.
- Returns
- out
ndarray
of float or complex The first dimension is sample-time, and the remainder given by
sample_shape
.
- out
-
readable
(self) [edit on github]¶ Whether the file can be read and decoded.
-
seek
(self, offset, whence=0) [edit on github]¶ Change the stream position.
This works like a normal filehandle seek, but the offset is in samples (or a relative or absolute time).
- Parameters
- offsetint,
Quantity
, orTime
Offset to move to. Can be an (integer) number of samples, an offset in time units, or an absolute time.
- whence{0, 1, 2, ‘start’, ‘current’, or ‘end’}, optional
Like regular seek, the offset is taken to be from the start if
whence=0
(default), from the current position if 1, and from the end if 2. One can alternativey use ‘start’, ‘current’, or ‘end’ for 0, 1, or 2, respectively. Ignored ifoffset
is a time.
- offsetint,
-
tell
(self, 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