fft_maker

class baseband_tasks.fourier.fft_maker(shape, dtype, *, direction='forward', axis=0, ortho=False, sample_rate=None)[source] [edit on github]

Bases: astropy.utils.state.ScienceState

Create an FFT, with a settable default engine.

Parameters
shapetuple

Shape of the time-domain data array, i.e. the input to the forward transform and the output of the inverse.

dtypedtype

Data type of the time-domain data array. May pass either a dtype instance, or anything that initializes one.

direction‘forward’ or ‘backward’, optional

Direction of the FFT. Default: ‘forward’

axisint, optional

Axis to transform. Default: 0.

orthobool, optional

Whether to use orthogonal normalization. Default: False.

sample_ratefloat, Quantity, or None, optional

Sample rate, used to determine the FFT sample frequencies. If None, a unitless rate of 1 is used.

Notes

The fft_maker.set method can be used to set the default engine for all tasks that require fourier transforms.

Examples

To set up to use numpy’s fft, and then create an fft function acting on arrays of 1000 elements:

>>> from baseband_tasks.fourier import fft_maker
>>> from astropy import units as u
>>> with fft_maker.set('numpy'):
...     fft = fft_maker((1000,), 'complex64', sample_rate=1.*u.kHz)
>>> fft
<NumpyFFT direction=forward,
    axis=0, ortho=False, sample_rate=1.0 kHz
    Time domain: shape=(1000,), dtype=complex64
    Frequency domain: shape=(1000,), dtype=complex64>

Attributes Summary

system_default

System default FFT factory.

Methods Summary

get()

Get the current science state value.

set(fft_engine, **kwargs)

Set the FFT factory to be used in new tasks.

validate(value)

Validate the value and convert it to its native type, if necessary.

Attributes Documentation

system_default

System default FFT factory.

Methods Documentation

classmethod get() [edit on github]

Get the current science state value.

classmethod set(fft_engine, **kwargs)[source] [edit on github]

Set the FFT factory to be used in new tasks.

This method can be used to set the factory only temporarily, by using it as a context in a with statement.

Parameters
fft_engine{‘numpy’, ‘pyfftw’}, FFTMaker instance, or None

Keyword identifying the FFT maker class to create, or an FFT maker instance. If None, the engine stored in the system_default attribute is used.

**kwargs

Additional keyword arguments for initializing the maker class (eg. n_simd for ‘pyfftw’). Only allowed when fft_engine is a name of a maker class.

Examples

To use PyFFTW on a machine with 4 threads:

>>> from baseband_tasks.fourier import fft_maker
>>> fft_maker.set('pyfftw', threads=4)
<ScienceState fft_maker: PyfftwFFTMaker(...)>

This factory will be used by default when defining new tasks that need fourier transforms (channelization, dedispersion, etc.)

To reset to the system default, pass in None:

>>> fft_maker.set(None)  
>>> assert fft_maker.get() is fft_maker.system_default

To use the settings only for a few specific tasks:

>>> with fft_maker.set('numpy'):  
...     ch = Channelize(fh, 1024)
classmethod validate(value)[source] [edit on github]

Validate the value and convert it to its native type, if necessary.