Cartesian

Convolutions

shift.cart.convolve_gaussian(k, sigma)[source]

Convolution weights in Fourier space.

Parameters:
  • k (array) – Fourier modes.

  • sigma (float) – Gaussian scale.

Returns:

kernel – Convolution kernel

Return type:

array

Differentiation

shift.cart.dfdk(k, fk)[source]

Differentiation in Fourier space. This can be used for all functions.

Parameters:
  • k (array) – Fourier scales.

  • fk (complex array) – Fourier mode amplitudes.

Returns:

dfk – Differential of the fourier modes.

Return type:

complex array

shift.cart.dfdk2(k1, fk, k2=None)[source]

Second order differentiation in Fourier space. This can be used for all functions.

Parameters:
  • k1 (array) – Fourier scales.

  • fk (complex array) – Fourier mode amplitudes.

  • k2 (array) – Fourier scales from a different axis, if you wish to different first by one axis and then a second.

Returns:

dfk2 – Differential of the fourier modes.

Return type:

complex

Cartesian grids

shift.cart.grid1D(boxsize, ngrid, origin=0.0)[source]

Returns the x coordinates of a cartesian grid.

Parameters:
  • boxsize (float) – Box size.

  • ngrid (int) – Grid division along one axis.

  • origin (float, optional) – Start point of the grid.

Returns:

  • xedges (array) – x coordinate bin edges.

  • x (array) – X coordinates bin centers.

shift.cart.grid2D(boxsize, ngrid, origin=0.0)[source]

Returns the x, y coordinates of a cartesian grid.

Parameters:
  • boxsize (float) – Box size or list of length along each axis.

  • ngrid (int) – Grid division along one axis or a list of the grid divisions along each axis.

  • origin (float, optional) – Origin of the grid. If all axes begin at the same origin this can be a scalar, if you instead wish to specify different origins for each axis this should be added as a list.

Returns:

  • x2D (array) – X coordinates on a 2D cartesian grid.

  • y2D (array) – Y coordinates on a 2D cartesian grid.

shift.cart.grid3D(boxsize, ngrid, origin=0.0)[source]

Returns the x, y, z coordinates of a cartesian grid.

Parameters:
  • boxsize (float) – Box size or list of length along each axis.

  • ngrid (int) – Grid division along one axis or a list of the grid divisions along each axis.

  • origin (float, optional) – Origin of the grid. If all axes begin at the same origin this can be a scalar, if you instead wish to specify different origins for each axis this should be added as a list.

Returns:

  • x3D (array) – X coordinates on a 3D cartesian grid.

  • y3D (array) – Y coordinates on a 3D cartesian grid.

  • z3D (array) – Z coordinates on a 3D cartesian grid.

FFT

Fourier grids

shift.cart.kgrid1D(boxsize, ngrid)[source]

Returns the fourier modes for the Fourier transform of a cartesian grid.

Parameters:
  • boxsize (float) – Box size.

  • ngrid (int) – Grid division along one axis.

Returns:

k – Fourier modes.

Return type:

array

shift.cart.kgrid2D(boxsize, ngrid)[source]

Returns the fourier modes for the Fourier transform of a cartesian grid.

Parameters:
  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • ngrid (int or list) – Grid division along one axis or a list for each axis.

Returns:

  • kx2D (array) – Fourier x-mode.

  • ky2D (array) – Fourier y-mode.

shift.cart.kgrid3D(boxsize, ngrid)[source]

Returns the fourier modes for the Fourier transform of a cartesian grid.

Parameters:
  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • ngrid (int or list) – Grid division along one axis or a list of divisions across each axes.

Returns:

  • kx3D (array) – Fourier x-mode.

  • ky3D (array) – Fourier y-mode.

  • kz3D (array) – Fourier z-mode.

Forward/Backward Transforms

shift.cart.fft1D(f_real, boxsize, axis=-1)[source]

Performs Forward FFT on real space data.

Parameters:
  • f_real (ndarray) – Real space data.

  • boxsize (float) – Box size.

  • axis (int, optional) – Axis to perform FFT.

Returns:

f_fourier – Fourier modes.

Return type:

ndarray

shift.cart.ifft1D(f_fourier, boxsize, axis=-1)[source]

Performs backward fft of a Fourier grid.

Parameters:
  • f_fourier (ndarray) – Fourier modes.

  • boxsize (float) – Box size.

  • axis (int, optional) – Axis to perform FFT.

Returns:

f_real – Real space data.

Return type:

ndarray

shift.cart.fft2D(f_real, boxsize)[source]

Performs Forward FFT on input grid data.

Parameters:
  • f_real (2darray) – Real space data.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

Returns:

f_fourier – Fourier modes.

Return type:

2darray

shift.cart.ifft2D(f_fourier, boxsize)[source]

Performs backward fft of a Fourier grid.

Parameters:
  • f_fourier (ndarray) – Fourier modes.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

Returns:

f_real – Real space data.

Return type:

2darray

shift.cart.fft3D(f_real, boxsize)[source]

Performs Forward FFT on input grid data.

Parameters:
  • f_real (3darray) – Real space data.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

