synphot

raw JSON →
1.7.0 verified Fri May 01 auth: no python

Synthetic photometry library for astronomy, providing tools to simulate observations through various bandpasses, compute count rates, and handle spectral flux densities. Current version 1.7.0, requires Python >=3.10 and Astropy. Release cadence is irregular, approximately 1-2 minor versions per year.

pip install synphot
error AttributeError: module 'synphot' has no attribute 'SourceSpectrum'
cause synphot is sometimes confused with the older stsci_package synphot (a different library). The correct package is installed as `synphot`, but import path is `from synphot import SourceSpectrum`.
fix
Uninstall any old version (pip uninstall synphot and then reinstall with pip install synphot). Ensure you are using the correct import.
error ValueError: The unit 'flam' is not recognized
cause In older versions, strings like 'flam' were accepted. Since 1.6.0, you must use astropy units.
fix
Use u.erg / (u.s * u.cm**2 * u.AA) instead of 'flam'.
error ImportError: cannot import name 'BlackBodyNorm1D' from 'synphot.models'
cause BlackBodyNorm1D was added in version 0.3. Ensure your version is up-to-date.
fix
Update synphot: pip install --upgrade synphot.
breaking In version 1.6.0, `force_flux_unit` was changed to require a unit instance, not a string. Passing a string will raise an error.
fix Replace strings like 'flam' with astropy units: e.g., `u.erg/u.s/u.cm**2/u.AA`.
deprecated The `countrate` method returns counts per second based on the default flux density units (FLAM). If you need counts per second in a different bandpass, specify the area explicitly.
fix Use `Observation.countrate(area=...)` or convert units appropriately.
gotcha When creating a `SourceSpectrum` from a model, the `points` argument must be in the correct wavelength unit. If omitted, the model's internal points may not match expectations.
fix Always pass `points` with explicit units (e.g., `wave * u.AA`) when constructing from models.

Basic example of creating a source spectrum and a bandpass, then computing synthetic photometry.

from synphot import SourceSpectrum, SpectralElement, Observation
from synphot.models import Empirical1D, BlackBodyNorm1D
from astropy import units as u
import numpy as np

# Define a simple blackbody source spectrum
bb = BlackBodyNorm1D(temperature=5000)
wave = np.arange(1000, 10000) * u.AA
source_spec = SourceSpectrum(bb, points=wave)

# Define a Johnson V filter
# (Filter throughput data can be loaded from a file or defined manually)
# Example using a built-in filter from specutils or a custom one:
# Here we create a simple Gaussian bandpass for demonstration
from astropy.modeling.models import Gaussian1D
v_filter = SpectralElement(Gaussian1D, mean=5500, stddev=500, points=wave)

# Compute the observation
obs = Observation(source_spec, v_filter)
count_rate = obs.countrate()  # counts per second
print(count_rate)

# Compute effective wavelength
eff_wave = obs.effective_wavelength()
print(eff_wave)