Grids
- class torusgrid.Grid(shape: Tuple[int, ...], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
Bases:
ABC,Generic[T]Base class for grids. The generic type T refers to the dtype of the wrapped numpy array (self.psi).
- __init__(shape: Tuple[int, ...], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
- abstract property isreal: bool
Return whether the field or grid object holds real data
- set_psi(psi1: npt.NDArray[T] | FloatLike) None
Deprecated: use psi[…] = … instead
- initialize_fft(*, threads: int = 1, planning_timelimit: Optional[float] = None, effort: Optional[Literal['FFTW_ESTIMATE', 'FFTW_MEASURE', 'FFTW_PATIENT', 'FFTW_EXHAUSTIVE']] = None, wisdom_only: bool = False, destroy_input: bool = False, unaligned: bool = False) None
Initialize the FFTW forward and backward plans. By default the fourier transform plans are not initialized as it can take a considerable amount of time.
- Parameters:
effort: FFTW planning effort
wisdom_only: Raise an error if no plan for the current transforms is present
- destroy_input: Whether to allow input to be destroyed during
transform, note that for certain transforms the input is destroyed anyway
unaligned: Alignment of the data will not be assumed.
- fft()
Run forward FFT on psi and store results to psi_k If FFT plans are not initialized, a TypeError will be raised
- ifft()
Run backward FFT on psi_k and store results to psi If FFT plans are not initialized, a TypeError will be raised
- fft_initialized() bool
Return whether the FFTW plans are initialized.
- property shape: Tuple[int, ...]
Return the shape in real space (x-space / time domain etc)
- property shape_k: Tuple[int, ...]
Return the shape in Fourier (k-space / frequency domain etc)
- property rank
Return the number of axes. Same as numpy’s ndim.
- property numel: int
Return the number of elements. Same as numpy’s size() or torch’s numel()
- property fft_axes
Return the axes along which FFT is performed
- property last_fft_axis
Return the last FFT axis. Useful when dealing with RFFTs.
- property psi
Real space data To assign values, use .psi[…] = …, not .psi = …
- property psi_k
k-space data To assign values, use .psi_k[…] = …, not .psi_k = …
- property precision
Return the floating point precision
- copy() Self
Build a new object with the same grid data. Must be overriden if __init__ signature is overriden
- metadata() dict
Everything except the data itself
- classmethod concat(*metas: dict, axis: int) dict
Concatenate metadata dicts.
- zero_()
Set all elements of psi to zero psi_k will not be affected
- class torusgrid.Grid1D(n: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
- class torusgrid.Grid1D(shape: Tuple[int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
Bases:
Grid[T]- __init__(n: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
- __init__(shape: Tuple[int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
- property n
=shape[0], the number of samples
- property N
Deprecated; use self.n instead.
- copy() Self
Build a new object with the same grid data. Must be overriden if __init__ signature is overriden
- class torusgrid.Grid2D(nx: int, ny: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
- class torusgrid.Grid2D(shape: Tuple[int, int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
Bases:
Grid[T]- __init__(nx: int, ny: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
- __init__(shape: Tuple[int, int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
- property nx
= shape[0], the number of samples in the x direction
- property ny
= shape[1], the number of samples in the y direction
- copy() Self
Build a new object with the same grid data. Must be overriden if __init__ signature is overriden
- class torusgrid.ComplexGrid(shape: Tuple[int, ...], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
Bases:
Grid[complexfloating]A ComplexGridND object is a complex array of shape (d1, d2, .., dN) equipped with fourier transform. No length scales are associated with the grid.
- property isreal
Return whether the field or grid object holds real data
- class torusgrid.RealGrid(shape: Tuple[int, ...], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
Bases:
Grid[floating]A RealGridND object is a real array of shape (d1, d2, .., dN) equipped with fourier transform. No length scales are associated with the grid.
The generic type variables are the dtypes of self.psi & self.psi_k.
- property isreal
Return whether the field or grid object holds real data
- class torusgrid.ComplexGrid1D(n: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
- class torusgrid.ComplexGrid1D(shape: Tuple[int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
Bases:
ComplexGrid,Grid1D[complexfloating]1D complex grid; fft axis is always axis 0.
- class torusgrid.ComplexGrid2D(nx: int, ny: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
- class torusgrid.ComplexGrid2D(shape: Tuple[int, int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
Bases:
ComplexGrid,Grid2D[complexfloating]2D complex grid
- class torusgrid.RealGrid1D(n: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
- class torusgrid.RealGrid1D(shape: Tuple[int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
Bases:
RealGrid,Grid1D[floating]1D real grid; fft axis is always axis 0.
- class torusgrid.RealGrid2D(nx: int, ny: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
- class torusgrid.RealGrid2D(shape: Tuple[int, int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
Bases:
RealGrid,Grid2D[floating]2D real grid