Reshape

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

Bases: baseband_tasks.shaping.ChangeSampleShapeBase

Reshapes the sample shape of a stream.

Useful to ensure, e.g., frequencies and polarizations are on separate axes before feeding a stream to Power.

Parameters
ihtask or baseband stream reader

Input data stream.

sample_shapetuple of int

Output sample shape.

See also

Transpose

to transpose sample axes

ReshapeAndTranspose

to reshape the samples and transpose the 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 frequency and polarization, 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)
>>> rh = Reshape(fh, (4, 2))
>>> rh.read(2).shape
(2, 4, 2)
>>> rh.polarization
array(['L', 'R'], dtype='<U1')
>>> rh.frequency  
<Quantity [[311.25],
           [327.25],
           [343.25],
           [359.25]] MHz>
>>> rh.sideband
array(1, dtype=int8)
>>> fh.close()

Methods Summary

task(data)

Reshape the data.

Methods Documentation

task(data)[source] [edit on github]

Reshape the data.