ChangeSampleShape¶
- class baseband_tasks.shaping.ChangeSampleShape(ih, task, method=None, **kwargs)[source] [edit on github]¶
Bases:
Task,ChangeSampleShapeBaseChange sample shape using a callable.
- Parameters:
- ihtask or
basebandstream 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, andpolarizationattributes of the underlying stream (if present).- methodbool, optional
Whether
taskis a method (two arguments) or a function (one argument). Default: inferred by inspection.
- ihtask or
See also
Reshapeto reshape the samples
Transposeto transpose sample axes
ReshapeAndTransposeto reshape the samples and transpose the axes
GetItemindex or slice the samples
GetSliceslice the time axis and index or slice the samples
Examples
The VDIF example file from
Basebandhas 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()