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

The flags in _smelib.GetNLTEflags() is not restored to 0 after NLTE runs #50

Open
MingjieJian opened this issue Oct 27, 2022 · 0 comments

Comments

@MingjieJian
Copy link

Hi Ansgar,

I am now using pySME to perform some abundance analysis, and I found that if I create two different SME_Struct() objects and perform LTE and NLTE spectrum synthesis, the flags in _smelib.GetNLTEflags() are always in the NLTE case so that if I run the LTE SME_Struct() again, the result will remain in NLTE even if the elements and grids in the LTE SME_Struct() are empty.

I am not sure if this is a bug or if I am not using pySME as designed. Now I import _smelib and run _smelib.ResetDepartureCoefficients() right before the SME_Struct() is created to make sure the flags are correct.

Here is the minimum code block which can recurrent this situation:

import matplotlib.pyplot as plt
# import pySME
from pysme.sme import SME_Structure as SME_Struct
from pysme.abund import Abund
from pysme.linelist.vald import ValdFile
from pysme.synthesize import synthesize_spectrum
from pysme.smelib import _smelib

teff, logg = 5000, 2.0
vald = ValdFile("Li_vald")

plt.figure(figsize=(15,3), dpi=150)

sme_lte = SME_Struct()
# If the next line is commented, the result will be as Figure 1; if not, then Figure 2.
_smelib.ResetDepartureCoefficients()
sme_lte.teff, sme_lte.logg, sme_lte.monh = teff, logg, 0
sme_lte.abund = Abund.solar()
sme_lte.linelist = vald
sme_lte.wran = [[6706, 6710]]
sme_lte = synthesize_spectrum(sme_lte)

sme_nlte = SME_Struct()
_smelib.ResetDepartureCoefficients()
sme_nlte.teff, sme_nlte.logg, sme_nlte.monh = teff, logg, 0
sme_nlte.abund = Abund.solar()
sme_nlte.linelist = vald
sme_nlte.wran = [[6706, 6710]]
sme_nlte.nlte.set_nlte("Li", "marcs2012_Li.grd")

sme_nlte = synthesize_spectrum(sme_nlte)

plt.plot(sme_lte.wave[0], sme_lte.synth[0], label='LTE', alpha=0.5)
plt.plot(sme_nlte.wave[0], sme_nlte.synth[0], label='NLTE', alpha=0.5)

plt.axvline(6707.79)

plt.ylim(0.8, 1.02)
plt.xlim(6707, 6709)
plt.legend()

image
Figure 1: LTE and NLTE synthetic spectra are the same when ResetDepartureCoefficients is not executed

image
Figure 2: LTE and NLTE synthetic spectra are different when ResetDepartureCoefficients is executed

Best,
Mingjie

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

No branches or pull requests

1 participant