API reference¶
Auto-generated from the source docstrings. The public API is the symbols below; treat everything else as internal.
Stellar populations¶
ceridwen.ssps.SSPData
dataclass
¶
SSPData(
ssp_lgmet,
ssp_lg_age_gyr,
ssp_wave,
ssp_flux,
ssp_resolution=None,
resolution_source=None,
isoc_type=None,
spec_library=None,
imf_type=None,
fsps_version=None,
fsps_kwargs=dict(),
wave_min=None,
wave_max=None,
schema_version=None,
_extra_datasets=(),
)
Immutable container for the SSP interpolation grids plus static provenance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ssp_lgmet
|
array (n_met,) -- log10 absolute metallicity Z, NOT log10 Z/Zsun
|
|
required |
ssp_lg_age_gyr
|
array(n_ages) - -log10(age / Gyr)
|
|
required |
ssp_wave
|
(array(n_wave), Angstrom)
|
|
required |
ssp_flux
|
array (n_met, n_ages, n_wave), L_sun/Hz per M_sun formed
|
|
required |
ssp_resolution
|
ndarray (n_wave,), km/s -- library sigma_v(lambda) on ssp_wave, NaN where unknown; optional in memory, required by save()/load()
|
|
None
|
with_resolution ¶
Return a copy carrying a library resolution curve from exactly one of sigma_v (km/s on ssp_wave, NaN where unknown) or segments.
Source code in ceridwen/ssps/ssp_data.py
display ¶
Print (or return as str when return_str) a summary of the grid and its provenance.
Source code in ceridwen/ssps/ssp_data.py
save ¶
Write grids, resolution curve and provenance attrs to HDF5 (overwrites); raises ValueError if ssp_resolution is None.
Source code in ceridwen/ssps/ssp_data.py
load
classmethod
¶
Load a grid from HDF5; raises ValueError if the file lacks ssp_resolution. flux_dtype casts the flux cube on read.
Source code in ceridwen/ssps/ssp_data.py
from_fsps
classmethod
¶
Build a grid from the SPS backend, attach the library resolution curve and record provenance.
Only library/IMF-defining kwargs (LIBRARY_IMF_KWARGS) are accepted.
The resolution curve is the element-wise maximum of the 2-pixel sampling
floor of ssp_wave and resolution_segments (if given, which then
require resolution_source). Raises ValueError otherwise.
Source code in ceridwen/ssps/ssp_data.py
ceridwen.ssps.SSPDataAfe
dataclass
¶
SSPDataAfe(
ssp_lgmet,
ssp_lg_age_gyr,
ssp_wave,
ssp_flux,
ssp_resolution=None,
resolution_source=None,
isoc_type=None,
spec_library=None,
imf_type=None,
fsps_version=None,
fsps_kwargs=dict(),
wave_min=None,
wave_max=None,
schema_version=None,
_extra_datasets=(),
*,
ssp_afe
)
Bases: SSPData
Immutable alpha-enhanced SSP grid: an SSPData whose flux cube has a leading [alpha/Fe] axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ssp_lgmet
|
jnp.ndarray (n_met,) -- log10 absolute TOTAL metallicity Z, NOT [Fe/H]
|
|
required |
ssp_afe
|
jnp.ndarray (n_afe,), keyword-only -- [alpha/Fe] grid, strictly increasing
|
|
required |
ssp_lg_age_gyr
|
ndarray(n_ages) - -log10(age / Gyr)
|
|
required |
ssp_wave
|
ndarray(n_wave) - -Angstrom
|
|
required |
ssp_flux
|
jnp.ndarray (n_afe, n_met, n_ages, n_wave) -- Lsun / Hz per Msun formed
|
|
required |
ssp_resolution
|
np.ndarray (n_wave,) or None -- sigma_v(lambda) [km/s] on ``ssp_wave``; required by save/load
|
|
None
|
load
classmethod
¶
Load from HDF5; a 3-D grid without ssp_afe is promoted to n_afe = 1 at [alpha/Fe] = 0.
Source code in ceridwen/ssps/ssp_data_afe.py
from_fsps
classmethod
¶
from_fsps(
save_to=None,
afe_values=None,
resolution_segments=None,
resolution_source=None,
**fsps_kwargs
)
Build the grid by looping get_spectrum(tage=0, zmet=i) over the [alpha/Fe] planes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
afe_values
|
array-like, optional -- [alpha/Fe] of each plane in ``afeindx`` order; defaults exist for n_afe 5 and 1 only
|
|
None
|
resolution_segments
|
list, optional -- documented library LSF segments, max-combined with the 2-pixel sampling floor
|
|
None
|
resolution_source
|
str, optional -- citation for ``resolution_segments``; each raises if given without the other
|
|
None
|
Source code in ceridwen/ssps/ssp_data_afe.py
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 | |
ceridwen.ssps.fetch_grid ¶
Return a local, checksum-verified path to the registry grid name,
downloading into :func:grid_cache_dir on first use (force re-downloads).
Source code in ceridwen/ssps/grid_fetch.py
ceridwen.ssps.available_grids ¶
Map of grid name -> one-line description.
Composite stellar population (forward model)¶
ceridwen.csp.CSPBasis ¶
CSPBasis(
SSPData,
theta=None,
tiny_logt=-70,
zh_const=False,
add_neb=True,
init_neb_params=None,
nebemlineinspec=False,
add_dust=True,
add_diffuse_dust=True,
add_dust_emission=False,
add_igm=False,
igm_model="madau1995",
igm_factor=1.0,
sps_home=None,
init_dust_params=None,
diffuse_law="kriek_conroy",
verbose=True,
sfh_interp="step",
track_zred_age=False,
lookback_time=None,
sfh_per_bin=False,
fesc_geometry="runaway_bc",
cosmo=None,
**kwargs
)
Composite stellar population basis. predict(theta, observations) projects the model onto observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
SSPData
|
SSPData -- SSP grids (wave, flux, ages, metallicities, optional resolution curve).
|
|
required |
theta
|
dict -- initial values; must contain "lookback_time" (Gyr, increasing, index 0 = today,
|
|
None
|
lookback_time
|
array -- shortcut for ``theta``: the node grid only, neutral initial values
|
(sfh = 1, metallicity = grid median). |
None
|
sfh_per_bin
|
bool -- with ``lookback_time=``, one SFR per bin (n_time-1,) instead of per node.
|
|
False
|
zh_const
|
bool -- constant metallicity ("Z") or a metallicity history ("zh", one per node).
|
|
False
|
add_neb
|
bool -- physics switches.
|
|
True
|
add_dust
|
bool -- physics switches.
|
|
True
|
add_diffuse_dust
|
bool -- physics switches.
|
|
True
|
add_dust_emission
|
bool -- physics switches.
|
|
True
|
add_igm
|
bool -- physics switches.
|
|
True
|
sps_home
|
str -- data directory for the nebular and dust-emission grids; defaults to $SPS_HOME.
|
|
None
|
init_neb_params
|
dict -- forwarded to NebularModel / Dust. ``isoc_type`` is
|
taken from the SSP grid's provenance when recorded. |
None
|
init_dust_params
|
dict -- forwarded to NebularModel / Dust. ``isoc_type`` is
|
taken from the SSP grid's provenance when recorded. |
None
|
sfh_interp
|
(step, linear)
|
piecewise-linear (analytic log-age integral, small negative weights clipped) SFH. |
'step'
|
track_zred_age
|
bool -- with a sampled ``zred``, rescale the lookback grid so its oldest node
|
is the age of the Universe at that redshift. |
False
|
fesc_geometry
|
(runaway_bc, picket)
|
|
'runaway_bc'
|
cosmo
|
Cosmology -- required; used for the flux factor and for the age of the Universe.
|
|
None
|
nebemlineinspec
|
bool -- default of ``include_lines`` in ``get_spectrum`` only.
|
|
False
|
Source code in ceridwen/csp/csp.py
103 104 105 106 107 108 109 110 111 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 | |
initialize_model_structure ¶
Validate theta (grid, sfh shape, metallicity key) and build theta_init / param_names.
Source code in ceridwen/csp/csp.py
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 | |
register_known_theta_keys ¶
Add keys that _warn_unknown_theta_keys must accept (model-level parameters consumed by transforms).
check_param_ranges ¶
Messages (and warnings) for metallicity / nebular parameters outside the interpolation grids, where the model clamps silently.
Source code in ceridwen/csp/csp.py
set_attenuation_function ¶
Assign self.attenuate_dust(wave, theta) -> (attn_birthcloud (n_bins, n_wave), attn_diffuse (n_wave,)) as optical depths.
Source code in ceridwen/csp/csp.py
get_spectrum_components ¶
(continuum, lines) on the rest-frame grid, unscaled (no mass, distance or IGM):
continuum is get_spectrum(include_lines=False) and lines the difference to the
full spectrum (the painted lines; with dust emission also their re-emitted energy).
Source code in ceridwen/csp/csp.py
predict ¶
{obs.name: prediction}: Photometry -> maggies (n_filters,), Spectrum -> F_nu [erg/s/cm^2/Hz]
on the observed pixels, Lines -> integrated fluxes (n_lines,). Observed-frame only when
theta carries zred.
kinematics (Kinematics or None) supplies sigma_gal / sigma_gas; broaden_photometry
applies them to the spectrum entering each Photometry's _broadener. Lines are painted on
the model grid only when a consumer needs them there (free-z Photometry, Photometry with a
sampled sigma_gas and broaden_photometry, or _force_paint_lines); otherwise fixed-z
Photometry adds them through the static basis G = obs._T @ (IGM * profiles), Spectrum
paints them on the observed pixels and Lines reads them from the grid.
eline_system (ElineSystem of SedModel, line marginalisation): returns
(predictions, aux) with the fitted lines removed from every prediction and
aux = {"prior_mean": CLOUDY fluxes of the fitted lines, "cols": {obs.name: design}}.
Source code in ceridwen/csp/csp.py
predict_line_fluxes ¶
Observed-frame fluxes of every nebular grid line (n_lines,), through the same weights, dust, escape, mass and distance factors as the spectrum.
Default: integrated fluxes [erg/s/cm^2] with the 1/(1+z) Jacobian, IGM at the line
wavelength and eline_scaling (the Lines observation). for_spectrum: the same
without eline_scaling (painted by the Spectrum projector). for_photometry: per-Hz
amplitudes with the full f_nu flux factor and no IGM (applied inside the photometric line
basis) and no eline_scaling.
Source code in ceridwen/csp/csp.py
get_line_spec ¶
Painted line component alone on the rest-frame grid, scaled by mass, flux factor and IGM as in
predict, times eline_scaling (the Lines-observation aperture factor).
Source code in ceridwen/csp/csp.py
age_at ¶
Age of the Universe [Gyr] at redshift z under self.cosmo
(a float for a scalar, a JAX array otherwise).
Source code in ceridwen/csp/csp.py
display_sfh ¶
display_sfh(
theta=None,
ax=None,
*,
overlay_nodes=True,
show_bin_edges=False,
units="Gyr",
**plot_kwargs
)
Plot the SFH exactly as _ssp_weights interprets it (step: constant per bin; linear:
chords between nodes); theta defaults to theta_init, units in {"Gyr", "Myr", "yr"}.
Returns the axes.
Source code in ceridwen/csp/csp.py
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 | |
calculate_ssp_weights_const_zh ¶
calculate_ssp_weights_const_zh_step ¶
calculate_ssp_weights_var_zh ¶
calculate_ssp_weights_var_zh_step ¶
get_spectrum_dattn_nodem_neb ¶
Dust attenuation + nebular emission. include_lines None -> self.nebemlineinspec.
Source code in ceridwen/csp/csp.py
get_spectrum_dattn_dem_neb ¶
Dust attenuation + nebular emission + dust emission.
Source code in ceridwen/csp/csp.py
get_spectrum_dattn_nodem_noneb ¶
Dust attenuation only (include_lines ignored).
Source code in ceridwen/csp/csp.py
get_spectrum_dattn_dem_noneb ¶
Dust attenuation + dust emission, no nebular (include_lines ignored).
Source code in ceridwen/csp/csp.py
get_spectrum_nodattn_nodem_noneb ¶
Stellar continuum only.
Source code in ceridwen/csp/csp.py
get_spectrum_nodattn_nodem_neb ¶
Nebular emission, no dust.
Source code in ceridwen/csp/csp.py
ceridwen.csp.CSPBasis_afe ¶
CSPBasis_afe(
SSPData,
theta=None,
tiny_logt=-70,
zh_const=False,
add_dust=True,
add_diffuse_dust=True,
add_dust_emission=False,
add_igm=False,
igm_model="madau1995",
igm_factor=1.0,
sps_home=None,
init_dust_params=None,
diffuse_law="kriek_conroy",
verbose=True,
sfh_interp="step",
track_zred_age=False,
lookback_time=None,
sfh_per_bin=False,
cosmo=None,
**kwargs
)
Bases: CSPBasis
Composite stellar population basis with [alpha/Fe] interpolation and no nebular model.
Same constructor and interface as CSPBasis minus the nebular arguments; requires an
SSPDataAfe grid (4-D ssp_flux with an ssp_afe axis). theta["afe"] is
optional: absent, the plane closest to [alpha/Fe] = 0 is used. The SFH weights,
dust, projection, flux factor and cosmology are those of CSPBasis.
Source code in ceridwen/csp/csp_afe.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | |
initialize_model_structure ¶
CSPBasis.initialize_model_structure plus the optional scalar theta['afe'].
Source code in ceridwen/csp/csp_afe.py
check_param_ranges ¶
CSPBasis.check_param_ranges plus theta['afe'] against the [alpha/Fe] grid.
Source code in ceridwen/csp/csp_afe.py
get_spectrum_components ¶
(continuum, zeros): no nebular model, so the line component is identically zero.
Source code in ceridwen/csp/csp_afe.py
get_line_spec ¶
get_spectrum_dattn_nodem_noneb ¶
Dust attenuation only (include_lines ignored).
Source code in ceridwen/csp/csp_afe.py
get_spectrum_dattn_dem_noneb ¶
Dust attenuation + dust emission (include_lines ignored).
Source code in ceridwen/csp/csp_afe.py
get_spectrum_nodattn_nodem_noneb ¶
Stellar continuum only.
Source code in ceridwen/csp/csp_afe.py
Broadening¶
ceridwen.broadening.Kinematics
dataclass
¶
Galaxy velocity dispersions [km/s]; set once on the model, shared by all observations.
sigma_gal : float (fixed) or str (theta key of a free parameter). No default here; SedModel defaults to DEFAULT_KINEMATICS (300 km/s, stars and gas). sigma_gas : float, str, or TIED (= sigma_gal). sigma_max : largest value the compiled kernels support; free values are clipped to it.
validate_theta ¶
Free keys are in theta (a dict or a set of names); a bounded prior on a
free key stays within sigma_max; fixed widths are not also in theta.
Source code in ceridwen/broadening.py
resolve ¶
(sigma_gal, sigma_gas) as JAX scalars; branching on Python types only.
Source code in ceridwen/broadening.py
ceridwen.broadening.Instrument
dataclass
¶
Line-spread function of a spectrograph; unit and convention are in the constructor name.
Instrument.R_fwhm(2700) R = lambda/FWHM (datasheet)
Instrument.R_sigma(6358) R = lambda/sigma (same LSF as R_fwhm(2700))
Instrument.fwhm_aa(2.5) FWHM [A], observed frame
Instrument.sigma_aa(1.06) sigma [A], observed frame
Instrument.sigma_kms(47.0) sigma [km/s]
Instrument.fwhm_kms(111.0) FWHM [km/s]
Instrument.
sigma_kms_at ¶
sigma [km/s] at each observed wavelength (NumPy, setup only).
Source code in ceridwen/broadening.py
ceridwen.broadening.DEFAULT_KINEMATICS
module-attribute
¶
ceridwen.broadening.SpectralProjector
dataclass
¶
SpectralProjector(
kinematics,
instrument,
subtract_library,
window,
J,
W,
paint,
line_idx,
sigma_inst_kms,
sigma_lib_kms,
sigma_fix_kms,
zred_range=None,
opz_ref=1.0,
wave_obs=None,
line_wave_rest=None,
line_sigma_table_kms=None,
)
Built once per Spectrum by setup_for_model; predict() is the per-likelihood call.
With zred_range the projector serves a sampled redshift: the log grid is the one of
the reference redshift extended at the same dv to cover every z in the range (so at
opz_ref it reproduces the fixed-z projector), the response is built at opz_ref and the model
is read at wave_log * opz_ref / opz per call (the sigma_gal kernel commutes with
the shift); the lines are painted at line_wave_rest * opz. The library width in
the fixed kernel is the one at opz_ref.
build
classmethod
¶
build(
kinematics,
instrument,
wave_model,
wave_obs,
zred,
lib_sigma_kms=None,
line_wave_rest=None,
subtract_library=True,
zred_range=None,
)
wave_model rest-frame model grid [A]
wave_obs observed pixel centres [A]
zred fixed redshift, or the reference redshift inside zred_range
lib_sigma_kms SSPData.ssp_resolution on wave_model, NaN = unknown (or None)
line_wave_rest rest wavelengths of all model lines, in predict_line_fluxes order (or None)
zred_range (z_min, z_max) of a SAMPLED redshift (None: fixed at zred)
Source code in ceridwen/broadening.py
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 562 563 564 565 566 567 568 569 570 571 572 573 | |
continuum ¶
Continuum on the observed pixels; opz = 1 + z (traced) when free_z.
Source code in ceridwen/broadening.py
line_basis ¶
(n_pix, n_kept) f_nu of UNIT-flux lines on the observed pixels, centred at
line_wave_rest * opz_line (traced), width sqrt(sigma_gas^2 + sigma_inst^2) with the
instrument width interpolated at the line; the painter's profile, one column per line.
Source code in ceridwen/broadening.py
predict_with_line_basis ¶
(prediction, A): continuum plus the lines of line_flux_obs_all painted with
:meth:line_basis at (1 + zred + eline_delta_zred) (theta key, default 0), and the
unit-flux columns A (n_pix, len(fit_pos)) of the kept lines at positions fit_pos
(None when fit_pos is None).
Source code in ceridwen/broadening.py
ceridwen.broadening.PhotometricBroadener
dataclass
¶
sigma_gal broadening of spec_rest over the rest range the filters cover; pixels outside pass through.
Observations¶
ceridwen.observation.Photometry ¶
Bases: Observation
Broadband photometric observation; flux and uncertainty in AB maggies (1 maggie = 3631 Jy).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
list of str or Filter -- names are resolved in the filter library
|
|
[]
|
flux
|
(array(n_filters), maggies)
|
|
required |
uncertainty
|
(array(n_filters), maggies - -1 - sigma)
|
|
required |
mask
|
bool array (n_filters,) -- True = used in the fit
|
|
required |
upper_limit
|
bool array (n_filters,) -- True = one-sided (model > data only) chi-squared penalty
|
|
None
|
Source code in ceridwen/observation/photometry.py
set_filters ¶
Set the filter list from filter-name strings or Filter objects.
Source code in ceridwen/observation/photometry.py
get_maggies ¶
Synthetic maggies, shape (n_filters,), of an F_nu spectrum on model_wave [Å]
(reference path; normalisation follows the input flux units).
Source code in ceridwen/observation/photometry.py
setup_for_model ¶
Precompute the (n_filters, n_wave) float32 projection matrix _T (F_nu -> maggies)
for the rest-frame grid wave_model [Å] observed at fixed zred; required before predict.
Source code in ceridwen/observation/photometry.py
setup_broadening ¶
Build the sigma_gal broadener over the rest range the filters cover (the
whole 912-25000 A window when free_z) and, when neb is given and
sigma_gas is fixed, the static line basis at that width. Both are None
for Kinematics.none(); call after setup_for_model.
Source code in ceridwen/observation/photometry.py
predict ¶
Synthetic AB maggies, shape (n_filters,), as _T @ spectrum (F_nu on wave_model).
Source code in ceridwen/observation/photometry.py
predict_at_redshift ¶
Observer-frame AB maggies, shape (n_filters,), for a traced zred: spectrum_fnu_observed
must already be observer-frame F_nu (flux factor and IGM applied) on the rest-frame grid wave_rest [Å].
Source code in ceridwen/observation/photometry.py
chi_sq ¶
Chi-squared (float) over unmasked bands; upper-limit bands are penalised only when model > data.
Source code in ceridwen/observation/photometry.py
residuals ¶
Per-filter (data - model) / sigma, shape (n_filters,); masked bands NaN, upper-limit bands 0 when model < data.
Source code in ceridwen/observation/photometry.py
ceridwen.observation.Spectrum ¶
Spectrum(
wavelength=None,
flux=None,
uncertainty=None,
mask=slice(None),
noise=None,
name=None,
instrument=None,
subtract_library=True,
calibration=None,
logify_spectrum=False,
sky=None,
noise_floor=0.0,
zred_range=None,
marginalize_elines=False,
eline_prior_width=0.0,
elines_to_fit=None,
elines_to_fix=None,
elines_to_ignore=None,
**kwargs
)
Bases: Observation
Spectroscopic observation on an observed-frame pixel grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelength
|
array-like (n_pix,), Å, vacuum, OBSERVED frame.
|
|
None
|
flux
|
array-like (n_pix,) -- same units as the model spectra
|
passed to |
None
|
uncertainty
|
array-like (n_pix,) -- same units as the model spectra
|
passed to |
None
|
mask
|
array-like of bool or slice -- True for pixels that are USED.
|
|
slice(None)
|
instrument
|
Instrument or None -- the spectrograph LSF; unit and convention
|
are the constructor name ( |
None
|
subtract_library
|
bool -- remove the SSP library resolution in quadrature
|
from the instrument width (default True; needs the grid's resolution curve). |
True
|
calibration
|
array-like (n_pix,) -- multiplicative model correction
|
(model * calibration ~ data), applied in chi_sq/residuals/log_likelihood. |
None
|
logify_spectrum
|
bool -- residuals in log-flux space.
|
|
False
|
sky
|
array-like (n_pix,) -- subtracted from data in chi_sq/residuals/
|
log_likelihood only (not in |
None
|
noise_floor
|
float -- fractional floor: sigma_eff^2 = sigma^2 + (floor*|model|)^2.
|
|
0.0
|
noise
|
GaussianProcess -- adds a correlated-residual term in ``log_likelihood``
|
only. |
None
|
zred_range
|
(z_min, z_max) -- support of a SAMPLED redshift; otherwise taken from
|
the finite bounds of the model's |
None
|
marginalize_elines
|
bool -- marginalise analytically over the fluxes of the nebular
|
lines in this spectrum (jointly with the model's Photometry and Lines), instead of
fixing them at the CLOUDY prediction; needs an |
False
|
eline_prior_width
|
float -- 0 (default): flat prior on each fitted line flux;
|
|
0.0
|
elines_to_fit
|
sequences of FSPS line names
|
( |
None
|
elines_to_fix
|
sequences of FSPS line names
|
( |
None
|
elines_to_ignore
|
sequences of FSPS line names
|
( |
None
|
The
|
|
required | |
they
|
|
required |
Source code in ceridwen/observation/spectrum.py
setup_for_model ¶
setup_for_model(
wave_model,
zred=0.0,
kinematics=None,
lib_resolution=None,
line_wave_rest=None,
zred_range=None,
)
Build the projector from the rest-frame model grid wave_model [Å]
redshifted by (1 + zred) onto self.wavelength; call once, outside JIT.
kinematics : Kinematics -- galaxy widths (None = Kinematics.none())
lib_resolution : (wave_rest [Å], sigma_v [km/s]) -- SSP library
resolution curve on wave_model (NaN = unknown); used when
subtract_library and an instrument are set
line_wave_rest : (n_lines,) rest wavelengths of the nebular grid lines
in predict_line_fluxes order, or None (no lines painted)
zred_range : (z_min, z_max) -- for a SAMPLED redshift (default self.zred_range):
the projection is then read at theta['zred'] on every call and zred
is the reference redshift inside the range
Source code in ceridwen/observation/spectrum.py
predict ¶
Model F_nu on the observed pixels (n_pix,): the rest-frame CONTINUUM
spectrum (n_wave,) broadened by sigma_gal, the instrument LSF (library
width removed) and resampled, plus the emission lines painted from their
observed-frame integrated fluxes line_flux (all grid lines, or None)
with sigma_gas + instrument. theta supplies the free widths and, for a
projector built with zred_range, the redshift.
Source code in ceridwen/observation/spectrum.py
synthetic_photometry ¶
Synthetic maggies (n_filters,) of this F_nu spectrum through
filterset; None if there is no data.
Source code in ceridwen/observation/spectrum.py
mask_wavelength_range ¶
Mask pixels with wavelength in [wave_min, wave_max] Å (inclusive).
Source code in ceridwen/observation/spectrum.py
mask_lines ¶
Mask +/- dv km/s around each rest-frame line wavelength [Å],
redshifted by (1 + zred) onto the observed grid.
Source code in ceridwen/observation/spectrum.py
chi_sq ¶
Sum of squared normalised residuals over unmasked pixels for
model_flux (n_pix,) on the observed grid.
Source code in ceridwen/observation/spectrum.py
residuals ¶
Per-pixel normalised residuals (n_pix,); masked pixels are NaN.
log_likelihood ¶
Gaussian log-likelihood of model_flux (n_pix,), including the
sigma_eff normalisation and the GP term when self.noise is set.
Source code in ceridwen/observation/spectrum.py
fit_polynomial_calibration ¶
Weighted least-squares Chebyshev calibration P(lambda) with data ~ P * model_flux over unmasked pixels; returns (coeffs (order+1,), P * model_flux (n_pix,)).
Source code in ceridwen/observation/spectrum.py
ceridwen.observation.Lines ¶
Lines(
line_ind,
line_names=None,
wavelength=None,
name=None,
upper_limit=None,
components=None,
sigma_v=200.0,
**kwargs
)
Bases: Observation
Observed emission-line fluxes with line indices, rest wavelengths and uncertainties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_ind
|
array-like of int -- indices of the observed lines in the SPS emission-line array
|
|
required |
line_names
|
list of str, optional -- one name per line; needed by ``mask_by_name`` / ``select_by_name``
|
|
None
|
wavelength
|
array-like of float, vacuum rest-frame Angstrom
|
|
None
|
flux
|
array-like of float, same units as the model prediction (typically erg/s/cm^2)
|
|
required |
uncertainty
|
array-like of float, same units as the model prediction (typically erg/s/cm^2)
|
|
required |
components
|
list of sequences of float, optional -- per observed line, the vacuum rest wavelengths
|
[Angstrom] of all grid lines summed into that measurement (unresolved doublets); default one per line |
None
|
upper_limit
|
array-like of bool, optional -- True treats the line as a non-detection: chi^2 penalises
|
only model > data |
None
|
sigma_v
|
float, km/s -- Gaussian aperture width of ``predict`` (integration of a painted
|
spectrum); |
200.0
|
Source code in ceridwen/observation/lines.py
to_json ¶
Base JSON plus line_names and line_components.
setup_for_model ¶
Record the model wavelength grid [Angstrom, rest, increasing], aperture sigma_v [km/s]
and redshift used to build the _W aperture matrix; must precede predict.
Source code in ceridwen/observation/lines.py
predict ¶
Return _W @ spectrum: Gaussian-aperture line fluxes, shape (n_lines,), from an F_nu
model spectrum; wave_model is unused, setup_for_model must have been called.
Source code in ceridwen/observation/lines.py
chi_sq ¶
Return chi^2 over unmasked lines; upper-limit lines are penalised only when model > data.
Source code in ceridwen/observation/lines.py
residuals ¶
Return per-line (data - model) / sigma, shape (n_lines,); masked lines NaN,
upper-limit lines with model <= data set to 0.
Source code in ceridwen/observation/lines.py
mask_by_name ¶
Set mask = False for lines whose name is in names; no-op without line_names.
Source code in ceridwen/observation/lines.py
select_by_name ¶
Return a new Lines containing only the named lines (KeyError on an unknown name).
Source code in ceridwen/observation/lines.py
Model¶
ceridwen.model.SedModel ¶
SedModel(
csp,
observations,
priors=None,
transforms=None,
free_param_init=None,
zred=0.0,
cosmo=None,
lumdist_mpc=None,
kinematics=None,
broaden_photometry=True,
)
Parameter manager and prediction layer: predict(theta) returns a dict keyed
by observation name, log_prob(theta) the summed log-prior on free parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
priors
|
dict[str, Prior] -- free-parameter name -> prior; absent names get a flat improper prior
|
|
None
|
transforms
|
dict[str, callable] -- derived CSP parameter name -> ``fn(free_theta)``; derived names leave the free set
|
|
None
|
free_param_init
|
dict[str, Array] -- initial values of the free parameters replacing derived ones
|
|
None
|
zred
|
float -- fixed redshift; zred = 0 without ``lumdist_mpc`` applies NO flux factor, so predictions
|
are L_sun/Hz x 10^logmass, not maggies |
0.0
|
cosmo
|
|
None
|
|
lumdist_mpc
|
float, Mpc -- explicit luminosity distance replacing D_L(zred) in the flux factor
|
|
None
|
kinematics
|
Kinematics -- the galaxy's stellar / gas velocity dispersions [km/s], fixed
|
(float) or sampled (theta key); default |
None
|
broaden_photometry
|
bool -- apply the kinematic broadening to the spectrum entering the
|
filters (default True; below 5e-4 mag for broad bands, per cent for a narrow band on a line) |
True
|
Source code in ceridwen/model/model.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | |
setup_observations ¶
Build every observation's projection for this model's grid, redshift and
kinematics (called by __init__ and by fitSED when it replaces the
observations); drops the cached jitted predictors.
Source code in ceridwen/model/model.py
apply_transforms ¶
Return free_theta plus every derived parameter fn(free_theta).
Source code in ceridwen/model/model.py
predict ¶
Predictions keyed by observation name from the free-parameter dict. A fixed zred/lumdist_mpc is injected into the CSP theta here; without a 'zred' the CSP applies no flux factor and the outputs are not maggies.
Source code in ceridwen/model/model.py
predict_with_elines ¶
(predictions, aux) for the emission-line marginalisation: the predictions with
the fitted lines removed, and aux = {"prior_mean", "cols"} (their CLOUDY fluxes and
the per-observation design columns). Needs a Spectrum with marginalize_elines=True.
Source code in ceridwen/model/model.py
predict_jit ¶
predict_vmap ¶
Vectorised :meth:predict over a leading batch axis of every theta entry.
ln_prior ¶
Scalar sum of prior.logpdf(theta[p]) over registered priors.
Source code in ceridwen/model/model.py
log_prob ¶
summary ¶
Multi-line summary of parameters, transforms, observations and CSP setup.
Source code in ceridwen/model/model.py
display ¶
Draw the model as a PGM diagram; returns (fig, ax) when return_fig.
Source code in ceridwen/model/model.py
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 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
ceridwen.model.transforms.logsfr_ratios_to_sfh ¶
Unit-mass SFH weight vector (n,) from logsfr_ratios[i] = log10(SFR[i]/SFR[i+1])
(n-1,), index 0 = today. With sfh_times_yr (lookback yr, (n,)) the trapezoidal
integral is normalised to 1 Msun; otherwise sum(sfh) = 1.
Source code in ceridwen/model/transforms.py
Priors¶
ceridwen.priors ¶
Prior distributions for CERIDWEN models.
A clean, discoverable import path for the priors (implemented in
ceridwen.sampler.priors)::
from ceridwen.priors import Uniform, Normal, ClippedNormal, LogNormal, StudentT
Each prior exposes logpdf (also __call__), sample, unit_transform
(inverse CDF) and inverse_unit_transform (CDF); bounds gives the support.
Prior
dataclass
¶
Bases: ABC
Prior base class delegating to a TFP-JAX distribution; subclasses define
prior_params and implement tfp_dist().
Source code in ceridwen/sampler/priors.py
serialize ¶
JSON-ready description: type, parameters (lists for arrays), name.
Source code in ceridwen/sampler/priors.py
Uniform
dataclass
¶
Bases: Prior
Uniform distribution on [low, high].
Source code in ceridwen/sampler/priors.py
TopHat
dataclass
¶
Bases: Uniform
Alias of Uniform kept for backwards compatibility.
Source code in ceridwen/sampler/priors.py
Normal
dataclass
¶
Bases: Prior
Gaussian prior with parameters mean, sigma.
Source code in ceridwen/sampler/priors.py
MultivariateNormalPrior
dataclass
¶
Bases: Prior
Multivariate Gaussian prior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
(d,)
|
|
required |
Sigma
|
(d, d) -- covariance matrix
|
|
required |
Source code in ceridwen/sampler/priors.py
ClippedNormal
dataclass
¶
Bases: Prior
Gaussian prior truncated to [low, high]; parameters mean, sigma, low, high.
Source code in ceridwen/sampler/priors.py
LogNormal
dataclass
¶
Bases: Prior
Log-normal prior; mode and sigma are the mean and std of ln(x).
Source code in ceridwen/sampler/priors.py
StudentT
dataclass
¶
Bases: Prior
Student's t prior with parameters mean, scale, df (degrees of freedom).
Source code in ceridwen/sampler/priors.py
Likelihood¶
ceridwen.likelihood.DiagonalGaussianLikelihood
dataclass
¶
Bases: LikelihoodBase
Gaussian log-likelihood with an independent (diagonal) noise model.
__call__ ¶
Return (lnl_total, LikelihoodOutput).
Source code in ceridwen/likelihood/likelihood.py
make_lnprobfn ¶
Return a jitted log-posterior for one observation (needs .flux, .uncertainty, .mask).
Source code in ceridwen/likelihood/likelihood.py
ceridwen.likelihood.DiagonalGaussianLikelihoodWithUpperLimits
dataclass
¶
Bases: LikelihoodBase
Diagonal Gaussian log-likelihood honouring per-datum upper-limit flags
(one-sided penalty; reduces to :class:DiagonalGaussianLikelihood when no flags are set).
__call__ ¶
Return (lnl_total, LikelihoodOutput); is_upper_limit=None means all detections.
Source code in ceridwen/likelihood/likelihood.py
make_lnprobfn ¶
Return a jitted log-posterior using observations.upper_limit (all-False if absent).
Source code in ceridwen/likelihood/likelihood.py
ceridwen.likelihood.MultiObservationLikelihood
dataclass
¶
Bases: LikelihoodBase
Sum of independent likelihoods over several observation keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
tuple of str -- observation keys, e.g. ``("phot", "spec", "lines")``
|
|
tuple()
|
likelihoods
|
tuple of LikelihoodBase -- one per key, same order
|
|
tuple()
|
__call__ ¶
Return (lnl_total, {key: LikelihoodOutput}); all inputs are dicts keyed like self.keys
(is_upper_limit only needs the keys whose likelihood honours upper limits).
Source code in ceridwen/likelihood/likelihood.py
make_lnprobfn ¶
Return a jitted log-posterior; observations and model.predict(theta) are dicts keyed
like self.keys. Each observation's sky, calibration and upper_limit are honoured
as in ceridwen.sampler.runner.run_sampler.
Source code in ceridwen/likelihood/likelihood.py
Fitting¶
ceridwen.fit.fitSED ¶
fitSED(
model,
observations=None,
output_dir=".",
*,
sampler="nested",
rng_key=None,
sampler_kwargs=None,
vi=None,
vi_kwargs=None,
filename="ceridwen_result.h5",
overwrite=True,
verbose=True
)
Fit model to observations with sampler ("nested" or "nuts") and return the
SamplingResult; writes output_dir/filename (HDF5) and a .log with the same stem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observations
|
list[Observation] -- replaces ``model.observations`` and re-runs ``setup_for_model`` at ``model.zred``
|
|
None
|
sampler_kwargs
|
dict -- forwarded to the sampler adapter constructor
|
|
None
|
vi
|
None, 'tril', 'iaf', or a VI map -- NUTS-only variational preconditioning
|
|
None
|
vi_kwargs
|
dict -- forwarded to VI training / map constructor
|
|
None
|
Source code in ceridwen/fit.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | |
ceridwen.fit.load_result_h5 ¶
Rebuild a SamplingResult from a result HDF5 file (the forward model itself is not restored).
Source code in ceridwen/fit.py
ceridwen.fit.read_result_h5 ¶
Read a result HDF5 file into a nested dict with keys 'obs', 'model', 'samples'
(and 'elines' when the fit marginalised the emission lines).
Source code in ceridwen/fit.py
ceridwen.fit.result_cosmology ¶
The Cosmology a result file was fitted with (/model attrs cosmo_*); KeyError if absent.
Source code in ceridwen/fit.py
ceridwen.sampler.run_sampler ¶
Build JIT loglike_fn (summed over observations, no prior) and
logprior_fn from model/likelihood and delegate to adapter.run.
Source code in ceridwen/sampler/runner.py
ceridwen.sampler.nested.BlackJAXNestedSamplerAdapter ¶
BlackJAXNestedSamplerAdapter(
priors,
num_live=500,
num_inner_steps=None,
num_delete=None,
logZ_tol=-5.0,
verbose=True,
checkpoint_interval_s=1200.0,
checkpoint_dir=None,
)
Bases: SamplerAdapter
Nested-sampling adapter driving the NSS kernel with a Ceridwen SedModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
priors
|
dict[str, Prior] -- every free parameter needs a proper prior
|
|
required |
num_inner_steps
|
int -- inner MCMC steps per iteration; default n_dims * 5
|
|
None
|
num_delete
|
int -- live points removed per iteration; default max(1, num_live // 5), must be < num_live
|
|
None
|
logZ_tol
|
float -- stop when ln(Z_live / Z) < logZ_tol; default -5
|
|
-5.0
|
checkpoint_interval_s
|
float -- seconds between checkpoints; <= 0 disables
|
|
1200.0
|
checkpoint_dir
|
str -- falls back to $CERIDWEN_CHECKPOINT_DIR, then $CERIDWEN_RESCUE_DIR, else off
|
|
None
|
Source code in ceridwen/sampler/nested.py
load_checkpoint
staticmethod
¶
Load a checkpoint/rescue pickle: {positions, loglikelihood, loglikelihood_birth, logZ, n_dead, partial}.
run ¶
Run nested sampling and return a SamplingResult; logprior_fn must be proper.
Source code in ceridwen/sampler/nested.py
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 325 326 | |
ceridwen.sampler.nuts.BlackJAXNUTSAdapter ¶
BlackJAXNUTSAdapter(
num_warmup=None,
num_samples=2000,
num_chains=4,
initial_step_size=None,
target_acceptance=0.95,
max_num_doublings=10,
dense_mass=None,
bounds=None,
vi=None,
vi_kwargs=None,
verbose=True,
)
Bases: SamplerAdapter
NUTS adapter with window adaptation; bounded (uniform-prior) parameters
are sampled in sigmoid/logit space, and an optional VI map (vi) whitens
the target before sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_warmup
|
int -- adaptation steps per chain; default 1500 (200 with ``vi``)
|
|
None
|
num_samples
|
int -- post-warmup draws per chain
|
|
2000
|
initial_step_size
|
float -- leapfrog step before adaptation; default 0.01 (0.5 with ``vi``)
|
|
None
|
target_acceptance
|
float -- dual-averaging target
|
|
0.95
|
max_num_doublings
|
int -- max tree depth (2**n leapfrog steps)
|
|
10
|
dense_mass
|
bool -- full inverse mass matrix; default True (False with ``vi``)
|
|
None
|
bounds
|
dict -- name -> (low, high); None auto-detects from model priors
|
|
None
|
vi
|
None | 'tril' | 'iaf' | VariationalMap | TrainedMap -- variational preconditioning
|
|
None
|
vi_kwargs
|
dict -- map constructor kwargs plus ``num_steps``, ``batch_size``, ``lr0`` for training
|
|
None
|
Source code in ceridwen/sampler/nuts.py
run ¶
Run NUTS (one warmup, then all chains) and return a SamplingResult in constrained space.
Source code in ceridwen/sampler/nuts.py
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 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 | |
Post-processing¶
ceridwen.postprocess.PostProcess ¶
PostProcess(
model,
result,
*,
n_samples=None,
seed=0,
windows_myr=DEFAULT_WINDOWS_MYR,
sfr=True,
ssfr=True,
uv=True,
ionizing=True,
predictions=True,
derived=None,
batch_size=256
)
Posterior post-processing of a fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
SedModel -- the model the samples were drawn with; parameter names must match the result's
|
|
required |
result
|
SamplingResult or path -- sampler output or the HDF5 file it was written to
|
|
required |
n_samples
|
int, optional -- equal-weight draws (default 2000 for weighted results, all for uniform)
|
|
None
|
windows_myr
|
sequence of float, Myr -- averaging windows W for ``sfrW`` / ``ssfrW``
|
|
DEFAULT_WINDOWS_MYR
|
derived
|
dict[str, callable] -- ``name -> f(SpectrumSample) -> float or 1-D array``, evaluated per draw
|
|
None
|
batch_size
|
int -- draws per compiled batch through the forward model
|
|
256
|
Source code in ceridwen/postprocess.py
run ¶
Compute and return (and store in self.output) the nested dict of the module docstring.
Source code in ceridwen/postprocess.py
figures ¶
Write the summary, corner and sampling-diagnostic figures
(:mod:ceridwen.plotting) to outdir; returns their paths.
truths ({name: value}) marks injected values in mock tests.
Source code in ceridwen/postprocess.py
save ¶
Write self.output (running first if needed) as a flat .npz with '/'-joined keys.
Source code in ceridwen/postprocess.py
ceridwen.postprocess.SpectrumSample
dataclass
¶
SpectrumSample(
wave_rest,
full,
intrinsic,
dustfree,
theta,
zred,
logmass,
sfr,
lookback_gyr,
cosmo,
)
One posterior draw as handed to a derived function: rest-frame L_nu
[L_sun/Hz] x 10**logmass on wave_rest [A]; theta after the model transforms.
index_of ¶
mean_lnu ¶
Wavelength-averaged L_nu of spectrum over [lo, hi] A (trapezoid).
Source code in ceridwen/postprocess.py
luminosity ¶
int L_nu dnu over [lo, hi] A of spectrum [erg/s].
Source code in ceridwen/postprocess.py
ceridwen.postprocess.load_postprocess ¶
Rebuild the nested dict written by :meth:PostProcess.save.
Source code in ceridwen/postprocess.py
Figures¶
ceridwen.plotting.summary_figure ¶
summary_figure(
out,
model,
*,
title=None,
prior_draws=500,
params=None,
truths=None,
savepath=None,
figsize=(15, 11)
)
Summary page: SED with residuals, emission lines, SFH with posterior and prior
bands, and 1-D marginals of the fitted parameters (median, 16-84 %, best fit).
out is PostProcess.run()'s dict; model the fitted SedModel;
truths ({name: value or array}) marks injected values in green.
Source code in ceridwen/plotting.py
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 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 | |
ceridwen.plotting.corner_figure ¶
Corner plot of all fitted parameters: 1-D marginals on the diagonal, 2-D
histograms with 1 and 2 sigma contours below; posterior median (blue, dashed),
maximum-likelihood sample (red) and, when given, truths (green) marked.
Source code in ceridwen/plotting.py
ceridwen.plotting.diagnostic_figure ¶
Sampling diagnostics. Nested sampling: every parameter's dead points in deletion order coloured by posterior weight, the log-likelihood run and the cumulative evidence. MCMC: per-chain traces with split-R-hat and ESS.
Source code in ceridwen/plotting.py
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 | |
ceridwen.plotting.make_figures ¶
Write summary, corner and diagnostic figures to outdir; returns their paths.
Source code in ceridwen/plotting.py
Dust, nebular, IGM, cosmology¶
ceridwen.dust.Dust ¶
Modular dust attenuation model: one attenuation law per age bin, parameters read from a plain theta dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_edges
|
list of (lo, hi), log10(Gyr) -- age range of each bin
|
|
[(-inf, -1.97)]
|
laws
|
list of str -- attenuation-law name per bin (see ``describe_attenuation_laws``)
|
|
['powerlaw']
|
Source code in ceridwen/dust/DustModel.py
ceridwen.dust.DiffuseDust ¶
Bases: Dust
Single-bin dust model covering all ages, with diffuse_-prefixed parameter names.
Source code in ceridwen/dust/DustModel.py
ceridwen.dust.DustEmission ¶
DustEmission ¶
Dust emission templates ('DL07' or 'THEMIS') interpolated onto spec_lambda [Angstrom].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dust_file
|
str -- data root containing dust/dustem/
|
|
None
|
kwargs
|
duste_qpah, duste_umin, duste_gamma defaults
|
|
{}
|
Source code in ceridwen/dust/DustEmission.py
get_default_params ¶
Return dict of default dust-emission fit parameters.
Source code in ceridwen/dust/DustEmission.py
update_dust_params ¶
Set the default dust-emission parameters.
compute_dust_emission ¶
compute_dust_emission(
spec_attn,
spec_dustfree,
spec_lambda,
diffuse_curve,
duste_qpah,
duste_umin,
duste_gamma,
)
Return (spec_attn + dust emission, dust mass, dust emission); diffuse_curve is exp(-tau_diffuse).
Source code in ceridwen/dust/DustEmission.py
ceridwen.neb.NebularModel ¶
NebularModel(
cloudy_dust,
sps_home,
csp_lambda,
ssp_flux=None,
ssp_ages_lgyr=None,
isoc_type="mist",
nebnz=11,
nebnage=10,
nebnip=7,
smooth_velocity=True,
sigma_smooth=0.0,
res_floor_factor=2.0,
nebular_smooth_init=None,
)
Nebular continuum and lines from the CLOUDY cubes under <sps_home>/nebular.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloudy_dust
|
bool -- ``ZAU_WD`` (True) or ``ZAU_ND`` (False) grids.
|
|
required |
csp_lambda
|
(nspec,) -- model wavelength grid [A].
|
|
required |
ssp_flux
|
(n_z, n_age, n_wave) -- SSP L_nu [L_sun/Hz]; gives ``log_qq`` (n_z, n_age).
|
|
None
|
ssp_ages_lgyr
|
(n_age,) -- log10(age/yr) of the SSPs; ages inside both cubes are "young".
|
|
None
|
isoc_type
|
str -- ZAU file suffix.
|
|
'mist'
|
nebnz
|
int -- cube dimensions.
|
|
11
|
nebnage
|
int -- cube dimensions.
|
|
11
|
nebnip
|
int -- cube dimensions.
|
|
11
|
smooth_velocity
|
bool -- ``sigma_smooth`` in km/s (True) or A.
|
|
True
|
sigma_smooth
|
float -- intrinsic width of the painted lines (0: pixel floor only).
|
|
0.0
|
res_floor_factor
|
float -- minimum painted width in local pixels.
|
|
2.0
|
Attributes
|
|
required | |
are
|
|
required |
Source code in ceridwen/neb/NebularGridModel.py
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 | |
compute_log_qq ¶
log10 Q [photons/s] for every SSP: (L_sun/h) * int_{lambda<912} L_nu / lambda dlambda (float64).
Source code in ceridwen/neb/NebularGridModel.py
line_profiles ¶
(nspec, nemline) NumPy profiles like gaussnebarr with width
sqrt(floor^2 + (lambda sigma_kms / c)^2): a line painted at the floor and then broadened.
Source code in ceridwen/neb/NebularGridModel.py
evaluate ¶
(cont (nspec,), lines (nspec,)) [L_sun/Hz] at one (logZ, logU, logage, logQ).
Source code in ceridwen/neb/NebularGridModel.py
evaluate_batch ¶
(n_z, n_young, nspec) nebular spectra at one (logZ_gas, logU) for the young SSP ages,
or (cont, lines) in that layout with return_components. The metallicity dependence
enters only through logqq_young; the per-age reference ref keeps 10**(...) in float32 range.
Source code in ceridwen/neb/NebularGridModel.py
evaluate_batch_factored ¶
(base (n_young, n_wave), scale (n_z, n_young)) with neb[z, y, w] == scale[z, y] * base[y, w]
(same arithmetic as evaluate_batch, not expanded).
Source code in ceridwen/neb/NebularGridModel.py
evaluate_batch_line_lum ¶
Line luminosities (n_z, n_young, nlines) [L_sun] at one (logZ_gas, logU), no painting.
Source code in ceridwen/neb/NebularGridModel.py
get_default_params ¶
ceridwen.igm ¶
Intergalactic-medium absorption models: transmission curves exp(-tau * factor)
on the rest-frame wavelength grid at a given source redshift.
IGMModel ¶
Madau1995 ¶
Bases: IGMModel
Madau (1995) IGM attenuation: 17 Lyman-series lines, Ly-α metal blanketing and Lyman-continuum absorption; tau is capped at its short-wavelength peak and is zero at zred = 0.
make_igm_model ¶
Return an :class:IGMModel from a registry name, an instance (as-is), or None (NoIGM).
Source code in ceridwen/igm.py
ceridwen.cosmology ¶
Flat LambdaCDM redshift helpers: :class:Cosmology presets, D_L(z), age(z)
and the maggies flux factor, JAX-native (differentiable in z) with an optional
scalar-only astropy backend.
Cosmology
dataclass
¶
Flat LambdaCDM cosmology with photons and effective neutrinos; the massive neutrino is folded into Om0 as cold matter. Defaults to Planck 2018.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
H0
|
(float, km / s / Mpc)
|
|
67.66
|
Om0
|
float -- cold matter today, EXCLUDING massive neutrinos.
|
|
0.30966
|
Tcmb0
|
(float, K)
|
|
2.7255
|
Neff
|
float -- effective number of neutrino species.
|
|
3.046
|
m_nu_ev_sum
|
float, eV -- sum of neutrino masses.
|
|
0.06
|
name
|
str -- label only; ignored in equality.
|
|
None
|
Onu0_massive_as_matter
property
¶
Massive-neutrino density today, treated as cold matter.
Onu0_relativistic
property
¶
Relativistic neutrino density today (Neff - 1 species).
is_planck18
property
¶
True when the parameters equal the Planck-2018 preset (name ignored).
wmap9
classmethod
¶
flat
classmethod
¶
Flat LCDM from H0 and Om0; radiation and neutrinos default to Planck 2018.
Source code in ceridwen/cosmology.py
from_name
classmethod
¶
Preset by name, case-insensitive (see available_cosmologies()).
Source code in ceridwen/cosmology.py
from_dict
classmethod
¶
Inverse of :meth:to_dict; also accepts cosmo_*-prefixed HDF5 attrs.
Source code in ceridwen/cosmology.py
to_dict ¶
age ¶
luminosity_distance ¶
from_astropy
classmethod
¶
Build from a flat astropy cosmology; a non-flat input raises.
Source code in ceridwen/cosmology.py
to_astropy ¶
Return the matching astropy.cosmology.FlatLambdaCDM (requires astropy).
Source code in ceridwen/cosmology.py
available_cosmologies ¶
resolve_cosmology ¶
E_of_z ¶
Dimensionless expansion rate E(z) = H(z)/H0; z is clamped to >= 0
so transient negative proposals cannot produce NaN.
Source code in ceridwen/cosmology.py
comoving_distance_mpc ¶
Line-of-sight comoving distance D_C(z) [Mpc].
Source code in ceridwen/cosmology.py
age_gyr ¶
Age of the Universe at z [Gyr], JAX-native and differentiable in z.
Source code in ceridwen/cosmology.py
luminosity_distance_mpc ¶
Luminosity distance D_L(z) [Mpc].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
('native', 'astropy')
|
'astropy' is scalar-z only. |
'native'
|
Source code in ceridwen/cosmology.py
flux_factor ¶
(1+z) / (4 pi D_L^2) with D_L in cm: converts rest-frame L_nu [erg/s/Hz] to observed F_nu [erg/s/cm^2/Hz].
Source code in ceridwen/cosmology.py
flux_factor_cgs ¶
Factor turning a CSP spectrum [L_sun/Hz/M_sun] into observed-frame F_nu [erg/s/cm^2/Hz] (cgs): (1+z) (10 pc / D_L)^2 times the 10 pc unit constant. z <= 0 is pinned to D_L = 10 pc. The AB-maggies photometry is obtained downstream by projecting this cgs spectrum through the filters (dividing by the 3631 Jy AB zero point); this factor itself is NOT maggies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
('native', 'astropy')
|
|
'native'
|
lumdist_mpc
|
float or Array, Mpc -- explicit D_L replacing D_L(z); the
|
(1+z) term still comes from z and the z <= 0 pin does not apply. |
None
|
Source code in ceridwen/cosmology.py
Spectrophotometric calibration¶
ceridwen.csp.spectrum_calibration.spectrum_calibration_factor ¶
Factor spectrum_scaling * (1 + spectrum_calib . P(x)) multiplying the MODEL spectrum:
a scalar (level only), an (n_pix,) vector (shape term), or None if neither key is in theta.
Source code in ceridwen/csp/spectrum_calibration.py
ceridwen.csp.spectrum_calibration.legendre_design_matrix ¶
(n_pix, order) float64 matrix of Legendre P_1..P_order on the pixel wavelengths
mapped affinely onto [-1, 1] (range over ALL pixels, masked or not; no P_0 term).