Metadata-Version: 2.5
Name: orbix
Version: 6.0.0
Summary: A JAX library of functions useful for exoplanet simulations
Project-URL: Homepage, https://github.com/CoreySpohn/orbix
Project-URL: Issues, https://github.com/CoreySpohn/orbix/issues
License: MIT License
        
        Copyright (c) 2024 Corey Spohn
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.12
Requires-Dist: equinox>=0.13.2
Requires-Dist: hwoutils[jax]>=3.0.0
Requires-Dist: interpax>=0.3.3
Requires-Dist: jax>=0.4.34
Requires-Dist: jaxtyping>=0.3.3
Requires-Dist: numpy>=2.2
Requires-Dist: priorities
Provides-Extra: docs
Requires-Dist: eyepiece>=0.15.0; extra == 'docs'
Requires-Dist: hwostyle>=1.7.0; extra == 'docs'
Requires-Dist: ipython>=8.24; extra == 'docs'
Requires-Dist: matplotlib>=3.11; extra == 'docs'
Requires-Dist: myst-nb>=1.1; extra == 'docs'
Requires-Dist: sphinx-autoapi>=3.1; extra == 'docs'
Requires-Dist: sphinx-autodoc-typehints>=2.1; extra == 'docs'
Requires-Dist: sphinx-book-theme>=1.1; extra == 'docs'
Requires-Dist: sphinx>=8.2; extra == 'docs'
Provides-Extra: test
Requires-Dist: astropy>=6.1; extra == 'test'
Requires-Dist: beartype>=0.18.5; extra == 'test'
Requires-Dist: blackjax>=1.6.2; extra == 'test'
Requires-Dist: exosims>=3.4.1; extra == 'test'
Requires-Dist: eyepiece>=0.15.0; extra == 'test'
Requires-Dist: hypothesis>=6.100.0; extra == 'test'
Requires-Dist: manim<0.22,>=0.21; extra == 'test'
Requires-Dist: matplotlib>=3.11; extra == 'test'
Requires-Dist: mpmath>=1.3; extra == 'test'
Requires-Dist: packaging>=23.2; extra == 'test'
Requires-Dist: pillow<13,>=11; extra == 'test'
Requires-Dist: pytest-fail-slow>=0.1.0; extra == 'test'
Requires-Dist: pytest-markdown-docs>=0.5.0; extra == 'test'
Requires-Dist: pytest-testmon>=2.0.7; extra == 'test'
Requires-Dist: pytest-timeout>=1.3.1; extra == 'test'
Requires-Dist: pytest-xdist>=2.5; extra == 'test'
Requires-Dist: pytest>=7.3.2; extra == 'test'
Provides-Extra: viz
Requires-Dist: eyepiece>=0.15.0; extra == 'viz'
Requires-Dist: matplotlib>=3.11; extra == 'viz'
Description-Content-Type: text/markdown

# orbix

<p align="center">
  <a href="https://pypi.org/project/orbix/"><img src="https://img.shields.io/pypi/v/orbix.svg?style=flat-square&logo=pypi" alt="PyPI"/></a>
  <a href="https://orbix.readthedocs.io"><img src="https://readthedocs.org/projects/orbix/badge/?version=latest&style=flat-square" alt="Documentation Status"/></a>
  <a href="https://github.com/CoreySpohn/orbix/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/CoreySpohn/orbix/ci.yml?branch=main&style=flat-square&logo=github&label=tests" alt="Tests"/></a>
  <a href="https://github.com/CoreySpohn/orbix/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square" alt="License"/></a>
  <a href="https://github.com/CoreySpohn/orbix/blob/main/pyproject.toml"><img src="https://img.shields.io/badge/python-3.12%2B-blue.svg?style=flat-square&logo=python" alt="Python 3.12+"/></a>
  <a href="https://doi.org/10.5281/zenodo.20819376"><img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.20819376-blue?style=flat-square" alt="DOI"/></a>
</p>

A JAX library of functions for exoplanet simulations: differentiable Keplerian
orbit propagation and Kepler-equation solvers, plus solar-system geometry
(observatory position, keepout) for the Habitable Worlds Observatory direct
imaging simulation suite. Scene composition (planet catalogs, EXOSIMS
integration, zodiacal photometry) lives in other libraries; see below.

## Install

```
pip install orbix
```

## Quickstart

```python
import jax.numpy as jnp
from hwoutils.constants import G, Msun2kg
from orbix.system import FrameOrbit, offset_arcsec, phase_angle_rad, distance_AU

orbit = FrameOrbit.from_classical(
    a_AU=1.0,
    e=0.0167,
    W_rad=0.0,
    i_rad=0.0,
    w_rad=0.0,
    M0_rad=0.0,
    epoch_d=0.0,
    mu_AU3_per_d2=G * Msun2kg,
)
time_d = jnp.linspace(0.0, 365.25, 5)
r_AU, v_AU_per_d = orbit.at(time_d)
beta_rad = phase_angle_rad(r_AU)
radius_AU = distance_AU(r_AU)
raoff, decoff = offset_arcsec(r_AU, 10.0)
print(r_AU.shape)  # (5, 3): (T times, xyz)
```

`FrameOrbit` stores a non-singular orbit frame and propagates through
`at(time_d)`. Times are days on the same origin as `epoch_d`; positions and
velocities have shape `(*batch, T, 3)`. `System` constructs Jacobi orbits for
multiple bodies and returns a solve-once `Ephemeris` through `solve(time_d)`.
For a Julian-date schedule, set the reference date on `SkyFrame.epoch` and
pass `frame.time_d(jd=dates)` to propagation and animation. Supply host dates
so the subtraction keeps sub-day offsets before the device cast.
The package root exports only `__version__`; import engine names from
`orbix.system` and solver names from `orbix.kepler`.

