ChangeSampleShape

class baseband_tasks.shaping.ChangeSampleShape(ih, task, method=None, **kwargs)[source] [edit on github]

Bases: baseband_tasks.base.Task, baseband_tasks.shaping.ChangeSampleShapeBase

Change sample shape using a callable.

Parameters
ihtask or baseband stream reader

Input data stream.

taskcallable

The function or method-like callable. The task must work with any number of data samples and change the sample shape only. It will also be applied to the frequency, sideband, and polarization attributes of the underlying stream (if present).

methodbool, optional

Whether task is a method (two arguments) or a function (one argument). Default: inferred by inspection.

See also

Reshape

to reshape the samples

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

Examples

The VDIF example file from Baseband has 8 threads which contain 4 channels and 2 polarizations, with very little data in the last channel. To produce a stream in which the sample axes are frequency and polarization and only the first three channels are kept, 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)
>>> sh = ChangeSampleShape(
...    fh, lambda data: data.reshape(-1, 4, 2)[:, :3])
>>> sh.read(2).shape
(2, 3, 2)
>>> sh.polarization
array(['L', 'R'], dtype='<U1')
>>> sh.frequency  
<Quantity [[311.25],
           [327.25],
           [343.25]] MHz>
>>> sh.sideband
array(1, dtype=int8)
>>> fh.close()