Fitting photometry with model spectra — species 0.1.2 documentation

# Fitting photometry with model spectra

    [1]:

    import species
    from IPython.display import Image

    [2]:

    species.SpeciesInit()

    Initiating species v0.1.0... [DONE]
    Creating species_config.ini... [DONE]
    Creating species_database.hdf5... [DONE]
    Creating data folder... [DONE]

    [2]:

    <species.core.setup.SpeciesInit at 0x12a338320>

    [3]:

    database = species.Database()

    [4]:

    database.add_model(model='drift-phoenix',
                       wavel_range=None,
                       spec_res=None
                       teff_range=None)

    Downloading DRIFT-PHOENIX model spectra (151 MB)... [DONE]
    Unpacking DRIFT-PHOENIX model spectra... [DONE]
    Adding DRIFT-PHOENIX model spectra... [DONE]

    [5]:

    database.add_companion(name='beta Pic b')

    Adding filter: LCO/VisAO.Ys... [DONE]
    Downloading Vega spectrum (270 kB)... [DONE]
    Adding Vega spectrum...[DONE]
    Adding filter: Paranal/NACO.J... [DONE]
    Adding filter: Gemini/NICI.ED286... [DONE]
    Adding filter: Paranal/NACO.H... [DONE]
    Adding filter: Paranal/NACO.Ks... [DONE]
    Adding filter: Paranal/NACO.NB374... [DONE]
    Adding filter: Paranal/NACO.Lp... [DONE]
    Adding filter: Paranal/NACO.NB405... [DONE]
    Adding filter: Paranal/NACO.Mp... [DONE]
    Adding object: beta Pic b... [DONE]

    [6]:

    objectbox = database.get_object(object_name='beta Pic b',
                                    filters=None,
                                    inc_phot=True,
                                    inc_spec=False)

    Getting object: beta Pic b... [DONE]

    [7]:

    fit = species.FitModel(object_name='beta Pic b',
                           filters=None,
                           model='drift-phoenix',
                           bounds=None,
                           inc_phot=True,
                           inc_spec=False)

    Getting object: beta Pic b... [DONE]

    [8]:

    fit.run_mcmc(nwalkers=200,
                 nsteps=1000,
                 guess={'teff': 1800, 'logg': None, 'feh': None, 'radius': 1.3},
                 tag='betapic',
                 prior=('mass', 13., 3.))

    Running MCMC...

    100%|██████████| 1000/1000 [14:59<00:00,  1.11it/s]

    Mean acceptance fraction: 0.479
    Integrated autocorrelation time = [3171.30662571]

    [9]:

    species.plot_walkers(tag='betapic',
                         nsteps=None,
                         offset=(-0.24, -0.09),
                         output='walkers.png')

    Plotting walkers: walkers.png... [DONE]

    [10]:

    Image('walkers.png')

    [10]:

    [11]:

    species.plot_posteriors(tag='betapic',
                            burnin=500,
                            offset=(-0.25, -0.25),
                            limits=[(1500., 1920.), (3.4, 4.7), (-0.6, 0.3), (1.1, 1.8)],
                            output='posteriors.png')

    Plotting posteriors: posteriors.png... [DONE]

    [12]:

    Image('posteriors.png')

    [12]:

    [13]:

    samples = database.get_mcmc_spectra(tag='betapic',
                                        burnin=500,
                                        random=30,
                                        wavel_range=(0.7, 6.5),
                                        spec_res=50.)

    Getting MCMC spectra: 100%|██████████| 30/30 [05:42<00:00, 11.42s/it]

    [14]:

    median = database.get_median_sample(tag='betapic',
                                        burnin=500)

    [15]:

    read_model = species.ReadModel(model='drift-phoenix',
                                   wavel_range=(0.7, 6.5))

    [16]:

    modelbox = read_model.get_model(model_param=median,
                                    spec_res=50.)

    [17]:

    modelbox = species.add_luminosity(modelbox)

    [18]:

    residuals = species.get_residuals(datatype='model',
                                      spectrum='drift-phoenix',
                                      parameters=median,
                                      filters=None,
                                      objectbox=objectbox,
                                      inc_phot=True,
                                      inc_spec=False)

    Calculating synthetic photometry... [DONE]
    Calculating residuals... [DONE]

    [19]:

    synphot = species.multi_photometry(datatype='model',
                                       spectrum='drift-phoenix',
                                       filters=objectbox.filters,
                                       parameters=median)

    Calculating synthetic photometry... [DONE]

    [20]:

    species.plot_spectrum(boxes=[samples, modelbox, objectbox, synphot],
                          filters=objectbox.filters,
                          residuals=residuals,
                          colors=('gray', 'tomato', ('black', None), 'black'),
                          xlim=(0.7, 6.0),
                          ylim=(-1.2e-15, 1.3e-14),
                          scale=('linear', 'linear'),
                          offset=(-0.25, -0.06),
                          output='spectrum.png')

    Plotting spectrum: spectrum.png... [DONE]

    [21]:

    Image('spectrum.png')

    [21]: