Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/227.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds unit handling to :class:`sunkit_spex.models.instrument_response.MatrixModel`.
30 changes: 18 additions & 12 deletions examples/fitting_NuSTAR_spectra-duncan2021.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
Fitting NuSTAR Spectra: Duncan *et al.* 2021 comparison
=========================================================

This spectrum corresponds to the may1618 microflare in [Duncan2021]_.
This spectrum corresponds to the may1618 microflare in `Duncan2021`_.

An example of fitting multiple spectra simultaneously with 2 models where each model is allowed to vary at different times

We also allow the gain slope response parameter to vary.

.. _Duncan2021: https://iopscience.iop.org/article/10.3847/1538-4357/abca3d
"""

import warnings
Expand Down Expand Up @@ -81,6 +83,7 @@
#####################################################
#
# freeze the ones we don't want to vary

spec.params["C_spectrum1"] = {"Status": "frozen"}

#####################################################
Expand All @@ -95,6 +98,7 @@
#####################################################
#
# Fit lower energy range with the first thermal model first

spec.params["T2_spectrum1"] = "frozen"
spec.params["EM2_spectrum1"] = "frozen"
spec.energy_fitting_range = [2.5, 4]
Expand All @@ -116,6 +120,7 @@
#####################################################
#
# Need the gain slope to vary too for this microflare but only needed for the 6.7 keV line

print(spec.rParams)
spec.rParams["gain_slope_spectrum1"] = "free"
spec.rParams["gain_slope_spectrum2"] = spec.rParams["gain_slope_spectrum1"]
Expand Down Expand Up @@ -156,21 +161,17 @@
# For the 2 thermal model fitting
#
# +----------------------------------------+-----------------------------------------------+------------------------------------------+
# | Model Parameter | XSPEC (Duncan et al. 2021) [*]_ | This Work |
# | Model Parameter | XSPEC (Duncan et al. 2021) | This Work |
# +========================================+===============================================+==========================================+
# | Temperature 1 [MK] | :math:`4.1^{+0.1}_{-0.1}` | 4.8\ |pm|\ 0.3 |
# | Temperature 1 [MK] | :math:`4.1^{+0.1}_{-0.1}` | :math:`4.8 \pm 0.3` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+
# | Emission Measure 1 [cm\ :sup:`-3`] | :math:`1.4^{+0.6}_{-0.4}\times10^{47}` | 7.6 |pm| 2.4\ |x|\ 10 :sup:`46` |
# | Emission Measure 1 [cm\ :sup:`-3`] | :math:`1.4^{+0.6}_{-0.4} \times 10^{47}` | :math:`7.6 \pm 2.4 \times 10^46` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+
# | Temperature 2 [MK] | :math:`10.00^{+0.03}_{-0.03}` | 10.4\ |pm|\ 0.1 |
# | Temperature 2 [MK] | :math:`10.00^{+0.03}_{-0.03}` | :math:`10.4 \pm 0.1` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+
# | Emission Measure 2 [cm\ :sup:`-3`] | :math:`4.6^{+0.1}_{-0.2}\times10^{45}` | 4.3 |pm| 0.3\ |x|\ 10 :sup:`45` |
# | Emission Measure 2 [cm\ :sup:`-3`] | :math:`4.6^{+0.1}_{-0.2} \times 10^{45}` | :math:`4.3 \pm 0.3 \times 10^45` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+
#
# .. |pm| replace:: :math:`\pm`
# .. |x| replace:: :math:`\times`
# .. [*] Duncan *et al.* 2021's may1618 microflare
# .. [Duncan2021] https://iopscience.iop.org/article/10.3847/1538-4357/abca3d

#####################################################
#
Expand All @@ -179,8 +180,13 @@
# +----------------------------------------+-----------------------------------------------+------------------------------------------+
# | Model Parameter | XSPEC (Duncan et al. 2021) | This Work |
# +========================================+===============================================+==========================================+
# | Gain Slope | 0.977\ |pm|\ 0.002 | 0.978\ |pm|\ 0.001 |
# | Gain Slope | :math:`0.977 \pm 0.002` | :math:`0.978 \pm 0.001` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+
#
# .. _[Duncan2021]: https://iopscience.iop.org/article/10.3847/1538-4357/abca3d

#####################################################
# Although these values are slightly different, it is important to note that XSPEC and sunkit-spex work from different atomic databases. We also note that for a similar isothermal fit the temperature can drop/rise if the emission measure rises/drops and so fitting not just one but two of these models allows for these to vary more. We do see that this work (for this microflare) produces higher temperatures but correspondingly lower emission measures.
# Although these values are slightly different, it is important to note that XSPEC and sunkit-spex work from different
# atomic databases. We also note that for a similar isothermal fit the temperature can drop/rise if the emission measure
# rises/drops and so fitting not just one but two of these models allows for these to vary more. We do see that this
# work (for this microflare) produces higher temperatures but correspondingly lower emission measures.
31 changes: 15 additions & 16 deletions examples/fitting_NuSTAR_spectra-glesener2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Fitting NuSTAR Spectra: Glesener *et al.* 2020 comparison
=========================================================

A real example from [Glesener2020]_ of fitting two NuSTAR spectra simultaneously with gain correction.
A real example from `Glesener2020`_ of fitting two NuSTAR spectra simultaneously with gain correction.

.. _Glesener2020: https://iopscience.iop.org/article/10.3847/2041-8213/ab7341
"""

