pyshqg.backend.numpy_backend module

Submodule dedicated to numpy backend.

class pyshqg.backend.numpy_backend.NumpyBackend(floatx)

Bases: Backend

Numpy backend.

from_numpy(array)

Converts an array from numpy into backend format.

Here the backend is numpy. Therefore, there is nothing to do except potentially change the data type.

Parameters:

array (numpy.ndarray) – Array in numpy format.

Returns:

array – Array in backend format.

Return type:

numpy.ndarray

static to_numpy(array)

Converts an array from backend into numpy format.

Here the backend is numpy. Therefore, there is nothing to do.

Parameters:

array (numpy.ndarray) – Array in backend format.

Returns:

array – Array in numpy format.

Return type:

numpy.ndarray

static expand_dims(*args, **kwargs)

Wrapper around numpy.expand_dims.

static pad(*args, **kwargs)

Wrapper around numpy.pad.

static einsum(*args, **kwargs)

Wrapper around numpy.einsum.

range(*args, **kwargs)

Wrapper around numpy.arange using real numbers.

static concatenate(*args, **kwargs)

Wrapper around numpy.concatenate.

static repeat(*args, **kwargs)

Wrapper around numpy.repeat.

static apply_fft(T, T_grid, leg_x)

Forward Fourier transformation for the spectral harmonics.

Notes

For the Gauss–Legendre grid used here, we have $N_{mathsf{lat}}=T_{mathsf{grid}}+1$ and $N_{mathsf{lon}}=2N_{mathsf{lat}}=2times(T_{mathsf{grid}}+1)$.

Parameters:
  • T (int) – Truncature of the data in spectral space.

  • T_grid (int) – Truncature of the Gauss–Legendre grid.

  • leg_x (np.ndarray, shape (..., 2, Nlat, T+1)) – Legendre transform of $hat{x}$.

Returns:

x – Variable $x$ in grid space.

Return type:

np.ndarray, shape (…, Nlat, Nlon)

static apply_ifft(T, T_grid, x)

Inverse Fourier transformation for the spectral harmonics.

Notes

For the Gauss–Legendre grid used here, we have $N_{mathsf{lat}}=T_{mathsf{grid}}+1$ and $N_{mathsf{lon}}=2N_{mathsf{lat}}=2times(T_{mathsf{grid}}+1)$.

Parameters:
  • T (int) – Truncature of the data in spectral space.

  • T_grid (int) – Truncature of the Gauss–Legendre grid.

  • x (np.ndarray, shape (..., Nlat, Nlon)) – Variable $x$ in grid space.

Returns:

leg_x – Legendre transform of $hat{x}$.

Return type:

np.ndarray, shape (…, 2, Nlat, T+1)