Returns:

f_fourier – Fourier modes.

Return type:

3darray

shift.cart.ifft3D(f_fourier, boxsize)[source]

Performs backward fft of a Fourier grid.

Parameters:
  • f_fourier (3darray) – Fourier modes.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

Returns:

f_real – Real space data.

Return type:

3darray

DCT

Fourier grids

shift.cart.kgrid1D_dct(boxsize, ngrid)[source]

Returns the fourier modes for the Discrete Cosine transform on a cartesian grid.

Parameters:
  • boxsize (float) – Box size.

  • ngrid (int) – Grid division along one axis.

Returns:

k – Fourier modes.

Return type:

array

shift.cart.kgrid2D_dct(boxsize, ngrid)[source]

Returns the fourier modes for the Discrete Cosine transform on a 2D cartesian grid.

Parameters:
  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • ngrid (int or list) – Grid division along one axis or a list of divisions across each axes.

Returns:

  • kx2D (array) – Fourier x-mode.

  • ky2D (array) – Fourier y-mode.

shift.cart.kgrid3D_dct(boxsize, ngrid)[source]

Returns the fourier modes for the Discrete Cosine transform on a 3D cartesian grid.

Parameters:
  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • ngrid (int or list) – Grid division along one axis or a list of divisions across each axes.

Returns:

  • kx3D (array) – Fourier x-mode.

  • ky3D (array) – Fourier y-mode.

  • kz3D (array) – Fourier z-mode.

Forward/Backward Transforms

shift.cart.dct1D(f_real, boxsize, axis=-1, type=2)[source]

Performs forward DCT in 1D.

Parameters:
  • f_real (1darray or ndarray) – Real space data.

  • Boxsize – Box size.

  • axis (int, optional) – Axis to perform DCT.

  • type (int, optional) – Type of DCT for scipy to perform.

Returns:

f_fourier – Fourier modes.

Return type:

ndarray

shift.cart.idct1D(f_fourier, boxsize, axis=-1, type=2)[source]

Performs backward DCT in 1D.

Parameters:
  • f_fourier (ndarray) – Fourier modes.

  • boxsize (float) – Box size.

  • axis (int, optional) – Axis to perform DCT.

  • type (int, optional) – Type of iDCT for scipy to perform.

Returns:

f_real – Real space data.

Return type:

1darray or ndarray

shift.cart.dct2D(f_real, boxsize, type=2)[source]

Performs forward DCT in 2D.

Parameters:
  • f_real (2darray) – Real space data.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • type (int, optional) – Type of DCT for scipy to perform.

Returns:

f_fourier – Fourier modes.

Return type:

ndarray

shift.cart.idct2D(f_fourier, boxsize, type=2)[source]

Performs backward DCT in 2D.

Parameters:
  • f_fourier (2darray) – Fourier modes.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • type (int, optional) – Type of iDCT for scipy to perform.

Returns:

f_real – Real space data.

Return type:

2darray

shift.cart.dct3D(f_real, boxsize, type=2)[source]

Performs forward DCT in 3D.

Parameters:
  • f_real (3darray) – Real space data.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • type (int, optional) – Type of DCT for scipy to perform.

Returns:

f_fourier – Fourier modes.

Return type:

ndarray

shift.cart.idct3D(f_fourier, boxsize, type=2)[source]

Performs backward DCT in 3D.

Parameters:
  • f_fourier (ndarray) – Fourier modes.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • type (int, optional) – Type of iDCT for scipy to perform.

Returns:

f_real – Real space data.

Return type:

3darray

DST

Fourier grids

shift.cart.kgrid1D_dst(boxsize, ngrid)[source]

Returns the fourier modes for the Discrete Sine Transform of a cartesian grid.

Parameters:
  • boxsize (float) – Box size.

  • ngrid (int) – Grid division along one axis.

Returns:

k – Fourier modes.

Return type:

array

shift.cart.kgrid2D_dst(boxsize, ngrid)[source]

Returns the fourier modes for the Discrete Sine transform on a 2D cartesian grid.

Parameters:
  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • ngrid (int or list) – Grid division along one axis or a list of divisions across each axes.

Returns:

  • kx2D (array) – Fourier x-mode.

  • ky2D (array) – Fourier y-mode.

shift.cart.kgrid3D_dst(boxsize, ngrid)[source]

Returns the fourier modes for the Discrete Sine transform on a 3D cartesian grid.

Parameters:
  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • ngrid (int or list) – Grid division along one axis or a list of divisions across each axes.

Returns:

  • kx3D (array) – Fourier x-mode.

  • ky3D (array) – Fourier y-mode.

  • kz3D (array) – Fourier z-mode.

Forward/Backward Transforms

shift.cart.dst1D(f_real, boxsize, axis=-1, type=2)[source]

Performs forward DST in 1D.

Parameters:
  • f_real (1darray or ndarray) – Real space data.

  • Boxsize – Box size.

  • axis (int, optional) – Axis to perform DST.

  • type (int, optional) – Type of DST for scipy to perform.

Returns:

f_fourier – Fourier modes.

Return type:

ndarray

