API Reference¶
Generated directly from the docstrings in the source — if a signature here disagrees with the prose guides, the source (and therefore this page) wins.
sed_model.grid¶
sed_model.grid ¶
sed_model.grid¶
Loads a SED_Tools-prepared stellar atmosphere grid (flux_cube.bin + lookup_table.csv) into memory and exposes the axes and flux array for downstream interpolation.
Binary format (flux_cube.bin)
Header : 4 × int32 -> (n_teff, n_logg, n_meta, n_lambda) Axes : n_teff + n_logg + n_meta + n_lambda float64 values (written consecutively, no padding) Payload : n_teff × n_logg × n_meta × n_lambda float64 values stored in (W, M, L, T) order on disk, loaded into (T, L, M, W).
This matches the layout written by SED_Tools and read by the MESA colors module (colors_utils.f90 :: load_flux_cube).
AtmosphereGrid
dataclass
¶
Immutable container for a loaded stellar atmosphere grid.
Attributes:
| Name | Type | Description |
|---|---|---|
teff_grid |
(ndarray, shape(n_T))
|
Effective temperature grid points in Kelvin. |
logg_grid |
(ndarray, shape(n_L))
|
log10(g / cm s^-2) grid points. |
meta_grid |
(ndarray, shape(n_M))
|
Metallicity [M/H] grid points. |
wavelengths |
(ndarray, shape(n_W))
|
Wavelength grid in Angstroms. |
flux |
(ndarray, shape(n_T, n_L, n_M, n_W))
|
Surface flux in erg/s/cm^2/Å at each (Teff, logg, [M/H]) node. |
model_dir |
Path
|
Directory from which the grid was loaded. |
in_bounds ¶
Return True if (teff, logg, meta) is within the grid axes.
Source code in sed_model/grid.py
clamp ¶
Clamp (teff, logg, meta) to the grid boundary.
Source code in sed_model/grid.py
interp_radius ¶
Euclidean distance in normalised parameter space from the
nearest grid point. Mirrors the Interp_rad diagnostic
produced by the MESA colors module.
Source code in sed_model/grid.py
load_grid ¶
Load a SED_Tools atmosphere grid from model_dir.
The directory must contain:
- flux_cube.bin — binary flux cube
- lookup_table.csv — parameter index (used for validation only)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir
|
str | Path
|
Path to the directory produced by |
required |
Returns:
| Type | Description |
|---|---|
AtmosphereGrid
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If the binary header is invalid or the file is truncated. |
Source code in sed_model/grid.py
validate_lookup_table ¶
Read and return the lookup_table.csv from grid.model_dir.
Useful for sanity-checking that the grid axes in the binary cube are consistent with the CSV metadata. Not called at load time to avoid the pandas overhead on every initialisation.
Source code in sed_model/grid.py
sed_model.filters¶
sed_model.filters ¶
sed_model.filters¶
Loads photometric filter transmission curves from SED_Tools-prepared
.dat files and precomputes Vega, AB, and ST zero-points using the
same photon-counting integrals as the MESA colors module
(colors/private/synthetic.f90).
Zero-point definitions
Vega : F_zp = ∫ F_vega(λ) T(λ) λ dλ / ∫ T(λ) λ dλ AB : F_zp = ∫ F_AB(λ) T(λ) λ dλ / ∫ T(λ) λ dλ where F_AB(λ) = 3.631e-20 × c / λ² [erg/s/cm²/Å] ST : F_zp = 3.63e-9 (flat F_lambda, constant)
All integrals use the trapezoid rule for wavelength grids that may be non-uniform. The Fortran runtime uses adaptive Simpson; the difference is negligible for the dense wavelength grids produced by SED_Tools.
Filter
dataclass
¶
Filter(name, path, wavelengths, transmission, vega_zero_point=-1.0, ab_zero_point=-1.0, st_zero_point=-1.0)
A single photometric filter with precomputed zero-points.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Short filter identifier (filename stem, e.g. |
path |
Path
|
Absolute path to the source |
wavelengths |
(ndarray, shape(n))
|
Filter wavelength grid in Angstroms. |
transmission |
(ndarray, shape(n))
|
Dimensionless transmission in [0, 1]. |
vega_zero_point |
float
|
Photon-counting flux zero-point for the Vega magnitude system.
|
ab_zero_point |
float
|
Photon-counting flux zero-point for the AB magnitude system. |
st_zero_point |
float
|
Photon-counting flux zero-point for the ST magnitude system. |
zero_point ¶
Return the zero-point for system ('Vega', 'AB', or 'ST').
Source code in sed_model/filters.py
load_filters ¶
Load a list of filter .dat files and return a list of
:class:Filter objects with precomputed zero-points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_paths
|
list[str | Path]
|
Paths to individual |
required |
vega_sed_path
|
str | Path | None
|
Optional path to a Vega reference SED CSV file
( |
None
|
Returns:
| Type | Description |
|---|---|
list of Filter, in the same order as *filter_paths*.
|
|
Source code in sed_model/filters.py
load_filters_from_instrument_dir ¶
Load all filters listed in a SED_Tools instrument directory.
The directory must contain an index file whose name matches the
last component of instrument_dir (e.g. Johnson/Johnson) that
lists one .dat filename per line. This mirrors the structure
expected by the MESA colors module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument_dir
|
str | Path
|
Path to a |
required |
vega_sed_path
|
str | Path | None
|
Optional Vega reference SED for Vega zero-point computation. |
None
|
Returns:
| Type | Description |
|---|---|
list of Filter
|
|
Source code in sed_model/filters.py
sed_model.forward¶
sed_model.forward ¶
sed_model.forward¶
Forward model: stellar parameters → SED + synthetic photometry.
Pipeline
(Teff, logg, [M/H]) → SED interpolation (Fortran, Hermite or linear) → distance dilution (Fortran, (R/d)²) → extinction (Python, optional, sed_extinction) → bolometric (Fortran) → filter convolution (Fortran, per filter) → ForwardResult
All five physical parameters — Teff, logg, [M/H], Av, distance — can be fixed or free, described by a FitParams object (sed_model.params). This shared vocabulary is what makes the module bidirectional: the inverse model unpacks a theta vector with FitParams.unpack and passes the result directly to run_forward.
Backward-compatible call
The original positional signature still works::
run_forward(teff, logg, meta, R, d, grid, filters)
FitParams call (used by the inverse model)::
run_forward(fit_params=params, theta=theta_vec,
R=R_sun, grid=grid, filters=filters)
ForwardResult
dataclass
¶
ForwardResult(wavelengths, surface_flux, observed_flux, magnitudes, band_fluxes, bol_flux, bol_mag, interp_radius, clamped, teff, logg, meta, R, d, a_v=0.0, mag_system='AB', extinction_applied=False)
Output of one forward-model evaluation.
The five physical parameters that produced this result are all stored
so the result is self-describing. The inverse model uses
ForwardResult.magnitudes to compute the likelihood; the forward
model reads parameters from FitParams — both sides work with the same
data structure.
run_forward ¶
run_forward(teff=None, logg=None, meta=None, R=None, d=None, grid=None, filters=None, mag_system='AB', interp_method='hermite', extinction=None, fit_params=None, theta=None)
Evaluate the forward model for one set of stellar parameters.
Two calling conventions are supported.
Classic (backward-compatible)::
run_forward(teff, logg, meta, R, d, grid, filters)
FitParams (used by the inverse model)::
run_forward(fit_params=params, theta=theta_vec,
R=R_sun, grid=grid, filters=filters)
In the FitParams convention theta contains only the free parameters
in canonical order (teff, logg, meta, a_v, d — skipping fixed ones).
fit_params.unpack(theta) fills in the fixed values. If Av or
distance are free parameters they are taken from theta, not from any
keyword argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
teff
|
float
|
Atmospheric parameters. Required in classic mode. |
None
|
logg
|
float
|
Atmospheric parameters. Required in classic mode. |
None
|
meta
|
float
|
Atmospheric parameters. Required in classic mode. |
None
|
R
|
float
|
Stellar radius in cm. Always required. |
None
|
d
|
float
|
Distance in cm. Required in classic mode; ignored if distance is a free parameter in fit_params. |
None
|
grid
|
AtmosphereGrid
|
|
None
|
filters
|
list of Filter
|
|
None
|
mag_system
|
('AB', 'Vega', 'ST')
|
|
'AB'
|
interp_method
|
('hermite', 'linear')
|
|
'hermite'
|
extinction
|
ExtinctionModel or None
|
Applied after dilution and before filter convolution. When Av is free in fit_params, the model's stored a_v is overridden by the value from theta at each call. |
None
|
fit_params
|
FitParams or None
|
|
None
|
theta
|
array - like or None
|
Required when fit_params is provided. |
None
|
Source code in sed_model/forward.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
run_forward_batch ¶
run_forward_batch(params, R, d, grid, filters, mag_system='AB', interp_method='hermite', extinction=None)
Run run_forward over an array of (teff, logg, meta) rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
(ndarray, shape(N, 3))
|
|
required |
Returns:
| Type | Description |
|---|---|
list of ForwardResult, length N.
|
|
Source code in sed_model/forward.py
sed_model.inverse¶
sed_model.inverse ¶
sed_model.inverse¶
Inverse model: observed magnitudes → posterior on stellar parameters.
The inverse model is the mirror of the forward model. Both share the same
FitParams object (from sed_model.params) which declares each
physical parameter as fixed or free. The MCMC samples only the free
parameters; fixed ones are threaded to the forward model unchanged.
This bidirectionality is concrete, not cosmetic:
- The forward model maps FitParams.unpack(theta) → magnitudes.
- The inverse model maps magnitudes → FitParams + posterior on theta.
- The same FitParams instance flows in both directions.
Parameter modes
Every physical quantity — Teff, logg, [M/H], Av, distance — is described
by a ParamSpec inside a FitParams. Three behaviours:
fixed(value)
Not sampled. Passed unchanged to the forward model at every step.
free(lo, hi)
Sampled by MCMC with a flat prior over [lo, hi].
bounded(lo, hi)
Alias for free — use it to be explicit about hard limits.
The simplest use::
from sed_model import run_inverse
from sed_model.params import fit_params_from_grid, PC_TO_CM
params = fit_params_from_grid(grid) # Teff/logg/meta free
result = run_inverse(obs_mags, obs_errs, filter_names,
R=R_sun, fit_params=params,
grid=grid, filters=filters)
To fit with extinction free::
params = fit_params_from_grid(grid, a_v=(0.0, 3.0)) # Av free 0–3 mag
ext = ExtinctionModel(enabled=True, law='fitzpatrick99', a_v=0.0)
result = run_inverse(..., fit_params=params, extinction=ext)
To fit with distance free (expect Av–d degeneracy in the posterior)::
params = fit_params_from_grid(
grid,
a_v=(0.0, 2.0),
d_cm=(100*PC_TO_CM, 2000*PC_TO_CM),
)
run_inverse ¶
run_inverse(obs_magnitudes, obs_uncertainties, filter_names, R, grid, filters, fit_params=None, d=None, extinction_law=None, extinction=None, mag_system='AB', interp_method='hermite', n_walkers=32, n_steps=2000, n_burn=500, n_thin=1, p0_centre=None, p0_teff=None, p0_logg=None, p0_meta=None, p0_scatter=0.02, seed=None, progress=True)
Infer stellar parameters from observed broadband photometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obs_magnitudes
|
(array - like, shape(n_filters))
|
Observed magnitudes in the same order as |
required |
obs_uncertainties
|
(array - like, shape(n_filters))
|
1-sigma uncertainties. Must all be > 0. |
required |
filter_names
|
list of str
|
Filter names matching elements of |
required |
R
|
float
|
Stellar radius in cm (always required; not currently sampled). |
required |
grid
|
AtmosphereGrid
|
|
required |
filters
|
list of Filter
|
|
required |
fit_params
|
FitParams or None
|
Full parameter specification. If None, one is built from |
None
|
d
|
float or None
|
Distance in cm. Used only when |
None
|
extinction
|
ExtinctionModel or None
|
Dust extinction model. Required if Av is free in fit_params. Ignored if Av is fixed at 0. |
None
|
mag_system
|
('AB', 'Vega', 'ST')
|
|
'AB'
|
interp_method
|
('hermite', 'linear')
|
|
'hermite'
|
n_walkers
|
int
|
emcee settings. |
32
|
n_steps
|
int
|
emcee settings. |
32
|
n_burn
|
int
|
emcee settings. |
32
|
n_thin
|
int
|
emcee settings. |
32
|
p0_centre
|
dict or None
|
Optional starting point keyed by parameter name, e.g.
|
None
|
p0_scatter
|
float
|
Width of initial ball as fraction of each parameter's range. |
0.02
|
seed
|
int or None
|
|
None
|
progress
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
InverseResult
|
|
Source code in sed_model/inverse.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
sed_model.params¶
sed_model.params ¶
sed_model.params¶
Shared parameter definitions used by both the forward and inverse models.
This is the single place that knows what a "stellar parameter" is, whether it is being sampled or held fixed, and what its physical bounds are. Having it here — rather than scattered across forward.py and inverse.py — is what makes the module genuinely bidirectional: both directions speak the same language about the same quantities.
Parameter modes
Every physical parameter (Teff, logg, [M/H], Av, distance) is described by
a ParamSpec. Three modes are supported:
fixed(value)
The parameter is not sampled. It is passed directly to the forward
model at every likelihood evaluation. This is the default for Av and
distance.
free(lo, hi)
The parameter is sampled by the MCMC over the interval [lo, hi]. A flat
prior is used. This is the default for Teff, logg, and [M/H] (bounds
taken from the atmosphere grid at construction time).
bounded(lo, hi)
Alias for free — included so user code can be explicit that it wants
the parameter sampled with a hard upper and lower limit.
The degeneracy between Av and distance is real and expected: if both are free simultaneously the posterior will be correlated. That is honest — the data genuinely cannot break the degeneracy without additional information. The MCMC will show it.
Usage
::
from sed_model.params import ParamSpec, FitParams, fixed, free
params = FitParams(
teff = free(4000, 8000),
logg = free(3.0, 5.0),
meta = free(-1.0, 0.5),
a_v = fixed(0.3), # Av fixed, not sampled
d = fixed(500 * PC_TO_CM), # distance fixed
)
# In the forward model:
result = run_forward(..., fit_params=params, theta=[5800, 4.4, 0.0])
# theta contains only the FREE parameters in the order teff, logg, meta, [av, d]
# Inspect what is being sampled:
print(params.free_names) # ['teff', 'logg', 'meta']
print(params.n_free) # 3
ParamSpec
dataclass
¶
Specification for a single physical parameter.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable parameter name (e.g. 'Teff', 'Av'). |
mode |
{'fixed', 'free'}
|
Whether the parameter is held constant or sampled. |
value |
float or None
|
Fixed value. Only meaningful when |
lo, hi |
float or None
|
Sampling bounds. Only meaningful when |
contains ¶
True if v is within the sampling bounds (free) or equals the fixed value.
FitParams
dataclass
¶
FitParams(teff, logg, meta, a_v=(lambda: fixed(0.0, name='a_v'))(), d=(lambda: fixed(PC_TO_CM, name='d'))())
Complete specification of all physical parameters for a fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
teff
|
ParamSpec
|
Effective temperature in Kelvin. |
required |
logg
|
ParamSpec
|
Log surface gravity (log10 g / cm s-2). |
required |
meta
|
ParamSpec
|
Metallicity [M/H] in dex. |
required |
a_v
|
ParamSpec
|
V-band extinction in magnitudes. Default: fixed(0.0). |
(lambda: fixed(0.0, name='a_v'))()
|
d
|
ParamSpec
|
Distance in cm. Default: fixed(1 pc). |
(lambda: fixed(PC_TO_CM, name='d'))()
|
Notes
The canonical theta vector used by the MCMC sampler contains only the
free parameters, in the order: teff, logg, meta, a_v, d (skipping any
that are fixed). Use pack / unpack to convert between the full
parameter space and the reduced theta vector.
pack ¶
Pack full physical values into the reduced free-parameter theta vector.
Only the free parameters are included, in canonical order. Fixed parameters are ignored (the values from the spec are used at unpack time).
Source code in sed_model/params.py
unpack ¶
Expand the reduced theta vector into a full {param: value} dict.
Fixed parameters are filled in from their specs. Free parameters are taken from theta in canonical order.
Source code in sed_model/params.py
in_prior ¶
Return True if all free parameters in theta are within their bounds.
Source code in sed_model/params.py
initial_ball ¶
Generate initial walker positions in a Gaussian ball.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_walkers
|
int
|
Number of walkers. |
required |
centre
|
dict or None
|
Central values keyed by parameter name. If None, the midpoint of the free bounds is used for free parameters. |
None
|
scatter
|
float
|
Width of the ball as a fraction of the parameter range. |
0.02
|
rng
|
Generator or None
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
pos |
(ndarray, shape(n_walkers, n_free))
|
|
Source code in sed_model/params.py
fixed ¶
free ¶
Return a free (sampled) ParamSpec with flat prior over [lo, hi].
fit_params_from_grid ¶
Build a FitParams from grid bounds plus optional user overrides.
By default Teff/logg/[M/H] are free over the full grid, Av is fixed to
zero, and distance is fixed to 1 pc. For any parameter, pass either a
float to fix it or a (lo, hi) tuple to sample it.
Examples:
Fit Teff/logg/meta, with Av fixed::
fit_params_from_grid(grid, a_v=0.3, d_cm=500*PC_TO_CM)
Fit only Teff and Av::
fit_params_from_grid(
grid,
teff=(5200, 6400),
logg=4.4,
meta=0.0,
a_v=(0.0, 1.5),
d_cm=500*PC_TO_CM,
)
Source code in sed_model/params.py
sed_model.io¶
sed_model.io ¶
sed_model.io¶
Result containers and persistence for SED_Model outputs.
InverseResult Holds the full emcee sampler output, summary statistics, and the input observations. Can be saved to / loaded from a NumPy .npz archive so posteriors are portable without pickling the sampler.
ForwardResult serialisation Thin helpers to write a ForwardResult SED to a two-column CSV.
InverseResult
dataclass
¶
InverseResult(samples, log_prob, filter_names, obs_magnitudes, obs_uncertainties, R, d, mag_system, n_walkers, n_steps, n_burn, n_thin, acceptance_fraction, autocorr_time=None, param_names=(lambda: ['teff', 'logg', 'meta'])(), fixed_params=dict())
Output of the inverse (photometry → stellar parameters) inference.
Attributes:
| Name | Type | Description |
|---|---|---|
samples |
(ndarray, shape(n_samples, n_free))
|
Flattened posterior samples after burn-in.
Columns follow |
log_prob |
(ndarray, shape(n_samples))
|
Log-posterior value for each sample. |
filter_names |
list of str
|
Names of filters used in the fit, in order. |
obs_magnitudes |
(ndarray, shape(n_filters))
|
Observed magnitudes supplied by the user. |
obs_uncertainties |
(ndarray, shape(n_filters))
|
Per-filter magnitude uncertainties (1-sigma). |
R |
float
|
Stellar radius used (cm). |
d |
float
|
Distance used (cm). |
mag_system |
str
|
Photometric system ('Vega', 'AB', 'ST'). |
n_walkers |
int
|
Number of emcee walkers. |
n_steps |
int
|
Total steps per walker (including burn-in). |
n_burn |
int
|
Steps discarded as burn-in. |
n_thin |
int
|
Thinning factor applied to the chain. |
acceptance_fraction |
(ndarray, shape(n_walkers))
|
Per-walker acceptance fraction. |
autocorr_time |
(ndarray or None, shape(n_free))
|
Estimated integrated autocorrelation time for each parameter. None if estimation failed (chain too short). |
summary ¶
Return median and 1-sigma credible interval for each sampled parameter.
Source code in sed_model/io.py
map_estimate ¶
Return the maximum a-posteriori sample as a {parameter: value} dict.
print_summary ¶
Print a formatted parameter summary for arbitrary free parameters.
Source code in sed_model/io.py
save ¶
Save the posterior to a compressed NumPy archive (.npz).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Output file. The |
required |
Source code in sed_model/io.py
load
classmethod
¶
Load an InverseResult saved with :meth:save.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to a |
required |
Source code in sed_model/io.py
save_sed ¶
Write the observed-frame SED from a ForwardResult to a CSV.
Columns: wavelength (Å), surface_flux, observed_flux (erg/s/cm²/Å).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ForwardResult
|
|
required |
path
|
str or Path
|
|
required |
Source code in sed_model/io.py
save_magnitudes ¶
Write the synthetic magnitudes from a ForwardResult to a CSV.
Columns: filter_name, magnitude, band_flux (erg/s/cm²/Å).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ForwardResult
|
|
required |
path
|
str or Path
|
|
required |
Source code in sed_model/io.py
sed_model.sed_extinction¶
sed_model.sed_extinction ¶
sed_extinction.py¶
Standalone interstellar dust extinction module for SED fitting.
All extinction laws are implemented in pure NumPy — no compiled Cython
dependency. The numerical coefficients are taken directly from the
extinction package (Barbary 2016, which itself faithfully reproduces
the original papers), plus a native implementation of Gordon et al. (2023).
Usage
Apply extinction to a spectrum before filter convolution::
from sed_extinction import ExtinctionModel
ext = ExtinctionModel(law='fitzpatrick99', r_v=3.1, a_v=0.3,
distance_pc=100.0)
flux_obs = ext.apply(wavelength_aa, flux_intrinsic)
Or use it purely as a forward-model modifier inside a fitter::
ext = ExtinctionModel(law='ccm89', r_v=3.1, a_v=0.0, # disabled
distance_pc=1.0, enabled=False)
# later, at evaluation time:
flux_obs = ext.apply(wave, flux) # returns flux unchanged when disabled
Supported laws
'ccm89' Cardelli, Clayton & Mathis (1989) ApJ 345 245 'odonnell94' O'Donnell (1994) ApJ 422 158 (CCM89 with revised optical) 'fitzpatrick99' Fitzpatrick (1999) PASP 111 63 (R_V-dependent spline) 'fm07' Fitzpatrick & Massa (2007) ApJ 663 320 (R_V = 3.1 fixed) 'calzetti00' Calzetti et al. (2000) ApJ 533 682 (starburst galaxies) 'gordon23' Gordon et al. (2023) ApJ 950 86 (piecewise, MW/SMC/LMC)
Distance scaling
The module also applies distance dimming so that
F_obs = F_intrinsic * (R_star / distance)^2
but ONLY when scale_distance is True (default False). Both Av and
distance are not fitted by default — they are fixed parameters passed
at construction time. To use them in a fit set enabled=True and
pass the appropriate a_v / distance_pc when constructing the model for
each likelihood evaluation.
Convention
All wavelengths are in Angstroms. Fluxes are in any linear unit (erg/s/cm²/Å, normalised, etc.) — only the ratio matters.
The extinction is applied as: F_obs(λ) = F_intrinsic(λ) × 10^(−0.4 × A(λ)) where A(λ) = a_v × k(λ) and k(λ) is the normalised extinction curve returned by the chosen law.
ExtinctionConfig
dataclass
¶
ExtinctionConfig(enabled=False, law='fitzpatrick99', r_v=3.1, a_v=0.0, gordon23_env='mw', distance_pc=1.0, scale_distance=False)
Configuration container for extinction + distance settings.
All parameters are fixed (not fitted) unless you rebuild the object for each likelihood evaluation in your fitter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
If False, |
False
|
law
|
str
|
Name of the extinction law. One of |
'fitzpatrick99'
|
r_v
|
float
|
R_V value (ignored by 'fm07' which fixes R_V = 3.1, and by 'calzetti00' which uses its own R_V = 4.05 unless overridden). |
3.1
|
a_v
|
float
|
V-band extinction in magnitudes. Default 0.0. |
0.0
|
gordon23_env
|
str
|
Only used when |
'mw'
|
distance_pc
|
float
|
Distance in parsecs. Default 1.0 (no dilution applied unless
|
1.0
|
scale_distance
|
bool
|
If True, multiply the flux by (R_star_cm / distance_cm)^2
where R_star_cm must be supplied to |
False
|
ExtinctionModel ¶
Apply extinction and (optionally) distance scaling to a spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ExtinctionConfig
|
Full configuration object. If None, a default (disabled) config is used. |
None
|
**kwargs
|
Convenience keyword arguments forwarded to |
{}
|
Examples:
Disabled (default) — passes flux through unchanged::
ext = ExtinctionModel()
flux_out = ext.apply(wave, flux)
Enabled, Fitzpatrick99, Av=0.5 at 200 pc::
ext = ExtinctionModel(enabled=True, law='fitzpatrick99',
a_v=0.5, r_v=3.1, distance_pc=200.)
flux_obs = ext.apply(wave, flux)
Gordon+2023 SMC curve::
ext = ExtinctionModel(enabled=True, law='gordon23',
a_v=0.8, gordon23_env='smc')
flux_obs = ext.apply(wave, flux)
Source code in sed_model/sed_extinction.py
extinction_curve ¶
Return A(λ) in magnitudes for the configured law and A_V.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A_lambda |
ndarray
|
Extinction in magnitudes. Returns zeros if |
Source code in sed_model/sed_extinction.py
apply ¶
Apply extinction (and optionally distance scaling) to a flux.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. |
required |
flux
|
array_like
|
Intrinsic flux in any linear unit. |
required |
r_star_cm
|
float
|
Stellar radius in cm. Required only when
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
flux_out |
ndarray
|
Processed flux. If |
Source code in sed_model/sed_extinction.py
remove ¶
Remove (de-redden) extinction from an observed flux.
Distance scaling is NOT reversed here — this only undoes extinction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. |
required |
flux
|
array_like
|
Observed flux. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
flux_intrinsic |
ndarray
|
De-reddened flux. |
Source code in sed_model/sed_extinction.py
disabled
classmethod
¶
from_dict
classmethod
¶
ccm89 ¶
Cardelli, Clayton & Mathis (1989) extinction in magnitudes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. Valid range: ~910–33 000 Å. |
required |
a_v
|
float
|
V-band extinction in magnitudes. |
required |
r_v
|
float
|
Total-to-selective extinction ratio (default 3.1). |
3.1
|
Returns:
| Name | Type | Description |
|---|---|---|
A_lambda |
ndarray
|
Extinction in magnitudes at each wavelength. |
Source code in sed_model/sed_extinction.py
odonnell94 ¶
O'Donnell (1994) extinction — CCM89 with revised optical coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. Valid range: ~910–33 000 Å. |
required |
a_v
|
float
|
V-band extinction in magnitudes. |
required |
r_v
|
float
|
Total-to-selective extinction ratio (default 3.1). |
3.1
|
Returns:
| Name | Type | Description |
|---|---|---|
A_lambda |
ndarray
|
Extinction in magnitudes at each wavelength. |
Source code in sed_model/sed_extinction.py
fitzpatrick99 ¶
Fitzpatrick (1999) R_V-dependent dust extinction.
Optical/IR: cubic spline through the Fitzpatrick (1999) knots updated by E. Fitzpatrick to match the IDL astrolib FM_UNRED routine. UV (< 2700 Å): analytic Fitzpatrick & Massa (1990) parametrization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. Valid range: 910–60 000 Å. |
required |
a_v
|
float
|
V-band extinction in magnitudes. |
required |
r_v
|
float
|
Total-to-selective extinction ratio (default 3.1). |
3.1
|
Returns:
| Name | Type | Description |
|---|---|---|
A_lambda |
ndarray
|
Extinction in magnitudes at each wavelength. |
Source code in sed_model/sed_extinction.py
fm07 ¶
Fitzpatrick & Massa (2007) extinction (R_V = 3.1 fixed).
Defined from 910 Å to 6 µm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. |
required |
a_v
|
float
|
V-band extinction in magnitudes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A_lambda |
ndarray
|
Extinction in magnitudes at each wavelength. |
Source code in sed_model/sed_extinction.py
calzetti00 ¶
Calzetti et al. (2000) starburst galaxy attenuation law.
Valid range: 1200–22 000 Å.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. |
required |
a_v
|
float
|
V-band attenuation in magnitudes (a_v = r_v * E(B−V)_s). |
required |
r_v
|
float
|
R_V for the starburst law (Calzetti default: 4.05). |
4.05
|
Returns:
| Name | Type | Description |
|---|---|---|
A_lambda |
ndarray
|
Attenuation in magnitudes at each wavelength. |
Source code in sed_model/sed_extinction.py
gordon23 ¶
Gordon et al. (2023) dust extinction law.
Native implementation of the piecewise FM-style law from Gordon, K. D. et al. 2023, ApJ, 950, 86.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. |
required |
a_v
|
float
|
V-band extinction in magnitudes. |
required |
r_v
|
float or None
|
Total-to-selective extinction ratio. If None, the environment default from Gordon+2023 is used (MW: 3.17, LMC: 3.41, SMC: 2.74). |
None
|
environment
|
('mw', 'lmc', 'smc')
|
Which average extinction curve to use (default 'mw'). |
'mw'
|
Returns:
| Name | Type | Description |
|---|---|---|
A_lambda |
ndarray
|
Extinction in magnitudes at each wavelength. |
Source code in sed_model/sed_extinction.py
apply_extinction ¶
Apply extinction magnitudes to a flux array.
F_obs = F_intrinsic × 10^(−0.4 × A_lambda)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a_lambda
|
ndarray
|
Extinction in magnitudes at each wavelength (same shape as flux). |
required |
flux
|
ndarray
|
Intrinsic flux array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
flux_obs |
ndarray
|
Observed (extincted) flux. |
Source code in sed_model/sed_extinction.py
remove_extinction ¶
Remove extinction from an observed flux (de-redden).
F_intrinsic = F_obs × 10^(+0.4 × A_lambda)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a_lambda
|
ndarray
|
Extinction in magnitudes at each wavelength. |
required |
flux
|
ndarray
|
Observed (extincted) flux. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
flux_intrinsic |
ndarray
|
De-reddened flux. |
Source code in sed_model/sed_extinction.py
make_extinction_model ¶
make_extinction_model(enabled=False, law='fitzpatrick99', r_v=3.1, a_v=0.0, distance_pc=1.0, scale_distance=False, gordon23_env='mw')
Convenience factory — mirrors the ExtinctionConfig keyword signature.
This is the recommended way to build an extinction model inside a fitter's forward-model function, e.g.::
ext = make_extinction_model(enabled=True, law='fitzpatrick99',
a_v=theta['a_v'])
flux_obs = ext.apply(wave, flux_intrinsic)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
Master switch. Default False — extinction is skipped entirely. |
False
|
law
|
str
|
Extinction law name. See |
'fitzpatrick99'
|
r_v
|
float
|
R_V (shape parameter). Default 3.1. |
3.1
|
a_v
|
float
|
V-band extinction. Default 0.0. |
0.0
|
distance_pc
|
float
|
Source distance in parsecs. Default 1 pc (absolute flux, no dilution). |
1.0
|
scale_distance
|
bool
|
Apply (R/d)^2 dilution. Default False. |
False
|
gordon23_env
|
str
|
Gordon+2023 environment preset: 'mw', 'lmc', or 'smc'. |
'mw'
|
Returns:
| Type | Description |
|---|---|
ExtinctionModel
|
|