import warnings
Expand Down Expand Up @@ -198,23 +200,20 @@
# For the thermal and cold thick target total model we compare
#
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Model Parameter | OSPEX (Glesener et al. 2020) [*]_ | This Work (just FPMB) | This Work (FPMA&B) |
# | Model Parameter | OSPEX (Glesener et al. 2020) | This Work (just FPMB) | This Work (FPMA&B) |
# +========================================+===============================================+==========================================+==========================================+
# | Temperature [MK] | 10.3\ |pm|\ 0.7 | 11.3\ |pm|\ 0.7 | 11.2\ |pm|\ 0.4 |
# | Temperature [MK] | :math:`10.3 \pm 0.7` | :math:`11.3 \pm 0.7` | :math:`11.2 \pm 0.4` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Emission Measure [cm\ :sup:`-3`] | 5.0 |pm| 1.3\ |x|\ 10 :sup:`45` | 3.7 |pm| 0.9\ |x|\ 10 :sup:`45` | 3.7 |pm| 0.5\ |x|\ 10 :sup:`45` |
# | Emission Measure [cm\ :sup:`-3`] | :math:`5.0 \pm 1.3 \times 10^45` | :math:`3.7 \pm 0.9 \times 10^45` | :math:`3.7 \pm 0.5 \times 10^45` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Electron Flux [e$^{-}$ s$^{-1}$] | 2.1\ |pm|\ 1.1\ |x|\ 10 :sup:`35` | 2.2\ |pm|\ 1.1\ |x|\ 10 :sup:`35` | 1.6\ |pm|\ 0.5\ |x|\ 10 :sup:`35` |
# | Electron Flux [e$^{-}$ s$^{-1}$] | :math:`2.1 \pm 1.1 \times 10^35` | :math:`2.2 \pm 1.1 \times 10^35` | :math:`1.6 \pm 0.5 \times 10^35` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Index | 6.2\ |pm|\ 0.6 | 6.5\ |pm|\ 0.8 | 6.5\ |pm|\ 0.6 |
# | Index | :math:`6.2 \pm 0.6` | :math:`6.5 \pm 0.8` | :math:`6.5 \pm 0.6` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Low Energy Cut-off [keV] | 6.2\ |pm|\ 0.9 | 6.5\ |pm|\ 1.0 | 6.7\ |pm|\ 0.7 |
# | Low Energy Cut-off [keV] | :math:`6.2 \pm 0.9` | :math:`6.5 \pm 1.0` | :math:`6.7 \pm 0.7` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
#
# .. |pm| replace:: :math:`\pm`
# .. |x| replace:: :math:`\times`
# .. [*] Glesener *et al.* 2020
# .. [Glesener2020] https://iopscience.iop.org/article/10.3847/2041-8213/ab7341
# .. _Glesener2020: https://iopscience.iop.org/article/10.3847/2041-8213/ab7341


