Skip to content

Commit

Permalink
feat: return PSP, not full orbit (GalacticDynamics#133)
Browse files Browse the repository at this point in the history
* feat: return PSP, not full orbit
* fix: tests

Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman committed Feb 24, 2024
1 parent 28f9d5a commit 0b65c78
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ position near the Sun::

>>> xyz = [-8., 0, 0] * u.kpc
>>> mw.potential_energy(xyz, t=0)
Quantity(value=f64[], unit=Unit("kpc2 / Myr2"))
Quantity[PhysicalType('specific energy')](value=f64[], unit=Unit("kpc2 / Myr2"))
>>> mw.acceleration(xyz, t=0)
Quantity(value=f64[3], unit=Unit("kpc / Myr2"))
Quantity[PhysicalType('acceleration')](value=f64[3], unit=Unit("kpc / Myr2"))

The values that are returned by most methods in :mod:`galax` are provided as
Astropy :class:`~astropy.units.Quantity` objects, which represent numerical data
Expand All @@ -78,9 +78,9 @@ re-represented in any equivalent units, so, for example, we could display the
energy or acceleration in other units::

>>> mw.potential_energy(xyz, t=0)
Quantity(value=f64[], unit=Unit("kpc2 / Myr2"))
Quantity[PhysicalType('specific energy')](value=f64[], unit=Unit("kpc2 / Myr2"))
>>> mw.acceleration(xyz, t=0)
Quantity(value=f64[3], unit=Unit("kpc / Myr2"))
Quantity[PhysicalType('acceleration')](value=f64[3], unit=Unit("kpc / Myr2"))

Now that we have a potential model, if we want to compute an orbit, we need to
specify a set of initial conditions to initialize the numerical orbit
Expand Down
16 changes: 8 additions & 8 deletions src/galax/dynamics/_dynamics/mockstream/mockstream_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from galax.coordinates import PhaseSpacePosition, PhaseSpaceTimePosition
from galax.dynamics._dynamics.integrate._api import Integrator
from galax.dynamics._dynamics.integrate._builtin import DiffraxIntegrator
from galax.dynamics._dynamics.orbit import Orbit, evaluate_orbit, integrate_orbit
from galax.dynamics._dynamics.orbit import evaluate_orbit, integrate_orbit
from galax.potential._potential.base import AbstractPotentialBase
from galax.typing import BatchVec6, FloatScalar, IntScalar, Vec6, VecN, VecTime

Expand Down Expand Up @@ -132,7 +132,7 @@ def run(
*,
seed_num: int,
vmapped: bool | None = None,
) -> tuple[MockStream, Orbit]:
) -> tuple[MockStream, PhaseSpaceTimePosition]:
"""Generate mock stellar stream.
Parameters
Expand All @@ -158,10 +158,10 @@ def run(
Returns
-------
mockstream : MockStream
mockstream : :class:`galax.dynamcis.MockStream`
Leading and/or trailing arms of the mock stream.
prog_o : Orbit
Orbit of the progenitor.
prog_o : :class:`galax.coordinates.PhaseSpaceTimePosition`
The final phase-space(+time) position of the progenitor.
"""
# TODO: ꜛ a discussion about the stripping times
# Parse vmapped
Expand All @@ -186,8 +186,8 @@ def run(
self.potential, w0, ts, integrator=self.progenitor_integrator
)

# Generate stream initial conditions along the integrated progenitor
# orbit. The release times are stripping times.
# Generate initial conditions from the DF, along the integrated
# progenitor orbit. The release times are the stripping times.
mock0_lead, mock0_trail = self.df.sample(
self.potential, prog_o, prog_mass, seed_num=seed_num
)
Expand Down Expand Up @@ -222,4 +222,4 @@ def run(

mockstream = MockStream(q=q, p=p, t=t, release_time=release_time)

return mockstream, prog_o
return mockstream, prog_o[-1]
2 changes: 1 addition & 1 deletion tests/unit/dynamics/mockstream/test_mockstreamgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_run_scan(

# TODO: more rigorous tests
assert mock.q.shape == (2 * len(t_stripping), 3)
assert prog_o.q.shape == (len(t_stripping), 3)
assert prog_o.q.shape == (3,)

# Test that the positions and momenta are finite
assert jnp.isfinite(mock.q).all()
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/potential/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any

import array_api_jax_compat as xp
import astropy.units as u
import equinox as eqx
import jax
import jax.numpy as jnp
Expand Down Expand Up @@ -111,7 +112,7 @@ def _potential_energy(self, q: Vec3, /, t: FloatOrIntScalar) -> FloatScalar:

def test_potential_energy(self, pot: AbstractPotentialBase, x: Vec3) -> None:
"""Test the `AbstractPotentialBase.potential_energy` method."""
assert pot.potential_energy(x, t=0) == 6
assert pot.potential_energy(x, t=0) == Quantity(6, u.kpc**2 / u.Myr**2)

# ---------------------------------

Expand Down

0 comments on commit 0b65c78

Please sign in to comment.