jvines / astroARIADNE

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

Multinest Error #30

Closed denizcdursun closed 2 years ago

denizcdursun commented 2 years ago

Hello,

I get this error when I run test_bma.py even though I have loaded and installed the module. what should I do?

ERROR: Could not load MultiNest library "libmultinest.so" ERROR: You have to build it first, and point the LD_LIBRARY_PATH environment variable to it!

jvines commented 2 years ago

Hi,

This is a typical problem with MultiNest, you need to properly install it and link the library to it. Instructions on how to build and install multinest can be found here

denizcdursun commented 2 years ago

Thank you for answer @jvines!

I have a quick question about star parameters. While values such as temperature, distance and Logg match well with in the literature, metallicity abundance value does not.

I'm studying for poor stars, but it shows metallicity abundance is high. How does the program reach the metallicity abundance value?

jvines commented 2 years ago

The thing is that SEDs don't constrain either Log g nor metallicity, so for a reasonable fit for metallicity I'd suggest using a prior other than the default one (i.e. setting a prior based on spectroscopy-derived metallicity or, if you know your stars are metal poor, then setting a prior for metallicity to be < 0)

More details on how ARIADNE works can be found on the paper

denizcdursun commented 2 years ago

Thank you very much for your message @jvines Since I study with are metal-poor stars ([Fe/H]<-1.5 dex), I will take your suggestion into consideration (i.e. setting a prior based on spectroscopy-derived metallicity or, if you know your stars are metal poor, then setting a prior for metallicity to be < 0) but I could not find which line to make this arrangement in the code. Can you help with this?

jvines commented 2 years ago

The readme has instructions on how to set priors, but here's the quick version:

f.prior_setup = {
    'teff': ('default'),
    'logg': ('default'),
    'z': ('normal', metallicity, uncertainty),
    'dist': ('default'),
    'rad': ('default'),
    'Av': ('default')
}

where metalicity is the value obtained from spectra and uncertainty its associated uncertainty

denizcdursun commented 2 years ago

Thank you for your previous reply @jvines I missed the readme file. I solved my problem, but I get a new error while plotting my output files.

Traceback (most recent call last):
   File "test_bma_2.py", line 77, in <module>
     artist = SEDPlotter(in_file, plots_out_folder, pdf=True)
   File "/Users/Deniz/Downloads/astroARIADNE-master/astroARIADNE/plotter.py", line 120, in __init__
     out = pickle.load(open(input_files, 'rb'))
FileNotFoundError: [Errno 2] No such file or directory: '/Users/Deniz/Downloads/astroARIADNE-master/outputs/BMA_out.pkl'

The file "BMA_out.pkl" was not created. I tried different stars and got the same error. Is there anything I can do?

jvines commented 2 years ago

Try changing the in_file for 'BMA.pkl' instead of 'BMA_out.pkl'

denizcdursun commented 2 years ago

Hello, thank you for your previous replies @jvines the program now works and I get the correct outputs.

In our research, we want to second fit the same SED model without extinction (Av=0). Is this possible for the program? If possible, how could it be?

jvines commented 2 years ago

Hi @denizcdursun , as per the instructions in the readme, you can put the prior as fixed and assign the value you want. In this case

f.prior_setup = {
    'teff': ('default'),
    'logg': ('default'),
    'z': ('default'),
    'dist': ('default'),
    'rad': ('default'),
    'Av': ('fixed', value)
}
denizcdursun commented 2 years ago

