API

Base reconstruction class

Implementation of base reconstruction class.

class pyrecon.recon.BaseReconstruction(f=0.0, bias=1.0, los=None, fft_engine='numpy', fft_wisdom=None, save_fft_wisdom=None, fft_plan='measure', wrap=False, **kwargs)

Bases: pyrecon.utils.BaseClass

Base template reconstruction class. Reconstruction algorithms should extend this class, by (at least) implementing:

A standard reconstruction would be:

# MyReconstruction is your reconstruction algorithm
recon = MyReconstruction(f=0.8, bias=2.0, nmesh=512, boxsize=1000., boxcenter=2000.)
recon.assign_data(positions_data, weights_data)
recon.assign_randoms(positions_randoms, weights_randoms)
recon.set_density_contrast()
recon.run()
positions_rec_data = recon.read_shifted_positions(positions_data)
# RecSym = remove large scale RSD from randoms
positions_rec_randoms = recon.read_shifted_positions(positions_randoms)
# Or RecIso
# positions_rec_randoms = recon.read_shifted_positions(positions_randoms, field='disp')
mesh_data

Mesh (3D grid) to assign (“paint”) galaxies to.

Type

RealMesh

mesh_randoms

Mesh (3D grid) to assign (“paint”) randoms to.

Type

RealMesh

f

Growth rate.

Type

float

bias

Galaxy bias.

Type

float

los

If None, local (varying) line-of-sight. Else line-of-sight (unit) 3-vector.

Type

array

info

Mesh information (boxsize, boxcenter, nmesh, etc.).

Type

MeshInfo

boxsize, boxcenter, cellsize, offset

Mesh properties; see MeshInfo.

Type

array

Initialize BaseReconstruction.

