Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kurucz spectrum #601

Draft
wants to merge 84 commits into
base: develop
Choose a base branch
from
Draft

Kurucz spectrum #601

wants to merge 84 commits into from

Conversation

menasrac
Copy link
Collaborator

@menasrac menasrac commented Aug 2, 2023

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 #

Copy link
Member

@erwanp erwanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

environment.yml Outdated Show resolved Hide resolved
examples/calc_spectrumkurucz.py Outdated Show resolved Hide resolved
examples/calc_spectrumkurucz.py Outdated Show resolved Hide resolved
examples/calc_spectrumkurucz.py Outdated Show resolved Hide resolved
examples/calc_spectrumkurucz.py Outdated Show resolved Hide resolved
radis/lbl/loader.py Show resolved Hide resolved
ionization_state = '00' # adjust as needed

# Create a spectrum factory
sf = SpectrumFactory(wavenum_min, wavenum_max, atom=atom, ionization_state=ionization_state, wstep="auto")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lineshape_optimization / optimization parameter in SpectrumFactory. It is designed for molecular spectra with millions of lines. I think it will slow your calculations with Kuruzc. Set it to None, compare calculation times.

In calc_spectrum you'll set the default based on the input parameters (I.e None for atomic spectra)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try with a None input and compare the runtime

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't change much, the runtime is sometimes even longer @erwanp

radis/lbl/factory.py Outdated Show resolved Hide resolved
radis/lbl/loader.py Outdated Show resolved Hide resolved
radis/test/io/test_kurucz.py Outdated Show resolved Hide resolved
Copy link
Member

@erwanp erwanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More comments.

I also cannot find the changes you must have made to the Partition functions to include the ones from Kuruzc

radis/lbl/base.py Outdated Show resolved Hide resolved
examples/calc_spectrumkurucz.py Outdated Show resolved Hide resolved
radis/lbl/broadening.py Outdated Show resolved Hide resolved
radis/lbl/broadening.py Outdated Show resolved Hide resolved
radis/lbl/broadening.py Outdated Show resolved Hide resolved
@minouHub minouHub self-requested a review August 3, 2023 09:07
@minouHub minouHub added this to the 0.16 milestone Aug 3, 2023
Copy link
Collaborator

@minouHub minouHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clean this PR. Notably:

  • remove all prints
  • delete pfdat.txt that is unnecessary. You can use git rm the_file_to_remove then git commit -am "removed duplicate pfdat"
  • move NIST_iE.txt to radis/db. You can use git mm old_loc new_loc then git commit -am "moved NIST_iE"
  • git revert to the files that you should not have modified
  • I proposed very minor commits so that it's easy to you to apply them ==> see printscreen below
    image

NIST_iE.txt Outdated Show resolved Hide resolved
pfdat.txt Outdated Show resolved Hide resolved
examples/calc_spectrumkurucz.py Outdated Show resolved Hide resolved
examples/plot_kuruczspec.py Outdated Show resolved Hide resolved
radis/lbl/base.py Outdated Show resolved Hide resolved
radis/lbl/broadening.py Outdated Show resolved Hide resolved
@@ -989,6 +1041,8 @@ def _check_accuracy(self, wstep):

# TODO: thresholds depend whether we're computing Transmittance/optically thin emission,
# for a homogeneous slab, or self-absorbed radiance combined with other slabs.
min_width = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
min_width = None

radis/lbl/broadening.py Outdated Show resolved Hide resolved
radis/lbl/loader.py Show resolved Hide resolved
radis/lbl/loader.py Outdated Show resolved Hide resolved
@minouHub minouHub marked this pull request as draft August 4, 2023 09:23
radis/lbl/base.py Outdated Show resolved Hide resolved
@@ -98,7 +98,7 @@ def load_pf_Barklem2016(self):
`Barklem & Collet (2016), Table 8 <https://doi.org/10.1051/0004-6361/201526961>`_

"""
file_path="radis/levels/pfTKurucz_values.txt"
file_path=r"radis/levels/pfTKurucz_values.txt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it an absolute path. There are some functions in Radis/dB and Radis/test/utils to get proper maths independently of 1) the working directory 2) your OS

)
+ "\n- under nonequilibrium: {0}".format(
MOLECULES_LIST_NONEQUILIBRIUM
if molecule is not None and species is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix molecule and/or species when reading the function parameters.

Then use one only through the whole code. Here you're still using both it makes the code hard to read.

You can rename the internal name to species to be very clear.

radis/lbl/loader.py Outdated Show resolved Hide resolved
@dcmvdbekerom
Copy link
Member

@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

@menasrac
Copy link
Collaborator Author

@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

requirements.txt Outdated Show resolved Hide resolved
@minouHub
Copy link
Collaborator

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'

@menasrac
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

@erwanp
Copy link
Member

erwanp commented Aug 28, 2023

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

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.

None yet

5 participants