radis icon indicating copy to clipboard operation
radis copied to clipboard

Kurucz spectrum

Open menasrac opened this issue 1 year ago • 8 comments

Description

PR for the 2023 GSOC project : Common API for large molecular databases. This PR includes the implementation of the Kurucz database to Radis with an example to plot spectrum using Spectrum Factory and all the related changes to the API or other sections of the code Follows PR #579 and adds broadening, a spectrum factory based example for Kurucz, also fixes minor requested changes.

Fixes #<Issue Number>

menasrac avatar Aug 02 '23 02:08 menasrac

Reviewed kuruczapi.py and partfunc.py. Main comment: there are some duplicates and I don't understand why

A global answer to all these comments : @minouHub The key structure will be modified to stick to the conventions when I introduce the species notations, I'm already working on it. The SiJ0 function and partfcn function in the API are not used because the int is added by radis but I let it for the moment to compare the results with the version of the code which adds int to the def ( see the #int in the read_kurucz methods). I will also remove it when we are satisfied with the physics. I will check what I can do for the hardcoded arrays and indeed load_atomic data is not needed any longer so I will remove it

menasrac avatar Aug 08 '23 15:08 menasrac

Codecov Report

Merging #601 (4a08a8b) into develop (460640b) will increase coverage by 0.07%. The diff coverage is 78.24%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #601      +/-   ##
===========================================
+ Coverage    73.15%   73.22%   +0.07%     
===========================================
  Files          143      147       +4     
  Lines        20046    20360     +314     
===========================================
+ Hits         14665    14909     +244     
- Misses        5381     5451      +70     

codecov-commenter avatar Aug 09 '23 10:08 codecov-commenter

@menasrac I believe the issue with test_gascomp.py is on Cantera's end, see also this issue I opened there: https://github.com/Cantera/cantera/issues/1607 For the moment, I would suggest to set - cantera>=2.5.1, <3.0.0 in environment.yml

dcmvdbekerom avatar Aug 27 '23 22:08 dcmvdbekerom

@menasrac I believe the issue with test_gascomp.py is on Cantera's end, see also this issue I opened there: Cantera/cantera#1607 For the moment, I would suggest to set - cantera>=2.5.1, <3.0.0 in environment.yml

I tried your suggestion, the test passed indeed but other tests in calc.py and broadening.py failed after this modification @dcmvdbekerom

menasrac avatar Aug 27 '23 23:08 menasrac

A few issues remaining, sorted in order of priority

  • [ ] the file plot_Kurucz.py is still not running (see below)
  • [ ] There is no test of SpectrumFactory using atoms
  • [ ] fetch_databank() is not implemented for atoms (see below)
  • [ ] the calc_spectrum function is not compatible with atomic spectra

---- fetchdatabank() ----

from radis import SpectrumFactory
from astropy import units as u
sf = SpectrumFactory(wavelength_min=4165 * u.nm,
                     wavelength_max=4200 * u.nm,
                     species='Fe_I',
                     medium='air',
                     verbose=1,    # more for more details
                     )
sf.fetch_databank()

---- plot_kurucz.py ---- output

Traceback (most recent call last):

  File C:\Anaconda\envs\radis-Kurucz\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File c:\users\nicolas minesi\python\examples\plot_kurucz.py:6
    hdf5_path = fetch_kurucz('Fe_I')[0] # replace 'Fe_I' with atom and ionization_state

  File c:\users\nicolas minesi\python\radis\io\kurucz.py:21 in fetch_kurucz
    kurucz = AdBKurucz(species)

  File c:\users\nicolas minesi\python\radis\api\kuruczapi.py:36 in __init__
    self.pfTdat, self.pfdat = self.load_pf_Barklem2016()

  File c:\users\nicolas minesi\python\radis\api\kuruczapi.py:99 in load_pf_Barklem2016
    with open(file_path, "r") as file:

FileNotFoundError: [Errno 2] No such file or directory: 'radis/levels/pfTKurucz_values.txt'

minouHub avatar Aug 28 '23 10:08 minouHub

A few issues remaining, sorted in order of priority

  • [ ] the file plot_Kurucz.py is still not running (see below)
  • [ ] There is no test of SpectrumFactory using atoms
  • [ ] fetch_databank() is not implemented for atoms (see below)
  • [ ] the calc_spectrum function is not compatible with atomic spectra

---- fetchdatabank() ----

from radis import SpectrumFactory
from astropy import units as u
sf = SpectrumFactory(wavelength_min=4165 * u.nm,
                     wavelength_max=4200 * u.nm,
                     species='Fe_I',
                     medium='air',
                     verbose=1,    # more for more details
                     )
sf.fetch_databank()

---- plot_kurucz.py ---- output

Traceback (most recent call last):

  File C:\Anaconda\envs\radis-Kurucz\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File c:\users\nicolas minesi\python\examples\plot_kurucz.py:6
    hdf5_path = fetch_kurucz('Fe_I')[0] # replace 'Fe_I' with atom and ionization_state

  File c:\users\nicolas minesi\python\radis\io\kurucz.py:21 in fetch_kurucz
    kurucz = AdBKurucz(species)

  File c:\users\nicolas minesi\python\radis\api\kuruczapi.py:36 in __init__
    self.pfTdat, self.pfdat = self.load_pf_Barklem2016()

  File c:\users\nicolas minesi\python\radis\api\kuruczapi.py:99 in load_pf_Barklem2016
    with open(file_path, "r") as file:

FileNotFoundError: [Errno 2] No such file or directory: 'radis/levels/pfTKurucz_values.txt'

Fetch databank is not implemented for atoms, however load_databank works with atoms as in the plot_kurucz examples. You have to mention sf.load_databank(path=hdf5_path, format='kurucz',parfuncfmt='kurucz') @minouHub

menasrac avatar Aug 28 '23 17:08 menasrac

A few issues remaining, sorted in order of priority

  • [ ] the file plot_Kurucz.py is still not running (see below)
  • [ ] There is no test of SpectrumFactory using atoms
  • [ ] fetch_databank() is not implemented for atoms (see below)
  • [ ] the calc_spectrum function is not compatible with atomic spectra

---- fetchdatabank() ----

from radis import SpectrumFactory
from astropy import units as u
sf = SpectrumFactory(wavelength_min=4165 * u.nm,
                     wavelength_max=4200 * u.nm,
                     species='Fe_I',
                     medium='air',
                     verbose=1,    # more for more details
                     )
sf.fetch_databank()

---- plot_kurucz.py ---- output

Traceback (most recent call last):

  File C:\Anaconda\envs\radis-Kurucz\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File c:\users\nicolas minesi\python\examples\plot_kurucz.py:6
    hdf5_path = fetch_kurucz('Fe_I')[0] # replace 'Fe_I' with atom and ionization_state

  File c:\users\nicolas minesi\python\radis\io\kurucz.py:21 in fetch_kurucz
    kurucz = AdBKurucz(species)

  File c:\users\nicolas minesi\python\radis\api\kuruczapi.py:36 in __init__
    self.pfTdat, self.pfdat = self.load_pf_Barklem2016()

  File c:\users\nicolas minesi\python\radis\api\kuruczapi.py:99 in load_pf_Barklem2016
    with open(file_path, "r") as file:

FileNotFoundError: [Errno 2] No such file or directory: 'radis/levels/pfTKurucz_values.txt'

Fetch databank is not implemented for atoms, however load_databank works with atoms as in the plot_kurucz examples. You have to mention sf.load_databank(path=hdf5_path, format='kurucz',parfuncfmt='kurucz') @minouHub

I have also added a test for fetch_kurucz. Though it is not directly a test for load_databank, it still asserts that the df which will be used by calc_spectrum contains all the required columns

menasrac avatar Aug 28 '23 18:08 menasrac

@menasrac please add a runnable test code in the PR main text so we can test it

erwanp avatar Aug 28 '23 20:08 erwanp

New work on this branch - see #652

minouHub avatar Jun 04 '24 16:06 minouHub