sed-model 0.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ SED_Model License
2
+
3
+ Copyright (c) 2026 Niall Miller
4
+
5
+ This repository uses a mixed-license structure:
6
+
7
+ 1. The Python source code, documentation, examples, tests, and packaging files
8
+ are distributed under the MIT License.
9
+
10
+ 2. The Fortran numerical kernels in the `fortran/` directory are distributed
11
+ under the GNU Lesser General Public License v3.0 or later (LGPL-3.0-or-later),
12
+ as indicated in their source headers.
13
+
14
+ MIT License
15
+ -----------
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ of the MIT-licensed portions of this software and associated documentation
19
+ files (the "Software"), to deal in those portions of the Software without
20
+ restriction, including without limitation the rights to use, copy, modify,
21
+ merge, publish, distribute, sublicense, and/or sell copies of those portions
22
+ of the Software, and to permit persons to whom those portions of the Software
23
+ are furnished to do so, subject to the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be included in all
26
+ copies or substantial portions of the MIT-licensed portions of the Software.
27
+
28
+ THE MIT-LICENSED PORTIONS OF THE SOFTWARE ARE PROVIDED "AS IS", WITHOUT
29
+ WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
30
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
32
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
34
+ THE USE OR OTHER DEALINGS IN THE MIT-LICENSED PORTIONS OF THE SOFTWARE.
35
+
36
+ LGPL Notice
37
+ -----------
38
+
39
+ The Fortran kernels in `fortran/` are licensed under LGPL-3.0-or-later. See
40
+ the source file headers for the applicable license notice. The full text of
41
+ the LGPL-3.0 license is available from the Free Software Foundation:
42
+ https://www.gnu.org/licenses/lgpl-3.0.html
@@ -0,0 +1 @@
1
+ recursive-include fortran *.f90
@@ -0,0 +1,431 @@
1
+ Metadata-Version: 2.1
2
+ Name: sed-model
3
+ Version: 0.1.7
4
+ Summary: Forward and inverse stellar photometry from SED grids.
5
+ Author-email: Niall Miller <niall.j.miller@gmail.com>
6
+ Project-URL: Homepage, https://github.com/nialljmiller/SED_Model
7
+ Project-URL: Repository, https://github.com/nialljmiller/SED_Model
8
+ Project-URL: Issues, https://github.com/nialljmiller/SED_Model/issues
9
+ Keywords: astronomy,astrophysics,stellar astronomy,synthetic photometry,spectral energy distributions,sed,stellar parameters,bayesian inference,mcmc
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Fortran
16
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
17
+ Classifier: Topic :: Scientific/Engineering :: Physics
18
+ Classifier: Operating System :: OS Independent
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.22
23
+ Requires-Dist: pandas>=1.5
24
+ Requires-Dist: emcee>=3.1
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest; extra == "dev"
27
+ Provides-Extra: demo
28
+ Requires-Dist: matplotlib; extra == "demo"
29
+
30
+ # SED_Model
31
+
32
+ **MESA-free synthetic photometry and stellar parameter inference.**
33
+
34
+ SED_Model is a Python package for computing observer-ready synthetic spectral energy distributions (SEDs) and broadband magnitudes from stellar atmosphere grids, and for recovering stellar parameters from observed photometry via Bayesian MCMC inference. It is designed to work directly downstream of `SED_Tools` and as a standalone drop-in for workflows that use MESA-style atmosphere grids and filter transmission curves.
35
+
36
+ Version: `0.1.0`
37
+
38
+ ---
39
+
40
+ ## Overview
41
+
42
+ SED_Model provides two paired models that share the same parameter language:
43
+
44
+ - **Forward model** — maps `(Teff, logg, [M/H], R, d)` to an interpolated SED, bolometric flux and magnitude, and synthetic magnitudes in any set of loaded filters.
45
+ - **Inverse model** — maps observed magnitudes with uncertainties to a posterior distribution over `(Teff, logg, [M/H])`, and optionally over `Av` and distance, via `emcee` MCMC sampling.
46
+
47
+ Both directions operate through a shared `FitParams` object. The same parameter specification flows from the forward model to the likelihood evaluator inside the sampler and back out again.
48
+
49
+ ---
50
+
51
+ ## Features
52
+
53
+ - Hermite and linear interpolation over 3D atmosphere grids `(Teff, logg, [M/H])`.
54
+ - Photon-counting filter convolution in Vega, AB, and ST photometric systems.
55
+ - Precomputed zero-points matching MESA `colors/private/synthetic.f90` conventions.
56
+ - Pure-NumPy interstellar dust extinction with multiple supported laws.
57
+ - Bayesian stellar-parameter inference via `emcee` with fixed, bounded, and fully free parameter modes.
58
+ - Structured result containers with summaries, persistence to CSV and NPZ, and interpolation diagnostics.
59
+ - Fortran kernels for performance-critical paths, compiled via `f2py`/Meson.
60
+ - Forward tests validated against MESA colors reference outputs; inverse tests verified by self-consistent synthetic recovery.
61
+
62
+ ---
63
+
64
+ ## Installation
65
+
66
+ ### From source
67
+
68
+ ```bash
69
+ git clone https://github.com/nialljmiller/SED_Model.git
70
+ cd SED_Model
71
+ python -m pip install -e .
72
+ ````
73
+
74
+ ### Build the Fortran extension
75
+
76
+ ```bash
77
+ python setup.py build_ext --inplace
78
+ ```
79
+
80
+ or:
81
+
82
+ ```bash
83
+ make
84
+ ```
85
+
86
+ The build compiles:
87
+
88
+ ```text
89
+ fortran/cc_kernels.f90
90
+ fortran/cc_api.f90
91
+ ```
92
+
93
+ into the `sed_model.cc_api` extension module.
94
+
95
+ ### Requirements
96
+
97
+ * Python >= 3.10
98
+ * `numpy`
99
+ * `pandas`
100
+ * `emcee`
101
+ * `gfortran`
102
+ * `meson`
103
+ * `ninja`
104
+
105
+ `matplotlib` is only needed for plotting/demo workflows.
106
+
107
+ ---
108
+
109
+ ## Quick Start
110
+
111
+ ```python
112
+ from sed_model import load_grid, load_filters, run_forward, run_inverse
113
+
114
+ grid = load_grid("/path/to/Kurucz2003all/")
115
+ filters = load_filters([
116
+ "/path/to/filters/GAIA/G.dat",
117
+ "/path/to/filters/2MASS/J.dat",
118
+ ])
119
+
120
+ # Forward model
121
+ result = run_forward(
122
+ teff=5777,
123
+ logg=4.44,
124
+ meta=0.0,
125
+ R=6.957e10,
126
+ d=3.086e19,
127
+ grid=grid,
128
+ filters=filters,
129
+ mag_system="Vega",
130
+ )
131
+
132
+ print(result.magnitudes)
133
+
134
+ # Inverse model
135
+ posterior = run_inverse(
136
+ obs_magnitudes=[5.03, 4.17],
137
+ obs_uncertainties=[0.01, 0.02],
138
+ filter_names=["G", "J"],
139
+ R=6.957e10,
140
+ d=3.086e19,
141
+ grid=grid,
142
+ filters=filters,
143
+ mag_system="Vega",
144
+ )
145
+
146
+ posterior.print_summary()
147
+ ```
148
+
149
+ ---
150
+
151
+ ## Grid Loading
152
+
153
+ ```python
154
+ from sed_model import load_grid
155
+
156
+ grid = load_grid("/path/to/Kurucz2003all/")
157
+ ```
158
+
159
+ `load_grid()` expects a MESA/SED_Tools-style atmosphere grid containing a `flux_cube.bin`, with optional validation against a co-located `lookup_table.csv`.
160
+
161
+ The returned `AtmosphereGrid` exposes:
162
+
163
+ * `teff_grid`, `logg_grid`, `meta_grid`
164
+ * `teff_bounds`, `logg_bounds`, `meta_bounds`
165
+ * `wavelengths`
166
+ * `in_bounds(teff, logg, meta)`
167
+ * `clamp(teff, logg, meta)`
168
+ * `interp_radius(teff, logg, meta)`
169
+
170
+ ---
171
+
172
+ ## Filter Loading
173
+
174
+ ```python
175
+ from sed_model import load_filters, load_filters_from_instrument_dir
176
+
177
+ filters = load_filters([
178
+ "/path/to/filters/Generic/Johnson/B.dat",
179
+ "/path/to/filters/Generic/Johnson/V.dat",
180
+ ])
181
+
182
+ filters = load_filters_from_instrument_dir(
183
+ "/path/to/filters/Generic/Johnson"
184
+ )
185
+ ```
186
+
187
+ Each `Filter` stores:
188
+
189
+ * `name`
190
+ * `wavelengths`
191
+ * `transmission`
192
+ * Vega, AB, and ST zero-points
193
+ * `zero_point(system)`
194
+
195
+ Supported systems are:
196
+
197
+ ```text
198
+ Vega
199
+ AB
200
+ ST
201
+ ```
202
+
203
+ ---
204
+
205
+ ## Forward Model
206
+
207
+ ```python
208
+ from sed_model import run_forward
209
+
210
+ result = run_forward(
211
+ teff=5778.0,
212
+ logg=4.44,
213
+ meta=0.0,
214
+ R=6.957e10,
215
+ d=3.086e19,
216
+ grid=grid,
217
+ filters=filters,
218
+ mag_system="Vega",
219
+ interp_method="hermite",
220
+ )
221
+ ```
222
+
223
+ `ForwardResult` contains:
224
+
225
+ * `wavelengths`
226
+ * `surface_flux`
227
+ * `observed_flux`
228
+ * `magnitudes`
229
+ * `band_fluxes`
230
+ * `bol_flux`
231
+ * `bol_mag`
232
+ * `interp_radius`
233
+ * `clamped`
234
+ * `teff`, `logg`, `meta`, `R`, `d`, `a_v`
235
+ * `mag_system`
236
+ * `extinction_applied`
237
+
238
+ ---
239
+
240
+ ## Inverse Model
241
+
242
+ ```python
243
+ from sed_model import run_inverse
244
+
245
+ result = run_inverse(
246
+ obs_magnitudes=[5.03, 4.17],
247
+ obs_uncertainties=[0.01, 0.02],
248
+ filter_names=["G", "J"],
249
+ R=6.957e10,
250
+ d=3.086e19,
251
+ grid=grid,
252
+ filters=filters,
253
+ n_walkers=32,
254
+ n_steps=1000,
255
+ n_burn=300,
256
+ seed=42,
257
+ )
258
+ ```
259
+
260
+ `InverseResult` contains:
261
+
262
+ * `samples`
263
+ * `log_prob`
264
+ * `filter_names`
265
+ * `obs_magnitudes`
266
+ * `obs_uncertainties`
267
+ * `R`, `d`, `mag_system`
268
+ * `n_walkers`, `n_steps`, `n_burn`, `n_thin`
269
+ * `acceptance_fraction`
270
+ * `autocorr_time`
271
+
272
+ It also provides:
273
+
274
+ ```python
275
+ result.summary()
276
+ result.print_summary()
277
+ result.save("posterior.npz")
278
+ ```
279
+
280
+ ---
281
+
282
+ ## Parameter Modes
283
+
284
+ `FitParams` and `ParamSpec` define the shared parameter language used by the forward and inverse models.
285
+
286
+ ```python
287
+ from sed_model import fit_params_from_grid, fixed, free, bounded
288
+
289
+ params = fit_params_from_grid(
290
+ grid,
291
+ a_v=(0.0, 2.0), # free Av
292
+ d_cm=3.086e19, # fixed distance
293
+ )
294
+ ```
295
+
296
+ Available modes:
297
+
298
+ ```python
299
+ fixed(value)
300
+ free(lo, hi)
301
+ bounded(lo, hi)
302
+ ```
303
+
304
+ Example:
305
+
306
+ ```python
307
+ from sed_model import FitParams, fixed, free
308
+
309
+ params = FitParams(
310
+ teff=free(5000.0, 6500.0),
311
+ logg=fixed(4.44),
312
+ meta=free(-1.0, 0.5),
313
+ a_v=fixed(0.0),
314
+ d=fixed(3.086e19),
315
+ )
316
+ ```
317
+
318
+ ---
319
+
320
+ ## Extinction
321
+
322
+ ```python
323
+ from sed_model import make_extinction_model, run_forward
324
+
325
+ ext = make_extinction_model(
326
+ enabled=True,
327
+ law="fitzpatrick99",
328
+ a_v=0.3,
329
+ r_v=3.1,
330
+ )
331
+
332
+ result = run_forward(
333
+ teff=5778,
334
+ logg=4.44,
335
+ meta=0.0,
336
+ R=6.957e10,
337
+ d=3.086e19,
338
+ grid=grid,
339
+ filters=filters,
340
+ extinction=ext,
341
+ )
342
+ ```
343
+
344
+ Supported extinction-law keys include:
345
+
346
+ ```text
347
+ ccm89
348
+ odonnell94
349
+ fitzpatrick99
350
+ fm07
351
+ calzetti00
352
+ gordon23
353
+ ```
354
+
355
+ ---
356
+
357
+ ## Output and I/O
358
+
359
+ ```python
360
+ from sed_model import save_sed, save_magnitudes
361
+
362
+ save_sed(result, "forward_sed.csv")
363
+ save_magnitudes(result, "forward_magnitudes.csv")
364
+ ```
365
+
366
+ Inverse results can be saved directly:
367
+
368
+ ```python
369
+ posterior.save("posterior_samples.npz")
370
+ ```
371
+
372
+ ---
373
+
374
+ ## Relationship to SED_Tools
375
+
376
+ SED_Model sits directly downstream of `SED_Tools`.
377
+
378
+ `SED_Tools` handles acquisition, standardization, filter downloads, grid construction, and SED completion/generation. SED_Model uses the resulting atmosphere grids and filter files for forward synthetic photometry and Bayesian stellar-parameter inference.
379
+
380
+ A typical workflow is:
381
+
382
+ ```text
383
+ SED_Tools -> build/download SED grids and filters
384
+ SED_Model -> generate synthetic magnitudes and infer stellar parameters
385
+ ```
386
+
387
+ ---
388
+
389
+ ## Testing
390
+
391
+ ```bash
392
+ pytest tests/test_forward.py
393
+ pytest tests/test_inverse.py
394
+ ```
395
+
396
+ The forward tests verify grid loading, bounds checking, interpolation, filter loading, zero-points, bolometric quantities, and synthetic magnitudes.
397
+
398
+ The inverse tests verify self-consistent posterior recovery and `InverseResult` persistence.
399
+
400
+ ---
401
+
402
+ ## Repository Structure
403
+
404
+ ```text
405
+ sed_model/
406
+ __init__.py
407
+ grid.py
408
+ filters.py
409
+ forward.py
410
+ inverse.py
411
+ params.py
412
+ io.py
413
+ sed_extinction.py
414
+
415
+ fortran/
416
+ cc_kernels.f90
417
+ cc_api.f90
418
+
419
+ demos/
420
+ tests/
421
+ Makefile
422
+ meson.build
423
+ pyproject.toml
424
+ setup.py
425
+ ```
426
+
427
+ ---
428
+
429
+ ## License
430
+
431
+ SED_Model uses a mixed-license structure. The Python source code, documentation, examples, tests, and packaging files are distributed under the MIT License. The Fortran numerical kernels in `fortran/` are distributed under LGPL-3.0-or-later. See `LICENSE` and source file headers for details.