Skip to content

Comments

Pass SpectralAxis to physical models rather than energy edges#223

Open
jajmitchell wants to merge 29 commits intosunpy:mainfrom
jajmitchell:pass-energy-centers
Open

Pass SpectralAxis to physical models rather than energy edges#223
jajmitchell wants to merge 29 commits intosunpy:mainfrom
jajmitchell:pass-energy-centers

Conversation

@jajmitchell
Copy link
Contributor

This PR enables the physical models to be used with a SpectralAxis

By passing a SpectralAxis to the physical models, they are effectively evaluated at bin centers, but have access to the bin edges as these are stored as an attribute in the SpectralAxis class. This change will allow for a clearer path to using Astropy model classes for fitting as the dimensionality of the input and output will no longer be an issue.

Adds SRM units and passes Spectralaxis to thermal
Checks input is SpectralAxis object, converts and warns if not
Adds check input function
ThickTarget and ThinTarget use centers
Albedo now takes SpectralAxis and centers
Pre-commit
scaling.py and models.py now function with centers
Fixes scaling and albedo tests
Adds __array_finalize__ method to SpectralAxis
Fixes tests
Fixes part of fitting_simulated_data.py
Reverts SRM model to main version
Fixes fitting tests
Fixes test_models.py
Fixes Albedo example
Fix Albedo example 2
Fixes examples
Adds changelog
Pre_commit fix
@samaloney
Copy link
Member

Nice is this ready for review?

@jajmitchell
Copy link
Contributor Author

jajmitchell commented Jul 21, 2025

Nice is this ready for review?

@samaloney I need to just check that the fitting works with the physical models, then I think its good to go

@jajmitchell
Copy link
Contributor Author

jajmitchell commented Jul 22, 2025

@samaloney the complications continue. The issue comes when fitting, specifically in Astropy fitting.py line 255, as can be seen below.

if isinstance(x, Quantity): 
    add_back_units = True
    xdata = x.value
else:
    xdata = np.asarray(x)

This means that for fitting, before being passed to evaluate, the fitter takes the value of the SpectralAxis object, which not only strips the units, but also all other attributes. I'm trying to think of ways around this, but haven't come up with anything yet.

Adds custom `__call__` to `ThermalEmission`
Fixes test_thermal.py
@jajmitchell
Copy link
Contributor Author

jajmitchell commented Jul 28, 2025

I have added a custom __call__ onto the ThermalEmission class, this is unnecessary for the ThickTarget as we evaluate at centers anyway

Adds meta to SpectralAxis, thermal model can now take Spectrum object, Spectral axis, or array
Can pass array without initialising
Fitting works
Tidy up
More tidy
Remove unused functions
Fixes continuum and line models
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants