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
¶
AtmosphereGrid(teff_grid, logg_grid, meta_grid, wavelengths, flux, flux_fortran, model_dir, lookup_nodes=None)
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. |
flux_fortran |
(ndarray, shape(n_T, n_L, n_M, n_W))
|
Fortran-contiguous copy of |
model_dir |
Path
|
Directory from which the grid was loaded. |
lookup_nodes |
(ndarray, shape(N, 3), optional)
|
(Teff, logg, [M/H]) of the tabulated models, i.e. the cube nodes
that hold a spectrum. MESA's |
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
cell_has_empty_nodes ¶
True if the cell containing the query touches a node with no model.
The cell is the one MESA's interpolators use (out-of-range queries take the boundary cell, dummy and single-point axes collapse). A corner counts only if it carries interpolation weight, so a query sitting exactly on a populated node is never reported. Corners that hold no spectrum are all-zero in the cube, and interpolating through them gives unreliable fluxes.
With stencil=True the check also covers the nodes the Hermite
derivative estimates read: each corner's axis-aligned neighbours, i.e.
one extra node on either side of the cell along each axis. Those
feed the cubic and an empty one makes it overshoot even when all
eight corners are populated. Linear interpolation does not use them.
Source code in sed_model/grid.py
nearest_grid_distance ¶
Distance in normalised parameter space from the nearest tabulated
model; identical to the Interp_rad diagnostic of the MESA colors
module (compute_interp_radius in colors/private/bolometric.f90).
Each axis is normalised by the range spanned by the tabulated models (floored at 1e-12), and an axis on which every model has the value 0, 999 or -999 (i.e. the axis does not exist for this grid) is ignored. The query is not clamped to the grid.
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.
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
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 integrals as the MESA colors module (colors/private/synthetic.f90):
photon counting (weight by wavelength), as MESA does.
Detector type
SED_Tools tags each filter file with the response convention of its curve,
DetectorType=photon or energy, as a ;-separated field after the
second comma of the column-name row::
Wavelength,Transmission,FilterID=GAIA/GAIA3.G;DetectorType=photon;...
Only the column row is read. An energy-counting curve T_E is
converted to its photon-counting equivalent T_E/λ (Bessell & Murphy 2012,
eq. A9), rescaled to keep its peak, so that the λ-weighted band integrals below
equal ∫F T_E / ∫T_E. This is what the MESA colors module does. A missing or
unrecognised tag means photon counting. A WavelengthUnit tag other than
Angstrom converts the file's wavelength column to Angstrom.
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)
Zero-points are computed through the compiled cc_api Fortran extension so the Python loader uses the same numerical kernels as run_forward() and the current MESA Colors implementation. A pure-Python trapezoid fallback is kept for environments where the extension has not yet been built.
Filter
dataclass
¶
Filter(name, path, wavelengths, transmission, vega_zero_point=-1.0, ab_zero_point=-1.0, st_zero_point=-1.0, photon_counting=True, detector_type='photon')
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. |
photon_counting |
bool
|
|
detector_type |
str
|
|
zero_point ¶
Return the zero-point for system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str
|
One of |
required |
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.
Filters are returned in index-file order, or alphabetically when
the index file is absent. Capture [f.name for f in filters]
immediately after loading to record the stable order for use with
obs_magnitudes arrays.
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, bounded Hermite, 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.
Calling conventions
Classic (keyword-explicit)::
run_forward(teff=5778, logg=4.44, meta=0.0,
R=6.957e10, d=3.086e19,
grid=grid, filters=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.
ForwardResult
dataclass
¶
ForwardResult(wavelengths, surface_flux, observed_flux, magnitudes, band_fluxes, bol_flux, bol_mag, nearest_grid_distance, 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.
Attributes:
| Name | Type | Description |
|---|---|---|
nearest_grid_distance |
float
|
Euclidean distance in normalised parameter space from the nearest
grid point (mirrors the MESA |
magnitudes |
dict[str, float]
|
Synthetic magnitudes keyed by filter name, in the order the
|
run_forward ¶
run_forward(teff=None, logg=None, meta=None, R=None, d=None, grid=None, filters=None, mag_system='AB', interp_method='hermite_bounded', 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')
|
Case-insensitive. |
'AB'
|
interp_method
|
('hermite_bounded', 'hermite', 'linear')
|
|
'hermite_bounded'
|
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
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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
run_forward_batch ¶
run_forward_batch(params, R, d, grid, filters, mag_system='AB', interp_method='hermite_bounded', 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. Two 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_bounded', n_walkers=32, n_steps=2000, n_burn=500, n_thin=1, p0_centre=None, p0_scatter=0.02, seed=None, progress=True, verbose=True, init='auto', sys_floor=0.0, fit_jitter=False, jitter_max=0.2, priors=None, upper_limits=None, auto_stop=False, moves=None, pool=None)
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_law
|
str or None
|
Convenience shorthand used to build a default extinction model when
both |
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_bounded', 'hermite', 'linear')
|
|
'hermite_bounded'
|
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
(only used by |
0.02
|
seed
|
int or None
|
|
None
|
progress
|
bool
|
Show the emcee progress bar. |
True
|
verbose
|
bool
|
Print the parameter summary and extinction configuration before sampling. Set to False for batch runs. |
True
|
init
|
('auto', 'ball')
|
Walker initialisation. |
'auto'
|
sys_floor
|
float
|
Systematic error floor in mag, added in quadrature to every uncertainty (default 0 = off). |
0.0
|
fit_jitter
|
bool
|
Fit one extra common noise term |
False
|
priors
|
dict or None
|
Extra priors on free parameters, e.g.
|
None
|
upper_limits
|
array-like of bool or None
|
Mark bands whose |
None
|
auto_stop
|
bool
|
Sample in blocks and stop early once the chain is >50 autocorrelation
times long and the estimate has stabilised; warns if |
False
|
moves
|
emcee move, list, str or None
|
Passed to |
None
|
pool
|
multiprocessing-style pool or None
|
Evaluate the posterior in parallel. |
None
|
Returns:
| Type | Description |
|---|---|
InverseResult
|
Includes |
Source code in sed_model/inverse.py
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 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
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. Two 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)
Explicit alias for free — use when you want to be unambiguous that
the parameter is sampled with hard upper and lower limits.
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', 'a_v'). |
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 always True (fixed).
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].
bounded ¶
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. All parameters
are keyword-only.
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(), converged=None, n_eff=None, chi2_best=None, n_data=None, init_info=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). |
converged |
bool or None
|
True if the post-burn-in chain is longer than 50 integrated autocorrelation times for every parameter (emcee's rule of thumb). None if the autocorrelation time could not be estimated. |
n_eff |
(ndarray or None, shape(n_free))
|
Effective number of independent samples per parameter,
|
chi2_best |
float or None
|
Data chi-square (sum of ((obs-model)/sigma_eff)^2 over detections) of the maximum-posterior sample. |
n_data |
int or None
|
Number of detected (non-upper-limit) bands used in the fit. |
init_info |
dict
|
How the walkers were initialised (method, number of modes found, ...) and sampler bookkeeping (number of likelihood evaluations). |
summary ¶
Return median and 1-sigma credible interval for each sampled parameter.
Source code in sed_model/io.py
credible_interval ¶
Credible interval for one sampled parameter.
method='hpd' (default) returns the shortest interval containing
level of the posterior mass. Unlike the equal-tailed interval
used by :meth:summary, it still contains the parameter when the
posterior piles up against a prior bound (e.g. [M/H] at the grid
edge). method='equal' gives the equal-tailed interval.
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)
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, 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)
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
¶
Configuration container for extinction settings.
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'
|
ExtinctionModel ¶
Apply extinction 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::
ext = ExtinctionModel(enabled=True, law='fitzpatrick99', a_v=0.5, r_v=3.1)
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 to a flux array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
array_like
|
Wavelengths in Angstroms. |
required |
flux
|
array_like
|
Intrinsic flux in any linear unit. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
flux_out |
ndarray
|
Extincted flux. If |
Source code in sed_model/sed_extinction.py
remove ¶
Remove (de-redden) extinction from an observed flux.
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
with_av ¶
Return a new ExtinctionModel identical to this one but with a different A_V.
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 ¶
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
|
gordon23_env
|
str
|
Gordon+2023 environment preset: 'mw', 'lmc', or 'smc'. |
'mw'
|
Returns:
| Type | Description |
|---|---|
ExtinctionModel
|
|