Parameters
  • f (float) – Growth rate.

  • bias (float) – Galaxy bias.

  • los (string, array_like, default=None) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

  • fft_engine (string, BaseFFTEngine, default='numpy') – Engine for fast Fourier transforms. See BaseFFTEngine. We strongly recommend using ‘fftw’ for multithreaded FFTs.

  • fft_wisdom (string, tuple, default=None) – Optionally, wisdom for FFTW, if fft_engine is ‘fftw’. If a string, should be a path to previously saved FFT wisdom (with numpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given in save_fft_wisdom will be loaded, if exists.

  • save_fft_wisdom (bool, string, default=None) – If not None, path where to save the wisdom for FFTW. If True, the wisdom will be saved in the default path: f’wisdom.shape-{nmesh[0]}-{nmesh[1]}-{nmesh[2]}.type-{type}.nthreads-{nthreads}.npy’.

  • fft_plan (string, default='measure') – Only used for FFTW. Choices are [‘estimate’, ‘measure’, ‘patient’, ‘exhaustive’]. The increasing amount of effort spent during the planning stage to create the fastest possible transform. Usually ‘measure’ is a good compromise.

  • wrap (boolean, default=False) – If True, wrap input particle positions into the box.

  • kwargs (dict) – Arguments to build mesh_data, mesh_randoms (see RealMesh).

assign_data(positions, weights=None)

Assign (paint) data to mesh_data. This can be done slab-by-slab (e.g. to reduce memory footprint).

Parameters
  • positions (array of shape (N,3)) – Cartesian positions.

  • weights (array of shape (N,), default=None) – Weights; default to 1.

assign_randoms(positions, weights=None)

Same as assign_data(), but for random objects.

property beta

\(\beta\) parameter, as the ratio of the growth rate to the galaxy bias.

read_shifted_positions(positions, field='disp+rsd')

Read shifted positions i.e. the difference positions - self.read_shifts(positions, field=field). Output (and input) positions are wrapped if wrap.

Parameters
  • positions (array of shape (N, 3)) – Cartesian positions.

  • field (string, default='disp+rsd') – Apply either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

positions – Shifted positions.

Return type

array of shape (N, 3)

read_shifts(positions, field='disp+rsd')

Read displacement at input positions. To get shifted/reconstructed positions, given reconstruction instance recon:

positions_rec_data = positions_data - recon.read_shifts(positions_data)
# RecSym = remove large scale RSD from randoms
positions_rec_randoms = positions_randoms - recon.read_shifts(positions_randoms)
# Or RecIso
# positions_rec_randoms = positions_randoms - recon.read_shifts(positions_randoms, field='disp')

Or directly use read_shifted_positions() (which wraps output positions if wrap).

Parameters
  • positions (array of shape (N, 3)) – Cartesian positions.

  • field (string, default='disp+rsd') – Either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

shifts – Displacements.

Return type

array of shape (N, 3)

run(*args, **kwargs)

Run reconstruction; to be implemented in your algorithm.

set_cosmo(f=None, bias=None, beta=None)

Set cosmology.

Parameters
  • f (float) – Growth rate. If None and beta` is provided, set f as beta * bias; else growth rate is left unchanged.

  • bias (float) – Bias. If None, bias is left unchanged.

  • beta (float) – \(\beta\) parameter. If not None, overrides f as beta * bias.

set_density_contrast(ran_min=0.75, smoothing_radius=15.0, **kwargs)

Set \(\delta\) field mesh_delta from data and randoms fields mesh_data and mesh_randoms. Eventually we will probably converge on a base method for all reconstructions.

Note

This method follows Martin’s reconstruction code: we are not satisfied with the ran_min prescription. At least ran_min should depend on random weights. See also Martin’s notes below.

Parameters
  • ran_min (float, default=0.75) – mesh_randoms points below this threshold have their density contrast set to 0.

  • smoothing_radius (float, default=15) – Smoothing scale, see RealMesh.smooth_gaussian().

  • kwargs (dict) – Optional arguments for RealMesh.smooth_gaussian().

set_los(los=None)

Set line-of-sight.

Parameters

los (string, array) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

exception pyrecon.recon.ReconstructionError

Bases: Exception

Error raised when issue with reconstruction.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

Multi grid reconstruction

Re-implementation of Martin J. White’s reconstruction code.

class pyrecon.multigrid.MultiGridReconstruction(*args, **kwargs)

Bases: pyrecon.multigrid.OriginalMultiGridReconstruction

Any update / test / improvement upon original algorithm.

Initialize MultiGridReconstruction. See BaseReconstruction for input parameters.

assign_data(positions, weights=None)

Assign (paint) data to mesh_data. This can be done slab-by-slab (e.g. to reduce memory footprint).

Parameters
  • positions (array of shape (N,3)) – Cartesian positions.

  • weights (array of shape (N,), default=None) – Weights; default to 1.

assign_randoms(positions, weights=None)

Same as assign_data(), but for random objects.

property beta

\(\beta\) parameter, as the ratio of the growth rate to the galaxy bias.

read_shifted_positions(positions, field='disp+rsd')

Read shifted positions i.e. the difference positions - self.read_shifts(positions, field=field). Output (and input) positions are wrapped if wrap.

Parameters
  • positions (array of shape (N, 3)) – Cartesian positions.

  • field (string, default='disp+rsd') – Apply either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

positions – Shifted positions.

Return type

array of shape (N, 3)

read_shifts(positions, field='disp+rsd')

Read displacement at input positions by deriving the computed displacement potential mesh_phi (finite difference scheme). See BaseReconstruction.read_shifts() for input parameters.

run(jacobi_damping_factor=0.4, jacobi_niterations=5, vcycle_niterations=6)

Run reconstruction, i.e. set displacement potential attr:mesh_phi from mesh_delta. Default parameter values are the same as in Martin’s code.

Parameters
  • jacobi_damping_factor (float, default=0.4) – Damping factor for Jacobi iterations.

  • jacobi_niterations (int, default=5) – Number of Jacobi iterations.

  • vcycle_niterations (int, default=6) – Number of V-cycle calls.

set_cosmo(f=None, bias=None, beta=None)

Set cosmology.

Parameters
  • f (float) – Growth rate. If None and beta` is provided, set f as beta * bias; else growth rate is left unchanged.

  • bias (float) – Bias. If None, bias is left unchanged.

  • beta (float) – \(\beta\) parameter. If not None, overrides f as beta * bias.

set_density_contrast(ran_min=0.75, smoothing_radius=15.0, **kwargs)

See BaseReconstruction.set_density_contrast.

set_los(los=None)

Set line-of-sight.

Parameters

los (string, array) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

class pyrecon.multigrid.OriginalMultiGridReconstruction(*args, **kwargs)

Bases: pyrecon.recon.BaseReconstruction

ctypes-based implementation for Martin J. White’s reconstruction code, using full multigrid V-cycle based on damped Jacobi iteration. We re-implemented https://github.com/martinjameswhite/recon_code/blob/master/multigrid.cpp, allowing for non-cubic (rectangular) mesh. Numerical agreement in the Zeldovich displacements between original code and this re-implementation is numerical precision (absolute and relative difference of 1e-10). To test this, change float to double and increase precision in io.cpp/write_data in the original code.

Initialize MultiGridReconstruction. See BaseReconstruction for input parameters.

assign_data(positions, weights=None)

Assign (paint) data to mesh_data. This can be done slab-by-slab (e.g. to reduce memory footprint).

Parameters
  • positions (array of shape (N,3)) – Cartesian positions.

  • weights (array of shape (N,), default=None) – Weights; default to 1.

assign_randoms(positions, weights=None)

Same as assign_data(), but for random objects.

property beta

\(\beta\) parameter, as the ratio of the growth rate to the galaxy bias.

read_shifted_positions(positions, field='disp+rsd')

Read shifted positions i.e. the difference positions - self.read_shifts(positions, field=field). Output (and input) positions are wrapped if wrap.

Parameters
  • positions (array of shape (N, 3)) – Cartesian positions.

  • field (string, default='disp+rsd') – Apply either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

positions – Shifted positions.

Return type

array of shape (N, 3)

read_shifts(positions, field='disp+rsd')

Read displacement at input positions by deriving the computed displacement potential mesh_phi (finite difference scheme). See BaseReconstruction.read_shifts() for input parameters.

run(jacobi_damping_factor=0.4, jacobi_niterations=5, vcycle_niterations=6)

Run reconstruction, i.e. set displacement potential attr:mesh_phi from mesh_delta. Default parameter values are the same as in Martin’s code.

Parameters
  • jacobi_damping_factor (float, default=0.4) – Damping factor for Jacobi iterations.

  • jacobi_niterations (int, default=5) – Number of Jacobi iterations.

  • vcycle_niterations (int, default=6) – Number of V-cycle calls.

set_cosmo(f=None, bias=None, beta=None)

Set cosmology.

Parameters
  • f (float) – Growth rate. If None and beta` is provided, set f as beta * bias; else growth rate is left unchanged.

  • bias (float) – Bias. If None, bias is left unchanged.

  • beta (float) – \(\beta\) parameter. If not None, overrides f as beta * bias.

set_density_contrast(ran_min=0.75, smoothing_radius=15.0, **kwargs)

Set \(\delta\) field mesh_delta from data and randoms fields mesh_data and mesh_randoms.

Note

This method follows Martin’s reconstruction code: we are not satisfied with the ran_min prescription. At least ran_min should depend on random weights. See also Martin’s notes below.

Parameters
  • ran_min (float, default=0.75) – mesh_randoms points below this threshold have their density contrast set to 0.

  • smoothing_radius (float, default=15) – Smoothing scale, see RealMesh.smooth_gaussian().

  • kwargs (dict) – Optional arguments for RealMesh.smooth_gaussian().

set_los(los=None)

Set line-of-sight.

Parameters

los (string, array) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

Iterative FFT reconstruction

Implementation of Burden et al. 2015 (https://arxiv.org/abs/1504.02591) algorithm.

class pyrecon.iterative_fft.IterativeFFTReconstruction(f=0.0, bias=1.0, los=None, fft_engine='numpy', fft_wisdom=None, save_fft_wisdom=None, fft_plan='measure', wrap=False, **kwargs)

Bases: pyrecon.recon.BaseReconstruction

Implementation of Burden et al. 2015 (https://arxiv.org/abs/1504.02591) field-level (as opposed to IterativeFFTParticleReconstruction) algorithm.

Initialize BaseReconstruction.

Parameters
  • f (float) – Growth rate.

  • bias (float) – Galaxy bias.

  • los (string, array_like, default=None) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

  • fft_engine (string, BaseFFTEngine, default='numpy') – Engine for fast Fourier transforms. See BaseFFTEngine. We strongly recommend using ‘fftw’ for multithreaded FFTs.

  • fft_wisdom (string, tuple, default=None) – Optionally, wisdom for FFTW, if fft_engine is ‘fftw’. If a string, should be a path to previously saved FFT wisdom (with numpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given in save_fft_wisdom will be loaded, if exists.

  • save_fft_wisdom (bool, string, default=None) – If not None, path where to save the wisdom for FFTW. If True, the wisdom will be saved in the default path: f’wisdom.shape-{nmesh[0]}-{nmesh[1]}-{nmesh[2]}.type-{type}.nthreads-{nthreads}.npy’.

  • fft_plan (string, default='measure') – Only used for FFTW. Choices are [‘estimate’, ‘measure’, ‘patient’, ‘exhaustive’]. The increasing amount of effort spent during the planning stage to create the fastest possible transform. Usually ‘measure’ is a good compromise.

  • wrap (boolean, default=False) – If True, wrap input particle positions into the box.

  • kwargs (dict) – Arguments to build mesh_data, mesh_randoms (see RealMesh).

assign_data(positions, weights=None)

Assign (paint) data to mesh_data. This can be done slab-by-slab (e.g. to reduce memory footprint).

Parameters
  • positions (array of shape (N,3)) – Cartesian positions.

  • weights (array of shape (N,), default=None) – Weights; default to 1.

assign_randoms(positions, weights=None)

Same as assign_data(), but for random objects.

property beta

\(\beta\) parameter, as the ratio of the growth rate to the galaxy bias.

read_shifted_positions(positions, field='disp+rsd')

Read shifted positions i.e. the difference positions - self.read_shifts(positions, field=field). Output (and input) positions are wrapped if wrap.

Parameters
  • positions (array of shape (N, 3)) – Cartesian positions.

  • field (string, default='disp+rsd') – Apply either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

positions – Shifted positions.

Return type

array of shape (N, 3)

read_shifts(positions, field='disp+rsd')

Read displacement at input positions. To get shifted/reconstructed positions, given reconstruction instance recon:

positions_rec_data = positions_data - recon.read_shifts(positions_data)
# RecSym = remove large scale RSD from randoms
positions_rec_randoms = positions_randoms - recon.read_shifts(positions_randoms)
# Or RecIso
# positions_rec_randoms = positions_randoms - recon.read_shifts(positions_randoms, field='disp')

Or directly use read_shifted_positions() (which wraps output positions if wrap).

Parameters
  • positions (array of shape (N, 3)) – Cartesian positions.

  • field (string, default='disp+rsd') – Either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

shifts – Displacements.

Return type

array of shape (N, 3)

run(niterations=3)

Run reconstruction, i.e. compute Zeldovich displacement fields mesh_psi.

Parameters

niterations (int) – Number of iterations.

set_cosmo(f=None, bias=None, beta=None)

Set cosmology.

Parameters
  • f (float) – Growth rate. If None and beta` is provided, set f as beta * bias; else growth rate is left unchanged.

  • bias (float) – Bias. If None, bias is left unchanged.

  • beta (float) – \(\beta\) parameter. If not None, overrides f as beta * bias.

set_density_contrast(ran_min=0.75, smoothing_radius=15.0, **kwargs)

Set \(\delta\) field mesh_delta from data and randoms fields mesh_data and mesh_randoms. Eventually we will probably converge on a base method for all reconstructions.

Note

This method follows Martin’s reconstruction code: we are not satisfied with the ran_min prescription. At least ran_min should depend on random weights. See also Martin’s notes below.

Parameters
  • ran_min (float, default=0.75) – mesh_randoms points below this threshold have their density contrast set to 0.

  • smoothing_radius (float, default=15) – Smoothing scale, see RealMesh.smooth_gaussian().

  • kwargs (dict) – Optional arguments for RealMesh.smooth_gaussian().

set_los(los=None)

Set line-of-sight.

Parameters

los (string, array) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

Iterative FFT particle reconstruction

Re-implementation of Bautista et al. 2018 (https://arxiv.org/pdf/1712.08064.pdf) algorithm.

class pyrecon.iterative_fft_particle.IterativeFFTParticleReconstruction(f=0.0, bias=1.0, los=None, fft_engine='numpy', fft_wisdom=None, save_fft_wisdom=None, fft_plan='measure', wrap=False, **kwargs)

Bases: pyrecon.iterative_fft_particle.OriginalIterativeFFTParticleReconstruction

Any update / test / improvement upon original algorithm.

Initialize BaseReconstruction.

Parameters
  • f (float) – Growth rate.

  • bias (float) – Galaxy bias.

  • los (string, array_like, default=None) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

  • fft_engine (string, BaseFFTEngine, default='numpy') – Engine for fast Fourier transforms. See BaseFFTEngine. We strongly recommend using ‘fftw’ for multithreaded FFTs.

  • fft_wisdom (string, tuple, default=None) – Optionally, wisdom for FFTW, if fft_engine is ‘fftw’. If a string, should be a path to previously saved FFT wisdom (with numpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given in save_fft_wisdom will be loaded, if exists.

  • save_fft_wisdom (bool, string, default=None) – If not None, path where to save the wisdom for FFTW. If True, the wisdom will be saved in the default path: f’wisdom.shape-{nmesh[0]}-{nmesh[1]}-{nmesh[2]}.type-{type}.nthreads-{nthreads}.npy’.

  • fft_plan (string, default='measure') – Only used for FFTW. Choices are [‘estimate’, ‘measure’, ‘patient’, ‘exhaustive’]. The increasing amount of effort spent during the planning stage to create the fastest possible transform. Usually ‘measure’ is a good compromise.

  • wrap (boolean, default=False) – If True, wrap input particle positions into the box.

  • kwargs (dict) – Arguments to build mesh_data, mesh_randoms (see RealMesh).

assign_data(positions, weights=None)

Assign (paint) data to mesh_data. Keeps track of input positions (for run()) and weights (for set_density_contrast()). See BaseReconstruction.assign_data() for parameters.

assign_randoms(positions, weights=None)

Assign (paint) randoms to mesh_randoms. Keeps track of sum of weights (for set_density_contrast()). See BaseReconstruction.assign_randoms() for parameters.

property beta

\(\beta\) parameter, as the ratio of the growth rate to the galaxy bias.

read_shifted_positions(positions, field='disp+rsd')

Read shifted positions i.e. the difference positions - self.read_shifts(positions, field=field). Output (and input) positions are wrapped if wrap.

Parameters
  • positions (array of shape (N, 3), string) – Cartesian positions. Pass string ‘data’ to get the shift positions for the input data positions passed to assign_data(). Note that in this case, shifts are read at the reconstructed data real-space positions.

  • field (string, default='disp+rsd') – Apply either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

positions – Shifted positions.

Return type

array of shape (N, 3)

read_shifts(positions, field='disp+rsd')

Read displacement at input positions.

Note

Data shifts are read at the reconstructed real-space positions, while random shifts are read at the redshift-space positions, is that consistent?

Parameters
  • positions (array of shape (N, 3), string) – Cartesian positions. Pass string ‘data’ to get the displacements for the input data positions passed to assign_data(). Note that in this case, shifts are read at the reconstructed data real-space positions.

  • field (string, default='disp+rsd') – Either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

shifts – Displacements.

Return type

array of shape (N, 3)

run(niterations=3)

Run reconstruction, i.e. compute reconstructed data real-space positions (_positions_rec_data) and Zeldovich displacements fields mesh_psi.

Parameters

niterations (int) – Number of iterations.

set_cosmo(f=None, bias=None, beta=None)

Set cosmology.

Parameters
  • f (float) – Growth rate. If None and beta` is provided, set f as beta * bias; else growth rate is left unchanged.

  • bias (float) – Bias. If None, bias is left unchanged.

  • beta (float) – \(\beta\) parameter. If not None, overrides f as beta * bias.

set_density_contrast(ran_min=0.01, smoothing_radius=15.0)

Set \(\delta\) field mesh_delta from data and randoms fields mesh_data and mesh_randoms.

Note

This method follows Julian’s reconstruction code. Handling of ran_min is better than in BaseReconstruction.set_density_contrast(). mesh_data and mesh_randoms fields are assumed to be smoothed already.

Parameters

ran_min (float, default=0.01) – mesh_randoms points below this threshold times mean random weights have their density contrast set to 0.

set_los(los=None)

Set line-of-sight.

Parameters

los (string, array) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

class pyrecon.iterative_fft_particle.OriginalIterativeFFTParticleReconstruction(f=0.0, bias=1.0, los=None, fft_engine='numpy', fft_wisdom=None, save_fft_wisdom=None, fft_plan='measure', wrap=False, **kwargs)

Bases: pyrecon.recon.BaseReconstruction

Exact re-implementation of Bautista et al. 2018 (https://arxiv.org/pdf/1712.08064.pdf) algorithm at https://github.com/julianbautista/eboss_clustering/blob/master/python/recon.py. Numerical agreement in the Zeldovich displacements between original codes and this re-implementation is machine precision (absolute and relative difference of 1e-12).

Initialize BaseReconstruction.

Parameters
  • f (float) – Growth rate.

  • bias (float) – Galaxy bias.

  • los (string, array_like, default=None) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

  • fft_engine (string, BaseFFTEngine, default='numpy') – Engine for fast Fourier transforms. See BaseFFTEngine. We strongly recommend using ‘fftw’ for multithreaded FFTs.

  • fft_wisdom (string, tuple, default=None) – Optionally, wisdom for FFTW, if fft_engine is ‘fftw’. If a string, should be a path to previously saved FFT wisdom (with numpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given in save_fft_wisdom will be loaded, if exists.

  • save_fft_wisdom (bool, string, default=None) – If not None, path where to save the wisdom for FFTW. If True, the wisdom will be saved in the default path: f’wisdom.shape-{nmesh[0]}-{nmesh[1]}-{nmesh[2]}.type-{type}.nthreads-{nthreads}.npy’.

  • fft_plan (string, default='measure') – Only used for FFTW. Choices are [‘estimate’, ‘measure’, ‘patient’, ‘exhaustive’]. The increasing amount of effort spent during the planning stage to create the fastest possible transform. Usually ‘measure’ is a good compromise.

  • wrap (boolean, default=False) – If True, wrap input particle positions into the box.

  • kwargs (dict) – Arguments to build mesh_data, mesh_randoms (see RealMesh).

assign_data(positions, weights=None)

Assign (paint) data to mesh_data. Keeps track of input positions (for run()) and weights (for set_density_contrast()). See BaseReconstruction.assign_data() for parameters.

assign_randoms(positions, weights=None)

Assign (paint) randoms to mesh_randoms. Keeps track of sum of weights (for set_density_contrast()). See BaseReconstruction.assign_randoms() for parameters.

property beta

\(\beta\) parameter, as the ratio of the growth rate to the galaxy bias.

read_shifted_positions(positions, field='disp+rsd')

Read shifted positions i.e. the difference positions - self.read_shifts(positions, field=field). Output (and input) positions are wrapped if wrap.

Parameters
  • positions (array of shape (N, 3), string) – Cartesian positions. Pass string ‘data’ to get the shift positions for the input data positions passed to assign_data(). Note that in this case, shifts are read at the reconstructed data real-space positions.

  • field (string, default='disp+rsd') – Apply either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

positions – Shifted positions.

Return type

array of shape (N, 3)

read_shifts(positions, field='disp+rsd')

Read displacement at input positions.

Note

Data shifts are read at the reconstructed real-space positions, while random shifts are read at the redshift-space positions, is that consistent?

Parameters
  • positions (array of shape (N, 3), string) – Cartesian positions. Pass string ‘data’ to get the displacements for the input data positions passed to assign_data(). Note that in this case, shifts are read at the reconstructed data real-space positions.

  • field (string, default='disp+rsd') – Either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

shifts – Displacements.

Return type

array of shape (N, 3)

run(niterations=3)

Run reconstruction, i.e. compute reconstructed data real-space positions (_positions_rec_data) and Zeldovich displacements fields mesh_psi.

Parameters

niterations (int) – Number of iterations.

set_cosmo(f=None, bias=None, beta=None)

Set cosmology.

Parameters
  • f (float) – Growth rate. If None and beta` is provided, set f as beta * bias; else growth rate is left unchanged.

  • bias (float) – Bias. If None, bias is left unchanged.

  • beta (float) – \(\beta\) parameter. If not None, overrides f as beta * bias.

set_density_contrast(ran_min=0.01, smoothing_radius=15.0)

Set \(\delta\) field mesh_delta from data and randoms fields mesh_data and mesh_randoms.

Note

This method follows Julian’s reconstruction code. Handling of ran_min is better than in BaseReconstruction.set_density_contrast(). mesh_data and mesh_randoms fields are assumed to be smoothed already.

Parameters

ran_min (float, default=0.01) – mesh_randoms points below this threshold times mean random weights have their density contrast set to 0.

set_los(los=None)

Set line-of-sight.

Parameters

los (string, array) – If los is None, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

Plane-parallel FFT reconstruction

Implementation of Burden et al. 2015 (https://arxiv.org/abs/1504.02591) algorithm.

class pyrecon.plane_parallel_fft.PlaneParallelFFTReconstruction(los=None, **kwargs)

Bases: pyrecon.recon.BaseReconstruction

Implementation of Eisenstein et al. 2007 (https://arxiv.org/pdf/astro-ph/0604362.pdf) algorithm. Section 3, paragraph starting with ‘Restoring in full the …’

Initialize IterativeFFTReconstruction.

Parameters
  • los (string, array, default=None) – May be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

  • kwargs (dict) – See BaseReconstruction for parameters.

assign_data(positions, weights=None)

Assign (paint) data to mesh_data. This can be done slab-by-slab (e.g. to reduce memory footprint).

Parameters
  • positions (array of shape (N,3)) – Cartesian positions.

  • weights (array of shape (N,), default=None) – Weights; default to 1.

assign_randoms(positions, weights=None)

Same as assign_data(), but for random objects.

property beta

\(\beta\) parameter, as the ratio of the growth rate to the galaxy bias.

read_shifted_positions(positions, field='disp+rsd')

Read shifted positions i.e. the difference positions - self.read_shifts(positions, field=field). Output (and input) positions are wrapped if wrap.

Parameters
  • positions (array of shape (N, 3)) – Cartesian positions.

  • field (string, default='disp+rsd') – Apply either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

positions – Shifted positions.

Return type

array of shape (N, 3)

read_shifts(positions, field='disp+rsd')

Read displacement at input positions. To get shifted/reconstructed positions, given reconstruction instance recon:

positions_rec_data = positions_data - recon.read_shifts(positions_data)
# RecSym = remove large scale RSD from randoms
positions_rec_randoms = positions_randoms - recon.read_shifts(positions_randoms)
# Or RecIso
# positions_rec_randoms = positions_randoms - recon.read_shifts(positions_randoms, field='disp')

Or directly use read_shifted_positions() (which wraps output positions if wrap).

Parameters
  • positions (array of shape (N, 3)) – Cartesian positions.

  • field (string, default='disp+rsd') – Either ‘disp’ (Zeldovich displacement), ‘rsd’ (RSD displacement), or ‘disp+rsd’ (Zeldovich + RSD displacement).

Returns

shifts – Displacements.

Return type

array of shape (N, 3)

run()

Run reconstruction, i.e. compute Zeldovich displacement fields mesh_psi.

set_cosmo(f=None, bias=None, beta=None)

Set cosmology.

Parameters
  • f (float) – Growth rate. If None and beta` is provided, set f as beta * bias; else growth rate is left unchanged.

  • bias (float) – Bias. If None, bias is left unchanged.

  • beta (float) – \(\beta\) parameter. If not None, overrides f as beta * bias.

set_density_contrast(ran_min=0.75, smoothing_radius=15.0, **kwargs)

Set \(\delta\) field mesh_delta from data and randoms fields mesh_data and mesh_randoms. Eventually we will probably converge on a base method for all reconstructions.

Note

This method follows Martin’s reconstruction code: we are not satisfied with the ran_min prescription. At least ran_min should depend on random weights. See also Martin’s notes below.

Parameters
  • ran_min (float, default=0.75) – mesh_randoms points below this threshold have their density contrast set to 0.

  • smoothing_radius (float, default=15) – Smoothing scale, see RealMesh.smooth_gaussian().

  • kwargs (dict) – Optional arguments for RealMesh.smooth_gaussian().

set_los(los=None)

Set line-of-sight.

Parameters

los (string, array_like) – May be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.

Metrics

Mesh

Implementation of RealMesh and ComplexMesh, along with FFT engines.

class pyrecon.mesh.BaseFFTEngine(shape, nthreads=None, type_complex=None, type_real=None, hermitian=True, **kwargs)

Bases: pyrecon.utils.BaseClass

Base engine for fast Fourier transforms. FFT engines should extend this class, by (at least) implementing:

shape

Shape of array (in real-space, i.e. not accounting for Hermitian symmetry) to transform.

Type

tuple

nthreads

Number of threads.

Type

int

type_real

Type for real values.

Type

np.dtype

type_complex

Type for complex values. Twice larger than type_float.

Type

np.dtype

hermitian

Whether complex array has Hermitian symmetry, i.e. is real when Fourier transformed.

Type

bool

Initialize FFT engine. Default types are ‘c16’ for type_complex and ‘f8’ for type_float.

Parameters
  • shape (list, tuple) – Array shape.

  • nthreads (int, default=None) – Number of threads.

  • type_complex (string, np.dtype, default=None) – Type for complex values. If not provided, use type_real instead.

  • type_real (string, np.dtype, default=None) – Type for real values. If not provided, use type_complex instead.

backward(fun)

Return backward transform of fun.

forward(fun)

Return forward transform of fun.

property hshape

Shape in Fourier-space, accounting for Hermitian symmetry.

property ndim

Number of dimensions.

property size

Size of array (in real-space, i.e. not accounting for Hermitian symmetry) to transform.

class pyrecon.mesh.BaseMesh(value=None, info=None, nthreads=None, attrs=None, **kwargs)

Bases: numpy.lib.mixins.NDArrayOperatorsMixin, pyrecon.utils.BaseClass

Base implementation for mesh. What follows are just methods to make BaseMesh behave like a numpy array. numpy functions can be applied directly to any instance mesh through e.g.:

np.sum(mesh)

Note

To get a deep copy of the mesh (including value), use deepcopy(). copy() will return a shallow copy.

value

Numpy array holding mesh values, or None when unset. Can be set any time using mesh.value = newvalue.

Type

array

info

Mesh information (boxsize, boxcenter, nmesh, etc.).

Type

MeshInfo

attrs

Dictionary of other attributes.

Type

dict

boxsize

See MeshInfo.

Type

array

boxcenter

See MeshInfo.

Type

array

nmesh

See MeshInfo.

Type

array

cellsize

See MeshInfo.

Type

array

ndim

See MeshInfo.

Type

array

Initialize BaseMesh.

Parameters
  • value (array, default=None) – Numpy array holding mesh values, or None (can set later through mesh.value = value.

  • info (MeshInfo, default=None) – Mesh information (boxsize, boxcenter, nmesh, etc.), copied and updated with kwargs.

  • nthreads (int, default=None) – Number of threads to use in mesh calculations; defaults to OpenMP’s default.

  • attrs (dict) – Dictionary of other attributes.

  • kwargs (dict) – Arguments for MeshInfo.

get_fft_engine(engine='numpy', **kwargs)

Return engine for fast Fourier transform.

Parameters
  • engine (string, BaseFFTEngine, default='numpy') – If string, use ‘numpy’ or ‘fftw’ (package pyfftw must be installed); else a FFT engine.

  • kwargs (dict) – Options for the FFT engines, used if engine is a FFT engine name (string). See NumpyFFTEngine and FFTWEngine.

Returns

engine – FFT engine.

Return type

BaseFFTEngine

property nthreads

Number of OpenMP threads.

set_fft_engine(engine='numpy', **kwargs)

Set engine for fast Fourier transform. See get_fft_engine().

set_num_threads(nthreads=None)

Set number of OpenMP threads used in mesh calculations.

class pyrecon.mesh.ComplexMesh(value=None, dtype=None, info=None, hermitian=True, nthreads=None, attrs=None, **kwargs)

Bases: pyrecon.mesh.BaseMesh

Class holding a 3D complex mesh.

Parameters

hermitian (bool) – Whether mesh has Hermitian symmetry, i.e. is real when Fourier transformed. In this case, shape is half nmesh on the last axis.

Initialize ComplexMesh.

Parameters
  • value (array, default=None) – Numpy array holding mesh values, or None (can set later through mesh.value = value.

  • dtype (string, np.dtype, defaut=None) – Type for value array. Defaults to ‘c16’.

  • info (MeshInfo, default=None) – Mesh information (boxsize, boxcenter, nmesh, etc.).

  • hermitian (bool) – Whether mesh has Hermitian symmetry, i.e. is real when Fourier transformed. In this case, shape is half nmesh on the last axis.

  • nthreads (int) – Number of threads to use in mesh calculations.

  • attrs (dict) – Dictionary of other attributes.

  • kwargs (dict) – Arguments for MeshInfo.

coords()

Return array of frequency (wavenumbers) along each axis.

property fundamental_freq

Fundamental frequency of the mesh along each axis.

get_fft_engine(engine='numpy', **kwargs)

Same as RealMesh.get_fft_engine().

property nthreads

Number of OpenMP threads.

prod_sum(arrays, exp=1)

Multiply mesh by (arrays[0][:,None,None] + arrays[1][None,:,None] + arrays[2][None,None,:]) ** exp

Parameters
  • arrays (sequence of 3 float arrays) – Arrays to multiply mesh by.

  • exp (int, default=1) – Exponent to raise broadcast sum of arrays to.

set_fft_engine(engine='numpy', **kwargs)

Set engine for fast Fourier transform. See get_fft_engine().

set_num_threads(nthreads=None)

Set number of OpenMP threads used in mesh calculations.

to_real(*args, **kwargs)

Return RealMesh computed with fast Fourier transforms. See get_fft_engine() for arguments. Raises a MeshError if FFT engine has not same Hermitian symmetry.

class pyrecon.mesh.FFTWEngine(shape, nthreads=None, wisdom=None, save_wisdom=None, plan='measure', **kwargs)

Bases: pyrecon.mesh.BaseFFTEngine

FFT engine based on pyfftw.

Initialize pyfftw engine.

Note

pyfftw.FFTW internally stores pyfftw.FFTW._input_array and pyfftw.FFTW._output_array, which is a waste of memory if one does not want to save them. e.g. performing engine.backward(engine.forward(array)) would take as much as 3 times (2 for the forward transform, and 1 output array in the backward transform) the memory footprint of array. As no access is provided to pyfftw.FFTW._input_array and pyfftw.FFTW._output_array attributes, we choose to destroy and rebuild pyfftw.FFTW for each transform, thereby allowing Python to destroy undesired arrays, at a relatively modest overhead (~ 0.5 s).

Parameters
  • shape (list, tuple) – Array shape.

  • nthreads (int, default=None) – Number of threads.

  • wisdom (string, tuple, default=None) – Precomputed pyfftw wisdom, used to accelerate FFTs. If a string, should be a path to previously saved FFT wisdom (with numpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given in save_wisdom will be loaded, if exists.

  • save_wisdom (bool, string, default=None) – If not None, path where to save the wisdom. If True, the wisdom will be saved in the default path: ‘wisdom.shape-{shape[0]}-{shape[1]}-{shape[2]}.type-{type}.nthreads-{nthreads}.npy’.

  • plan (string, default='measure') – Choices are [‘estimate’, ‘measure’, ‘patient’, ‘exhaustive’]. The increasing amount of effort spent during the planning stage to create the fastest possible transform. Usually ‘measure’ is a good compromise.

  • kwargs (dict) – Optional arguments for BaseFFTEngine.

backward(fun, destroy_input=True)

Return backward transform of fun; destroy_input = True to allow destroy fun (in case dimension > 1 and hermitian).

forward(fun)

Return forward transform of fun.

property hshape

Shape in Fourier-space, accounting for Hermitian symmetry.

property ndim

Number of dimensions.

property size

Size of array (in real-space, i.e. not accounting for Hermitian symmetry) to transform.

exception pyrecon.mesh.MeshError

Bases: Exception

Exception raised when issue with mesh.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class pyrecon.mesh.MeshInfo(nmesh=None, boxsize=None, boxcenter=None, cellsize=None, value=None, positions=None, boxpad=1.5, dtype=None)

Bases: pyrecon.utils.BaseClass

Class holding mesh information.

dtype

Type for mesh array.

Type

np.dtype

nmesh

Mesh size, i.e. number of mesh nodes along each axis.

Type

array

boxsize

Physical size of the box.

Type

array

boxcenter

Box center.

Type

array

Initalize MeshInfo.

Parameters
  • nmesh (array, int, default=None) – Mesh size, i.e. number of mesh nodes along each axis. If not provided, see value.

  • boxsize (array, float, default=None) – Physical size of the box. If not provided, see positions.

  • boxcenter (array, float, default=None) – Box center. If not provided, see positions.

  • cellsize (array, float, default=None) – Physical size of mesh cells. If not None, and mesh size nmesh is not None, used to set boxsize as nmesh * cellsize. If nmesh is None, it is set as (the nearest integer(s) to) boxsize/cellsize.

  • value (array, default=None) – Only used to get mesh size.

  • positions (array of shape (N,3), default=None) – If boxsize and / or boxcenter is None, use these positions to determine boxsize and / or boxcenter.

  • boxpad (float, default=1.5) – When boxsize is determined from positions, take boxpad times the smallest box enclosing positions as boxsize.

  • dtype (string, np.dtype, defaut=None) – Type for value array. If None, defaults to np.asarray(value).dtype if value is not None, else ‘f8’.

property cellsize

Physical size of mesh cells.

clone(**kwargs)

Clone current MeshInfo instance, optionally updating attributes with kwargs.

property ndim
Type

Number of dimensions

property offset

Coordinates of the (0, 0, 0) corner of the box.

wrap(positions)

Wrap input positions.

class pyrecon.mesh.NumpyFFTEngine(shape, nthreads=None, type_complex=None, type_real=None, hermitian=True, **kwargs)

Bases: pyrecon.mesh.BaseFFTEngine

FFT engine based on numpy.fft.

Initialize FFT engine. Default types are ‘c16’ for type_complex and ‘f8’ for type_float.

Parameters
  • shape (list, tuple) – Array shape.

  • nthreads (int, default=None) – Number of threads.

  • type_complex (string, np.dtype, default=None) – Type for complex values. If not provided, use type_real instead.

  • type_real (string, np.dtype, default=None) – Type for real values. If not provided, use type_complex instead.

backward(fun)

Return backward transform of fun.

forward(fun)

Return forward transform of fun.

property hshape

Shape in Fourier-space, accounting for Hermitian symmetry.

property ndim

Number of dimensions.

property size

Size of array (in real-space, i.e. not accounting for Hermitian symmetry) to transform.

class pyrecon.mesh.RealMesh(value=None, dtype=None, info=None, nthreads=None, attrs=None, **kwargs)

Bases: pyrecon.mesh.BaseMesh

Class holding a 3D real mesh.

Initalize RealMesh.

Parameters
  • value (array, default=None) – Numpy array holding mesh values, or None (can set later through mesh.value = value.

  • dtype (string, np.dtype, defaut=None) – Type for value array. Defaults to ‘f8’.

  • info (MeshInfo, default=None) – Mesh information (boxsize, boxcenter, nmesh, etc.), copied and updated with kwargs.

  • nthreads (int) – Number of threads to use in mesh calculations.

  • attrs (dict) – Dictionary of other attributes.

  • kwargs (dict) – Arguments for MeshInfo.

assign_cic(positions, weights=None, wrap=False)

Assign (paint) positions to mesh with Cloud-in-Cell scheme.

Parameters
  • positions (array of shape (N, 3)) – Cartesian positions.

  • weights (array of shape (N,), default=None) – Weights; default to 1.

  • wrap (boolean, default=False) – If True, wrap input particle positions into the box.

coords()

Return array of coordinates along each axis.

get_fft_engine(engine='numpy', **kwargs)

Return engine for fast Fourier transform.

Parameters
  • engine (string, BaseFFTEngine, default='numpy') – If string, use ‘numpy’ or ‘fftw’ (package pyfftw must be installed); else a FFT engine.

  • kwargs (dict) – Options for the FFT engines, used if engine is a FFT engine name (string). See NumpyFFTEngine and FFTWEngine.

Returns

engine – FFT engine.

Return type

BaseFFTEngine

property nthreads

Number of OpenMP threads.

prod_sum(arrays, exp=1)

Multiply mesh by (arrays[0][:,None,None] + arrays[1][None,:,None] + arrays[2][None,None,:]) ** exp

Parameters
  • arrays (sequence of 3 float arrays) – Arrays to multiply mesh by.

  • exp (int, default=1) – Exponent to raise broadcast sum of arrays to.

read_cic(positions, wrap=False)

Read mesh values interpolated at input positions with Cloud-in-Cell scheme.

Parameters
  • positions (array of shape (N,3)) – Cartesian positions.

  • wrap (boolean, default=False) – If True, wrap input particle positions into the box.

Returns

values – Mesh values interpolated at input positions.

Return type

array of shape (N,)

read_finite_difference_cic(positions, wrap=False)

Read derivative (finite difference scheme) of mesh values along each axis interpolated at input positions with Cloud-in-Cell scheme.

Parameters
  • positions (array of shape (N,3)) – Cartesian positions.

  • wrap (boolean, default=False) – If True, wrap input particle positions into the box.

Returns

values – Derivative of mesh values interpolated at input positions.

Return type

array of shape (N,)

set_fft_engine(engine='numpy', **kwargs)

Set engine for fast Fourier transform. See get_fft_engine().

set_num_threads(nthreads=None)

Set number of OpenMP threads used in mesh calculations.

smooth_gaussian(radius, method='fft', nsigmas=2.5, **kwargs)

Apply Gaussian smoothing to mesh.

Parameters
  • radius (array, float) – Smoothing scale (along each axis, or same for all axes).

  • method (string, default='fft') – Perform Gaussian smoothing in real space (‘real’) or using FFT (‘fft’).

  • nsigmas (float, default=2.5) – If method is ‘real’, number of Gaussian sigmas where to stop convolution.

  • kwargs (dict) – Optional arguments for get_fft_engine().

to_complex(*args, **kwargs)

Return ComplexMesh computed with fast Fourier transforms. See get_fft_engine() for arguments.

class pyrecon.mesh.SetterProperty(func, doc=None)

Bases: object

Attribute setter, runs func when setting a class attribute. Taken from https://stackoverflow.com/questions/17576009/python-class-property-use-setter-but-evade-getter

pyrecon.mesh.get_fft_engine(engine, *args, **kwargs)

Return FFT engine.

Parameters
  • engine (BaseFFTEngine, string) – FFT engine, or one of [‘numpy’, ‘fftw’].

  • args (tuple, dict) – Arguments for FFT engine.

  • kwargs (tuple, dict) – Arguments for FFT engine.

Returns

engine

Return type

BaseFFTEngine

Utilities

class pyrecon.utils.BaseClass

Bases: object

Base class that implements copy(). To be used throughout this package.

class pyrecon.utils.BaseMetaClass(name, bases, class_dict)

Bases: type

Meta class to add logging attributes to BaseClass derived classes.

mro()

Return a type’s method resolution order.

set_logger()

Add attributes for logging:

  • logger

  • methods log_debug, log_info, log_warning, log_error, log_critical

class pyrecon.utils.DistanceToRedshift(distance, zmax=100.0, nz=2048, interp_order=3)

Bases: object

Class that holds a conversion distance -> redshift.

Initialize DistanceToRedshift. Creates an array of redshift -> distance in log(redshift) and instantiates a spline interpolator distance -> redshift.

Parameters
  • distance (callable) – Callable that provides distance as a function of redshift (array).

  • zmax (float, default=100.) – Maximum redshift for redshift <-> distance mapping.

  • nz (int, default=2048) – Number of points for redshift <-> distance mapping.

  • interp_order (int, default=3) – Interpolation order, e.g. 1 for linear interpolation, 3 for cubic splines.

class pyrecon.utils.MemoryMonitor(pid=None)

Bases: object

Class that monitors memory usage and clock, useful to check for memory leaks.

>>> with MemoryMonitor() as mem:
        '''do something'''
        mem()
        '''do something else'''

Initalize MemoryMonitor and register current memory usage.

Parameters

pid (int, default=None) – Process identifier. If None, use the identifier of the current process.

pyrecon.utils.broadcast_arrays(*arrays)

Return broadcastable arrays given input 1D arrays.

Parameters

arrays (1D arrays) – N 1D arrays of size (n1, n2, …)

Returns

arrays – N ND arrays of shape (n1,1,1,1…(N - 1 times)), etc.

Return type

ND arrays

pyrecon.utils.cartesian_to_sky(position, wrap=True, degree=True)

Transform Cartesian coordinates into distance, RA, Dec.

Parameters
  • position (array of shape (N, 3)) – Position in Cartesian coordinates.

  • wrap (bool, default=True) – Whether to wrap RA in \([0, 2 \pi]\).

  • degree (bool, default=True) – Whether RA, Dec are in degrees (True) or radians (False).

Returns

  • dist (array) – Distance.

  • ra (array) – Right Ascension.

  • dec (array) – Declination.

pyrecon.utils.distance(position)

Return cartesian distance, taking coordinates along position last axis.

pyrecon.utils.exception_handler(exc_type, exc_value, exc_traceback)

Print exception with a logger.

pyrecon.utils.mkdir(dirname)

Try to create dirnm and catch OSError.

pyrecon.utils.random_box_positions(boxsize, boxcenter=0.0, size=None, nbar=None, rng=None, seed=None, dtype=None)

Return Cartesian positions in a 3D box.

Parameters
  • boxsize (array, float) – Physical size of the box.

  • boxcenter (array, float, default=0.) – Box center.

  • size (float, default=None) – Number of particles. See nbar.

  • nbar (float, default=None) – If size is None, size is obtained as the nearest integer to nbar * volume where volume is the box volume.

  • rng (np.RandomState, default=None) – Random generator, optional.

  • seed (int, default=None) – If rng is None, the random seed.

  • dtype (string, np.dtype, defaut=None) – Type output array.

Returns

positions

Return type

array of shape (size, 3)

pyrecon.utils.setup_logging(level=20, stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, filename=None, filemode='w', **kwargs)

Set up logging.

Parameters
  • level (string, int, default=logging.INFO) – Logging level.

  • stream (_io.TextIOWrapper, default=sys.stdout) – Where to stream.

  • filename (string, default=None) – If not None stream to file name.

  • filemode (string, default='w') – Mode to open file, only used if filename is not None.

  • kwargs (dict) – Other arguments for logging.basicConfig().

pyrecon.utils.sky_to_cartesian(dist, ra, dec, degree=True, dtype=None)

Transform distance, RA, Dec into Cartesian coordinates.

Parameters
  • dist (array of shape (N,)) – Distance.

  • ra (array of shape (N,)) – Right Ascension.

  • dec (array of shape (N,)) – Declination.

  • degree (default=True) – Whether RA, Dec are in degrees (True) or radians (False).

  • dtype (numpy.dtype, default=None) – numpy.dtype for returned array.

Returns

position – Position in Cartesian coordinates.

Return type

array of shape (N, 3)