jvines / astroARIADNE

Easy stellar SED fitting!
MIT License
56 stars 7 forks source link

An error when I fitted the age and mass #45

Closed ShenDongxiang closed 1 year ago

ShenDongxiang commented 1 year ago

Hello @jvines : Happy new year! I'm trying to repeat the example that you show in the introduction in astroARIANDE, however, I meet a question. Can you help me to solve it? The detail as follows:

from astroARIADNE.star import Star ra = 75.795 dec = -30.399 starname = "NGTS-6" gaia_id = 4875693023844840448 s = Star(starname, ra, dec, g_id=gaia_id, dustmap="Bayestar")

    #####################################
    ##             ARIADNE             ##
    #####################################
        Author : Jose Vines
        Contact : jose . vines at ug . uchile . cl
        Star : NGTS-6
    *** LOOKING UP ARCHIVAL INFORMATION ***
        Gaia DR3 ID : 4875693023844840448
        TIC : 1528696
        Gaia Effective temperature : 4975.000 +/- 104.390
        Gaia Stellar radius : 0.656 +/- 0.141
        Gaia Stellar Luminosity : 0.238 +/- 0.003
        Gaia Parallax : 3.306 +/- 0.013
        Bailer-Jones distance : 303.932 +/- 1.190
        Maximum Av : 0.015

           Filter           Magnitude   Uncertainty
    --------------------    ---------   -----------
         GALEX_NUV           21.9520      0.4090   
      GROUND_JOHNSON_B       15.1710      0.0140   
           SDSS_g            14.6390      0.0580   
        GaiaDR2v2_BP         14.3654      0.0040   
      GROUND_JOHNSON_V       14.0870      0.0210   
           SDSS_r            13.7030      0.0320   
        GaiaDR2v2_G          13.8020      0.0028   
           SDSS_i            13.3780      0.0570   
        GaiaDR2v2_RP         13.0970      0.0040   
            TESS             13.1686      0.0062   
          2MASS_J            12.2220      0.0330   
          2MASS_H            11.7670      0.0380   
          2MASS_Ks           11.6500      0.0320   
        WISE_RSR_W1          11.5550      0.0270   
        WISE_RSR_W2          11.6360      0.0270  

from astroARIADNE.fitter import Fitter out_folder = "/home/sdx/data/magnetic_variables/SED_data/test/" engine = "dynesty" nlive = 500 dlogz = 0.5 bound = 'multi' sample = 'rwalk' threads = 4 dynamic = False setup = [engine, nlive, dlogz, bound, sample, threads, dynamic] models = ["phoenix","btsettl", "btnextgen", "btcond", "kurucz", "ck04"]

f = Fitter() f.star = s f.setup = setup f.av_law = "fitzpatrick" f.out_folder = out_folder f.bma = True f.models = models f.n_samples = 100000 f.prior_setup = {"teff":("normal", 5600, 100), 'logg':('default'), 'z':('default'), 'dist':('default'), 'rad':('default'), 'Av':("fixed", 0.0) } f.initialize()

        *** EXECUTING MAIN FITTING ROUTINE ***
            Selected engine : Bayesian Model Averaging
            Live points : 500
            log Evidence tolerance : 0.5
            Free parameters : 21
            Bounding : multi
            Sampling : rwalk
            N threads : 4
`f.fit_bma()`
            FITTING MODEL : phoenix
13039it [02:17, 94.55it/s, +500 | bound: 152 | nc: 1 | ncall: 300144 | eff(%):  4.518 | loglstar:   -inf < 393.231 <    inf | logz: 367.803 +/-  0.224 | dlogz:  0.001 >  0.500]   
            FITTING MODEL : btsettl
13396it [02:23, 93.09it/s, +500 | bound: 158 | nc: 1 | ncall: 310992 | eff(%):  4.475 | loglstar:   -inf < 393.347 <    inf | logz: 367.112 +/-    nan | dlogz:  0.001 >  0.500]    
            FITTING MODEL : kurucz
13839it [02:33, 90.21it/s, +500 | bound: 165 | nc: 1 | ncall: 321263 | eff(%):  4.470 | loglstar:   -inf < 393.767 <    inf | logz: 366.603 +/-    nan | dlogz:  0.001 >  0.500]    
            FITTING MODEL : ck04
14482it [02:37, 92.06it/s, +500 | bound: 172 | nc: 1 | ncall: 335799 | eff(%):  4.468 | loglstar:   -inf < 392.879 <    inf | logz: 364.499 +/-    nan | dlogz:  0.001 >  0.500]    
        *** AVERAGING POSTERIOR SAMPLES ***
100%|███████████████████████████████████████████| 26/26 [00:00<00:00, 61.64it/s]
        *** ESTIMATING AGE AND MASS USING MIST ISOCHRONES ***
