def process_smbh_cluster(H0, WM, WV): smbh_cluster_file = 'SMBH_cluster' smbh_cluster = get_cluster_file(os.path.join(cluster_folder, smbh_cluster_file)) for i, line in enumerate(smbh_cluster): sys.stdout.write(''.join(['\rConverting z to age in SMBH Cluster for #', str(i+1), ' of ', str(len(smbh_cluster))])) sys.stdout.flush() z = float(line[0]) input_params= [z, H0, WM, WV] age = CC.get_output_params(input_params) line.insert(1, age) print smbh_cluster = np.array(smbh_cluster, dtype=object) smbh_cluster = sorted(smbh_cluster, key=lambda l:l[2]) F = open(os.path.join(cluster_folder, 'smbh_cluster.pkl'), 'wb') pickle.dump(smbh_cluster, F) F.close() print('Saved SMBH Cluster array to pickle') print print(smbh_cluster[0]) print(smbh_cluster[int(len(smbh_cluster)/4)]) print(smbh_cluster[int(len(smbh_cluster)/2)]) print(smbh_cluster[3*int(len(smbh_cluster)/4)]) print(smbh_cluster[len(smbh_cluster)-1]) return smbh_cluster
def process_galaxies_cluster(H0, WM, WV): galaxies_cluster_file = 'galaxies_cluster' galaxies_cluster = get_cluster_file(os.path.join(cluster_folder, galaxies_cluster_file)) galaxies_cluster_length = len(galaxies_cluster) for i, line in enumerate(galaxies_cluster): if len(line) >= 6: line[5] = line[5:] if len(line) >= 7: line[6:] = [] sys.stdout.write(''.join(['\rConverting z to age in Galaxy Cluster for #', str(i+1), ' of ', str(galaxies_cluster_length)])) sys.stdout.flush() z = float(line[0]) input_params= [z, H0, WM, WV] age = CC.get_output_params(input_params) line.insert(1, age) print #galaxies_cluster = np.array([np.array(line, dtype=object) for line in galaxies_cluster], dtype=object) galaxies_cluster = np.array(galaxies_cluster, dtype=object) galaxies_cluster = sorted(galaxies_cluster, key=lambda l:l[2]) # print(galaxies_cluster) F = open(os.path.join(cluster_folder, 'galaxies_cluster.pkl'), 'wb') pickle.dump(galaxies_cluster, F) F.close() print('Saved Galaxies Cluster array to pickle') return galaxies_cluster
def run(): # z_s = [4, 3.1, 2.8, 2.5, 2.2, 2.0, 1.9, 1.75, 1.6, 1.5, 1.35, 1.3, 1.25, 1.2, 1.15, 1.1, 1.05, 1.0, 0.95, 0.9, 0.85, # 0.8, 0.75, 0.7, 0.65, 0.6, 0.55, 0.5, 0.45, 0.4, 0.35, 0.25, 0.2, 0.15, 0.1, 0.05, 0.0] z_s = np.linspace(4., 0., num=1000) print z_s age = [] for z in z_s: input_params= [z, H0, WM, WV] age.append(CC.get_output_params(input_params)) print age sigma = np.ones(len(age)) sigma[[0, -1]] = 0.02 popt, pcov = scipy.optimize.curve_fit(func, age, z_s, sigma=sigma) print popt z_est = np.array([func(x, *tuple(popt)) for x in age]) # print zip(age, z_est) plt.figure(1) plt.plot(age, z_s, label='t-to-z func') plt.plot(age, z_est, label='curve fit') locs, labels = plt.xticks() plt.setp(labels, rotation=45) # plt.xticks(np.arange(1.5, 14., 0.5)) plt.yticks(np.arange(0., 4.5, 0.5)) plt.legend() plt.grid(b=True, which='both', color='0.65',linestyle='-') plt.xlabel('Age (Gyr)') plt.ylabel('Z') plt.figure(2) diff = [(zest-zs)/zs for (zest, zs) in zip(z_est, z_s)] plt.plot(age, diff) plt.xlabel('Age (Gyr)') plt.ylabel('(z_est-z_s)/z_s') locs, labels = plt.xticks() plt.setp(labels, rotation=45) plt.xticks(np.arange(1.5, 14., 0.5)) plt.yticks(np.arange(-0.5, 9., 0.5)) plt.grid(b=True, which='both', color='0.65',linestyle='-') plt.title('Difference ratio between curve fit and z_function') plt.show()