ReshapeAndTranspose¶
- class baseband.tasks.ReshapeAndTranspose(ih, sample_shape, sample_axes)[source] [edit on github]¶
Bases:
baseband_tasks.shaping.Reshape
Reshapes the sample shape of a stream and transpose its axes.
Useful to ensure, e.g., frequencies and polarizations are on separate axes before feeding a stream to, e.g.,
Power
.This is just the combination of
Reshape
andTranspose
(avoiding intermediate results).- Parameters
- ihtask or
baseband
stream reader Input data stream.
- sample_shapetuple of int
Output sample shape.
- sample_axestuple of int
Where the input sample shape axes should end up in the output sample shape (as for
transpose
). Should contain all axes of the sample shape, starting at1
(time axis 0 always stays in place).
- ihtask or
See also
Reshape
to just reshape the samples
Transpose
to just transpose sample axes
GetItem
index or slice the samples
GetSlice
slice the time axis and index or slice the samples
ChangeSampleShape
to change the samples with a user-supplied function.
Examples
The VDIF example file from
Baseband
has 8 threads which contain 4 channels and 2 polarizations. To produce a stream in which the sample axes are polarization and frequency, one could do:>>> import numpy as np, astropy.units as u, baseband >>> from baseband_tasks.shaping import ChangeSampleShape >>> fh = baseband.open(baseband.data.SAMPLE_VDIF) >>> fh.frequency = 311.25 * u.MHz + (np.arange(8.) // 2) * 16. * u.MHz >>> fh.sideband = 1 >>> fh.polarization = np.tile(['L', 'R'], 4) >>> rth = ReshapeAndTranspose(fh, (4, 2), (2, 1)) >>> rth.read(2).shape (2, 2, 4) >>> rth.polarization array([['L'], ['R']], dtype='<U1') >>> rth.frequency <Quantity [311.25, 327.25, 343.25, 359.25] MHz> >>> rth.sideband array(1, dtype=int8) >>> fh.close()
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.
task
(data)Reshape and transpose the axes of data.
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,
- task(data)[source] [edit on github]¶
Reshape and transpose the axes of data.
- 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