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.BaseClassBase 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')
- 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
- 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
losisNone, 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_engineis ‘fftw’. If a string, should be a path to previously saved FFT wisdom (withnumpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given insave_fft_wisdomwill be loaded, if exists.save_fft_wisdom (bool, string, default=None) – If not
None, path where to save the wisdom for FFTW. IfTrue, 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(seeRealMesh).
- 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 ifwrap.- 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 ifwrap).- 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
Noneand beta` is provided, setfasbeta * bias; else growth rate is left unchanged.bias (float) – Bias. If
None, bias is left unchanged.beta (float) – \(\beta\) parameter. If not
None, overridesfasbeta * bias.
- set_density_contrast(ran_min=0.75, smoothing_radius=15.0, **kwargs)¶
Set \(\delta\) field
mesh_deltafrom data and randoms fieldsmesh_dataandmesh_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_minprescription. At leastran_minshould depend on random weights. See also Martin’s notes below.- Parameters
ran_min (float, default=0.75) –
mesh_randomspoints 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
losisNone, use local (varying) line-of-sight. Else, may be ‘x’, ‘y’ or ‘z’, for one of the Cartesian axes. Else, a 3-vector.
Multi grid reconstruction¶
Re-implementation of Martin J. White’s reconstruction code.
- class pyrecon.multigrid.MultiGridReconstruction(*args, **kwargs)¶
Bases:
pyrecon.multigrid.OriginalMultiGridReconstructionAny update / test / improvement upon original algorithm.
Initialize
MultiGridReconstruction. SeeBaseReconstructionfor 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 ifwrap.- 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). SeeBaseReconstruction.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
Noneand beta` is provided, setfasbeta * bias; else growth rate is left unchanged.bias (float) – Bias. If
None, bias is left unchanged.beta (float) – \(\beta\) parameter. If not
None, overridesfasbeta * 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
losisNone, 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.BaseReconstructionctypes-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. SeeBaseReconstructionfor 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 ifwrap.- 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). SeeBaseReconstruction.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
Noneand beta` is provided, setfasbeta * bias; else growth rate is left unchanged.bias (float) – Bias. If
None, bias is left unchanged.beta (float) – \(\beta\) parameter. If not
None, overridesfasbeta * bias.
- set_density_contrast(ran_min=0.75, smoothing_radius=15.0, **kwargs)¶
Set \(\delta\) field
mesh_deltafrom data and randoms fieldsmesh_dataandmesh_randoms.Note
This method follows Martin’s reconstruction code: we are not satisfied with the
ran_minprescription. At leastran_minshould depend on random weights. See also Martin’s notes below.- Parameters
ran_min (float, default=0.75) –
mesh_randomspoints 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
losisNone, 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.BaseReconstructionImplementation 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
losisNone, 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_engineis ‘fftw’. If a string, should be a path to previously saved FFT wisdom (withnumpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given insave_fft_wisdomwill be loaded, if exists.save_fft_wisdom (bool, string, default=None) – If not
None, path where to save the wisdom for FFTW. IfTrue, 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(seeRealMesh).
- 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 ifwrap.- 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 ifwrap).- 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
Noneand beta` is provided, setfasbeta * bias; else growth rate is left unchanged.bias (float) – Bias. If
None, bias is left unchanged.beta (float) – \(\beta\) parameter. If not
None, overridesfasbeta * bias.
- set_density_contrast(ran_min=0.75, smoothing_radius=15.0, **kwargs)¶
Set \(\delta\) field
mesh_deltafrom data and randoms fieldsmesh_dataandmesh_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_minprescription. At leastran_minshould depend on random weights. See also Martin’s notes below.- Parameters
ran_min (float, default=0.75) –
mesh_randomspoints 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
losisNone, 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.OriginalIterativeFFTParticleReconstructionAny update / test / improvement upon original algorithm.
Initialize
BaseReconstruction.- Parameters
f (float) – Growth rate.
bias (float) – Galaxy bias.
los (string, array_like, default=None) – If
losisNone, 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_engineis ‘fftw’. If a string, should be a path to previously saved FFT wisdom (withnumpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given insave_fft_wisdomwill be loaded, if exists.save_fft_wisdom (bool, string, default=None) – If not
None, path where to save the wisdom for FFTW. IfTrue, 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(seeRealMesh).
- assign_data(positions, weights=None)¶
Assign (paint) data to
mesh_data. Keeps track of input positions (forrun()) and weights (forset_density_contrast()). SeeBaseReconstruction.assign_data()for parameters.
- assign_randoms(positions, weights=None)¶
Assign (paint) randoms to
mesh_randoms. Keeps track of sum of weights (forset_density_contrast()). SeeBaseReconstruction.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 ifwrap.- 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 fieldsmesh_psi.- Parameters
niterations (int) – Number of iterations.
- set_cosmo(f=None, bias=None, beta=None)¶
Set cosmology.
- Parameters
f (float) – Growth rate. If
Noneand beta` is provided, setfasbeta * bias; else growth rate is left unchanged.bias (float) – Bias. If
None, bias is left unchanged.beta (float) – \(\beta\) parameter. If not
None, overridesfasbeta * bias.
- set_density_contrast(ran_min=0.01, smoothing_radius=15.0)¶
Set \(\delta\) field
mesh_deltafrom data and randoms fieldsmesh_dataandmesh_randoms.Note
This method follows Julian’s reconstruction code. Handling of
ran_minis better than inBaseReconstruction.set_density_contrast().mesh_dataandmesh_randomsfields are assumed to be smoothed already.- Parameters
ran_min (float, default=0.01) –
mesh_randomspoints 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
losisNone, 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.BaseReconstructionExact 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
losisNone, 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_engineis ‘fftw’. If a string, should be a path to previously saved FFT wisdom (withnumpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given insave_fft_wisdomwill be loaded, if exists.save_fft_wisdom (bool, string, default=None) – If not
None, path where to save the wisdom for FFTW. IfTrue, 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(seeRealMesh).
- assign_data(positions, weights=None)¶
Assign (paint) data to
mesh_data. Keeps track of input positions (forrun()) and weights (forset_density_contrast()). SeeBaseReconstruction.assign_data()for parameters.
- assign_randoms(positions, weights=None)¶
Assign (paint) randoms to
mesh_randoms. Keeps track of sum of weights (forset_density_contrast()). SeeBaseReconstruction.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 ifwrap.- 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 fieldsmesh_psi.- Parameters
niterations (int) – Number of iterations.
- set_cosmo(f=None, bias=None, beta=None)¶
Set cosmology.
- Parameters
f (float) – Growth rate. If
Noneand beta` is provided, setfasbeta * bias; else growth rate is left unchanged.bias (float) – Bias. If
None, bias is left unchanged.beta (float) – \(\beta\) parameter. If not
None, overridesfasbeta * bias.
- set_density_contrast(ran_min=0.01, smoothing_radius=15.0)¶
Set \(\delta\) field
mesh_deltafrom data and randoms fieldsmesh_dataandmesh_randoms.Note
This method follows Julian’s reconstruction code. Handling of
ran_minis better than inBaseReconstruction.set_density_contrast().mesh_dataandmesh_randomsfields are assumed to be smoothed already.- Parameters
ran_min (float, default=0.01) –
mesh_randomspoints 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
losisNone, 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.BaseReconstructionImplementation 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
BaseReconstructionfor 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 ifwrap.- 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 ifwrap).- 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
Noneand beta` is provided, setfasbeta * bias; else growth rate is left unchanged.bias (float) – Bias. If
None, bias is left unchanged.beta (float) – \(\beta\) parameter. If not
None, overridesfasbeta * bias.
- set_density_contrast(ran_min=0.75, smoothing_radius=15.0, **kwargs)¶
Set \(\delta\) field
mesh_deltafrom data and randoms fieldsmesh_dataandmesh_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_minprescription. At leastran_minshould depend on random weights. See also Martin’s notes below.- Parameters
ran_min (float, default=0.75) –
mesh_randomspoints 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.BaseClassBase 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_complexand ‘f8’ fortype_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_realinstead.type_real (string, np.dtype, default=None) – Type for real values. If not provided, use
type_complexinstead.
- 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.BaseClassBase implementation for mesh. What follows are just methods to make
BaseMeshbehave like a numpy array. numpy functions can be applied directly to any instancemeshthrough e.g.:np.sum(mesh)
Note
To get a deep copy of the mesh (including
value), usedeepcopy().copy()will return a shallow copy.- value¶
Numpy array holding mesh values, or
Nonewhen unset. Can be set any time usingmesh.value = newvalue.- Type
array
- attrs¶
Dictionary of other attributes.
- Type
dict
Initialize
BaseMesh.- Parameters
value (array, default=None) – Numpy array holding mesh values, or
None(can set later throughmesh.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
engineis a FFT engine name (string). SeeNumpyFFTEngineandFFTWEngine.
- Returns
engine – FFT engine.
- Return type
- 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.BaseMeshClass holding a 3D complex mesh.
- Parameters
hermitian (bool) – Whether mesh has Hermitian symmetry, i.e. is real when Fourier transformed. In this case,
shapeis halfnmeshon the last axis.
Initialize
ComplexMesh.- Parameters
value (array, default=None) – Numpy array holding mesh values, or
None(can set later throughmesh.value = value.dtype (string, np.dtype, defaut=None) – Type for
valuearray. 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,
shapeis halfnmeshon 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
RealMeshcomputed with fast Fourier transforms. Seeget_fft_engine()for arguments. Raises aMeshErrorif 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.BaseFFTEngineFFT engine based on
pyfftw.Initialize
pyfftwengine.Note
pyfftw.FFTWinternally storespyfftw.FFTW._input_arrayandpyfftw.FFTW._output_array, which is a waste of memory if one does not want to save them. e.g. performingengine.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 ofarray. As no access is provided topyfftw.FFTW._input_arrayandpyfftw.FFTW._output_arrayattributes, we choose to destroy and rebuildpyfftw.FFTWfor 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
pyfftwwisdom, used to accelerate FFTs. If a string, should be a path to previously saved FFT wisdom (withnumpy.save()). If a tuple, directly corresponds to the wisdom. By default the wisdom given insave_wisdomwill be loaded, if exists.save_wisdom (bool, string, default=None) – If not
None, path where to save the wisdom. IfTrue, 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 = Trueto allow destroyfun(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:
ExceptionException 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.BaseClassClass 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 sizenmeshis notNone, used to setboxsizeasnmesh * cellsize. IfnmeshisNone, 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
boxsizeand / orboxcenterisNone, use these positions to determineboxsizeand / orboxcenter.boxpad (float, default=1.5) – When
boxsizeis determined frompositions, takeboxpadtimes the smallest box enclosingpositionsasboxsize.dtype (string, np.dtype, defaut=None) – Type for
valuearray. IfNone, defaults tonp.asarray(value).dtypeifvalueis notNone, else ‘f8’.
- property cellsize¶
Physical size of mesh cells.
- 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.BaseFFTEngineFFT engine based on
numpy.fft.Initialize FFT engine. Default types are ‘c16’ for
type_complexand ‘f8’ fortype_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_realinstead.type_real (string, np.dtype, default=None) – Type for real values. If not provided, use
type_complexinstead.
- 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.BaseMeshClass holding a 3D real mesh.
Initalize
RealMesh.- Parameters
value (array, default=None) – Numpy array holding mesh values, or
None(can set later throughmesh.value = value.dtype (string, np.dtype, defaut=None) – Type for
valuearray. 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
engineis a FFT engine name (string). SeeNumpyFFTEngineandFFTWEngine.
- Returns
engine – FFT engine.
- Return type
- 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
methodis ‘real’, number of Gaussian sigmas where to stop convolution.kwargs (dict) – Optional arguments for
get_fft_engine().
- to_complex(*args, **kwargs)¶
Return
ComplexMeshcomputed with fast Fourier transforms. Seeget_fft_engine()for arguments.
- class pyrecon.mesh.SetterProperty(func, doc=None)¶
Bases:
objectAttribute setter, runs
funcwhen 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
Utilities¶
- class pyrecon.utils.BaseClass¶
Bases:
objectBase class that implements
copy(). To be used throughout this package.
- class pyrecon.utils.BaseMetaClass(name, bases, class_dict)¶
Bases:
typeMeta class to add logging attributes to
BaseClassderived 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:
objectClass 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.
1for linear interpolation,3for cubic splines.
- class pyrecon.utils.MemoryMonitor(pid=None)¶
Bases:
objectClass that monitors memory usage and clock, useful to check for memory leaks.
>>> with MemoryMonitor() as mem: '''do something''' mem() '''do something else'''
Initalize
MemoryMonitorand 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
positionlast axis.
- pyrecon.utils.exception_handler(exc_type, exc_value, exc_traceback)¶
Print exception with a logger.
- pyrecon.utils.mkdir(dirname)¶
Try to create
dirnmand catchOSError.
- 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
sizeisNone,sizeis obtained as the nearest integer tonbar * volumewherevolumeis the box volume.rng (np.RandomState, default=None) – Random generator, optional.
seed (int, default=None) – If
rngisNone, 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
Nonestream 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.dtypefor returned array.
- Returns
position – Position in Cartesian coordinates.
- Return type
array of shape (N, 3)