def __init__(self, **kwargs): """ This is the initial function for the `RedSeq` class object. Parameters: ----------- """ super().__init__() ## Assigning variables # Downloading dataset self.mband_1 = kwargs.get('mband_1', 'mag_auto_g') self.mband_2 = kwargs.get('mband_2', 'mag_auto_z') self.mband_3 = kwargs.get('mband_3', 'mag_auto_i') self.mag_diff_tresh = kwargs.get('mag_diff_tresh', 4.) self.mag_min = kwargs.get('mag_min', 24.) self.mag_max = kwargs.get('mag_max', 17.) self.master_limit = kwargs.get('master_limit', 100000) # Analysis self.radius = kwargs.get('radius', 5. / 3600.) self.radius_unit = kwargs.get('radius_unit', 'deg') self.cosmo_choice = kwargs.get('cosmo_choice', 'WMAP7') self.zbin = kwargs.get('zbin', 0.0125) self.zmin = kwargs.get('zmin', 0.4) self.zmax = kwargs.get('zmax', 1.0) self.input_loc = kwargs.get('input_catl_loc', 'RedMapper') # Extra variables self.proj_dict = cwpaths.cookiecutter_paths(__file__)
def __init__(self, **kwargs): """ Parameters ----------- """ super().__init__() # Assigning variables self.catl_type = kwargs.get('catl_type', 'mr') self.survey = kwargs.get('survey', 'ECO') self.hmf_model = kwargs.get('hmf_model', 'warren') self.halotype = kwargs.get('halotype', 'fof') self.cpu_frac = kwargs.get('cpu_frac', 0.75) self.remove_files = kwargs.get('remove_files', False) self.cosmo_choice = kwargs.get('cosmo_choice', 'Planck') self.clf_type = kwargs.get('clf_type', 2) self.zspace = kwargs.get('zspace', 2) self.nmin = kwargs.get('nmin', 1) self.seed = kwargs.get('seed', 1) self.l_perp = kwargs.get('l_perp', 0.07) self.l_para = kwargs.get('l_para', 1.1) self.verbose = kwargs.get('verbose', False) # # Extra variables self.zmed_val = 'zmed_val' self.znow = 0 self.cens = 1 self.sats = 0 self.proj_dict = cwpaths.cookiecutter_paths(__file__)
def main(args): """ Script to turn specific simulation data into Pandas Dataframes """ ## Reading all elements and converting to python dictionary param_dict = vars(args) ## Checking for correct input param_vals_test(param_dict) ## Adding extra variables param_dict = add_to_dict(param_dict) ## Program message Prog_msg = param_dict['Prog_msg'] ## ## Creating Folder Structure # proj_dict = directory_skeleton(param_dict, cwpaths.cookiecutter_paths(__file__)) proj_dict = directory_skeleton(param_dict, cwpaths.cookiecutter_paths('./')) ## ## Printing out project variables print('\n' + 50 * '=' + '\n') for key, key_val in sorted(param_dict.items()): if key != 'Prog_msg': print('{0} `{1}`: {2}'.format(Prog_msg, key, key_val)) print('\n' + 50 * '=' + '\n') # # Extracting info from `simfile` sim_pd = simfile_data_extraction(param_dict, proj_dict)
def main(args): """ Main function that calls all other functions Parameters ---------- args: Input arguments to the script """ global model_init global survey global path_to_proc rseed = 12 np.random.seed(rseed) survey = args.survey machine = args.machine nproc = args.nproc nwalkers = args.nwalkers nsteps = args.nsteps dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_proc = dict_of_paths['proc_dir'] if machine == 'bender': halo_catalog = '/home/asadm2/.astropy/cache/halotools/halo_catalogs/'\ 'vishnu/rockstar/vishnu_rockstar_test.hdf5' elif machine == 'mac': halo_catalog = path_to_raw + 'vishnu_rockstar_test.hdf5' if survey == 'eco': catl_file = path_to_raw + "eco_all.csv" elif survey == 'resolvea' or survey == 'resolveb': catl_file = path_to_raw + "RESOLVE_liveJune2018.csv" print('Reading catalog') catl, volume, cvar, z_median = read_catl(catl_file, survey) print('Retrieving stellar mass from catalog') stellar_mass_arr = catl.logmstar.values maxis_data, phi_data, err_data, bins_data = \ diff_smf(stellar_mass_arr, volume, cvar, False) print('Initial population of halo catalog') model_init = halocat_init(halo_catalog, z_median) print('Running MCMC') sampler = mcmc(nproc, nwalkers, nsteps, phi_data, err_data) print('Writing to files:') write_to_files(sampler)
def Initalize_Global_Settings(self): dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_data = dict_of_paths['data_dir'] self.path_to_proc = dict_of_paths['proc_dir'] if self.machine == 'bender': self.halo_catalog = '/home/asadm2/.astropy/cache/halotools/'\ 'halo_catalogs/vishnu/rockstar/vishnu_rockstar_test.hdf5' elif self.machine == 'mac': self.halo_catalog = path_to_raw + 'vishnu_rockstar_test.hdf5' if self.quenching == 'halo': self.run = 46 elif self.quenching == 'hybrid': self.run = 45 if self.run >= 37: self.chi2_file = self.path_to_proc + \ 'smhm_colour_run{0}/chain.h5'.\ format(self.run, self.survey) self.chain_file = self.path_to_proc + \ 'smhm_colour_run{0}/chain.h5'.\ format(self.run, self.survey) elif self.run < 37: self.chi2_file = self.path_to_proc + \ 'smhm_colour_run{0}/{1}_colour_chi2.txt'.\ format(self.run, self.survey) self.chain_file = self.path_to_proc + \ 'smhm_colour_run{0}/mcmc_{1}_colour_raw.txt'.\ format(self.run, self.survey) if self.survey == 'eco': # catl_file = path_to_raw + "eco/eco_all.csv" ## Updated catalog with group finder run on subset after applying M* # and cz cuts: changed volume to be in h=1 instead of 0.7 self.catl_file = self.path_to_proc + \ "gal_group_eco_data_buffer_volh1_dr2.hdf5" self.path_to_mocks = path_to_data + 'mocks/m200b/eco/' elif self.survey == 'resolvea' or self.survey == 'resolveb': self.catl_file = path_to_raw + "RESOLVE_liveJune2018.csv"
def main(): """ """ ## Reading all elements and converting to python dictionary param_dict = vars(args) ## Checking for correct input param_vals_test(param_dict) ## Program message Prog_msg = param_dict['Prog_msg'] ## ## Creating Folder Structure # proj_dict = directory_skeleton(param_dict, cwpaths.cookiecutter_paths(__file__)) proj_dict = directory_skeleton(param_dict, cwpaths.cookiecutter_paths('./')) ## ## Printing out project variables print('\n' + 50 * '=' + '\n') for key, key_val in sorted(param_dict.items()): if key != 'Prog_msg': print('{0} `{1}`: {2}'.format(Prog_msg, key, key_val)) print('\n' + 50 * '=' + '\n')
for idx,row in enumerate(emcee_table.values): if np.isnan(row)[4] == True and np.isnan(row)[3] == False: scatter_val = emcee_table.values[idx+1][0] row[4] = scatter_val # Cases where rows of NANs appear emcee_table = emcee_table.dropna(axis='index', how='any').\ reset_index(drop=True) return emcee_table def read_chi2(path_to_file): chi2_df = pd.read_csv(path_to_file,header=None,names=['chisquared']) return chi2_df # Path to pre and post breaking files dict_of_paths = cwpaths.cookiecutter_paths() path_to_proc = dict_of_paths['proc_dir'] + 'bmhm_run3/' pre_986_raw_path = path_to_proc + 'mcmc_eco_raw.txt' post_986_raw_path = path_to_proc + 'mcmc_eco_raw_bmf986.txt' pre_986_chi2_path = path_to_proc + 'eco_chi2.txt' post_986_chi2_path = path_to_proc + 'eco_chi2_bmf986.txt' # Reading in raw chain and chi squared files pre_986_raw = read_raw(pre_986_raw_path) post_986_raw = read_raw(post_986_raw_path) pre_986_chi2 = read_chi2(pre_986_chi2_path) post_986_chi2 = read_chi2(post_986_chi2_path) # Combining pre and post breaking files combined_raw = pre_986_raw.append(post_986_raw, ignore_index=True) combined_chi2 = pre_986_chi2.append(post_986_chi2, ignore_index=True)
def main(args): """ Main function that calls all other functions Parameters ---------- args: Input arguments to the script """ global survey global mf_type global survey_dict survey = args.survey mf_type = args.mf_type survey_dict = survey_definitions() # Paths dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_external = dict_of_paths['ext_dir'] if survey == 'eco': path_to_mocks = path_to_external + 'ECO_mvir_catls/' elif survey == 'resolvea': path_to_mocks = path_to_external + 'RESOLVE_A_mvir_catls/' elif survey == 'resolveb': path_to_mocks = path_to_external + 'RESOLVE_B_mvir_catls/' if survey == 'eco': catl_file = path_to_raw + "eco_all.csv" elif survey == 'resolvea' or survey == 'resolveb': catl_file = path_to_raw + "RESOLVE_liveJune2018.csv" catl, volume, cvar, z_median = read_data(catl_file, survey) stellar_mass_arr = np.log10((10**catl.logmstar.values) / 2.041) gas_mass_arr = np.log10((10**catl.logmgas.values) / 2.041) bary_mass_arr = np.log10(10**(stellar_mass_arr) + 10**(gas_mass_arr)) print("Measuring mass function for data") if mf_type == 'smf': max_data, phi_data, err_data, bins_data, counts_data = \ diff_smf(stellar_mass_arr, volume, cvar, True) elif mf_type == 'bmf': max_data, phi_data, err_data, bins_data, counts_data = \ diff_bmf(bary_mass_arr, volume, cvar, False, True) print("Measuring total mass function for mock") max_mock, phi_mock, err_mock = measure_mock_total_mf(path_to_mocks) print("Measuring colour mass function") smf_red, smf_blue = measure_mock_colour_mf(path_to_mocks) print("Measuring covariance matrix") measure_cov_mat(phi_mock) print("Measuring correlation matrix") measure_corr_mat(phi_mock) print("Plotting total mass functions for mocks and data") plot_total_mf(max_mock, phi_mock, err_mock, max_data, phi_data, err_data, counts_data) print("Plotting colour mass functions for mocks") plot_colour_mf(smf_red, smf_blue) print("Comparing cosmic and poisson error for {0}".format(survey)) cosmic_vs_poisson(catl_file)
def main(args): """ Main function that calls all other functions Parameters ---------- args: Input arguments to the script """ global model_init global survey global path_to_proc global mf_type rseed = 12 np.random.seed(rseed) survey = args.survey machine = args.machine nproc = args.nproc nwalkers = args.nwalkers nsteps = args.nsteps mf_type = args.mf_type dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_proc = dict_of_paths['proc_dir'] path_to_external = dict_of_paths['ext_dir'] path_to_data = dict_of_paths['data_dir'] if machine == 'bender': halo_catalog = '/home/asadm2/.astropy/cache/halotools/halo_catalogs/'\ 'vishnu/rockstar/vishnu_rockstar_test.hdf5' elif machine == 'mac': halo_catalog = path_to_raw + 'vishnu_rockstar_test.hdf5' if survey == 'eco': # catl_file = path_to_raw + "eco/eco_all.csv" catl_file = path_to_proc + "gal_group_eco_data.hdf5" elif survey == 'resolvea' or survey == 'resolveb': catl_file = path_to_raw + "RESOLVE_liveJune2018.csv" if survey == 'eco': path_to_mocks = path_to_data + 'mocks/m200b/eco/' elif survey == 'resolvea': path_to_mocks = path_to_external + 'RESOLVE_A_mvir_catls/' elif survey == 'resolveb': path_to_mocks = path_to_external + 'RESOLVE_B_mvir_catls/' print('Reading catalog') catl, volume, z_median = read_data_catl(catl_file, survey) print('Measuring SMF for data') stellar_mass_arr = catl.logmstar.values if mf_type == 'smf': maxis_data, phi_data, err_data, bins_data, counts_data = \ diff_smf(stellar_mass_arr, volume, False) elif mf_type == 'bmf': gas_mass_arr = catl.logmgas.values bary_mass_arr = calc_bary(stellar_mass_arr, gas_mass_arr) maxis_data, phi_data, err_data, bins_data, counts_data = \ diff_bmf(bary_mass_arr, volume, False) print('Measuring spread in vel disp for data') std_data, centers_data = get_deltav_sigma_data(catl) print('Initial population of halo catalog') model_init = halocat_init(halo_catalog, z_median) print('Measuring error in data from mocks') err_data, inv_corr_mat = get_err_data(survey, path_to_mocks) print(err_data, inv_corr_mat) print('Running MCMC') sampler = mcmc(nproc, nwalkers, nsteps, phi_data, std_data, err_data, inv_corr_mat)
def main(args): """ Main function that calls all other functions Parameters ---------- args: Input arguments to the script """ # Paths dict_of_paths = cwpaths.cookiecutter_paths() path_to_data = dict_of_paths['data_dir'] path_to_raw = dict_of_paths['raw_dir'] global survey global temp_dict survey = args.survey # Path to mocks if survey == 'eco': path_to_mocks = path_to_data + 'mocks/m200b/eco/' catl_file = path_to_raw + 'eco/eco_all.csv' elif survey == 'resolvea': path_to_mocks = path_to_data + 'mocks/m200b/resolve_a/' catl_file = path_to_raw + 'resolve/RESOLVE_liveJune2018.csv' elif survey == 'resolveb': path_to_mocks = path_to_data + 'mocks/m200b/resolve_b/' catl_file = path_to_raw + 'resolve/RESOLVE_liveJune2018.csv' # Survey definition dictionaries - all without buffer eco = { 'mock_name': 'ECO', 'num_mocks': 8, 'min_cz': 3000, 'max_cz': 7000, 'mag_limit': -17.33, 'mstar_limit': 8.9, 'volume': 151829.26 #[Mpc/h]^3 } resolvea = { 'mock_name': 'A', 'num_mocks': 59, 'min_cz': 4500, 'max_cz': 7000, 'mag_limit': -17.33, 'mstar_limit': 8.9, 'volume': 13172.384 #[Mpc/h]^3 } resolveb = { 'mock_name': 'B', 'num_mocks': 104, 'min_cz': 4500, 'max_cz': 7000, 'mag_limit': -17, 'mstar_limit': 8.7, 'volume': 4709.8373 #[Mpc/h]^3 } # Changes string name of survey to variable so that the survey dict can # be accessed temp_dict = vars()[survey] catl, volume, cvar, z_median = read_data(catl_file, survey) smf, bmf = measure_corr_mat(path_to_mocks) measure_mass_funcs(smf, bmf, catl) measure_lum_funcs(catl, path_to_mocks) measure_num_dens(catl, path_to_mocks)
def main(args): """ Main function that calls all other functions Parameters ---------- args: Input arguments to the script """ global model_init global survey global path_to_figures global mf_type survey = args.survey machine = args.machine nproc = args.nproc mf_type = args.mf_type ver = 2.0 # No more .dat dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_proc = dict_of_paths['proc_dir'] path_to_data = dict_of_paths['data_dir'] path_to_figures = dict_of_paths['plot_dir'] path_to_external = dict_of_paths['ext_dir'] if machine == 'bender': halo_catalog = '/home/asadm2/.astropy/cache/halotools/halo_catalogs/'\ 'vishnu/rockstar/vishnu_rockstar_test.hdf5' elif machine == 'mac': halo_catalog = path_to_raw + 'vishnu_rockstar_test.hdf5' if mf_type == 'smf': path_to_proc = path_to_proc + 'smhm_run6/' elif mf_type == 'bmf': path_to_proc = path_to_proc + 'bmhm_run3/' chi2_file = path_to_proc + '{0}_chi2.txt'.format(survey) if mf_type == 'smf' and survey == 'eco' and ver == 1.0: chain_file = path_to_proc + 'mcmc_{0}.dat'.format(survey) else: chain_file = path_to_proc + 'mcmc_{0}_raw.txt'.format(survey) if survey == 'eco': catl_file = path_to_raw + 'eco/eco_all.csv' path_to_mocks = path_to_data + 'mocks/m200b/eco/' elif survey == 'resolvea' or survey == 'resolveb': catl_file = path_to_raw + 'RESOLVE_liveJune2019.csv' if survey == 'resolvea': path_to_mocks = path_to_external + 'RESOLVE_A_mvir_catls/' else: path_to_mocks = path_to_external + 'RESOLVE_B_mvir_catls/' print('Reading chi-squared file') chi2 = read_chi2(chi2_file) print('Reading mcmc chain file') mcmc_table = read_mcmc(chain_file) print('Reading catalog') catl, volume, cvar, z_median = read_data_catl(catl_file, survey) print('Getting data in specific percentile') mcmc_table_pctl, bf_params, bf_chi2 = \ get_paramvals_percentile(mcmc_table, 68, chi2) print('Retrieving stellar mass from catalog') stellar_mass_arr = catl.logmstar.values if mf_type == 'smf': maxis_data, phi_data, err_data_, bins_data, counts_data = \ diff_smf(stellar_mass_arr, volume, False) elif mf_type == 'bmf': gas_mass_arr = catl.logmgas.values bary_mass_arr = calc_bary(stellar_mass_arr, gas_mass_arr) maxis_data, phi_data, err_data_, bins_data, counts_data = \ diff_bmf(bary_mass_arr, volume, False) print('Getting error in data') err_data_mf = get_err_data(survey, path_to_mocks) print('Initial population of halo catalog') model_init = halocat_init(halo_catalog, z_median) print('Retrieving Behroozi 2010 centrals') model_init.mock.populate() if survey == 'eco' or survey == 'resolvea': if mf_type == 'smf': limit = np.round(np.log10((10**8.9) / 2.041), 1) elif mf_type == 'bmf': limit = np.round(np.log10((10**9.4) / 2.041), 1) elif survey == 'resolveb': if mf_type == 'smf': limit = np.round(np.log10((10**8.7) / 2.041), 1) elif mf_type == 'bmf': limit = np.round(np.log10((10**9.1) / 2.041), 1) sample_mask = model_init.mock.galaxy_table['stellar_mass'] >= 10**limit gals_b10 = model_init.mock.galaxy_table[sample_mask] cen_gals_b10, cen_halos_b10 = get_centrals_mock(gals_b10) print('Retrieving survey centrals') cen_gals_data, cen_halos_data = get_centrals_data(catl) # Need following two lines ONLY if using groupmass_s for RESOLVE-A # cen_halos_data = np.array(list(cen_halos_data.values[:65]) + list(cen_halos_data.values[66:])) # cen_gals_data = np.array(list(cen_gals_data.values[:65]) + list(cen_gals_data.values[66:])) print('Multiprocessing') result = mp_init(mcmc_table_pctl, nproc) print('Getting best fit model and centrals') maxis_bf, phi_bf, err_tot_bf, counts_bf, cen_gals_bf, cen_halos_bf = \ get_best_fit_model(bf_params) print('Plotting MF') plot_mf(result, maxis_bf, phi_bf, err_tot_bf, maxis_data, phi_data, err_data_mf, bf_chi2) print('Plotting XMHM') plot_xmhm(result, cen_gals_bf, cen_halos_bf, cen_gals_data, cen_halos_data, cen_gals_b10, cen_halos_b10, bf_chi2)
def main(args): """ Main function that calls all other functions Parameters ---------- args: Input arguments to the script """ global survey global model global model_init global mf_type survey = args.survey model = args.quenching_model mf_type = 'smf' # Paths dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_proc = dict_of_paths['proc_dir'] path_to_interim = dict_of_paths['int_dir'] path_to_figures = dict_of_paths['plot_dir'] path_to_external = dict_of_paths['ext_dir'] if survey == 'eco': path_to_mocks = path_to_external + 'ECO_mvir_catls/' elif survey == 'resolvea': path_to_mocks = path_to_external + 'RESOLVE_A_mvir_catls/' elif survey == 'resolveb': path_to_mocks = path_to_external + 'RESOLVE_B_mvir_catls/' vol_sim = 130**3 # Mpc/h chi2_file = path_to_proc + 'smhm_run4/{0}_chi2.txt'.format(survey) if mf_type == 'smf' and survey == 'eco': chain_file = path_to_proc + 'smhm_run4/mcmc_{0}.dat'.format(survey) else: chain_file = path_to_proc + 'smhm_run4/mcmc_{0}_raw.txt'.format(survey) if survey == 'eco': catl_file = path_to_raw + "eco_all.csv" elif survey == 'resolvea' or survey == 'resolveb': catl_file = path_to_raw + "RESOLVE_liveJune2018.csv" halo_catalog = path_to_raw + 'vishnu_rockstar_test.hdf5' catl, volume, cvar, z_median = read_data(catl_file, survey) print('Reading chi-squared file') chi2 = read_chi2(chi2_file) print('Reading mcmc chain file') mcmc_table = read_mcmc(chain_file) print('Getting data in specific percentile') mcmc_table_pctl, bf_params = get_paramvals_percentile(mcmc_table, 68, chi2) print('Initial population of halo catalog') model_init = halocat_init(halo_catalog, z_median) print('Populating mock using best fit parameters') gals_df = populate_mock(bf_params) print('Assigning centrals and satellites flag') gals_df = assign_cen_sat_flag(gals_df) print('Applying quenching model') if model == 'hybrid': f_red_cen, f_red_sat = hybrid_quenching_model(gals_df) elif model == 'halo': f_red_cen, f_red_sat = halo_quenching_model(gals_df) print('Assigning colour labels to mock galaxies') gals_df = assign_colour_label_mock(f_red_cen, f_red_sat, gals_df) print('Plotting comparison Zu and Mandelbaum 2015') # plot_zumand_fig4(gals_df) print('Assigning colour labels to data') catl = assign_colour_label_data(catl) print('Assigning colour to mock galaxies') gals_df = assign_colour_mock(gals_df, catl, 'median') print('Measuring SMF for data') total_data, red_data, blue_data = measure_all_smf(catl, volume, 0, True) total_data[2], red_data[2], blue_data[2], max_blue, phi_blue, err_blue = \ get_err_data(survey, path_to_mocks) print('Measuring SMF for model') total_model, red_model, blue_model = measure_all_smf( gals_df, vol_sim, 0, False) print('Plotting SMF') plot_smf(total_data, red_data, blue_data, total_model, red_model, blue_model, model, max_blue, phi_blue, err_blue) print('Plotting SMHM') gals_bf_red = np.log10(gals_df.stellar_mass.loc[\ (gals_df.colour_label == 'R') & (gals_df.C_S == 1)]) gals_bf_blue = np.log10(gals_df.stellar_mass.loc[\ (gals_df.colour_label == 'B') & (gals_df.C_S == 1)]) halos_bf_red = np.log10(gals_df.halo_mvir.loc[\ (gals_df.colour_label == 'R') & (gals_df.C_S == 1)]) halos_bf_blue = np.log10(gals_df.halo_mvir.loc[\ (gals_df.colour_label == 'B') & (gals_df.C_S == 1)]) plot_smhm(gals_bf_red, halos_bf_red, gals_bf_blue, halos_bf_blue)
def main(): global survey global mf_type global ver survey = 'eco' mf_type = 'smf' machine = 'bender' ver = 2.0 H0 = 100 # h(km/s)/Mpc cz_inner = 3000 # not starting at corner of box cz_outer = 120 * H0 # utilizing until 120 Mpc of Vishnu box dist_inner = kms_to_Mpc(H0, cz_inner) #Mpc/h dist_outer = kms_to_Mpc(H0, cz_outer) #Mpc/h v_inner = vol_sphere(dist_inner) v_outer = vol_sphere(dist_outer) v_sphere = v_outer - v_inner survey_vol = v_sphere / 8 eco = { 'c': 3 * 10**5, 'survey_vol': survey_vol, 'min_cz': cz_inner, 'max_cz': cz_outer, 'zmin': cz_inner / (3 * 10**5), 'zmax': cz_outer / (3 * 10**5), 'l_perp': 0.07, 'l_para': 1.1, 'nmin': 1, 'verbose': True, 'catl_type': 'mstar' } # Changes string name of survey to variable so that the survey dict can # be accessed param_dict = vars()[survey] dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_data = dict_of_paths['data_dir'] path_to_processed = dict_of_paths['proc_dir'] if machine == 'bender': halo_catalog = '/home/asadm2/.astropy/cache/halotools/halo_catalogs/'\ 'vishnu/rockstar/vishnu_rockstar_test.hdf5' elif machine == 'mac': halo_catalog = path_to_raw + 'vishnu_rockstar_test.hdf5' if survey == 'eco': catl_file = path_to_raw + "eco/eco_all.csv" chi2_file = path_to_processed + 'smhm_run6/{0}_chi2.txt'.format(survey) if mf_type == 'smf' and survey == 'eco' and ver == 1.0: chain_file = path_to_processed + 'mcmc_{0}.dat'.format(survey) else: chain_file = path_to_processed + 'smhm_run6/mcmc_{0}_raw.txt'.\ format(survey) print('Reading chi-squared file') chi2 = read_chi2(chi2_file) print('Reading mcmc chain file') mcmc_table = read_mcmc(chain_file) print('Getting parameters') params = get_paramvals_percentile(mcmc_table, chi2, 68, 95) print('Reading survey data') catl, volume, cvar, z_median = read_data_catl(catl_file, survey) print('Populating halos') model_init = halocat_init(halo_catalog, z_median) gals_df = populate_mock(params, model_init) gals_df = assign_cen_sat_flag(gals_df) print('Applying RSD') gals_rsd_df = apply_rsd(gals_df) gals_rsd_subset_df = gals_rsd_df.loc[(gals_rsd_df.cz >= cz_inner) & \ (gals_rsd_df.cz <= cz_outer) & (gals_rsd_df.stellar_mass >= (10**8.9/2.041))].reset_index(drop=True) gal_group_df, group_df = group_finding(gals_rsd_subset_df, path_to_data + 'interim/', param_dict) gal_group_df_new, group_df_new = \ group_mass_assignment(gal_group_df, group_df, param_dict) print('Writing to output files') pandas_df_to_hdf5_file(data=gal_group_df_new, hdf5_file=path_to_processed + 'gal_group_95perc_r4.hdf5', key='gal_group_df') pandas_df_to_hdf5_file(data=group_df_new, hdf5_file=path_to_processed + 'group_95perc_r4.hdf5', key='group_df')
def main(args): """ Main function that calls all other functions Parameters ---------- args: Input arguments to the script """ global survey global mass global h global path_to_figures survey = args.survey mass = args.type dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_figures = dict_of_paths['plot_dir'] if survey == 'eco': catl_file = path_to_raw + "eco_all.csv" elif survey == 'resolvea' or survey == 'resolveb': catl_file = path_to_raw + "RESOLVE_liveJune2018.csv" h = 0.7 print('Reading catalog') catl, volume, cvar = read_catl(catl_file, survey) print("{0} : {1} total".format(survey, len(catl))) print('Retrieving masses from catalog') if mass == 'smf': mstellar_arr = catl.logmstar.values maxis_70, phi_70, err_70, bins_70 = \ diff_smf(mstellar_arr, volume, cvar) elif mass == 'bmf': mstellar_arr = catl.logmstar.values mgas_arr = catl.logmgas.values mbary_arr, bin_num = calc_bary(mstellar_arr, mgas_arr) maxis_70, phi_70, err_70, bins_70 = \ diff_bmf(mbary_arr, volume, cvar, bin_num) h = 1.0 print('Reading catalog') catl, volume, cvar = read_catl(catl_file, survey) print("{0} : {1} total".format(survey, len(catl))) print('Retrieving masses from catalog') if mass == 'smf': mstellar_arr = catl.logmstar.values maxis_100, phi_100, err_100, bins_100 = \ diff_smf(mstellar_arr, volume, cvar) elif mass == 'bmf': mstellar_arr = catl.logmstar.values mgas_arr = catl.logmgas.values mbary_arr, bin_num = calc_bary(mstellar_arr, mgas_arr) maxis_100, phi_100, err_100, bins_100 = \ diff_bmf(mbary_arr, volume, cvar, bin_num) """
def main(args): """ Main function that calls all other functions Parameters ---------- args: Input arguments to the script """ # global model_init global gal_group_df global survey global path_to_proc global mf_type global ver # global mocknum_queue rseed = 12 np.random.seed(rseed) survey = args.survey machine = args.machine nproc = args.nproc nwalkers = args.nwalkers nsteps = args.nsteps mf_type = args.mf_type use_behroozi_sample = False ver = 2.0 dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_proc = dict_of_paths['proc_dir'] path_to_external = dict_of_paths['ext_dir'] path_to_data = dict_of_paths['data_dir'] path_to_int = dict_of_paths['int_dir'] if machine == 'bender': halo_catalog = '/home/asadm2/.astropy/cache/halotools/halo_catalogs/'\ 'vishnu/rockstar/vishnu_rockstar_test.hdf5' elif machine == 'mac': halo_catalog = path_to_raw + 'vishnu_rockstar_test.hdf5' if survey == 'eco': catl_file = path_to_proc + "gal_group_eco_data.hdf5" elif survey == 'resolvea' or survey == 'resolveb': catl_file = path_to_raw + "resolve/RESOLVE_liveJune2018.csv" if survey == 'eco': path_to_mocks = path_to_data + 'mocks/m200b/eco/' elif survey == 'resolvea': path_to_mocks = path_to_external + 'RESOLVE_A_mvir_catls/' elif survey == 'resolveb': path_to_mocks = path_to_external + 'RESOLVE_B_mvir_catls/' print('Reading catalog') #No Mstar cut catl, volume, z_median = read_data_catl(catl_file, survey) print('Assigning colour to data') catl = assign_colour_label_data(catl) print('Measuring SMF for data') total_data, red_data, blue_data = measure_all_smf(catl, volume, True) print('Measuring error in data from mocks') sigma, corr_mat_inv = get_err_data(survey, path_to_mocks) print('sigma: \n', sigma) print('inv corr mat: \n', corr_mat_inv) print('red phi data: \n', red_data[1]) print('blue phi data: \n', blue_data[1]) if use_behroozi_sample: print('Reading 100 vishnu group catalogs') gal_group_df = reading_catls(path_to_proc + "gal_group.hdf5") col_idxs = [str(int(x)) for x in np.linspace(1, 101, 101)] cols_to_keep_set_one = [] for idx in range(len(col_idxs)): idx += 1 cols_to_keep_set_one.append('g_galtype_{0}'.format(idx)) cols_to_keep_set_one.append('groupid_{0}'.format(idx)) cols_to_keep_set_one.append('{0}_y'.format(idx)) if idx == 50: break cols_to_keep_set_one.append('cz') cols_to_keep_set_one.append('halo_mvir') cols_to_keep_set_one.append('cs_flag') cols_to_keep_set_two = [] for idx in range(len(col_idxs)): idx += 51 cols_to_keep_set_two.append('g_galtype_{0}'.format(idx)) cols_to_keep_set_two.append('groupid_{0}'.format(idx)) cols_to_keep_set_two.append('{0}_y'.format(idx)) if idx == 101: break cols_to_keep_set_two.append('cz') cols_to_keep_set_two.append('halo_mvir') cols_to_keep_set_two.append('cs_flag') global gal_group_df_one global gal_group_df_two gal_group_df_one = gal_group_df[cols_to_keep_set_one] gal_group_df_two = gal_group_df[cols_to_keep_set_two] else: ## Stellar mass in this is not in log whereas in the df in the if above ## it is print('Reading single Vishnu group catalog') gal_group_df = reading_catls(path_to_proc + "gal_group_95perc_r4.hdf5") print('Running MCMC') sampler = mcmc(nproc, nwalkers, nsteps, red_data[1], blue_data[1], sigma, corr_mat_inv)
def main(args): """ Main function that calls all other functions Parameters ---------- args: Input arguments to the script """ global model_init global survey global path_to_proc global mf_type rseed = 12 np.random.seed(rseed) survey = args.survey machine = args.machine nproc = args.nproc nwalkers = args.nwalkers nsteps = args.nsteps mf_type = args.mf_type dict_of_paths = cwpaths.cookiecutter_paths() path_to_raw = dict_of_paths['raw_dir'] path_to_proc = dict_of_paths['proc_dir'] path_to_external = dict_of_paths['ext_dir'] if machine == 'bender': halo_catalog = '/home/asadm2/.astropy/cache/halotools/halo_catalogs/'\ 'vishnu/rockstar/vishnu_rockstar_test.hdf5' elif machine == 'mac': halo_catalog = path_to_raw + 'vishnu_rockstar_test.hdf5' if survey == 'eco': catl_file = path_to_raw + "eco_all.csv" elif survey == 'resolvea' or survey == 'resolveb': catl_file = path_to_raw + "RESOLVE_liveJune2018.csv" if survey == 'eco': path_to_mocks = path_to_external + 'ECO_mvir_catls/' elif survey == 'resolvea': path_to_mocks = path_to_external + 'RESOLVE_A_mvir_catls/' elif survey == 'resolveb': path_to_mocks = path_to_external + 'RESOLVE_B_mvir_catls/' chi2_file = path_to_proc + 'smhm_run3/{0}_chi2.txt'.format(survey) chain_file = path_to_proc + 'smhm_run3/mcmc_{0}.dat'.format(survey) print('Reading chi-squared file') chi2 = read_chi2(chi2_file) print('Reading mcmc chain file') mcmc_table = read_mcmc(chain_file) print('Getting data in specific percentile') bf_params = get_paramvals_percentile(mcmc_table, 68, chi2) print('Reading catalog') catl, volume, cvar, z_median = read_catl(catl_file, survey) print('Assigning colour to data') catl = assign_colour_label_data(catl) print('Measuring SMF for data') total_data, red_data, blue_data = measure_all_smf(catl, volume, True) print('Measuring error in data from mocks') total_data[2], red_data[2], blue_data[2] = \ get_err_data(survey, path_to_mocks) print('Loading halo catalog') model_init = halocat_init(halo_catalog, z_median) print('Populating halos using best fit shmr params') gals_df_ = populate_mock(bf_params, model_init) gals_df_ = assign_cen_sat_flag(gals_df_) print('Running MCMC') sampler = mcmc(nproc, nwalkers, nsteps, red_data[1], blue_data[1], red_data[2], blue_data[2], gals_df_)