SME icon indicating copy to clipboard operation
SME copied to clipboard

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

Open MingjieJian opened this issue 1 year ago • 0 comments

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

MingjieJian avatar Oct 27 '22 08:10 MingjieJian