Skip to content

Commit

Permalink
Working with astropy modelis with units
Browse files Browse the repository at this point in the history
  • Loading branch information
samaloney committed Oct 31, 2024
1 parent 9be4e97 commit 6dc46f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 5 additions & 7 deletions examples/fitting_simulated_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
from sunkit_spex.fitting.objective_functions.optimising_functions import minimize_func
from sunkit_spex.fitting.optimizer_tools.minimizer_tools import scipy_minimize
from sunkit_spex.fitting.statistics.gaussian import chi_squared
# from sunkit_spex.extern.astropy.modeling import CompoundModel, fix_inputs
from sunkit_spex.models.instrument_response import MatrixModel
from sunkit_spex.models.models import GaussianModel, StraightLineModel
from sunkit_spex.spectrum import Spectrum
from sunkit_spex.spectrum.spectrum import SpectralAxis

Expand Down Expand Up @@ -73,7 +71,7 @@
with quantity_support():
plt.figure()
plt.imshow(
srm_model.matrix.value,
srm_model.matrix,
origin="lower",
extent=(
srm_model.inputs_axis[0].value,
Expand All @@ -94,7 +92,7 @@

sim_gauss = {"amplitude": 70 * u.ct, "mean": 40 * u.keV, "stddev": 2 * u.keV}
# the brackets are very necessary
ct_model = (ph_model | srm_model) + GaussianModel(**sim_gauss)
ct_model = (ph_model | srm_model) + Gaussian1D(**sim_gauss)

#####################################################
#
Expand All @@ -119,7 +117,7 @@
with quantity_support():
plt.figure()
plt.plot(ph_energies, (ph_model | srm_model)(ph_energies), label="photon model features")
plt.plot(ph_energies, GaussianModel(**sim_gauss)(ph_energies), label="gaussian feature")
plt.plot(ph_energies, Gaussian1D(**sim_gauss)(ph_energies), label="gaussian feature")
plt.plot(ph_energies, sim_count_model, label="total sim. spectrum")
plt.plot(obs_spec._spectral_axis, obs_spec.data, label="total sim. spectrum + noise", lw=0.5)
plt.xlabel(f"Energy [{ph_energies.unit}]")
Expand All @@ -144,8 +142,8 @@
#
# Define a new model since we have a rough idea of the mode we should use

ph_mod_4fit = StraightLineModel(**guess_cont) + GaussianModel(**guess_line)
count_model_4fit = (ph_mod_4fit | srm_model) + GaussianModel(**guess_gauss)
ph_mod_4fit = Linear1D(**guess_cont) + Gaussian1D(**guess_line)
count_model_4fit = (ph_mod_4fit | srm_model) + Gaussian1D(**guess_gauss)

#####################################################
#
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ authors = [
{ name = "The SunPy Community", email = "[email protected]" },
]
dependencies = [
"astropy @ git+https://github.com/samaloney/astropy.git#bugfix-model-changing-units",
"corner>=2.2",
"emcee>=3.1",
"matplotlib>=3.7",
Expand Down

0 comments on commit 6dc46f5

Please sign in to comment.