Skip to content

About

Synthetic photometry, spectral reconstruction and true-color imaging for astronomy

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

AstroColor

AstroColor is a Python library for astronomical data analysis: it performs synthetic photometry, converts between photometric systems, reconstructs spectra from broadband measurements, and propagates uncertainties. It also computes colors and renders true-color images from spectral data.

Beta: the public API may change before 1.0. Requires Python 3.12+.

Highlights

  • synthetic photometry with filters from the SVO Filter Profile Service;
  • Tikhonov spectral reconstruction with smoothness and nonnegativity constraints, suited to continuum-dominated spectra of planets, moons and small bodies;
  • a common 1D/2D/3D object model for spectra, filter sets and color images;
  • uncertainty propagation through measurements, scaling and color rendering;
  • a high-level celestial-body model built from spectra, photometry or color indices, with albedo constraints and phase functions;
  • small dependency footprint: NumPy, SciPy and certifi.

Installation

pip install astrocolor

In a uv project use uv add astrocolor. For the latest development version:

pip install git+https://github.com/Askaniy/AstroColor.git

Quick start

The examples build on each other.

import astrocolor as ac

spectrum = ac.Spectrum([400, 500, 600, 700], [1, 2, 3, 4])  # wavelength_nm, spectral_dist
bessell_V = ac.Filter.get('Generic/Bessell.V')
flux, flux_std = ac.get_photometry(spectrum, bessell_V)

bessell_BVR = ac.FilterSet.get('Generic/Bessell.B', 'Generic/Bessell.V', 'Generic/Bessell.R')
photospectrum_BVR = ac.Photospectrum(filter_set=bessell_BVR, spectral_dist=[1, 2, 3])
sloan_gr = ac.FilterSet.get('SLOAN/SDSS.g', 'SLOAN/SDSS.r')
photospectrum_gr = ac.get_photometry(photospectrum_BVR, sloan_gr)

# Only the min/max of requested_wavelengths are used.
reconstructed = ac.get_spectrometry(photospectrum_BVR, requested_wavelengths=[400, 700])

Photometry-to-photometry reconstructs an intermediate spectrum; get_spectrometry() makes the reconstruction explicit. Out-of-range spectral measurements warn by default: use overlap='error' to fail or overlap='extrapolate' to silence the warning.

End-to-end true-color estimation with uncertainty:

hyperion = ac.CelestialObject(
    name='Hyperion',
    filter_set='Generic/Bessell',
    color_indices={'B-V': [0.798, 0.030], 'V-R': [0.438, 0.031]},
    calibration_system='Vega',
    is_reflecting_sunlight=True,
)
photometry, _ = hyperion.get_spectral_data()
rgb, rgb_err = ac.get_color(photometry).render()

Core model

The first axis of spectral_dist is always the spectral, filter or color-channel axis; the remaining axes are spatial. 1D is a single spectrum, filter or color point; 2D is a set or line; 3D is a cube or image.

Object family 1D 2D 3D
Spectral Spectrum SpectralSet SpectralCube
Photospectral Photospectrum PhotospectralSet PhotospectralCube
Filter Filter FilterSet —
Color ColorPoint ColorLine ColorImage

Spectral objects store continuous distributions, photospectral objects store measurements through a filter set, filter objects store normalized profiles, and color objects store three channels with optional spatial axes. Spectral, photospectral and filter families share arithmetic and dimensional metrics; color objects share the metrics but stay outside spectral arithmetic.

Arithmetic

Spectral, photospectral and filter objects support +, -, * and / with scalars, arrays and other objects. The higher-dimensional operand determines the result: Spectrum + SpectralSet is a SpectralSet, and Filter * SpectralCube is a SpectralCube. Photospectral wins over spectral, and filter arithmetic returns an ordinary spectral object.

Uncertainty

Spectral, photospectral and color objects accept standard deviations or a full covariance matrix and keep the most compact representation. Uncertainty propagates through arithmetic, reconstruction, scaling and color conversion; scale_to_match_value() and albedo constraints add a fully correlated multiplicative component. get_photometry(..., Filter) returns (value, standard deviation); with a FilterSet, it returns a photospectral object with a standard_deviation attribute.

render() returns (values, uncertainty); uncertainty is None when it cannot be propagated. error_colors() returns six linear colors at the 1σ principal-axis endpoints of a color covariance ellipsoid, or None without uncertainty.

Data and models

Filters and spectra

Filter IDs follow the SVO FPS convention Facility/Instrument.Band. Filter.get() and FilterSet.get() load a profile by ID; get_facilities(), get_instruments() and get_bands() browse the catalog. Bundled profiles are always available; missing ones are fetched from the SVO Filter Profile Service and cached, with a local fallback on network failure.

Profiles are normalized to unit integral on construction, so photometry is a simple integral of the product. Arithmetic returns ordinary spectral objects; construct a new Filter/FilterSet from the result if you need normalized profiles again.

Bundled Sun and Vega spectra are available through get_standard_spectrum(): Sun defaults to TSIS-1 HSRS, Vega to CALSPEC, and every call returns a fresh Spectrum.

Celestial objects

CelestialObject accepts TrueColorTools-style parameters: a continuous spectrum, photometry, magnitudes, color indices or a compact description, plus optional albedo constraints, Vega/AB calibration, reflected-sunlight and photon-counter flags. get_spectral_data() returns the requested representation and whether its albedo was estimated.

mercury = ac.CelestialObject(
    name='Mercury',
    filter_set='Generic/Bessell',
    filters=['U', 'B', 'V', 'R'],
    sd_geometric=[0.087, 0.105, 0.142, 0.172],
    spherical_albedo=['Generic/Bessell.V', 0.07],
)
geometric, estimated = mercury.get_spectral_data('geometric')

Phase-function models (HG, HG1G2, Exponentials, Hapke, PhaseCoefficient) live in ac.photometric_models; pass one through phase_function by name.

Color output

For visualization and true-color rendering, get_color() returns linear sRGB with an Illuminant E white point by default and returns the matching ColorPoint, ColorLine or ColorImage. render() applies a DisplaySettings preset (color system, transfer function, brightness normalization, scale) and returns (values, uncertainty); to_html() returns a color as a hexadecimal string.

color = ac.get_color(ac.get_standard_spectrum('Sun'))
rgb, rgb_std = color.render()
html = color.to_html()  # '#ecfeff'

ColorPoint.from_spectral_data() keeps the scientific linear CIE 1931 XYZ representation; display methods convert to a display color system.

Development

uv sync --dev
uv run pytest
uv run basedpyright src/astrocolor tests benchmarks
uv run ruff check src/astrocolor tests benchmarks

Benchmarks: uv run pytest benchmarks --benchmark-only. CI runs the tests, type check and lint on Python 3.12–3.14.

License

MIT. See LICENSE.txt.

Acknowledgments

This research has made use of the SVO Filter Profile Service "Carlos Rodrigo", funded by MCIN/AEI/10.13039/501100011033/ through grant PID2023-146210NB-I00.

About

Synthetic photometry, spectral reconstruction and true-color imaging for astronomy

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages