Metadata-Version: 2.5
Name: coronagraphoto
Version: 6.1.0
Summary: A python library to simulate coronagraphic observations of exoplanets.
Project-URL: Homepage, https://github.com/CoreySpohn/coronagraphoto
Project-URL: Issues, https://github.com/CoreySpohn/coronagraphoto/issues
Author-email: Corey Spohn <corey.a.spohn@nasa.gov>
License: MIT License
        
        Copyright (c) 2023 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
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Astronomy
Requires-Python: >=3.12
Requires-Dist: equinox>=0.13.2
Requires-Dist: hwoutils>=2.1.0
Requires-Dist: jax>=0.8.1
Requires-Dist: numpy>=2.1.2
Requires-Dist: optixstuff>=6.1.0
Requires-Dist: orbix>=5.0.0
Requires-Dist: skyscapes>=5.1.0
Requires-Dist: yippy>=3.0.0
Provides-Extra: dev
Requires-Dist: pre-commit>=3.5.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: ipython>=8.18.1; extra == 'docs'
Requires-Dist: myst-nb>=1.0.0; extra == 'docs'
Requires-Dist: sphinx-autoapi>=3.0.0; extra == 'docs'
Requires-Dist: sphinx-book-theme>=1.1.0; extra == 'docs'
Requires-Dist: sphinx>=7.2.6; extra == 'docs'
Requires-Dist: sphinxcontrib-mermaid>=0.9.2; extra == 'docs'
Requires-Dist: zodi[jax]>=2.0.0; extra == 'docs'
Provides-Extra: test
Requires-Dist: hypothesis>=6.79.1; extra == 'test'
Requires-Dist: ineedvalidation>=1.1.0; extra == 'test'
Requires-Dist: jaxedith>=2.1.2.dev6; extra == 'test'
Requires-Dist: lod-unit>=1.8.0; extra == 'test'
Requires-Dist: packaging>=23.1; 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'
Requires-Dist: zodi[jax]>=2.0.0; extra == 'test'
Description-Content-Type: text/markdown

<p align="center">
  <img width="500" src="https://raw.githubusercontent.com/coreyspohn/coronagraphoto/main/docs/_static/tmp_logo.png" alt="coronagraphoto logo" />
  <br><br>
</p>

<p align="center">
  <a href="https://pypi.org/project/coronagraphoto/"><img src="https://img.shields.io/pypi/v/coronagraphoto.svg?style=flat-square&logo=pypi" alt="PyPI"/></a>
  <a href="https://coronagraphoto.readthedocs.io"><img src="https://readthedocs.org/projects/coronagraphoto/badge/?version=latest&style=flat-square" alt="Documentation Status"/></a>
  <a href="https://github.com/CoreySpohn/coronagraphoto/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/CoreySpohn/coronagraphoto/ci.yml?branch=main&style=flat-square&logo=github&label=tests" alt="Tests"/></a>
  <a href="https://github.com/CoreySpohn/coronagraphoto/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/coronagraphoto/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.10950736"><img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.10950736-blue?style=flat-square" alt="DOI"/></a>
</p>

---

# coronagraphoto

**coronagraphoto** is a Python library designed to simulate coronagraphic observations of exoplanetary systems. The base "thing" it produces are images/photos, hence the name. It has been designed to bridge the gap between yield calculations and concrete image generation for missions like the Habitable Worlds Observatory (HWO).

