Skip to content

Commit

Permalink
chianti emission model (#123)
Browse files Browse the repository at this point in the history
* New folder for chianti files

* Adding CHIANTI_hybrid.geny file

* Adding CHIANTI_photospheric.geny file

* Created a dictionary with _abundance_model_file_path

* Importing packages

* Setting a _abundance_model_data dictionary

* Updating folder name

* Correction to methods of importing files.

* Updating name to be more define as filter name.

* Re-defining method of getting data from geny files

* Creating a function to call data from geny file

* Defing file type name

* Define users input for abundance to retrun the correct data set.

* Updated functions to take data from requested abundance file

* Code return users requested abundance file

* Updating text strings and doc strings in the functions

* Add two articles that reference the new abundance file

* Updating site to having information about the new abundance files

* Adding a link reference for XRT temperature response with other choice of abundances

* Adding information about Additional Abundances

* Fixing text details

* Updating information in the glossary related to the TR.

* Adding more information to Additional Abundances section

* Update xrtpy/response/temperature_response.py

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Update xrtpy/response/temperature_response.py

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Update docs/bibliography.bib

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Update xrtpy/response/temperature_response.py

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Update xrtpy/response/temperature_response.py

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Update xrtpy/response/temperature_response.py

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Creating a private function

* clarified meaning of the version function

* Correction the method of calling a function in the effective area code

* Updating temperature function name

* Adding a TIP on how to call a different abundance model

* Fixing head info to reference easier in a different rst file

* Adding text to give user information about using abundance_model in command line

* Removed package

* IDL testing text file - Temp Resp.

* IDL testing text file - Temp Resp.

* IDL testing text file - Temp Resp.

* IDL testing text file - Temp Resp.

* IDL photospheric testing text file - Temperature Response

* IDL photospheric testing text file - Temperature Response

* IDL photospheric testing text file - Temperature Response

* IDL hybrid testing text file: 2022 - Temperature Response

* IDL hybrid testing text file: 2021 - Temperature Response

* IDL hybrid testing text file: 2019 - Temperature Response

* IDL hybrid testing text file: 2017 - Temperature Response

* IDL hybrid testing text file: 2015 - Temperature Response

* IDL hybrid testing text file: 2013 - Temperature Response

* IDL hybrid testing text file: 2011 - Temperature Response

* IDL hybrid testing text file: 2009 - Temperature Response

* IDL hybrid testing text file: 2007 - Temperature Response

* Updating folder name

* Name correction to data I am calling

* Updated the path to the testing data.

* Correction to folder name;

* Updated name - coronal o.g. test file

* TR Hybrid test for the moment, will merge all TR test.

* TR Photospheric test for the moment, will merge all TR test.

* Updated directory to getting test files.

* Updated directory to getting test files.

* Updated directory to getting test files.

* Updated directory to getting test files.

* New dictionary to call IDL testing file paths

* Update code to look for all new abundance files

* Removed used code

* Updating xrt_teem to take other abundance

* Cleaned up code

* Updated doc information about these abundance

* Correction to title

* Updated word choice

* Updated path method to reference the dic.

* Working on testing all abundance in a single test

* Returning into stadard test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated docstring in xrt_teem to reflect the fact that abundance_model is now a parameter

* Fixed format of string literal in docstring in xrt_teem

---------

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Slavin <jslavin@cfa.harvard.edu>
  • Loading branch information
4 people authored Apr 20, 2023
1 parent ff2cd0a commit 7425c11
Show file tree
Hide file tree
Showing 231 changed files with 10,632 additions and 58 deletions.
26 changes: 26 additions & 0 deletions docs/bibliography.bib
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,29 @@ @ARTICLE{feldman:1992
pages = {202-220},
doi = {10.1088/0031-8949/46/3/002}
}
@ARTICLE{Fludra:1999,
author = {{Fludra}, A. and {Schmelz}, J.~T.},
title = "{The absolute coronal abundances of sulfur, calcium, and iron from Yohkoh-BCS flare spectra}",
journal = "{Astronomy \& Astrophysics}",
keywords = {SUN: ABUNDANCES, SUN: CORONA, SUN: FLARES, SUN: X-RAYS, GAMMA RAYS},
year = 1999,
month = aug,
volume = {348},
pages = {286-294},
adsurl = {https://ui.adsabs.harvard.edu/abs/1999A&A...348..286F},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
@ARTICLE{Grevesse:2007,
author = {{Grevesse}, N. and {Asplund}, M. and {Sauval}, A.~J.},
title = "{The Solar Chemical Composition}",
journal = {\ssr},
keywords = {Sun: abundances, photosphere, corona},
year = 2007,
month = jun,
volume = {130},
number = {1-4},
pages = {105-114},
doi = {10.1007/s11214-007-9173-7},
adsurl = {https://ui.adsabs.harvard.edu/abs/2007SSRv..130..105G},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
28 changes: 24 additions & 4 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,32 @@ Refer to the `SolarSoft XRT Analysis Guide`_ for more information about the inst
Temperature Response
--------------------
XRTpy produces the temperature response for each XRT filter channel, assuming a spectral emission model, refer to :cite:t:`narukage:2011` and :cite:t:`narukage:2014`.
XRTpy default emission model is from CHIANTI. This structure contains data and information about a plasma emission model, as a function of wavelength and temperature.
The default model assumes coronal abundances :cite:t:`feldman:1992`.
The XRT default emission model is `CHIANTI`_ atomic database version 10.0 with coronal abundances :cite:t:`feldman:1992`. This structure contains data and information about a plasma emission model, as a function of wavelength and temperature.


Abundance Model
---------------------
The standard XRT temperature response routines are calculated assuming `CHIANTI`_ coronal abundances, :cite:t:`feldman:1992`.
In addition, XRTpy offers the ability to choose two other sets of `CHIANTI`_ abundances i.e. Hybrid and Photospheric.
The Hybrid abundances are base on :cite:t:`Fludra:1999` and Photospheric abundances are base on :cite:t:`Grevesse:2007`.
The `CHIANTI`_ files contain data and information about a plasma emission model, as a function of wavelength and temperature.
Visit `XRT temperature response with other choice of abundances`_ for future detailed information.

.. note::
XRTpy has future plans to accept other plasma emission spectra models.
XRTpy has future plans to accept other plasma emission spectra models.

XRTpy defaults to using CHIANTI `"coronal"` abundance. You are able to specify the other abundances by defining the abundance type name
i.e. `"hybrid"` or `"photospheric"` in `abundance_model`. For example:

.. code-block:: bash
xrtpy.response.TemperatureResponseFundamental('Al-poly', '2022/07/04T23:43:12', abundance_model = 'Hybrid')
The `abundance_model` method is used in the same format in `xrt_teem`.

Deriving Temperature and Emission Measure for a Pair of Images
--------------------------------------------------------------
XRTpy provides a routine, xrt_teem, that employs the objects listed above to derive the temperature and emission measure in for a given pair of images using the filter ratio method. This uses the same methods as in the SolarSoft IDL routine of the same name.
XRTpy provides a routine, `xrt_teem`, that employs the objects listed above to derive the temperature and emission measure in for a given pair of images using the filter ratio method. This uses the same methods as in the SolarSoft IDL routine of the same name.


X-Ray Filter Channel
Expand Down Expand Up @@ -71,5 +88,8 @@ in the `SolarSoft XRT Analysis Guide`_ for more information about the XRT filter
that selects the titanium-on-polyimide filter, then the string would be ``'Ti-poly'``. The process is the same for all XRT
filter channels.


.. _CHIANTI: https://www.chiantidatabase.org/chianti_database_history.html
.. _SolarSoft XRT Analysis Guide: https://xrt.cfa.harvard.edu/resources/documents/XAG/XAG.pdf
.. _xrt-cfa-harvard: https://xrt.cfa.harvard.edu/index.php
.. _XRT temperature response with other choice of abundances: http://solar.physics.montana.edu/takeda/xrt_response/xrt_resp.html
11 changes: 9 additions & 2 deletions docs/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ Glossary
.. glossary::
:sorted:

Temperature
Temperature :math:`T`, is a `~astropy.units.Quantity` with units of temperature (e.g., kelvin).
DN
Data number (DN) per unit.

Contamination (related to the XRT)
Contaminating material has accumulated on the XRT CCD and focal plane filters (FPFs), causing a decrease in sensitivity.
Refer to Section 2.5.3 `Contamination` in the `SolarSoft XRT Analysis Guide`_ in the `SolarSoft XRT Analysis Guide`_ for
more information about the XRT contamination.

Temperature response
Instrument temperature response function, for a filter-channel. Units are
DN cm\ :sup:`5` s\ :sup:`−1` pix\ :sup:`-1`\ .

Solar-emission-spectra
A set of plasma emission spectra for a set of temperature.

.. _SolarSoft XRT Analysis Guide: https://xrt.cfa.harvard.edu/resources/documents/XAG/XAG.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
142 changes: 96 additions & 46 deletions xrtpy/response/temperature_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import scipy.io
import sunpy.time

from astropy import units as u
from astropy.constants import c, h
Expand All @@ -18,107 +17,155 @@
_h_eV_s = h.to(u.eV * u.s).value


_CHIANTI_filename = (
Path(__file__).parent.absolute() / "data" / "XRT_emiss_model.default_CHIANTI.geny"
)
_CHIANTI_file = scipy.io.readsav(_CHIANTI_filename)
_XRT_emiss_model_file = _CHIANTI_file["p0"]


CHIANTI_file = {
"abundance_model": _XRT_emiss_model_file["ABUND_MODEL"][0],
"dens_model": _XRT_emiss_model_file["DENS_MODEL"][0],
"ioneq_model": _XRT_emiss_model_file["IONEQ_MODEL"][0],
"name": _XRT_emiss_model_file["NAME"][0],
"spectra": _XRT_emiss_model_file["SPEC"],
"spectra_units": _XRT_emiss_model_file["SPEC_UNITS"][0],
"temperature": _XRT_emiss_model_file["TEMP"][0],
"temp_units": _XRT_emiss_model_file["TEMP_UNITS"][0],
"tlength": _XRT_emiss_model_file["TLENGTH"][0],
"wlength": _XRT_emiss_model_file["WLENGTH"][0],
"wavelength": _XRT_emiss_model_file["WAVE"][0],
"wavelength_units": _XRT_emiss_model_file["WAVE_UNITS"][0],
_abundance_model_file_path = {
"coronal_abundance_path": Path(__file__).parent.absolute()
/ "data/chianti_emission_models"
/ "XRT_emiss_model.default_CHIANTI.geny",
"hybrid_abundance_path": Path(__file__).parent.absolute()
/ "data/chianti_emission_models"
/ "XRT_emiss_model.default_CHIANTI_photospheric.geny",
"photospheric_abundance_path": Path(__file__).parent.absolute()
/ "data/chianti_emission_models"
/ "XRT_emiss_model.default_CHIANTI_hybrid.geny",
}

_abundance_model_data = {
"coronal": scipy.io.readsav(_abundance_model_file_path["coronal_abundance_path"])[
"p0"
],
"hybrid": scipy.io.readsav(_abundance_model_file_path["hybrid_abundance_path"])[
"p0"
],
"photospheric": scipy.io.readsav(
_abundance_model_file_path["photospheric_abundance_path"]
)["p0"],
}

list_of_abundance_name = ["coronal", "hybrid", "photospheric"]


def _resolve_abundance_model_type(abundance_model):
"""Formats and checks users abundance model input name."""
if not isinstance(abundance_model, str):
raise TypeError("Abundance model name must be a string")
abundance_name = abundance_model.lower()
if abundance_name not in list_of_abundance_name:
raise ValueError(
f"\n{abundance_name} is not a current abundance model for XRTpy.\n"
"Available abundance models:\n"
"'coronal', 'hybrid', and 'photospheric'.\n"
)
return abundance_name


class TemperatureResponseFundamental:
"""Produce the temperature response for each XRT x-ray channel, assuming a spectral emission model."""

def __init__(self, filter_name, observation_date):
def __init__(self, filter_name, observation_date, abundance_model="coronal"):
self._name = resolve_filter_name(filter_name)
self._channel = Channel(self.filter_name)
# self.observation_date = self.observation_date
self._abundance_model = _resolve_abundance_model_type(abundance_model)
self._effective_area_fundamental = EffectiveAreaFundamental(
self.name, observation_date
self._name, observation_date
)
self._channel = Channel(self.name)

@property
def name(self):
def filter_name(self):
"""Name of searched filter."""
return self._name

@property
def abundances(self) -> str:
"""Defined the name of the requested abundance model as a string."""
return self._abundance_model

@property
def observation_date(self):
"""Date of observation."""
return self._effective_area_fundamental.observation_date

@property
def CHIANTI_version(self):
"""Name of the emission model."""
return CHIANTI_file["name"]
def get_abundance_data(self):
"""Returning the requested abundance data that is used to calculate the temperature response."""
abundance_type_name = self.abundances
data = _abundance_model_data[abundance_type_name]
if abundance_type_name not in list_of_abundance_name:
ValueError("Unable to process data. ")

return {
"abundance_model_info": data["ABUND_MODEL"][0],
"dens_model": data["DENS_MODEL"][0],
"ioneq_model": data["IONEQ_MODEL"][0],
"name": data["NAME"][0],
"spectra": data["SPEC"],
"spectra_units": data["SPEC_UNITS"][0],
"temperature": data["TEMP"][0],
"temp_units": data["TEMP_UNITS"][0],
"tlength": data["TLENGTH"][0],
"wlength": data["WLENGTH"][0],
"wavelength": data["WAVE"][0],
"wavelength_units": data["WAVE_UNITS"][0],
}

@property
def chianti_abundance_version(self):
"""Version of the chianti abundance model."""
return self.get_abundance_data["name"]

@property
def abundance_model(self):
def abundance_model_information(self):
"""A brief description of what abundance model was used in the creation of the emission spectra."""
return CHIANTI_file["abundance_model"]
return self.get_abundance_data["abundance_model_info"]

@property
def density_model(self):
"""A brief description of the plasma density, emission measure,or differential emission measure that was used in the creation of the emission spectra."""
return CHIANTI_file["dens_model"]
return self.get_abundance_data["dens_model"]

@property
def ionization_model(self):
"""A brief description of that ionization equilibrium model was used in the creation of the emission spectra."""
return CHIANTI_file["ioneq_model"]
return self.get_abundance_data["ioneq_model"]

@property
@u.quantity_input
def CHIANTI_temperature(self):
"""CHIANTI temperatures in kelvin."""
return u.Quantity(CHIANTI_file["temperature"] * u.K)
"""Emission model temperatures in kelvin."""
return u.Quantity(self.get_abundance_data["temperature"] * u.K)

@property
def CHIANTI_file_spectra(self):
"""CHIANTI file spectra."""
return CHIANTI_file["spectra"]
def file_spectra(self):
"""Emission model file spectra."""
return self.get_abundance_data["spectra"][0]

@property
@u.quantity_input
def CHIANTI_wavelength(self):
"""CHIANTI file wavelength values in Å."""
return u.Quantity(CHIANTI_file["wavelength"] * u.Angstrom)
def wavelength(self):
"""Emission model file wavelength values in Å."""
return u.Quantity(self.get_abundance_data["wavelength"] * u.Angstrom)

@property
@u.quantity_input
def channel_wavelength(self):
"""Array of wavelengths for every X-ray channel in Å."""
return u.Quantity((Channel(self.name).wavelength[:3993]) * u.photon)
return u.Quantity((Channel(self.filter_name).wavelength[:3993]) * u.photon)

@property
def focal_len(self):
"""Focal length of the telescope in units of cm."""
return Channel(self.name).geometry.geometry_focal_len
return Channel(self.filter_name).geometry.geometry_focal_len

@property
def ev_per_electron(self):
"""Amount of energy it takes to dislodge 1 electron in the CCD."""
return Channel(self.name).ccd.ccd_energy_per_electron
return Channel(self.filter_name).ccd.ccd_energy_per_electron

@property
@u.quantity_input
def pixel_size(self) -> u.cm:
"""CCD pixel size. Units converted from μm to cm."""
ccd_pixel_size = Channel(self.name).ccd.ccd_pixel_size
ccd_pixel_size = Channel(self.filter_name).ccd.ccd_pixel_size
return ccd_pixel_size.to(u.cm)

@property
Expand All @@ -133,7 +180,9 @@ def spectra(self) -> u.photon * u.cm**3 / (u.sr * u.s * u.Angstrom):
spectra_interpolate = []
for i in range(61):
interpolater = interpolate.interp1d(
self.CHIANTI_wavelength, CHIANTI_file["spectra"][0][i], kind="linear"
self.wavelength,
self.file_spectra[i],
kind="linear",
)
spectra_interpolate.append(interpolater(self.channel_wavelength))
return spectra_interpolate * (
Expand All @@ -142,6 +191,7 @@ def spectra(self) -> u.photon * u.cm**3 / (u.sr * u.s * u.Angstrom):

@u.quantity_input
def effective_area(self) -> u.cm**2:
# return effective_area(self.filter_name, self.observation_date)
return self._effective_area_fundamental.effective_area()

@u.quantity_input
Expand All @@ -166,7 +216,7 @@ def integration(self) -> u.electron * u.cm**5 / (u.s * u.pix):
@u.quantity_input
def ccd_gain_right(self) -> u.electron / u.DN:
"""Provide the camera gain in electrons per data number."""
return Channel(self.name).ccd.ccd_gain_right
return Channel(self.filter_name).ccd.ccd_gain_right

@u.quantity_input
def temperature_response(self) -> u.DN * u.cm**5 / (u.s * u.pix):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Temperature Response: IDL Results
Abundance_model hybrid
Filter Al-med
observation_date 22-Sept-2007 22:45:45
Temperature Temperature Response
100000. 2.19654e-36
112202. 2.83905e-36
125893. 4.11514e-36
141254. 6.46438e-36
158489. 1.02296e-35
177828. 1.55973e-35
199526. 2.25359e-35
223872. 3.07464e-35
251189. 3.89549e-35
281838. 4.40142e-35
316228. 4.64052e-35
354814. 5.33387e-35
398107. 6.73237e-35
446684. 8.62099e-35
501187. 1.12587e-34
562341. 1.96639e-34
630958. 7.20764e-34
707946. 3.59215e-33
794328. 1.61838e-32
891251. 6.42349e-32
1.00000e+06 2.33399e-31
1.12202e+06 7.84793e-31
1.25893e+06 2.37168e-30
1.41254e+06 6.34721e-30
1.58489e+06 1.52579e-29
1.77828e+06 3.36681e-29
1.99526e+06 6.97998e-29
2.23872e+06 1.36832e-28
2.51189e+06 2.49099e-28
2.81838e+06 4.19238e-28
3.16228e+06 6.59565e-28
3.54814e+06 9.80474e-28
3.98107e+06 1.38720e-27
4.46684e+06 1.87501e-27
5.01187e+06 2.42907e-27
5.62341e+06 3.02825e-27
6.30958e+06 3.64568e-27
7.07946e+06 4.25010e-27
7.94328e+06 4.81729e-27
8.91250e+06 5.34668e-27
1.00000e+07 5.84188e-27
1.12202e+07 6.22687e-27
1.25893e+07 6.30359e-27
1.41254e+07 5.96482e-27
1.58489e+07 5.37829e-27
1.77828e+07 4.77259e-27
1.99526e+07 4.25235e-27
2.23872e+07 3.83292e-27
2.51189e+07 3.50310e-27
2.81838e+07 3.24246e-27
3.16228e+07 3.03185e-27
3.54814e+07 2.85659e-27
3.98108e+07 2.70554e-27
4.46684e+07 2.57191e-27
5.01187e+07 2.45039e-27
5.62341e+07 2.33929e-27
6.30958e+07 2.23732e-27
7.07946e+07 2.14467e-27
7.94328e+07 2.06166e-27
8.91251e+07 1.98826e-27
1.00000e+08 1.92372e-27
Loading

0 comments on commit 7425c11

Please sign in to comment.