Beispiel #1
0
def plot_bestmodel(self, fitter, modelcode, folded=False, burnin_pct=0.1):
    print('calling _mp_visuals.py/plot_bestmodel().')
    ### THIS FUNCTION PLOTS YOUR BEST FIT LIGHT CURVE MODEL OVER THE DATA.
    if folded == True:
        self.fold()

    if modelcode == "LUNA":
        folded = False  ### should not be generating a folded light curve for a moon fit.

    self.initialize_priors(modelcode=modelcode)

    if fitter == 'emcee':
        if modelcode == 'batman':
            chainsdir = moonpydir + '/emcee_fits/batman/' + str(
                self.target) + '/chains'
        elif modelcode == 'LUNA':
            chainsdir = moonpydir + '/emcee_fits/LUNA/' + str(
                self.target) + '/chains'
        samples = np.genfromtxt(chainsdir + '/' + str(self.target) +
                                '_mcmc_chain.txt')
        sample_shape = samples.shape
        samples = samples[int(burnin_pct * sample_shape[0]):, 1:]

        best_fit_dict = {}
        for npar, parlab in enumerate(self.param_labels):
            best_fit_dict[parlab] = np.nanmedian(samples.T[npar])
        print("best fit values: ")
        for parkey in best_fit_dict.keys():
            print(parkey, ' = ', best_fit_dict[parkey])

        if modelcode == 'batman':
            ### use batman to generate a model!!!
            if folded == True:
                batman_times, batman_fluxes = run_batman(self.fold_times,
                                                         **best_fit_dict,
                                                         add_noise='n',
                                                         show_plots='n')
                plt.scatter(np.hstack(self.fold_times),
                            np.hstack(self.fluxes_detrend),
                            facecolor='LightCoral',
                            edgecolor='k')
            else:
                batman_times, batman_fluxes = run_batman(self.times,
                                                         **best_fit_dict,
                                                         add_noise='n',
                                                         show_plots='n')
                plt.scatter(np.hstack(self.times),
                            np.hstack(self.fluxes_detrend),
                            facecolor='LightCoral',
                            edgecolor='k')
            batman_sort = np.argsort(batman_times)
            batman_times, batman_fluxes = batman_times[
                batman_sort], batman_fluxes[batman_sort]
            plt.plot(batman_times, batman_fluxes, c='g', linewidth=2)
            plt.show()
Beispiel #2
0
def pymn_loglike_batman(cube, ndim, nparams):

    pymn_var_dict = {
    }  #### dictionary of variables, will take the cube as the argument.
    pymn_fixed_dict = {
    }  ### dictionary of fixed variables, will stay constant for each run.

    for pidx, parlab in enumerate(mn_variable_labels):
        pymn_var_dict[parlab] = cube[pidx]

    for pidx, parlab in enumerate(mn_fixed_labels):
        pymn_fixed_dict[parlab] = mn_param_dict[parlab][
            1]  ### grabs the fixed value!

    ### now you should be able to run_LUNA(param_dict)
    batman_times, batman_fluxes = run_batman(data_times,
                                             **pymn_var_dict,
                                             **pymn_fixed_dict,
                                             model=mn_model,
                                             add_noise='n',
                                             show_plots='n')

    loglikelihood = np.nansum(
        -0.5 * ((batman_fluxes - data_fluxes) / data_errors)**2
    )  ### SHOULD MAKE THIS BETTER, to super-penalize running out of bounds!
    return loglikelihood
Beispiel #3
0
def emcee_lnlike_batman(params, data_times, data_fluxes, data_errors):
    emcee_param_dict = {}  ### initialize it
    emcee_var_param_dict = {}
    emcee_fixed_param_dict = {}
    """
	for pidx, parlab in enumerate(mn_param_labels):
		emcee_param_dict[parlab] = params[pidx]
	"""
    for pidx, parlab in enumerate(mc_variable_labels):
        emcee_var_param_dict[parlab] = params[pidx]

    for pidx, parlab in enumerate(mc_fixed_labels):
        emcee_fixed_param_dict[parlab] = mc_param_dict[parlab][
            1]  ### fixed value!

    batman_times, batman_fluxes = run_batman(data_times,
                                             **emcee_var_param_dict,
                                             **emcee_fixed_param_dict,
                                             model=mc_model,
                                             add_noise='n',
                                             show_plots='n')

    loglikelihood = np.nansum(
        -0.5 * ((batman_fluxes - data_fluxes) / data_errors)**2
    )  ### SHOULD MAKE THIS BETTER, to super-penalize running out of bounds!
    #if (np.isfinite(loglikelihood) == False) or type(loglikelihood) != float:
    #	print("loglikelihood = ", loglikelihood)
    #	raise Exception('emcee_lnlike_batman loglikelihood value is invalid."')
    return loglikelihood