ReshapeAndTranspose

class baseband_tasks.shaping.ReshapeAndTranspose(ih, sample_shape, sample_axes)[source] [edit on github]

Bases: 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 and Transpose (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 at 1 (time axis 0 always stays in place).

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()

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.