mirror of
https://github.com/Richard-Sti/csiborgtools.git
synced 2024-12-23 01:28:02 +00:00
Fix bugs
This commit is contained in:
parent
b8c58c7f82
commit
c9829c0acc
1 changed files with 15 additions and 9 deletions
|
@ -79,15 +79,14 @@ def evaluate_sky(*fields, pos, box, isdeg=True):
|
||||||
pos = force_single_precision(pos, "pos")
|
pos = force_single_precision(pos, "pos")
|
||||||
# We first calculate convert the distance to box coordinates and then
|
# We first calculate convert the distance to box coordinates and then
|
||||||
# convert to Cartesian coordinates.
|
# convert to Cartesian coordinates.
|
||||||
X = numpy.copy(pos)
|
pos[:, 0] = box.mpc2box(pos[:, 0])
|
||||||
X[:, 0] = box.mpc2box(X[:, 0])
|
|
||||||
X = radec_to_cartesian(pos, isdeg)
|
X = radec_to_cartesian(pos, isdeg)
|
||||||
# Then we move the origin to match the box coordinates
|
# Then we move the origin to match the box coordinates
|
||||||
X -= 0.5
|
X += 0.5
|
||||||
return evaluate_cartesian(*fields, pos=X)
|
return evaluate_cartesian(*fields, pos=X)
|
||||||
|
|
||||||
|
|
||||||
def make_sky(field, angpos, dist, verbose=True):
|
def make_sky(field, angpos, dist, box, verbose=True):
|
||||||
r"""
|
r"""
|
||||||
Make a sky map of a scalar field. The observer is in the centre of the
|
Make a sky map of a scalar field. The observer is in the centre of the
|
||||||
box the field is evaluated along directions `angpos`. Along each
|
box the field is evaluated along directions `angpos`. Along each
|
||||||
|
@ -103,7 +102,9 @@ def make_sky(field, angpos, dist, verbose=True):
|
||||||
:math:`\in [0, 360]` and dec :math:`\in [-90, 90]` degrees,
|
:math:`\in [0, 360]` and dec :math:`\in [-90, 90]` degrees,
|
||||||
respectively.
|
respectively.
|
||||||
dist : 1-dimensional array
|
dist : 1-dimensional array
|
||||||
Radial distances to evaluate the field.
|
Uniformly spaced radial distances to evaluate the field.
|
||||||
|
box : :py:class:`csiborgtools.read.CSiBORGBox`
|
||||||
|
The simulation box information and transformations.
|
||||||
verbose : bool, optional
|
verbose : bool, optional
|
||||||
Verbosity flag.
|
Verbosity flag.
|
||||||
|
|
||||||
|
@ -111,14 +112,19 @@ def make_sky(field, angpos, dist, verbose=True):
|
||||||
-------
|
-------
|
||||||
interp_field : 1-dimensional array of shape `(n_pos, )`.
|
interp_field : 1-dimensional array of shape `(n_pos, )`.
|
||||||
"""
|
"""
|
||||||
|
dx = dist[1] - dist[0]
|
||||||
|
assert numpy.allclose(dist[1:] - dist[:-1], dx)
|
||||||
assert angpos.ndim == 2 and dist.ndim == 1
|
assert angpos.ndim == 2 and dist.ndim == 1
|
||||||
# We loop over the angular directions, at each step evaluating a vector
|
# We loop over the angular directions, at each step evaluating a vector
|
||||||
# of distances. We pre-allocate arrays for speed.
|
# of distances. We pre-allocate arrays for speed.
|
||||||
dir_loop = numpy.full((dist.size, 3), numpy.nan, dtype=numpy.float32)
|
dir_loop = numpy.full((dist.size, 3), numpy.nan, dtype=numpy.float32)
|
||||||
ndir = angpos.shape[0]
|
ndir = angpos.shape[0]
|
||||||
out = numpy.zeros(ndir, numpy.nan, dtype=numpy.float32)
|
out = numpy.full(ndir, numpy.nan, dtype=numpy.float32)
|
||||||
for i in trange(ndir) if verbose else range(ndir):
|
for i in trange(ndir) if verbose else range(ndir):
|
||||||
dir_loop[1, :] = angpos[i, 0]
|
dir_loop[:, 0] = dist
|
||||||
dir_loop[2, :] = angpos[i, 1]
|
dir_loop[:, 1] = angpos[i, 0]
|
||||||
out[i] = numpy.sum(evaluate_sky(field, dir_loop, isdeg=True))
|
dir_loop[:, 2] = angpos[i, 1]
|
||||||
|
out[i] = numpy.sum(
|
||||||
|
dist**2 * evaluate_sky(field, pos=dir_loop, box=box, isdeg=True))
|
||||||
|
out *= dx
|
||||||
return out
|
return out
|
||||||
|
|
Loading…
Reference in a new issue