shift.cart.idst1D(f_fourier, boxsize, axis=-1, type=2)[source]

Performs backward DST in 1D.

Parameters:
  • f_fourier (ndarray) – Fourier modes.

  • boxsize (float) – Box size.

  • axis (int, optional) – Axis to perform DST.

  • type (int, optional) – Type of iDST for scipy to perform.

Returns:

f_real – Real space data.

Return type:

1darray or ndarray

shift.cart.dst2D(f_real, boxsize, type=2)[source]

Performs forward DST in 2D.

Parameters:
  • f_real (2darray) – Real space data.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • type (int, optional) – Type of DST for scipy to perform.

Returns:

f_fourier – Fourier modes.

Return type:

ndarray

shift.cart.idst2D(f_fourier, boxsize, type=2)[source]

Performs backward DST in 2D.

Parameters:
  • f_fourier (2darray) – Fourier modes.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • type (int, optional) – Type of iDST for scipy to perform.

Returns:

f_real – Real space data.

Return type:

2darray

shift.cart.dst3D(f_real, boxsize, type=2)[source]

Performs forward DST in 3D.

Parameters:
  • f_real (3darray) – Real space data.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • type (int, optional) – Type of DST for scipy to perform.

Returns:

f_fourier – Fourier modes.

Return type:

ndarray

shift.cart.idst3D(f_fourier, boxsize, type=2)[source]

Performs backward DST in 3D.

Parameters:
  • f_fourier (ndarray) – Fourier modes.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • type (int, optional) – Type of iDST for scipy to perform.

Returns:

f_real – Real space data.

Return type:

3darray

Multiply

shift.cart.mult_fk_2D(fgrid, boxsize, k, fk)[source]

Multiply 2D grid in Fourier space by k dependent function.

Parameters:
  • fgrid (2darray) – 2D grid data.

  • boxsize (float) – Size of the box the grid is defined on.

  • k (array) – K values for k-dependent function f(k).

  • fk (array) – Function values at k.

shift.cart.mult_fk_3D(fgrid, boxsize, k, fk)[source]

Multiply 3D grid in Fourier space by k dependent function.

Parameters:
  • fgrid (ndarray) – 3D grid data.

  • boxsize (float) – Size of the box the grid is defined on.

  • k (array) – K values for k-dependent function f(k).

  • fk (array) – Function values at k.

Power Spectrum

shift.cart.get_pofk_2D(dgrid, boxsize, ngrid, kmin=None, kmax=None)[source]

Returns the power spectrum of a 2D data set.

Parameters:
  • dgrid (2darray) – Density contrast.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • ngrid (int or list) – Grid division along one axis or a list for each axis.

  • kmin (float, optional) – Minimum Fourier mode, default = Minimum k mode of the grid.

  • kmax (float, optional) – Maximum Fourier mode, default = Maximum k mode of the grid.

Returns:

  • k (array) – k modes for the measured power spectrum.

  • keff (array) – Effective k modes for the measured power spectrum.

  • pk (array) – Measure power spectrum.

shift.cart.get_pofk_3D(dgrid, boxsize, ngrid, kmin=None, kmax=None)[source]

Returns the power spectrum of a 3D data set.

Parameters:
  • dgrid (3darray) – Density contrast.

  • boxsize (float or list) – Box size or a list of the dimensions of each axis.

  • ngrid (int or list) – Grid division along one axis or a list for each axis.

  • kmin (float, optional) – Minimum Fourier mode, default = Minimum k mode of the grid.

  • kmax (float, optional) – Maximum Fourier mode, default = Maximum k mode of the grid.

Returns:

  • k (array) – k modes for the measured power spectrum.

  • keff (array) – Effective k modes for the measured power spectrum.

  • pk (array) – Measure power spectrum.

Utility Functions

shift.cart.get_kf(boxsize)[source]

Returns the Fundamental Fourier mode.

Parameters:

boxsize (float) – Box size.

Returns:

kf – Fundamental mode.

Return type:

float

shift.cart.get_kn(boxsize, ngrid)[source]

Returns the Nyquist Fourier mode.

Parameters:
  • boxsize (float) – Box size.

  • ngrid (int) – Grid size.

Returns:

kn – Nyquist frequency.

Return type:

float

shift.cart.fftshift(freq)[source]

Centers FFT frequencies so that 0 is in the center.

Parameters:

freq (array) – Reorders any FFT frequency-like array to have the 0th element in the center.

shift.cart.ifftshift(freq)[source]

Uncenters FFT frequencies so that 0 is no longer in the center.

Parameters:

freq (array) – Reorders any FFT frequency-like array to have the 0th element back to the normal convention and not in the center.

shift.cart.normalise_freq(freq, boxsize)[source]

Normalises fourier frequencies, i.e. removing the dependency on boxsize.

Parameters:
  • freq (array) – FFT frequencies.

  • boxsize (float) – Size of the original box.

shift.cart.unnormalise_freq(freq, boxsize)[source]

Unnormalises fourier frequencies, i.e. adds the dependency on boxsize.

Parameters:
  • freq (array) – FFT frequencies.

  • boxsize (float) – Size of the original box.