ReshapeAndTranspose¶
- class baseband_tasks.shaping.ReshapeAndTranspose(ih, sample_shape, sample_axes)[source] [edit on github]¶
Bases:
ReshapeReshapes 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
ReshapeandTranspose(avoiding intermediate results).- Parameters:
- ihtask or
basebandstream 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
Reshapeto just reshape the samples
Transposeto just transpose sample axes
GetItemindex or slice the samples
GetSliceslice the time axis and index or slice the samples
ChangeSampleShapeto change the samples with a user-supplied function.
Examples
The VDIF example file from
Basebandhas 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()
Methods Summary
task(data)Reshape and transpose the axes of data.
Methods Documentation
- task(data)[source] [edit on github]¶
Reshape and transpose the axes of data.