Raw orbit rows are **(east, north, away)** in AU, a right-handed frame.
Velocities share this order in AU/day; dz/dt is the body's radial velocity
relative to the star, positive receding. `state_vector_to_keplerian` takes
position and velocity in that frame. `offset_arcsec` returns `(raoff,
decoff)` = (Delta alpha cos delta, Delta delta), east and north offsets in
arcsec. Omega is the ascending (receding) node's PA measured north through
east; i < 90 deg gives increasing PA, and omega is measured from that node
in the direction of motion. Phase angle is beta, with cos(beta) = z/r;
alpha denotes angular separation. See the documentation's sky-coordinate
convention for details.

The default solver is the table-free `Markley()` strategy. Pass
`solver=Halley()` or `solver=Grid()` to `at`, `solve`, or the non-singular
`kepler(mean_longitude, ex, ey, solver=...)` function from `orbix.kepler`.
It returns `(sin(F), cos(F))` for `lambda = F - ex*sin(F) + ey*cos(F)`,
where `(ex, ey) = e*(cos(p), sin(p))` and `p` is longitude of periapsis.
All strategies support broadcasting and implicit forward/reverse derivatives,
including circular orbits and higher orders. Enable
`jax.config.update("jax_enable_x64", True)` for double-precision accuracy.

## Orbits as fit parameters

`orbix.system` also describes an orbit as the free parameter of a fit. Three pieces work
together:

- A chart maps an orbit to a vector of real coordinates and back, with the exact volume of
  the map: `ClassicalChart`, `EccentricityVectorChart`, `FrameChart`, `CartesianChart` and
  `ThieleInnesChart`.
- An orbit law is the prior density of an orbit, independent of the chart. `OrbitLaw`
  takes a law on the semi-major axis or the period and one on the eccentricity, with
  isotropic orientation and uniform phase.
- A block combines a chart, a law and the rows of a `System` it frees. `OrbitBlock` works
  with every chart except the Thiele-Innes one, and `ThieleInnesBlock` frees one row
  through the Thiele-Innes chart and writes the star mass its coordinates imply.
  `SkyPositionBlock` frees instead the star-relative sky offsets of some planets at one
  time and holds the shape of each orbit, for a fit of a single image. All three follow
  the `hwoutils.blocks.AbstractBlock` contract, which is how photomancy fits use them.

```python
import jax
from hwoutils.constants import G, Msun2kg
from orbix.system import (
    Body,
    EccentricityVectorChart,
    FrameOrbit,
    OrbitBlock,
    OrbitLaw,
    SkyFrame,
    System,
)
from priorities import LogUniform, Uniform

jax.config.update("jax_enable_x64", True)

orbit = FrameOrbit.from_classical(
    a_AU=[1.0],
    e=0.2,
    W_rad=0.5,
    i_rad=1.0,
    w_rad=0.3,
    M0_rad=0.0,
    mu_AU3_per_d2=G * Msun2kg,
)
system = System(Body(1.0), Body([0.0]), orbit, SkyFrame(10.0))

law = OrbitLaw(period_d=LogUniform(100.0, 10_000.0), eccentricity=Uniform(0.0, 0.9))
block = OrbitBlock(EccentricityVectorChart(), law, rows=(0,), system="")

x = block.sample(jax.random.key(0), system)  # {name: (1,)} per coordinate
orbits = block.forward(x, system)["orbits"]  # the freed row written into the orbits
log_p = block.log_prob(x, system)  # normalized density of the coordinates
print(block.coordinate_names)
```

Every coordinate takes any real value. A size coordinate that the law bounds is mapped onto
the real line, by a logit on a finite interval or a softplus when one end is open, and named
with the prefix `mapped_` (`mapped_ln_a_AU` above), and the density includes the log
derivative of that map. In the Thiele-Innes chart the sky
position of a planet is linear in the four constants `(A, B, F, G)`: `sky_design` gives the
design matrix at a fixed orbit shape and `linear_gaussian_conditional` the exact Gaussian
conditional of the constants under Gaussian astrometric errors.

Block coordinates and log densities require float64. A float64 block can fit a
float32 `System`. It widens the model values for inference and returns each model
update in the destination leaf's dtype. The linear astrometric fit requires a
float64 orbit, and the Gaussian conditional requires a float64 design matrix.

A radial-velocity or phase-dependent likelihood can tell apart two orbits that share one
sky track and differ only in the sign of the line-of-sight coordinate. `line_of_sight_sheet`
reads that sign (+1 or -1) of an orbit, and `reflect_line_of_sight(orbits, planet)` returns
the orbits with one planet mirrored through the sky plane, which has the same east and
north positions at every time and the opposite away coordinate.

## Observatory geometry

`orbix.observatory` places the telescope on its L2 halo orbit and answers whether a target
is outside the keepout zones at a given time (`Observatory.is_observable_at`) or for what
fraction of an interval (`Observatory.observability`). `ecliptic_pointing` returns the
ecliptic latitude and helioecliptic longitude that the local zodiacal light models need.

## Scope

orbix provides Keplerian orbit geometry, Kepler-equation solvers, and the charts, laws
and blocks that make an orbit a fit parameter. Scene composition lives in skyscapes, and
inference lives in photomancy.

## Citation

If you use orbix, please cite it as described in
[CITATION.cff](CITATION.cff).
