def test_fitting(): mod_dar = _check_fitting(StarModel(Dartmouth_Isochrone, **props)) mod_mist = _check_fitting(StarModel(MIST_Isochrone, **props)) _check_saving(mod_dar) _check_saving(mod_mist)
def _check_spec(ic): mod = StarModel(ic, Teff=(5700, 100), logg=(4.5, 0.1), feh=(0.0, 0.2)) eep = ic.get_eep(1., 9.6, 0.1, accurate=True) assert np.isfinite(mod.lnlike([eep, 9.6, 0.1, 200, 0.2]))
def iso_age(teff, logg, feh): dar = Dartmouth_Isochrone() mod = StarModel(dar, Teff=(teff, 80), Logg=(logg, 0.10), Feh=(feh, 0.1)) logage, _, _ = mod.maxlike() age = np.exp(logage) return age
def test_fitting(): mod_mist = _check_fitting(StarModel(MIST_Isochrone, **props)) _check_saving(mod_mist)
#("W3", "w3mpro", "w3sigmpro"), #("G", "G", "ERR_G"), #("R", "R", "ERR_R"), #("I", "I", "ERR_I") ] for magnitude, column, error_column in columns: if np.isfinite(star[column]) and np.isfinite(star[error_column]): kwds[magnitude] = (star[column], star[error_column]) # Update kwds with parallax if available. if np.isfinite(star["parallax"]): kwds["parallax"] = (star["parallax"], star["parallax_error"]) print(kwds) model = StarModel(mist, **kwds) # Update uniform priors on age and distance. model._bounds["age"] = (np.log10(5.0e9), np.log10(13.721e9)) model._bounds["distance"] = distance_bounds.get(star["Name"], (0, 50000.0)) model.fit(refit=True, n_live_points=1000, evidence_tolerance=0.5) model.samples.to_csv(output_path) fig_output_path = os.path.join(DATA_FOLDER, "{}_mist_samples.pdf".format(star["Name"])) fig = model.corner_physical() try: fig.savefig(fig_output_path) except:
def test_likelihood_rotation_giant(): """ Make sure that the lhf can cope with zeros, NaNs and None values for the rotation period. Also, check that there is a drop in likelihood at the eep = 454 boundary. """ iso_params = pd.DataFrame(dict({"teff": (5777, 10), "logg": (4.44, .05), "feh": (0., .001), "parallax": (1., .01)})) # mas # Set up the StarModel isochrones object. mod = StarModel(mist, **iso_params) lnparams = [355, np.log10(4.56*1e9), 0., np.log(1000), 0.] args = [mod, None, None, .65, 1., False, False] # the lnprob arguments] none_lnprob = lnprob(lnparams, *args) args = [mod, np.nan, np.nan, .65, 1., False, False] # the lnprob arguments] nan_lnprob = lnprob(lnparams, *args) args = [mod, 0., 0., .65, 1., False, False] # the lnprob arguments] zero_lnprob = lnprob(lnparams, *args) args = [mod, 26., 1., .65, 1., True, False] # the lnprob arguments] iso_lnprob = lnprob(lnparams, *args) args = [mod, 26., 1., .65, 1., False, True] # the lnprob arguments] gyro_lnprob = lnprob(lnparams, *args) # check that gyro is switched off for all of these. none_lnprob == nan_lnprob nan_lnprob == zero_lnprob # check that gyro on gives different lnprob assert gyro_lnprob != iso_lnprob # Likelihood should be greater for dwarfs because gyro lnlike is a broad # Gaussian for giants. giant_params = [455, np.log10(4.56*1e9), 0., np.log(1000), 0.] dwarf_params = [453, np.log10(4.56*1e9), 0., np.log(1000), 0.] args = [mod, 26., 1., None, None, False, False] giant_lnprob = lnprob(giant_params, *args) dwarf_lnprob = lnprob(dwarf_params, *args) assert giant_lnprob[0] < dwarf_lnprob[0] # Likelihood should be greater for cool stars because gyro lnlike is a # broad Gaussian for giants. heep, hage, hfeh = 405, np.log10(2.295*1e9), 0. ceep, cage, cfeh = 355, np.log10(4.56*1e9), 0. hot_params = [heep, hage, hfeh, np.log(1000), 0.] cool_params = [ceep, cage, cfeh, np.log(1000), 0.] cool_prot = gyro_model_rossby( cage, calc_bv(cool_params), mist.interp_value([ceep, cage, cfeh], ["mass"])) hot_prot = gyro_model_rossby( hage, calc_bv(hot_params), mist.interp_value([heep, hage, hfeh], ["mass"])) cool_args = [mod, cool_prot, 1., None, None, False, False] hot_args = [mod, hot_prot, 1., None, None, False, False] hot_lnprob = lnprob(hot_params, *args) cool_lnprob = lnprob(cool_params, *args) assert hot_lnprob[0] < cool_lnprob[0], "cool star likelihood should be" \ " higher than hot star likelihood"