def get_fit_param(param_fname): fit_fname = get_fit_limits_fname(param_fname) print(fit_fname) fit_param = load_fit_limits(fit_fname) fit_mi = 10**fit_param['mi'] fit_rd = fit_param['rd'] * 1e-3 return fit_mi, fit_rd
def get_survival_rate(param_fname, fit, mass_bins): param = dtk.Param(param_fname) cluster_loc = param.get_string('cluster_loc') cluster_load_num = param.get_int('cluster_load_num') cluster_data = load_clusters(cluster_loc) # getting the Ngal with and without disruption model_fit_fname = "figs/"+param_fname+"/calc_likelihood_bounds.py/grid_fit_param.txt" model_fit = load_fit_limits(model_fit_fname) return get_survival_rate_cluster(cluster_data, cluster_load_num, mass_bins, model_fit, )
def plot_radii_effects(param_files, radii, params, xlabel=None, plot_reference=None): parameter_labels = {'mi': r"M$_{infall}$"+"\n"+r"[log10 h$^{-1}$ M$_\odot$]", 'rd': r"R$_{disrupt}$"+"\n"+r"[h$^{-1}$ kpc]", 'rm': r"R$_{merge}$"+"\n"+r"[h$^{-1}$ Mpc]", 'x2': r"$\chi^2_{reduced}$",} param_fits = [] for pfile in param_files: print(pfile) fit = load_fit_limits(pfile) param_fits.append(fit) size = len(params) gs = gridspec.GridSpec(size, 1) sharex_ax = None fig = plt.figure() for i, param in enumerate(params): if sharex_ax is None: ax = plt.subplot(gs[i, 0]) else: ax = plt.subplot(gs[i, 0], sharex=sharex_ax) y, y_err_lower, y_err_upper = get_param_line(param_fits, param, param!='x2') ax.plot(radii, y) if param != 'x2': print(param) ax.fill_between(radii, y-y_err_lower, y+y_err_upper, alpha=0.3) if plot_reference is not None: ax.axhline(y[plot_reference], ls='--', color='k') ax.axhline(y[plot_reference]-y_err_lower[plot_reference], ls=':', color='k') ax.axhline(y[plot_reference]+y_err_upper[plot_reference], ls=':', color='k') ax.set_ylabel(parameter_labels[param]) if param == 'x2' : if xlabel is not None: #x2 is always last ax.set_xlabel(xlabel) else: ax.xaxis.set_ticklabels([]) gs.tight_layout(fig)
def load_fit_limits_set(param_fnames): return [ load_fit_limits("figs/"+param_fname+"/calc_likelihood_bounds.py/grid_fit_param.txt") for param_fname in param_fnames]
def plot_miscentering_effects(fname_pattern, distances_str, distances_val): param_files_rd = [ fname_pattern.replace("${displacement}", distance) for distance in distances_str ] # [print(pfd) for pfd in param_files_rd] rds = [] rds_ue = [] rds_le = [] mis = [] mis_ue = [] mis_le = [] chi2 = [] for pfd in param_files_rd: fit = load_fit_limits(pfd) print(fit) mis.append(fit['mi']) mis_ue.append(fit['mi_limits'][0]) mis_le.append(fit['mi_limits'][1]) rds.append(fit['rd']) rds_ue.append(fit['rd_limits'][0]) rds_le.append(fit['rd_limits'][1]) chi2.append(fit['x2']) # Convert Mpc to kpc distances_val *= 1000 distances_val += 1 # plt.figure() # plt.plot(distances_val+0.01, mis, '-o') # plt.fill_between(distances_val+0.01, mis_le, mis_ue, alpha=0.3) # plt.xlabel('Center Displacement') # plt.ylabel('M$_{infall}$ [Msun/h]') # plt.xscale('log') # plt.figure() # plt.plot(distances_val+0.01, rds, '-o') # plt.fill_between(distances_val+0.01, rds_le, rds_ue, alpha=0.3) # plt.xlabel('Center Displacement') # plt.ylabel('R$_{disrupt}$ [kpc/h]') # plt.xscale('log') gs = gridspec.GridSpec(3, 1) sharex_ax = None fig = plt.figure(figsize=(6, 10)) ax1 = plt.subplot(gs[0, 0]) ax1.plot(distances_val, mis, '-o') ax1.fill_between(distances_val, mis_le, mis_ue, alpha=0.3) ax1.set_xscale('log') ax1.set_ylabel("M$_{infall}$" + "\n" + r"[log10 h$^{-1}$ M$_\odot$]") ax1.xaxis.set_ticklabels([]) # ax1.plot(distances_val+0.01, mis, '-o') # ax1.fill_between(distances_val+0.01, mis_le, mis_ue, alpha=0.3) ax2 = plt.subplot(gs[1, 0]) ax2.plot(distances_val, rds, '-o') ax2.fill_between(distances_val, rds_le, rds_ue, alpha=0.3) ax2.set_ylabel("R$_{disrupt}$" + "\n" + r"[h$^{-1}$ kpc]") ax2.set_xscale('log') ax2.xaxis.set_ticklabels([]) ax3 = plt.subplot(gs[2, 0]) ax3.plot(distances_val, chi2, '-o') ax3.set_ylabel("$\widetilde\chi^2$") ax3.set_xscale('log') ax3.set_yscale('log') # ax3.fill_between(distances_val+0.01, rds_le, rds_ue, alpha=0.3) ax3.set_xlabel('Center Displacement + 1 [h$^{-1}$ kpc]') gs.tight_layout(fig)