dfm / python-fsps

Python bindings to Charlie Conroy's Flexible Stellar Population Synthesis (FSPS) Fortran code
https://python-fsps.readthedocs.io
MIT License
66 stars 38 forks source link

v0.4.2 dev: nebular emission not properly added for very young stellar populations #192

Closed zychen-astro closed 2 years ago

zychen-astro commented 2 years ago

Hi,

I used python-fsps to produce the SEDs for a 3 Myr CSFH, but the output spectrum does not look quite right -- the emission lines are too weak and the nebular continuum is not added. But I checked that the add_neb_emission, add_neb_continuum, and nebemlineinspec are all turned on.

The used python-fsps version is the current dev version, and I tested with $SPS_HOME to both the one in the python-fsps directory, and the FSPS I installed separately.

However, when another member of the team ran the same code on another machine, the results looks reasonable (i.e., compared to another code). I am wondering if there is some configuration issue with my own installment of the package (fsps, python-fsps, and prospector).

Thanks! Zuyi

The code to reproduce the issue are as follows, and the resulting SEDs are also shown (with and without nebular emission)

import fsps

t_age = 3*1e-3
sp = fsps.StellarPopulation(tage = t_age, imf_type = 1, sfh=1, const=1, zcontinuous = 1, logzsol=-0.7)

sp.params['add_neb_emission'] = True
sp.params['add_neb_continuum'] = True
sp.params['nebemlineinspec'] = True
wl_neb, flux_neb = sp.get_spectrum(tage=t_age)

sp.params['add_neb_emission'] = False
sp.params['add_neb_continuum'] = False
sp.params['nebemlineinspec'] = False
wl_noneb, flux_noneb = sp.get_spectrum(tage=t_age)

plt.plot(wl_neb,flux_neb,label='With neb')
plt.plot(wl_noneb,flux_noneb,label='No neb')

plt.xlim(3000,6000)
plt.ylim(0.3e-13,1.5e-13)
plt.legend()
plt.xlabel('Wavelength')

plt.ylabel('Flux')
# plt.savefig('sed_young.png',dpi=100)

sed_young

zychen-astro commented 2 years ago

Updates:

The previous plot was generated with prospect and python-fsps version of

prospect 1.1.0 
fsps 0.4.2.dev20+g8476280

But they worked fine when I install the stable version of python-fsps (see attached figure)

prospect 1.1.0
fsps 0.4.1

But I need the 0.4.2 dev version of python-fsps as I hope to adopt the SMC attenuation curve. Is there a issue with the 0.4.2 dev version?

image

dfm commented 2 years ago

Thanks! I assume this is something to do with a version mismatch between FSPS and the Python bindings, but @bd-j will be able to say more, I'm sure.

bd-j commented 2 years ago

sorry for the slow reply. Trying to track this down, it appears to have been introduced somewhere between 3297748 (correct nebular lines) and 2b61492 (incorrect nebular lines). The only actual change to the source code there was to FSPS itself - some unintended changes were made and then supposedly reverted (manually), but the add_nebular module was potentially affected. Strange.

anyway, till I get this sorted in FSPS you can, in the python-fsps repo, do

git checkout 3297748
git submodule update
python -m pip install .
bd-j commented 2 years ago

ok, I found the bug in FSPS. I'll update there and run the update fsps workflow (which is still failing to build wheels on either macos or windows depending on the workflow we use)

bd-j commented 2 years ago

@zychen-astro This should now be resolved by #190, it at least works for me locally. In the python-fsps repo

git checkout main
git pull
git submodule update
python -m pip uninstall fsps
python -m pip install .
zychen-astro commented 2 years ago

Thank you, Ben and Dan! I confirmed that the nebular emission works as expected. I'll close this issue now.