The library integrates high-fidelity coronagraph models from the standard format used for yield calculations (dubbed a "Yield Input Package" and loaded via **[yippy](https://github.com/CoreySpohn/yippy)**) with detailed planetary system simulations (via **[ExoVista](https://github.com/alexrhowe/ExoVista)**) to produce realistic detector images.

Built on **JAX**, `coronagraphoto` supports JIT compilation and differentiation of scene predictions with fixed instrument geometry. JAX provides CPU and accelerator execution.

## Key Features

*   **End-to-End Simulation**: From astrophysical scenes to detector readouts.
*   **JAX & JIT Compatible**: High-performance simulations using functional programming patterns.
*   **Modular Design**: flexible optical paths, easily swappable coronagraphs and detectors.
*   **HWO Ready**: Specifically designed to support yield modeling for future direct imaging missions.

## Installation

```bash
pip install coronagraphoto
```

*(Note: You may need to install JAX separately to match your specific hardware acceleration requirements (CUDA/TPU/CPU).)*

## Photon budgets and detector images

Scenes come from `skyscapes`; hardware and detector statistics come from
`optixstuff`. One `Exposure` record, built once with `build_exposure`, carries
the epoch, roll, wavelength quadrature and frame plan. The image reader takes
`(scene, instrument, exposure)`:

| Function | Output | Units |
|---|---|---|
| `photon_rates` | `PhotonRates`, each field `(W, Q, ny, nx)` | photons/s/nm/pixel |
| `expected` | `ElectronRates`, each field `(W, ny, nx)` | electrons/s/pixel |
| `observe` | `Image`, data `(W, ny, nx)` | electrons/pixel |

The fields are `planet`, `star_leakage`, `local_zodi`, `exozodi`, `thermal`
and `stellar_companions`; the reader does not model the last two, so they hold
zeros. Call `.total()`
to combine terms. Optical throughput excludes detector yield. Only
`detector.electrons` applies QE and survival, at the quadrature nodes.
`observe` calls `detector.draw` once on the combined electron budget.

`expected` scans nodes and accumulates band images, holding one node's
images at a time. `photon_rates` retains all nodes for inspection and small
problems. `build_exposure` builds the quadrature on the host from the scene's
zodi and the instrument. Its Gauss-Legendre rule splits at every declared
break, including detector QE knots. Reuse one exposure across readers, and
change fields with `dataclasses.replace`.

## Quick start

Enable float64 before loading orbital state vectors. This example downloads
a public scene and YIP on first use; the epoch must lie in the scene's recorded
time range.

```python notest
import jax

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

from hwoutils.spectral import Band
from optixstuff import FramePlan, Instrument
from skyscapes import from_exovista
from skyscapes.datasets import fetch_scene
from yippy import fetch_yip, open_yip
from coronagraphoto import build_exposure, expected, observe

scene = from_exovista(fetch_scene(), load_disk=False)
coronagraph = open_yip(fetch_yip("eac1_aavc_2d")).prepare()
instrument = Instrument.from_default_setup(
    coronagraph,
    attenuating_throughput=0.4,
    qe=0.8,
    detector_shape=(128, 128),
    pixel_scale_arcsec=0.01,
)
bands = (Band(500.0, 600.0),)
exposure = build_exposure(
    scene,
    instrument,
    bands,
    time_d=0.0,
    roll_deg=30.0,
    plan=FramePlan(frame_time_s=100.0, n_frames=36),
)
rates = expected(scene, instrument, exposure)
image = observe(jax.random.PRNGKey(0), scene, instrument, exposure)
# imshow(image.data[0], origin="lower")
```

For disks, load the disk and give the coronagraph a scene renderer with
`coronagraph.with_scene_operator()`. The reader requests disk photon radiance on the detector sky grid and passes
its per-pixel flux through the coronagraph's field-dependent PSFs.

Rows increase along detector +y and columns along detector +x. Pixel `(j,i)`
is centred at `(x,y)=(i,j)`, including even grids. `roll_deg` is the position
angle of detector +y, north through east. At zero, east is left and north is
up; at 90 degrees, north is right. A roll changes this orientation for both
planets and disks.

Speckle fields are supplied through `Instrument.speckle`. Their positive excess joins `star_leakage`; their existing
physics is retained. The reader calls `realize(wavelength_nm=..., time_d=...)`
and leaves epoch conversion to the field. The speckle pattern remains fixed
in detector coordinates as pointing rolls.

Select record fields for per-source access. See
[rate and observation contracts](docs/explanation/rate_vs_readout.md) and
[JAX and memory](docs/explanation/performance.md) for details.
