dfm / python-fsps

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

Import error in isochrones method #143

Closed dfm closed 3 years ago

dfm commented 3 years ago

I have installed FSPS using "python -m pip install fsps==0.3.0rc1"

Now when I am running the code written as

sps = fsps.StellarPopulation(zcontinuous=1)
sps.params['imf_type'] = 0   # Salpeter IMF
sps.params['sfh'] = 1  # Tau model SFH
iso = sps.isochrones()
print(iso)

getting the error

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-f05bfc0d10d8> in <module>
----> 1 iso = sps.isochrones()
      2 print(iso)

~/anaconda3/lib/python3.7/site-packages/fsps/fsps.py in isochrones(self, outfile)
    848             self._compute_csp()
    849 
--> 850         from . import ev, list_filters
    851 
    852         absfile = os.path.join(ev, "OUTPUTS", outfile + ".cmd")

ImportError: cannot import name 'ev' from 'fsps' (/home/khushboo_astro/anaconda3/lib/python3.7/site-packages/fsps/__init__.py)
---------------------------------------------------------------------------------

I am not able to understand how to resolve this error. Any suggestions would be appreciated. Thanks!

Originally posted by @Dh-hgi in https://github.com/dfm/python-fsps/issues/141#issuecomment-786569880

dfm commented 3 years ago

I think this should be fixed by changing the lines

from . import ev, list_filters

absfile = os.path.join(ev, "OUTPUTS", outfile + ".cmd")

to

from . import list_filters

absfile = os.path.join(os.environ["SPS_HOME"], "OUTPUTS", outfile + ".cmd")

We should also audit the code to see if this hanging import is anywhere else and the isochrones method should also have a test!

I'll try to fix it next week, but I'd also be happy to review a pull request!

ghost commented 3 years ago

Hi @dfm, I have tried making the suggested changes in the fsps.py file, but this is not resolving the issue.

bd-j commented 3 years ago

I tried the suggested changes and it worked for me (PR coming soon). Also, just to note that the value of params["sfh"] is irrelevant for isochrones(); only parameters listed in params.ssp_params matter and the weights only come from the IMF, not from the SFH.

bd-j commented 3 years ago

Also I don't see ev anywhere else in the code.