def fit_cat_F2_test(IDS, filt_list, fit_instructions, run): fit_cat = pipes.fit_catalogue(IDS, fit_instructions, load_zfk2_cdfs_data, spectrum_exists=False, cat_filt_list=filt_list, run=run) fit_cat.fit(verbose=False) fit_cat_nokbr = pipes.fit_catalogue(IDS, fit_instructions, load_zfk2_cdfs_data_nokbr, spectrum_exists=False, cat_filt_list=filt_list[:-2], run=run + '_no_kbr') fit_cat_nokbr.fit(verbose=False) print('Done!') return fit_cat, fit_cat_nokbr
def fitcatmodel(ID, run): filt_list = np.loadtxt("filters/goodss_filt_list.txt", dtype="str") exp = {} exp["age"] = (0.1, 15.) exp["tau"] = (0.3, 12.) exp["massformed"] = (2., 15.) exp["metallicity"] = (0., 2.5) dust = {} dust["type"] = "Cardelli" dust["Av"] = (0., 2.) fit_instructions = {} fit_instructions["redshift"] = (0., 10.) fit_instructions["exponential"] = exp fit_instructions["dust"] = dust fit_cat = pipes.fit_catalogue(ID, fit_instructions, load_goodss,\ spectrum_exists=False, cat_filt_list=filt_list, run=run) fit_cat.fit(verbose=False) fig = fit_cat.plot_spectrum_posterior(save=False, show=True) fig = fit_cat.plot_sfh_posterior(save=False, show=True) fig = fit_cat.plot_corner(save=False, show=True)
fit_instructions["t_bc"] = 0.01 fit_instructions["dblplaw"] = dblplaw fit_instructions["dust"] = dust fit_instructions["nebular"] = nebular fit_instructions["calib"] = calib return fit_instructions # Load list of objects to be fitted from catalogue. IDs = np.array(["UDS-HST020821SELECT"]) redshifts = np.array([1.0909]) # Fit the catalogue of objects. cat_filt_list = get_cat_filt_list(IDs) fit_instructions = get_fit_instructions() fit_cat = pipes.fit_catalogue(IDs, fit_instructions, load_vandels, run="no_noise", cat_filt_list=cat_filt_list, vary_filt_list=True, redshifts=redshifts, redshift_sigma=0.005, make_plots=True, time_calls=True, full_catalogue=True, n_posterior=1000) fit_cat.fit(verbose=False)
fit_instructions["nebular"] = nebular # load the catalog cat_name = sys.argv[2] if cat_name in ['cosmos', 'xmm', 'deep', 'elais']: cat = Table.read('../catalogs/' + cat_name + '_to_fit_' + sys.argv[3] + '.fits') IDs = cat['ID'] redshifts = cat['Z_BEST'] redshift_sigmas = np.maximum(cat['Z_BEST'] - cat['Z_BEST68_LOW'], (cat['Z_BEST68_HIGH'] - cat['Z_BEST68_LOW']) / 2).tolist() fit_cat = pipes.fit_catalogue(IDs, fit_instructions, load_gal, spectrum_exists=False, cat_filt_list=filt_list_full, run=sys.argv[1], redshifts=redshifts, redshift_sigma=redshift_sigmas) else: cat = Table.read('../catalogs/' + cat_name) IDs = cat['ID'] redshifts = cat['z'] redshift_sigmas = cat['z_sigma'].tolist() fit_cat = pipes.fit_catalogue(IDs, fit_instructions, load_gal_model_cat, spectrum_exists=False, cat_filt_list=filt_list_full, run=sys.argv[1], redshifts=redshifts,
ID = str(fit.galaxy.ID) fit.posterior.get_advanced_quantities() if "redshift" in fit.fitted_model.params: redshift = np.median(fit.posterior.samples["redshift"]) else: redshift = fit.fitted_model.model_components["redshift"] # Plot the posterior photometry and full spectrum. wavs = (fit.posterior.model_galaxy.wavelengths) * (1 + redshift) / 10 posterior = fit.posterior.samples["spectrum_full"] spectrum = np.median(posterior, axis=0) data = np.c_[wavs, spectrum] distance = cosmo.luminosity_distance(redshift).value * (10**5) uvj = fit.posterior.samples["uvj"] umag = np.median(uvj[:, 0]) umag_obs = umag + 5 * np.log(distance) fname = 'G13_spectra/' + ID + '_spectrum.dat' np.savetxt(fname, data) IDs = np.array([2408, 1424, 2782, 18180, 8785, 22211, 22085, 3973, 9209]) fit_cat = pipes.fit_catalogue(IDs, fit_instructions, load_goodss,\ spectrum_exists=False, cat_filt_list=filt_list, run="guo_2020atopten", make_plots = True, analysis_function=analysisfunc, full_catalogue=True) fit_cat.fit(verbose=False, n_live=1000)
redshifts.append(redshift_percentile) ssfrs.append(ssfr_percentile) IDlist.append(ID) i = np.where(IDs == ID)[0][0] if (i % 20) == 0: np.savetxt('redshift_percentiles', np.array(redshifts)) np.savetxt('ssfr_percentiles', np.array(ssfrs)) np.savetxt('subsample_IDs', np.array(IDlist)) if ID == IDs[-1]: np.savetxt('redshift_percentiles_full', np.array(redshifts)) np.savetxt('ssfr_percentiles_full', np.array(ssfrs)) np.savetxt('subsample_IDs_full', np.array(IDlist)) fit_cat = pipes.fit_catalogue(IDs, fit_instructions, loaduds, spectrum_exists=False, cat_filt_list=filt_list, run="uds_20to23kmag", make_plots=False, analysis_function=analysisfunc, full_catalogue=True) fit_cat.fit(verbose=False, n_live=1000, mpi_serial=False) data['redshift_2.5'] = np.array(redshifts) data['ssfr_97.5'] = np.array(ssfrs) newtable = fits.BinTableHDU(data=data) newtable.writeto('output_cats/subsample.fits')
dblplaw = {} dblplaw["tau"] = (0., 15.) dblplaw["alpha"] = (0.01, 1000.) dblplaw["beta"] = (0.01, 1000.) dblplaw["alpha_prior"] = "log_10" dblplaw["beta_prior"] = "log_10" dblplaw["massformed"] = (1., 13.) dblplaw["metallicity"] = (0.01, 2.5) dblplaw["metallicity_prior"] = "log_10" dust = {} dust["type"] = "Calzetti" dust["Av"] = (0., 8.) dust["eta"] = 2. nebular = {} nebular["logU"] = -3. fit_instructions = {} fit_instructions["redshift"] = (0., 10.) #fit_instructions["exponential"] = exp fit_instructions["dblplaw"] = dblplaw fit_instructions["dust"] = dust fit_instructions["t_bc"] = 0.01 fit_instructions["nebular"] = nebular IDs = np.arange(1, 6001) fit_cat = pipes.fit_catalogue(IDs, fit_instructions, load_goodss,\ spectrum_exists=False, cat_filt_list=filt_list, run="guo_v2") fit_cat.fit(verbose=False)