/home/sdx/.local/lib/python3.8/site-packages/dynesty/dynamicsampler.py:446: RuntimeWarning: All the initial likelihood values are the same. You likely have a plateau in the likelihood. Nested sampling is *NOT* guaranteed to work in this case
  warnings.warn(
0it [00:00, ?it/s]
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 f.fit_bma()

File /usr/local/lib/python3.8/dist-packages/astroARIADNE-1.0.9-py3.8.egg/astroARIADNE/fitter.py:590, in Fitter.fit_bma(self)
    587 c = np.random.choice(self.colors)
    588 avgd = self.bayesian_model_average(outs, self._grids, self._norm,
    589                                    self.n_samples, c)
--> 590 self.save_bma(avgd)
    592 elapsed_time = execution_time(self.start)
    593 end(self.coordinator, elapsed_time, self.out_folder,
    594     'Bayesian Model Averaging', self.norm)

File /usr/local/lib/python3.8/dist-packages/astroARIADNE-1.0.9-py3.8.egg/astroARIADNE/fitter.py:1120, in Fitter.save_bma(self, avgd)
   1114     logdat_average = out_filler(sampw, logdat_average, 'AD', 'AD', out,
   1115                                 method='averaged')
   1117 # Add estimated age to best fit dictionary. This is done with the wider
   1118 # sampled distribution instead of the averaged one in order to save time
-> 1120 age_samp, mass_samp, eep_samp = self.estimate_age(
   1121     out['best_fit_samples'],
   1122     out['uncertainties_samples'],
   1123     c=choice(self.colors)
   1124 )
   1125 # Create new thingy for MIST samples. Sadly now everything done before
   1126 # this update will be incompatible :(
   1127 out['mist_samples'] = dict()

File /usr/local/lib/python3.8/dist-packages/astroARIADNE-1.0.9-py3.8.egg/astroARIADNE/fitter.py:1457, in Fitter.estimate_age(self, bf, unc, c)
   1454         params[b] = (m, e)
   1455         used_bands.append(b)
-> 1457 age_samp, mass_samp, eep_samp = estimate(used_bands, params, logg=False)
   1459 return age_samp, mass_samp, eep_samp

File /usr/local/lib/python3.8/dist-packages/astroARIADNE-1.0.9-py3.8.egg/astroARIADNE/isochrone.py:66, in estimate(bands, params, logg, out_folder)
     59 sampler = dynesty.NestedSampler(
     60     loglike, prior_transform, model.n_params + len(bands),
     61     nlive=500, bound='multi', sample='rwalk',
     62     logl_args=([model, params, bands]),
     63     ptform_args=([model])
     64 )
     65 try:
---> 66     sampler.run_nested(dlogz=0.01)
     67 except ValueError as e:
     68     dump_out = f'{out_folder}/isochrone_DUMP.pkl'

File ~/.local/lib/python3.8/site-packages/dynesty/sampler.py:952, in Sampler.run_nested(self, maxiter, maxcall, dlogz, logl_max, n_effective, add_live, print_progress, print_func, save_bounds, checkpoint_file, checkpoint_every, resume)
    950 try:
    951     ncall = self.ncall
--> 952     for it, results in enumerate(
    953             self.sample(maxiter=maxiter,
    954                         maxcall=maxcall,
    955                         dlogz=dlogz,
    956                         logl_max=logl_max,
    957                         save_bounds=save_bounds,
    958                         save_samples=True,
    959                         n_effective=n_effective,
    960                         resume=resume,
    961                         add_live=add_live)):
    962         ncall += results.nc
    964         # Print progress.

File ~/.local/lib/python3.8/site-packages/dynesty/sampler.py:778, in Sampler.sample(self, maxiter, maxcall, dlogz, logl_max, n_effective, add_live, save_bounds, save_samples, resume)
    773     old_blob = None
    775 # Sample a new live point from within the likelihood constraint
    776 # `logl > loglstar` using the bounding distribution and sampling
    777 # method from our sampler.
--> 778 u, v, logl, nc = self._new_point(loglstar_new)
    779 ncall += nc
    780 self.ncall += nc

File ~/.local/lib/python3.8/site-packages/dynesty/sampler.py:385, in Sampler._new_point(self, loglstar)
    382 ncall, nupdate = 0, 0
    383 while True:
    384     # Get the next point from the queue
--> 385     u, v, logl, nc, blob = self._get_point_value(loglstar)
    386     ncall += nc
    388     # Bounding checks.

File ~/.local/lib/python3.8/site-packages/dynesty/sampler.py:368, in Sampler._get_point_value(self, loglstar)
    366 # If the queue is empty, refill it.
    367 if self.nqueue <= 0:
--> 368     self._fill_queue(loglstar)
    370 # Grab the earliest entry.
    371 u, v, logl, nc, blob = self.queue.pop(0)

File ~/.local/lib/python3.8/site-packages/dynesty/sampler.py:311, in Sampler._fill_queue(self, loglstar)
    309     args = (np.nonzero(self.live_logl > loglstar)[0], )
    310     if len(args[0]) == 0:
--> 311         raise RuntimeError(
    312             'No live points are above loglstar. '
    313             'Do you have a likelihood plateau ? '
    314             'It is also possible that you are trying to sample '
    315             'excessively around the very peak of the posterior')
    316 else:
    317     args = ()

RuntimeError: No live points are above loglstar. Do you have a likelihood plateau ? It is also possible that you are trying to sample excessively around the very peak of the posterior
denizcdursun commented 1 year ago

Hello @ShenDongxiang , I think your problem is:

'Av':("fixed", 0.0) on the line. 'Av':("fixed", 0) or 'Av': ('default') should be. I get the same error sometimes. Changing it with these values fixes your problem.

jvines commented 1 year ago

@ShenDongxiang Hi, sorry, I didn't see this bug until now.

I'll try to check it out ASAP, but can't make any promises as I'm currently writing my thesis and that's got me quite busy.

What @denizcdursun says sounds weird to me, but it's worth a shot looking into. If that's indeed the source of the bug, please let me know so I can investigate further.

denizcdursun commented 1 year ago

What @denizcdursun says sounds weird to me, but it's worth a shot looking into. If that's indeed the source of the bug, please let me know so I can investigate further.

I'll add the screenshot here when I get the similar error again.

ShenDongxiang commented 1 year ago

Hello, @denizcdursun : Thank you very much for the method you provided. I modified my code according to the method you said, however, the same error was still occurred.

jvines commented 1 year ago

I figured it wouldn't fix anything. It doesn't make much sense. Does the error happen every time you run ariadne? with every star?

jvines commented 1 year ago

This has been dormant for a while so I'll close it. Feel free to reopen if needed.