mirror of
https://github.com/Richard-Sti/csiborgtools.git
synced 2024-12-22 17:18:02 +00:00
Small updates
This commit is contained in:
parent
07bb03b15d
commit
524434c7de
3 changed files with 44 additions and 5 deletions
|
@ -19,7 +19,7 @@ try:
|
||||||
|
|
||||||
from .density import DensityField, PotentialField, VelocityField # noqa
|
from .density import DensityField, PotentialField, VelocityField # noqa
|
||||||
from .interp import (evaluate_cartesian, evaluate_sky, field2rsp, # noqa
|
from .interp import (evaluate_cartesian, evaluate_sky, field2rsp, # noqa
|
||||||
make_sky)
|
make_sky, fill_outside) # noqa
|
||||||
from .utils import nside2radec, smoothen_field # noqa
|
from .utils import nside2radec, smoothen_field # noqa
|
||||||
except ImportError:
|
except ImportError:
|
||||||
warn("MAS_library not found, `DensityField` will not be available", UserWarning) # noqa
|
warn("MAS_library not found, `DensityField` will not be available", UserWarning) # noqa
|
||||||
|
|
|
@ -173,8 +173,7 @@ def field2rsp(field, parts, box, nbatch=30, flip_partsxz=True, init_value=0.,
|
||||||
"""
|
"""
|
||||||
Forward model real space scalar field to redshift space. Attaches field
|
Forward model real space scalar field to redshift space. Attaches field
|
||||||
values to particles, those are then moved to redshift space and from their
|
values to particles, those are then moved to redshift space and from their
|
||||||
positions reconstructs back the field on a regular grid by NGP
|
positions reconstructs back the field on a grid by NGP interpolation.
|
||||||
interpolation. This by definition produces a discontinuous field.
|
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -190,7 +189,7 @@ def field2rsp(field, parts, box, nbatch=30, flip_partsxz=True, init_value=0.,
|
||||||
Particles are assumed to be lazily loaded to memory.
|
Particles are assumed to be lazily loaded to memory.
|
||||||
flip_partsxz : bool, optional
|
flip_partsxz : bool, optional
|
||||||
Whether to flip the x and z coordinates of the particles. This is
|
Whether to flip the x and z coordinates of the particles. This is
|
||||||
because of a BORG bug.
|
because of a RAMSES bug.
|
||||||
init_value : float, optional
|
init_value : float, optional
|
||||||
Initial value of the RSP field on the grid.
|
Initial value of the RSP field on the grid.
|
||||||
verbose : bool, optional
|
verbose : bool, optional
|
||||||
|
@ -233,3 +232,43 @@ def field2rsp(field, parts, box, nbatch=30, flip_partsxz=True, init_value=0.,
|
||||||
# Finally divide by the number of particles in each cell and smooth.
|
# Finally divide by the number of particles in each cell and smooth.
|
||||||
divide_nonzero(rsp_field, cellcounts)
|
divide_nonzero(rsp_field, cellcounts)
|
||||||
return rsp_field
|
return rsp_field
|
||||||
|
|
||||||
|
|
||||||
|
@jit(nopython=True)
|
||||||
|
def fill_outside(field, fill_value, rmax, boxsize):
|
||||||
|
"""
|
||||||
|
Fill cells outside of a sphere of radius `rmax` with `fill_value`. Centered
|
||||||
|
in the middle of the box.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
field : 3-dimensional array of shape `(grid, grid, grid)`
|
||||||
|
Field to be filled.
|
||||||
|
fill_value : float
|
||||||
|
Value to fill the field with.
|
||||||
|
rmax : float
|
||||||
|
Radius outside of which to fill the field..
|
||||||
|
boxsize : float
|
||||||
|
Size of the box.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
field : 3-dimensional array of shape `(grid, grid, grid)`
|
||||||
|
"""
|
||||||
|
imax, jmax, kmax = field.shape
|
||||||
|
assert imax == jmax == kmax
|
||||||
|
N = imax
|
||||||
|
# Squared radial distance from the center of the box in box units.
|
||||||
|
rmax_box2 = (N * rmax / boxsize)**2
|
||||||
|
# print("Box ", rmax_box2)
|
||||||
|
|
||||||
|
for i in range(N):
|
||||||
|
idist2 = (i - 0.5 * (N - 1))**2
|
||||||
|
for j in range(N):
|
||||||
|
jdist2 = (j - 0.5 * (N - 1))**2
|
||||||
|
for k in range(N):
|
||||||
|
kdist2 = (k - 0.5 * (N - 1))**2
|
||||||
|
# print(idist2 + jdist2 + kdist2 > rmax_box2)
|
||||||
|
if idist2 + jdist2 + kdist2 > rmax_box2:
|
||||||
|
field[i, j, k] = fill_value
|
||||||
|
return field
|
||||||
|
|
|
@ -13,6 +13,6 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
dpi = 450
|
dpi = 600
|
||||||
fout = "../plots/"
|
fout = "../plots/"
|
||||||
mplstyle = ["science"]
|
mplstyle = ["science"]
|
||||||
|
|
Loading…
Reference in a new issue