Task¶
- class baseband.tasks.Task(ih, task, method=None, **kwargs)[source] [edit on github]¶
Bases:
TaskBase
Apply a user-supplied callable to a stream.
The task can either behave like a function or a method. If a function, it will be passed just the frame data read from the underlying file or task; if a method, it will be passed the Task instance (with its offset at the correct sample) as well as the frame data read.
Note that for common functions it is recommended to instead define a new subclass of
TaskBase
in which atask
(static)method is defined.- Parameters:
- ihfilehandle
Source of data, or another task, from which samples are read.
- taskcallable
The function or method-like callable.
- methodbool, optional
Whether
task
is a method (two arguments) or a function (one argument). Default: inferred by inspection.- **kwargs
Additional arguments and metadata to be passed on to the base class.
- — Possible arguments(see
TaskBase
) - shapetuple, optional
Overall shape of the stream, with first entry the total number of complete samples, and the remainder the sample shape. By default, the shape of the underlying stream, possibly adjusted for a difference of sample rate.
- sample_rate
Quantity
, optional With units of a rate. If not given, taken from the underlying stream. Should be passed in if the function reduces or expands the number of elements.
- samples_per_frameint, optional
Number of samples which should be fed to the function in one go. If not given, by default the number from the underlying file, possibly adjusted for a difference in sample rate.
- dtype
dtype
, optional Output dtype. If not given, the dtype of the underlying file.
- — Possible metadata(see
BaseTaskBase
) - frequency
Quantity
, optional Frequencies for each channel. Should be broadcastable to the sample shape. Default: taken from the underlying stream, if available.
- sidebandarray, optional
Whether frequencies are upper (+1) or lower (-1) sideband. Should be broadcastable to the sample shape. Default: taken from the underlying stream, if available.
- polarizationarray or (nested) list of char, optional
Polarization labels. Should broadcast to the sample shape, i.e., the labels are in the correct axis. For instance,
['X', 'Y']
, or[['L'], ['R']]
. Default: taken from the underlying stream, if available.
- Raises:
- TypeError
If inspection of the task does not work.
- AssertionError
If the task has zero or more than 2 arguments.
Attributes Summary
Data type of the output.
Number of dimensions of the output.
Number of complete samples per second.
Shape of a complete sample.
Number of samples per frame of data.
Shape of the output.
Number of component samples in the output.
Start time of the output.
Time at the end of the output, just after the last sample.
Time of the sample pointer's current offset in the output.
Methods Summary
close
()Close task.
read
([count, out])Read a number of complete samples.
seek
(offset[, whence])Change the sample pointer position.
tell
([unit])Current offset in the file.
Attributes Documentation
- closed = False¶
- complex_data¶
- dtype¶
Data type of the output.
- meta¶
- ndim¶
Number of dimensions of the output.
- offset = 0¶
- sample_rate¶
Number of complete samples per second.
- sample_shape¶
Shape of a complete sample.
- samples_per_frame¶
Number of samples per frame of data.
For compatibility with file readers, to help indicate what a nominal chunk of data is.
- shape¶
Shape of the output.
- size¶
Number of component samples in the output.
- stop_time¶
Time at the end of the output, just after the last sample.
See also
start_time
andtime
.
- time¶
Time of the sample pointer’s current offset in the output.
See also
start_time
andstop_time
.
Methods Documentation
- close() [edit on github]¶
Close task.
Note that this does not explicitly close the underlying source; instead, it just deletes the reference to it.
- read(count=None, out=None) [edit on github]¶
Read a number of complete samples.
- Parameters:
- countint or None, optional
Number of complete samples to read. If
None
(default) or negative, the number of samples left. Ignored ifout
is given.- outNone or array, optional
Array to store the samples in. If given,
count
will be inferred from the first dimension; the remaining dimensions should equalsample_shape
.
- Returns:
- out
ndarray
of float or complex The first dimension is sample-time, and the remaining ones are as given by
sample_shape
.
- out
- seek(offset, whence=0) [edit on github]¶
Change the sample pointer 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. For the latter two, the pointer will be moved to the nearest integer sample.
- 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(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: