Fix neighbours

This commit is contained in:
rstiskalek 2023-07-28 20:14:05 +01:00
parent acb8d9571c
commit 61077940f3
2 changed files with 15 additions and 5 deletions

View file

@ -288,7 +288,7 @@ class BaseCatalogue(ABC):
""" """
return numpy.vstack([self["v{}".format(p)] for p in ("x", "y", "z")]).T return numpy.vstack([self["v{}".format(p)] for p in ("x", "y", "z")]).T
def redshift_space_position(self, cartesian=True): def redshift_space_position(self, cartesian=True, subtract_observer=False):
""" """
Calculates the position of objects in redshift space. Positions can be Calculates the position of objects in redshift space. Positions can be
returned in either Cartesian coordinates (default) or spherical returned in either Cartesian coordinates (default) or spherical
@ -299,12 +299,17 @@ class BaseCatalogue(ABC):
cartesian : bool, optional cartesian : bool, optional
Returns position in Cartesian coordinates if True, else in Returns position in Cartesian coordinates if True, else in
spherical coordinates. spherical coordinates.
subtract_observer : bool, optional
If True, subtract the observer's location from the returned
positions.
Returns Returns
------- -------
pos : 2-dimensional array of shape `(nobjects, 3)` pos : 2-dimensional array of shape `(nobjects, 3)`
Position of objects in the desired coordinate system. Position of objects in the desired coordinate system.
""" """
# Force subtraction of observer if not in Cartesian coordinates
subtract_observer = subtract_observer or not cartesian
rsp = real2redshift(self.position(cartesian=True), self.velocity(), rsp = real2redshift(self.position(cartesian=True), self.velocity(),
self.observer_location, self.box, make_copy=False) self.observer_location, self.box, make_copy=False)
return rsp if cartesian else cartesian_to_radec(rsp) return rsp if cartesian else cartesian_to_radec(rsp)
@ -417,8 +422,8 @@ class BaseCatalogue(ABC):
# Get positions of haloes in this catalogue # Get positions of haloes in this catalogue
if in_rsp: if in_rsp:
# TODO what to do with subtracting the observer here? pos = self.redshift_space_position(cartesian=True,
pos = self.redshift_space_position(cartesian=True) subtract_observer=True)
else: else:
pos = self.position(in_initial=False, cartesian=True, pos = self.position(in_initial=False, cartesian=True,
subtract_observer=True) subtract_observer=True)

View file

@ -81,7 +81,7 @@ def radec_to_cartesian(X, isdeg=True):
def real2redshift(pos, vel, observer_location, box, periodic_wrap=True, def real2redshift(pos, vel, observer_location, box, periodic_wrap=True,
make_copy=True): subtract_observer=False, make_copy=True):
r""" r"""
Convert real-space position to redshift space position. Convert real-space position to redshift space position.
@ -98,6 +98,9 @@ def real2redshift(pos, vel, observer_location, box, periodic_wrap=True,
periodic_wrap : bool, optional periodic_wrap : bool, optional
Whether to wrap around the box, particles may be outside the default Whether to wrap around the box, particles may be outside the default
bounds once RSD is applied. bounds once RSD is applied.
subtract_observer : bool, optional
If True, subtract the observer's location from the returned
positions.
make_copy : bool, optional make_copy : bool, optional
Whether to make a copy of `pos` before modifying it. Whether to make a copy of `pos` before modifying it.
@ -116,7 +119,9 @@ def real2redshift(pos, vel, observer_location, box, periodic_wrap=True,
# Compute the norm squared of the displacement # Compute the norm squared of the displacement
norm2 = numpy.sum(pos**2, axis=1) norm2 = numpy.sum(pos**2, axis=1)
pos *= (1 + box._aexp / box.H0 * vr_dot / norm2).reshape(-1, 1) pos *= (1 + box._aexp / box.H0 * vr_dot / norm2).reshape(-1, 1)
# Place the observer back at the original location # Place the observer back at the original location
if not subtract_observer:
pos += observer_location pos += observer_location
if periodic_wrap: if periodic_wrap: