Repository navigation
Speed up synthetic photometry by tabulating grid spectra and bandpasses - #174
Conversation
stsynphot returns interpolated grid spectra and HST bandpasses as trees of synphot models (a 580-node tree for a spectrum interpolated from 8 grid spectra), each node carrying a FITS header. synphot merges and deep-copies that metadata in every arithmetic operation and Observation, ~1,100 header copies per 10 magnitudes, which dominated synthetic photometry. - synphot_bridge.tabulate() returns the same spectrum or bandpass as one Empirical1D table on its own waveset (negative values kept, top-level meta kept). A bandpass becomes a plain SpectralElement. - atmospheres.grid_to_spec() wraps stsynphot.grid_to_spec with it; all grid lookups in atmospheres.py use the wrapper. - get_filter_info() returns the tabulated bandpass, after the Vega zero point is computed as before. Photometry per star and filter: ~34 ms -> ~4.7 ms. A full IsochronePhot (1547 stars, 4 HST filters) takes 410 s instead of 554 s and is identical in every column; the rest of the time is now reading grid spectra in stsynphot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
These changes should be pushed in stsynphot and I have an issue submitted there. I would suggest submitting a pull request there first and see if we can get it pushed through quickly. I'll note that the suggested changes remove units (I think) from the calculations; but this has been very useful in catching other types of photometric errors. |
|
Yes, I have already submitted a pull request to stsynphot spacetelescope/stsynphot_refactor#244. Let's see if it gets merged. But the units are not dropped:
|
stsynphot_refactor#244 (grid-spectrum cache) is merged but 1.7.0 is not on PyPI yet. Point pyproject.toml, the docs requirements, the install instructions and the Dockerfile at the merge commit instead of the pull request branch on the fork. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts commit a23aedd. Installing stsynphot is out of scope for this pull request; keep dev's setup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This is ready to merge. GitHub reports no conflicts with dev. I merged the current dev (including the SPISEA version check, 01d4dfb) into this branch locally and ran the full test suite: 88 passed, 2 skipped (the COSMIC integration tests; the optional cosmic package is not installed here). The slowest test, The PR does not change the installation: it works with the synphot/stsynphot versions dev already installs. The failing "Fast tests" check is not caused by this PR. Test collection stops with "Missing MISTv1/v1.2-synthpop/" because the CI runner has no SPISEA model grids. Dev's own CI fails the same way. This PR and #173 do not conflict, so they can be merged in either order. |
Keep the tabulating grid_to_spec wrapper with the narrower ParameterOutOfBounds exception from dev, and use the wrapper in the new FlameSkimmer loaders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Since the move to synphot, generating isochrone photometry takes about 4.7× longer: 554 s instead of 117 s for a 1547-star
IsochronePhotin four HST filters. Two causes:Observation, about 1,100 header copies per 10 magnitudes, which dominated photometry.stsynphot.grid_to_specre-reads its up-to-8 grid files on every call, and each synphot read costs about 21 ms against about 4 ms in pysynphot. Cache grid spectra read by grid_to_spec spacetelescope/stsynphot_refactor#244 caches the grid spectra; it is merged but not yet released.Changes
synphot_bridge.tabulate()returns the same spectrum or bandpass as oneEmpirical1Dtable on its own waveset. Negative values are kept, not clipped, and the top-levelmetais kept. A bandpass becomes a plainSpectralElement, because stsynphot'sObservationSpectralElementcannot be built without an obsmode.atmospheres.grid_to_spec()wrapsstsynphot.grid_to_specwith it, and all grid lookups inatmospheres.pyuse the wrapper.get_filter_info()returns the tabulated bandpass, after the Vega zero point has been computed as before.Results
Magnitudes are unchanged: identical to the last bit for 30 test stars in four HST filters, and every column of a full isochrone is identical.
IsochronePhot(1547 stars, 4 filters)devThe speedup in this PR does not depend on the stsynphot version: it works with the stsynphot that
devinstalls and with the current PyPI release. A 42-starIsochronePhot(four HST filters), with magnitudes identical in all four cases:dev(with #244)devTests
All fast tests in
test_imf.py,test_atmospheres.py,test_synthetic.pyandtest_reddening.pypass locally, as do the slowtest_isochrone,test_iso_waveandtest_IsochronePhot, which compare against the stored reference data. CI currently fails ondevitself, because the runner has no model grids (Missing MISTv1/v1.2-synthpop/).