def compute_chi_sq(mpv_database, fiducial_vals, id_to_load, cov_path, r_eval_vals, Nz): path = mpv_database['results_path'].loc[id_to_load] success = mpv_database['successful_TF'].loc[id_to_load] if not success: return np.nan vals = load_results_file(path, success) cov = Cov.load_covariance(cov_path) chi_sq = 0 for i in range(Nz): inv_cov = cov.get_inverted_covariance(i) result_vs = interp1d(vals[0], vals[1][i])(r_eval_vals) chi_sq += np.dot((fiducial_vals[i] - result_vs)**2, np.dot(inv_cov, (fiducial_vals[i] - result_vs)**2)) / Nz return chi_sq
delta_r = 2.0 r_vals = np.arange(20.0, 180.0, delta_r) zmin = 0.1 zmax = 0.6 Nz = 5 z_step = (zmax - zmin) / Nz z_vals = np.linspace(zmin + z_step / 2, zmax - z_step / 2, Nz) filename = "../../data/axion_frac=0.000_matterpower_out.dat" P_CAMB = np.loadtxt(filename) p_interp = interpolate(P_CAMB[:, 0] * phys.h, P_CAMB[:, 1] / phys.h**3, phys.P_cdm, phys.P_cdm) try: cov = Cov.load_covariance("covariance_matrix_{}.dat".format(run_code)) except (IOError, OSError) as e: print("Covariance matrix not found. Recomputing...") cov = Cov(p_interp, None, zmin, zmax, Nz, r_vals, delta_r, 10000 / 129600 * np.pi, 120.0, kmin=min(P_CAMB[:, 0] * phys.h), kmax=max(P_CAMB[:, 0] * phys.h), mMin=0.6e14, mMax=1e16,
z_step = (zmax - zmin) / Nz z_vals = np.linspace(zmin + z_step / 2, zmax - z_step / 2, Nz) print("Getting covariance matrix.") start_cov = time.time() filename = "../../data/axion_frac=0.000_matterpower_out.dat" P_CAMB = np.loadtxt(filename) p_interp = interpolate(P_CAMB[:, 0] * phys.h, P_CAMB[:, 1] / phys.h**3, phys.P_cdm, phys.P_cdm) cov_path = "covariance_matrix_{}_{}.dat".format( ['top-hat', 'gaussian', 'sharp-k', 'no-filter'][window], ["stageII", "stageIII", "stageIV"][stage]) try: cov = Cov.load_covariance(cov_path) except (IOError, OSError) as e: print("Covariance matrix not found. Recomputing...") cov = Cov(p_interp, None, zmin, zmax, Nz, r_vals, delta_r, overlap_area[stage] / 129600 * np.pi, sigma_v_vals[stage], kmin=min(P_CAMB[:, 0] * phys.h), kmax=max(P_CAMB[:, 0] * phys.h), mMin=minClusterMass[stage], mMax=1e16,
print(len(r_vals)) zmin = zmin_vals[stage] zmax = zmax_vals[stage] Nz = z_bin_no[stage] z_step = (zmax - zmin) / Nz z_vals = np.linspace(zmin + z_step / 2, zmax - z_step / 2, Nz) print("Getting covariance matrix.") start_cov=time.time() filename = "../../data/axion_frac=0.000_matterpower_out.dat" P_CAMB = np.loadtxt(filename) p_interp = interpolate(P_CAMB[:, 0] * phys.h, P_CAMB[:, 1] / phys.h ** 3, phys.P_cdm, phys.P_cdm) try: cov = Cov.load_covariance("covariance_matrix_{}_{}.dat".format(['top-hat', 'gaussian', 'sharp-k', 'no-filter'][window], ["stageII", "stageIII", "stageIV"][stage])) except (IOError, OSError) as e: print("Covariance matrix not found. Recomputing...") cov = Cov(p_interp, None, zmin, zmax, Nz, r_vals, delta_r, overlap_area[stage] / 129600 * np.pi, sigma_v_vals[stage], kmin=min(P_CAMB[:, 0] * phys.h), kmax=max(P_CAMB[:, 0] * phys.h), mMin=minClusterMass[stage], mMax=1e16, physics=phys, window_function=window) cov.save_covariance("covariance_matrix_{}_{}.dat".format(['top-hat', 'gaussian', 'sharp-k', 'no-filter'][window], ["stageII", "stageIII", "stageIV"][stage])) print("Total time take to get covariance matrices: {:.2}s".format(time.time()-start_cov)) params=[] for m in axion_masses: for f in axion_frac_vals: phys = Physics.create_parameter_set(axion_mass=m, axion_frac=f) params.append(phys) #with MyProcessPool(12) as p: # p.map(lambda i: run_axionCAMB("CAMB_run4plots_{}".format(i), params[i]), range(0, len(params)))