Quickstart#
We’ll run through a quick example to demonstrate basic capabilities. In this example, we’ll use the M dwarf IRAS 04171+2756 from López-Valdivia et al. 2021 (DOI: 10.3847/1538-4357/ac1a7b).
stelpar uses the emcee package to run a Markov chain Monte Carlo (MCMC) simulation. For more information about emcee, see the emcee documentation.
from stelpar import Estimate
target = 'IRAS 04171+2756'
est = Estimate(target)
The next cell is here to make sure there is a result to show in this tutorial without waiting an hour or so (depending on processing power). The MCMC was previously run and saved to a file, which we can reuse here. To run the MCMC yourself, ignore these three lines of code and remove backend=backend or set backend=None in the call to est.run() in the third cell.
Backends can be useful, but not necessary. For more information see the emcee backend documentation and tutorial example.
import emcee
filename = "tutorial.h5"
backend = emcee.backends.HDFBackend(filename)
We’ll run a quick MCMC simulation using 32 walkers for 5000 steps. The function run() returns an emcee.EnsemberSampler object, which we’ll name sampler.
A typical simulation should use more steps and more walkers. The few steps we’re using here let us run a reasonably quick simulation to get the point across, but the results will likely be incorrect.
nwalkers = 32
nsteps = 5000
sampler = est.run(nwalkers, nsteps, backend=backend)
running MCMC for IRAS 04171+2756:
100%|████████████████████████████████████████████████████████████████████████████████████████| 5000/5000 [00:00<?, ?it/s]
Now we’ll use the built-in function posterior() to extract the results from sampler. posterior() returns 3 pandas.DataFrame objects: posterior contains the quotable values and uncertainties of the fit parameters and other stellar parameters, photometry containes the measured and estimated magnitudes and fluxes, and chains contains the full posterior distributions of the estimated parameters.
We’ll cut out the first 1000 steps (burn-in) and retrieve every 15 samples.
posterior, photometry, chains = est.posterior(sampler, discard=1000, thin=15)
extracting posterior for IRAS 04171+2756:
getting other parameter chains:
100%|████████████████████████████████████████████████████████████████████████████████| 8512/8512 [04:20<00:00, 32.72it/s]
Now we can look at the results.
posterior
| median | uncertainty | + | - | |
|---|---|---|---|---|
| parameter | ||||
| age | 4829.34 | 3435.68 | 3486.5 | 3384.86 |
| mass | 0.720074 | 0.082887 | 0.080098 | 0.0856761 |
| Av | 1.72606 | 0.960063 | 0.895973 | 1.02415 |
| f | 1.25206 | 0.267193 | 0.305375 | 0.22901 |
| Teff | 4169.52 | 350.823 | 395.851 | 305.794 |
| logg | 4.5234 | 0.0594516 | 0.0722559 | 0.0466473 |
| logL | -0.790298 | 0.249691 | 0.239917 | 0.259465 |
| radius | 0.772997 | 0.0924317 | 0.0778321 | 0.107031 |
| density | 1.57009 | 0.432523 | 0.585534 | 0.279511 |
photometry.iloc[:, -5:]
| median_apparent_magnitude | median_apparent_magnitude_error | median_flux | median_flux_error | median_percent_error | |
|---|---|---|---|---|---|
| band | |||||
| 2mass_jmag | 11.1653 | 1.25225 | 1.07452e-14 | 1.23932e-14 | 39.928 |
| 2mass_hmag | 10.283 | 1.25227 | 8.81516e-15 | 1.01673e-14 | 26.4802 |
| 2mass_kmag | 10.0056 | 1.25221 | 4.2838e-15 | 4.94062e-15 | 24.7415 |
| gaia_gmag | 13.9115 | 1.25208 | 6.82357e-15 | 7.869e-15 | 34.4993 |
| gaia_bpmag | 15.0903 | 1.25208 | 3.75299e-15 | 4.32799e-15 | 15.6038 |
| gaia_rpmag | 12.8388 | 1.25208 | 9.28845e-15 | 1.07115e-14 | 40.8917 |
| sdss_gmag | 15.8421 | 1.25208 | 2.29639e-15 | 2.64822e-15 | 23.7282 |
| sdss_rmag | 14.1157 | 1.25208 | 6.51715e-15 | 7.51564e-15 | 0.892624 |
| sdss_imag | 13.3015 | 1.25218 | 9.3546e-15 | 1.07887e-14 | 2809.44 |
| sdss_zmag | 12.7177 | 1.25208 | 1.11883e-14 | 1.29024e-14 | 46.7752 |
| johnson_bmag | 16.5406 | 1.25457 | 1.52269e-15 | 1.75947e-15 | 22.3477 |
| johnson_vmag | 14.796 | 1.25553 | 4.31402e-15 | 4.98865e-15 | 3.17093 |
chains
| age | mass | Av | f | Teff | logg | logL | radius | density | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 5740.71 | 0.723883 | 1.70614 | 1.40271 | 4186.48 | 4.50774 | -0.769426 | 0.785069 | 1.49605 |
| 1 | 1359.66 | 0.723102 | 1.48132 | 1.12224 | 4174.28 | 4.54481 | -0.812002 | 0.75186 | 1.70133 |
| 2 | 6981.31 | 0.720057 | 2.08123 | 1.07853 | 4173.39 | 4.50035 | -0.769682 | 0.78966 | 1.46233 |
| 3 | 7617.85 | 0.625994 | 1.07766 | 1.19837 | 3843.48 | 4.59033 | -1.0636 | 0.663927 | 2.13899 |
| 4 | 4512.63 | 0.678672 | 1.03169 | 1.03101 | 4006.6 | 4.55301 | -0.918929 | 0.721552 | 1.80658 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8507 | 902.623 | 0.827666 | 2.29915 | 1.08957 | 4665.88 | 4.51378 | -0.528961 | 0.833629 | 1.42869 |
| 8508 | 4792.55 | 0.771613 | 1.98411 | 1.32647 | 4415.75 | 4.49241 | -0.633803 | 0.82496 | 1.37436 |
| 8509 | 4609.08 | 0.664529 | 1.36998 | 1.23574 | 3955.79 | 4.56481 | -0.962101 | 0.704391 | 1.9014 |
| 8510 | 6189.55 | 0.638328 | 0.674638 | 1.33148 | 3874.84 | 4.58283 | -1.03345 | 0.676178 | 2.06472 |
| 8511 | 3315.29 | 0.771882 | 2.03417 | 0.945239 | 4405.41 | 4.5052 | -0.650505 | 0.813042 | 1.43619 |
8512 rows × 9 columns
Clearly, the photometry shows the result is wrong. Increasing the number of walkers/steps may help with convergence. Check out the other tutorial notebooks for different ways to try to improve this result.