timothydmorton / isochrones

Pythonic stellar model grid access; easy MCMC fitting of stellar properties
http://isochrones.readthedocs.org
MIT License
117 stars 63 forks source link

'NoneType' object has no attribute 'Nstars' error when running starfit #133

Open ehu-21 opened 4 years ago

ehu-21 commented 4 years ago

Dear Timothy,

I installed isochrones in ubuntu on a windows laptop and tried to run starfit in anaconda. I got the following error message:

Holoviews not imported. Some visualizations will not be available. PyMultiNest not imported. MultiNest fits will not work. 1 of 1: . Fitting . single starfit... single starfit calculation failed for .. Traceback (most recent call last): File "/home/elizabeth/anaconda3/envs/isochrones/lib/python3.8/site-packages/isochrones/starfit.py", line 96, in starfit mod.fit(verbose=verbose, overwrite=overwrite, kwargs) File "/home/elizabeth/anaconda3/envs/isochrones/lib/python3.8/site-packages/isochrones/starmodel.py", line 669, in fit return self.fit_mcmc(kwargs) File "/home/elizabeth/anaconda3/envs/isochrones/lib/python3.8/site-packages/isochrones/starmodel.py", line 887, in fit_mcmc return self.fit_mcmc_old(**kwargs) File "/home/elizabeth/anaconda3/envs/isochrones/lib/python3.8/site-packages/isochrones/starmodel.py", line 950, in fit_mcmc_old p0 = self.emcee_p0(nwalkers) File "/home/elizabeth/anaconda3/envs/isochrones/lib/python3.8/site-packages/isochrones/starmodel.py", line 859, in emceep0 for , n in self.obs.Nstars.items(): AttributeError: 'NoneType' object has no attribute 'Nstars'

When I looked at the starmodel.py code, it seems like the reason why starfit was failing is because the ObservationTree/ obs variable is empty. In the starmodel.py file, there's a definition called from_ini and from reading the comments in that definition, I think I need a obs.csv file to create the obs variable. Do you know how to fix this error?

Thanks, Elizabeth

RaynaRampalli commented 3 years ago

also had the same issue, any luck Elizabeth? Thanks!

awmann commented 3 years ago

I'm actually hitting the same problem. Interestingly, the code worked fine ~8 months ago. My suspicion is that this is a change in one of the dependencies, but the region around the call is not clear to me so I'm not even sure which dependency might be at fault (or even if this assumption is right).

timothydmorton commented 3 years ago

@ehu-21 @rrampall @awmann : Can you try using multinest rather than emcee? Also, try using SingleStarModel instead of StarModel. I'm not sure what your use case is, but StarModel uses the ObservationTree thing, and if you're just fitting an isolated (non-resolved) single (or binary or triple) system, you can use SingleStarmodel (or BinaryStarModel or TripleStarModel). Nonetheless, we should find this bug. Can one of you post a minimal self-contained example that demonstrates it? Thanks!

awmann commented 3 years ago

Hi Tim,

I encountered this simply running starfit (actually running vespa, which calls isochrones via starfit). I did try starfit --all vs starfit --triple vs others does not seem to change anything. Swapping to pymultinest seems to have fixed it. Or at least I think it did; I had to make a few other edits (e.g., 'df_list = [[self.df.ix[f,a]'-> 'df_list = [[self.df.loc[f,a]') but I'm pretty sure those are all unrelated.

RaynaRampalli commented 3 years ago

Hi All, I also ran starfit just following what you had under basic usage. I can't use multinest at the moment since there are some incompatibilities when I try to install/run it using the latest fortran compiler, but that's unrelated.

nielsenmb commented 3 years ago

Just a simple case that produces a similar error to the original issue. I might be doing something wrong, but simply tried to do something similar to one of the examples in the docs.

from isochrones import SingleStarModel, get_ichrone

mist = get_ichrone('mist', bands=['B','V'])

props = {'B': (8.37, 0.1),
               'V': (7.52, 0.1),
               'parallax': (36.9783, 0.0318),
               }

mod = SingleStarModel(mist, name='demo', **props, use_emcee=True)

Looks like an ObservationTree instance is not being created when initializing StarModel (or versions thereof).

I seems this is only an issue when initializing the model with use_emcee=True. While I haven't tried with MultiNest, it doesn't look like StarModel.fit_multinest uses the observationtree, whereas StarModel.fit_mcmc does.

This is with the GitHub version of Isochrones installed with pip.

timothydmorton commented 3 years ago

Hi all- Sorry for not having had the chance to look into this; just no free cycles these days. Hopefully next week I can take a day or two of isochrones-issue cleanup. A SingleStarModel shouldn't be trying to use an ObservationTree ever. Since I never use emcee really, I've probably neglected to implement some method or other for the BasicStarModel (/SingleStarModel), and it's defaulting back to the StarModel implementation that does use ObservationTree.