#####################################################
Expand Down Expand Up @@ -344,15 +343,15 @@
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Model Parameter | OSPEX (Glesener et al. 2020) | This Work (just FPMB) | This Work (FPMA&B) |
# +========================================+===============================================+==========================================+==========================================+
# | Temperature [MK] | 10.2\ |pm|\ 0.7 | 11.2\ |pm|\ 0.6 | 11.2\ |pm|\ 0.4 |
# | Temperature [MK] | :math:`10.2 \pm 0.7` | :math:`11.2 \pm 0.6` | :math:`11.2 \pm 0.4` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Plasma Density [cm\ :sup:`-3`] | 6.0 |pm| 2.0\ |x|\ 10 :sup:`9` | 5.0 |pm| 1.3\ |x|\ 10 :sup:`9` | 5.7 |pm| 1.1\ |x|\ 10 :sup:`9` |
# | Plasma Density [cm\ :sup:`-3`] | :math:`6.0 \pm 2.0 \times 10^9` | :math:`5.0 \pm 1.3 \times 10^9` | :math:`5.7 \pm 1.1 \times 10^9` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Electron Flux [e$^{-}$ s$^{-1}$] | 1.8\ |pm|\ 0.8\ |x|\ 10 :sup:`35` | 2.0\ |pm|\ 0.8\ |x|\ 10 :sup:`35` | 1.6\ |pm|\ 0.5\ |x|\ 10 :sup:`35` |
# | Electron Flux [e$^{-}$ s$^{-1}$] | :math:`1.8 \pm 0.8\times 10^35` | :math:`2.0 \pm 0.8 \times 10^35` | :math:`1.6 \pm 0.5 \times 10^35` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Index | 6.3\ |pm|\ 0.7 | 6.6\ |pm|\ 0.8 | 6.5\ |pm|\ 0.6 |
# | Index | :math:`6.3 \pm 0.7` | :math:`6.6 \pm 0.8` | :math:`6.5 \pm 0.6` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+
# | Low Energy Cut-off [keV] | 6.5\ |pm|\ 0.9 | 6.7\ |pm|\ 0.9 | 6.7\ |pm|\ 0.7 |
# | Low Energy Cut-off [keV] | :math:`6.5 \pm 0.9` | :math:`6.7 \pm 0.9` | :math:`6.7 \pm 0.7` |
# +----------------------------------------+-----------------------------------------------+------------------------------------------+------------------------------------------+

#####################################################
Expand Down
19 changes: 9 additions & 10 deletions examples/fitting_NuSTAR_spectra-simultaneously.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Fitting NuSTAR Spectra: Simultaneous Fitting
============================================

A real example from [Cooper2021]_ of fitting two NuSTAR spectra simultaneously.
A real example from `Cooper2021`_ of fitting two NuSTAR spectra simultaneously.

.. _Cooper2021: https://academic.oup.com/mnras/article/507/3/3936/6354806
"""

import warnings
Expand Down Expand Up @@ -120,21 +122,18 @@
# Comparison
#
# +------------------------------------------+-----------------------------------------------+------------------------------------------+
# | Model Parameter | XSPEC (Cooper et al. 2021) [*]_ | This Work |
# | Model Parameter | XSPEC (Cooper et al. 2021) | This Work |
# +==========================================+===============================================+==========================================+
# | Temperature 1 [MK] | :math:`3.05^{+0.04}_{-0.35}` | 3.19\ |pm|\ 0.23 |
# | Temperature 1 [MK] | :math:`3.05^{+0.04}_{-0.35}` | :math:`3.19 \pm 0.23` |
# +------------------------------------------+-----------------------------------------------+------------------------------------------+
# | Emission Measure 1 [cm\ :sup:`-3`] | :math:`1.70^{+1.99}_{-0.08}\times10^{47}` | 1.45 |pm| 0.72\ |x|\ 10 :sup:`46` |
# | Emission Measure 1 [cm\ :sup:`-3`] | :math:`1.70^{+1.99}_{-0.08}\times10^{47}` | :math:`1.45 \pm 0.72 \times 10^46` |
# +------------------------------------------+-----------------------------------------------+------------------------------------------+
# | Temperature 2 [MK] | :math:`6.60^{+0.20}_{-0.61}` | 7.13\ |pm|\ 0.97 |
# | Temperature 2 [MK] | :math:`6.60^{+0.20}_{-0.61}` | :math:`7.13 \pm 0.97` |
# +------------------------------------------+-----------------------------------------------+------------------------------------------+
# | Emission Measure 2 [cm\ :sup:`-3`] | :math:`3.8^{+4.0}_{-0.7}\times10^{43}` | 2.80 |pm| 2.80\ |x|\ 10 :sup:`43` |
# | Emission Measure 2 [cm\ :sup:`-3`] | :math:`3.8^{+4.0}_{-0.7}\times10^{43}` | :math:`2.80 \pm 2.80 \times 10^43` |
# +------------------------------------------+-----------------------------------------------+------------------------------------------+
#
# .. |pm| replace:: :math:`\pm`
# .. |x| replace:: :math:`\times`
# .. [*] Cooper *et al.* 2021's microflare 10, pre-flare.
# .. [Cooper2021] https://academic.oup.com/mnras/article/507/3/3936/6354806
# .. _Cooper2021: https://academic.oup.com/mnras/article/507/3/3936/6354806

#####################################################
# Although these values are slightly different (almost or are within error margins), it is important to note that XSPEC and sunkit-spex work from different atomic databases. We also note that for a similar isothermal fit the temperature can drop/rise if the emission measure rises/drops and so fitting not just one but two of these models allows for these to vary more. We do see that this work (for this microflare time) produces slightly higher temperatures but correspondingly lower emission measures.
Expand Down
Loading