Thanks for your quick reply @jvines but you misunderstood me. I want to plot two different fits on the SED.pdf at the same time. Both Av=0 and Av=Default (two different SED fits (curves?). I couldn't find how to change it to the plot part.

jvines commented 2 years ago

My bad.

There's not a straightforward way to do that, since the plotter class reads one bma output at a time. The only solution I can think of right now is that you read the bma.pkl file and manually plot whatever you need. I'm sorry :(

denizcdursun commented 2 years ago

Hello @jvines,

In which part of the code should I use remove_mag or add_mag? Before fitter() or before fit_bma? I get an error when I put it before Estimate_log.

I have my own observational brightness values, I can easily add them. I also want to clear some bad points in the SED.

I had no problem adding it, but when I delete it, I get an error. I think I didn't put it in the right place.

jvines commented 2 years ago

Please include the error message of ‘remove_mag’ and an example of the script, otherwise I won’t be able to find out what’s wrong

denizcdursun commented 2 years ago

Please include the error message of ‘remove_mag’ and an example of the script, otherwise I won’t be able to find out what’s wrong

                    Estimated log g : 4.428 +/- 0.143

Creation of the directory /Users/Deniz/Downloads/astroARIADNE-master/outputs failed. It might already exist /Users/Deniz/Downloads/astroARIADNE-master/astroARIADNE/fitter.py:467: RuntimeWarning: divide by zero encountered in double_scalars b = (1 - flx) / flx_e

            *** EXECUTING MAIN FITTING ROUTINE ***
                    Selected engine : Bayesian Model Averaging
                    Live points : 100
                    log Evidence tolerance : 0.5
                    Free parameters : 24
                    Bounding : multi
                    Sampling : rwalk
                    N threads : 4

                    FITTING MODEL : ck04

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py:2129: RuntimeWarning: invalid value encountered in multiply upper_bound = _b scale + loc /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py:2129: RuntimeWarning: invalid value encountered in multiply upper_bound = _b scale + loc /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py:2129: RuntimeWarning: invalid value encountered in multiply upper_bound = _b scale + loc /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py:2129: RuntimeWarning: invalid value encountered in multiply upper_bound = _b scale + loc /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py:2129: RuntimeWarning: invalid value encountered in multiply upper_bound = _b scale + loc /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py:2129: RuntimeWarning: invalid value encountered in multiply upper_bound = _b scale + loc /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py:2129: RuntimeWarning: invalid value encountered in multiply upper_bound = _b scale + loc /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/scipy/stats/_distn_infrastructure.py:2129: RuntimeWarning: invalid value encountered in multiply upper_bound = _b scale + loc Traceback (most recent call last): File "test_bma_2.py", line 78, in f.fit_bma() # Begin fit! File "/Users/Deniz/Downloads/astroARIADNE-master/astroARIADNE/fitter.py", line 568, in fit_bma self.fit_dynesty(out_file=out_file) File "/Users/Deniz/Downloads/astroARIADNE-master/astroARIADNE/fitter.py", line 714, in fit_dynesty queue_size=self._threads - 1, File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/dynesty/dynesty.py", line 613, in NestedSampler 'prior_transform', True)) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/dynesty/dynamicsampler.py", line 392, in initialize_live_points "log-likelihood.", n_attempts)) RuntimeError: After 100 attempts, not a single live point had a valid log-likelihood! Please check your prior transform and/or log-likelihood.

jvines commented 2 years ago

I don’t see where are you running remove_mag there. The error seems unrelated to that.

can you provide the script you’re running? And please wrap errors and code with backtics (`) in order to make them more readable here! With 3 backticks (```) you start a multiline block of code

denizcdursun commented 2 years ago

Thank you for quick answer. It works fine when I don't add s.remove_mag('SDSS_g')



try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context
from astroARIADNE.fitter import Fitter
from astroARIADNE.plotter import SEDPlotter
from astroARIADNE.star import Star
#from dustmaps.config import config
#config.reset()

if __name__ == '__main__':
    starname = 'HD 284248'
    ra = 63.6479583
    dec = 22.3511806
    gaia_id = 52624073910834176

    s = Star(starname, ra, dec, g_id=gaia_id)
    #s.add_mag(13.751, 0.032, 'PS1_r')
    s.remove_mag('SDSS_g')
    s.remove_mag('STROMGEN_y')
    s.remove_mag('SDSS_i')
    s.print_mags()

    # Comment to use a custom log g prior or the default prior
    s.estimate_logg()

    # Output setup
    out_folder = '/Users/Deniz/Downloads/astroARIADNE-master/outputs'
    in_file = out_folder + '/BMA.pkl'  # used as input for plotting
    plots_out_folder = out_folder + '/plots'

    # Setup parameters
    engine = 'dynesty'  # Only dynesty is available for BMA
    nlive = 100  # number of live points to use
    dlogz = 0.5  # evidence tolerance
    bound = 'multi'  # Unit cube bounds. Options are multi, single
    sample = 'rwalk'  # Sampling method. Options are rwalk, unif
    threads = 4  # Number of threads to use.
    dynamic = False  # Use dynamic nested sampling?
    setup = [engine, nlive, dlogz, bound, sample, threads, dynamic]
    models = [
        #'phoenix',
        #'btsettl',
        #'btnextgen',
        'btcond',
        #'kurucz',
        'ck04',
    ]

    # Now to setup the fitter and run the modelling.
    f = Fitter()
    f.star = s
    f.setup = setup
    f.norm = False  # fit normalization constant instead of radius + distance
    f.av_law = 'fitzpatrick'
    f.verbose = True
    f.out_folder = out_folder
    f.bma = True
    f.models = models
    f.n_samples = 100000  # If set as None it will choose automatically.
    f.prior_setup = {
        'teff': ('default'),
        'logg': ('default'),
        'z': ('normal', -1.62, 0.05),
        #'z': ('default'),
        'dist': ('default'),
        'rad': ('default'),
        'Av': ('default')
    }

    f.initialize()
    f.fit_bma()  # Begin fit!

    # Setting up plotter, which is independent to the main fitting routine
    # Bear in mind this will only work if you have downloaded the models
    # And have set up the ARIADNE_MODELS environment variable!

    artist = SEDPlotter(in_file, plots_out_folder, pdf=True)
    artist.plot_SED_no_model()  # Plots the stellar SED without the model
    artist.plot_SED()  # Plots stellar SED with model included
    artist.plot_bma_hist()  # Plots bayesian model averaging histograms
    artist.plot_bma_HR(10)  # Plots HR diagram with 10 samples from posterior
    artist.plot_corner()  # Corner plot of the posterior parameters```
jvines commented 2 years ago

When I run s.remove_mag('SDSS_g') I can see the value has been correctly removed from the photometry pool:

             Filter         Magnitude   Uncertainty
        ----------------    ---------   -----------
          STROMGREN_u        10.6270      0.0450
        GROUND_JOHNSON_U     9.4900       0.0000
          STROMGREN_v        9.9450       0.0257
          TYCHO_B_MvB        9.6730       0.0230
        GROUND_JOHNSON_B     9.6350       0.0210
          STROMGREN_b        9.5520       0.0172
             SDSS_g          10.0690      0.0200
          GaiaDR2v2_BP       9.3502       0.0009
          TYCHO_V_MvB        9.3140       0.0190
          STROMGREN_y        9.2300       0.0140
        GROUND_JOHNSON_V     9.2550       0.0190
          GaiaDR2v2_G        9.0847       0.0002
             SDSS_i          10.1430      0.0000
          GaiaDR2v2_RP       8.6841       0.0009
            2MASS_J          8.1650       0.0180
            2MASS_H          7.9270       0.0230
            2MASS_Ks         7.8710       0.0230
          WISE_RSR_W1        7.8360       0.0270
          WISE_RSR_W2        7.8530       0.0210

             Filter         Magnitude   Uncertainty
        ----------------    ---------   -----------
          STROMGREN_u        10.6270      0.0450
        GROUND_JOHNSON_U     9.4900       0.0000
          STROMGREN_v        9.9450       0.0257
          TYCHO_B_MvB        9.6730       0.0230
        GROUND_JOHNSON_B     9.6350       0.0210
          STROMGREN_b        9.5520       0.0172
          GaiaDR2v2_BP       9.3502       0.0009
          TYCHO_V_MvB        9.3140       0.0190
          STROMGREN_y        9.2300       0.0140
        GROUND_JOHNSON_V     9.2550       0.0190
          GaiaDR2v2_G        9.0847       0.0002
             SDSS_i          10.1430      0.0000
          GaiaDR2v2_RP       8.6841       0.0009
            2MASS_J          8.1650       0.0180
            2MASS_H          7.9270       0.0230
            2MASS_Ks         7.8710       0.0230
          WISE_RSR_W1        7.8360       0.0270
          WISE_RSR_W2        7.8530       0.0210

First is after creating the Star object, second is s.print_mags() after removing SDSS_g

Sadly right now I can't test if the fit works as I'm working on an update and ARIADNE is currently broken :(

Does the fit run correctly if you don't remove SDSS_g but something else??

denizcdursun commented 2 years ago

Yes the fit run correctly if I don't remove any magnitude. The code gave all histograms and SED images.

I printed mags twice (before/after) its correctly deleted. But I get same error: /Users/Deniz/Downloads/astroARIADNE-master/astroARIADNE/fitter.py:467: RuntimeWarning: divide by zero encountered in double_scalars b = (1 - flx) / flx_e

I guess when I clear the brightness the value becomes zero and there is a division by 0 error. I want to disable it completely when I delete it.

jvines commented 2 years ago

Indeed removing the value completely is the expected behavior. I can’t debug this at the moment. As a workaround I recommend adding the relevant catalogs (probably apass) to the ignore list and manually add the magnitudes you need.

I’ll let you know once I’ve looked into this

denizcdursun commented 2 years ago

Hello @jvines, any progress on this issue? (to ignore inaccurate measured magnitude values ​​that distort the SED)

jvines commented 2 years ago

Hi.

I haven't been able to work on this. In the meantime try bypassing the problem with my above response.

jvines commented 2 years ago

Hi @denizcdursun , I'm happy to inform you that the issue has been addressed and fixed and will be available with the next version.

jvines commented 2 years ago

Closed with b3ebaf9efff7accd69002df9340b350cf0a7d684