def file(self): """ FFT data file name """ #corrdict = (self.cat_corr)['correction'] specdict = (self.cat_corr)['spec'] fft_dir = direc('fft', self.cat_corr) self.data_file = self.galdata.file_name # galaxy data file # FFT label fft_str = 'FFT_' if specdict['ell'] != 0: fft_str += 'Q_' #if (corrdict['name'].lower() in ('floriansn', 'hectorsn')) & (self.type != 'random'): # fft_corr_str = ''.join(['.', corrdict['name'].lower()]) # FFTs from data file fft_file = ''.join([ fft_dir, fft_str, (self.data_file).rsplit('/')[-1], '.grid', str(specdict['Ngrid']), '.P0', str(specdict['P0']), '.box', str(int(specdict['Lbox'])) ]) return fft_file
def file(self): """ power/bispectrum file """ catdict = (self.cat_corr)['catalog'] corrdict = (self.cat_corr)['correction'] specdict = (self.cat_corr)['spec'] # powerspectrum or bispectrum if self.type in ('pk'): spec_str = 'POWER_' elif self.type == 'bk': spec_str = 'BISP_' #if 'quad' not in specdict.keys(): # specdict['quad'] = False #if specdict['quad']: # spec_str += 'Q_' if self.ell != 0: spec_str += 'Q_' gal_data = Data('data', self.cat_corr, **self.kwargs) self.data_file = gal_data.file_name gal_file = (gal_data.file_name).split('/')[-1] rand_data = Data('random', self.cat_corr, **self.kwargs) self.random_file = rand_data.file_name spec_dir = direc('spec', self.cat_corr) if self.type == 'pk': specparam_str = ''.join([ '.grid', str(specdict['Ngrid']), '.P0', str(specdict['P0']), '.box', str(specdict['Lbox']) ]) elif self.type == 'bk': # (hardcoded) spectrum_str = ''.join([ '.grid', str(specdict['Ngrid']), '.nmax40.ncut3.s3', '.P0', str(specdict['P0']), '.box', str(specdict['Lbox']) ]) else: raise NotImplementedError() file_name = ''.join([ spec_dir, spec_str, gal_file, specparam_str ]) return file_name
def file(self): ''' Override parent class file() method in order to return file name of random catalog file. Everything is quite hardcoded. ''' cat_name = ((self.cat_corr)['catalog'])['name'].lower() data_dir = direc('data', self.cat_corr) if 'cmass' in cat_name: # CMASS if cat_name == 'cmass': # CMASS random catalog file_name = 'cmass-dr12v4-N-Reid.ran.dat' elif 'cmasslowz' in cat_name: # CMASS LOWZ combined random catalog if 'e2' in cat_name: cmasslowz_str = 'e2' elif 'e3' in cat_name: cmasslowz_str = 'e3' else: cmasslowz_str = '' if '_low' in cat_name: zbin_str = '_LOW' elif 'high' in cat_name: zbin_str = '_HIGH' else: raise NameError("Must specify redshift bin of CMASS LOWZ sample") file_name = ''.join([ 'random0_DR12v5_CMASSLOWZ', cmasslowz_str.upper(), zbin_str, '_North.ran.dat' ]) else: raise NotImplementedError() elif cat_name == 'nseries': # Nseries file_name = 'Nseries_cutsky_randoms_50x_redshifts_comp.dat' elif cat_name == 'qpm': # QPM file_name = 'a0.6452_rand50x.dr12d_cmass_ngc.vetoed.dat' else: raise NotImplementedError() return ''.join([data_dir, file_name])
def dlosenv_peakfit_sigma_env_fit(cat_corr, n_NN=3, fit='gauss', **kwargs): """ Linear fit of the best-fit sigma as a function of environment. Bestfit sigma values are computed for the dLOS distribution in bins of galaxy environment. Linear fit is done using MPFit. """ env_low, env_high, fpeaks, fpeak_errs, sigmas, sigma_errs, amps, nbins = \ dlos_envbin_peakfit( cat_corr, n_NN = n_NN, fit = fit, **kwargs ) env_mid = np.array( 0.5 * (env_low + env_high) ) if n_NN == 5: fit_range = np.where( env_mid < 40.0 ) else: raise NotImplementedError() p0 = [ -0.03, 4.0 ] # guess fa = {'x': env_mid[fit_range], 'y': sigmas[fit_range], 'err': sigma_errs[fit_range]} fit_param = mpfit.mpfit(mpfit_linear, p0, functkw=fa, quiet=1) best_slope = fit_param.params[0] best_yint = fit_param.params[1] try: if kwargs['writeout']: dlos_fpeak_envbin_fit_file = ''.join([ direc('data', cat_corr), 'DLOS_sigma_env_d', str(n_NN), 'NN_bin_bestfit.dat' ]) data_hdr = "Columns : bestfit_slope, bestfit_yint" data_fmt = ['%10.5f', '%10.5f'] np.savetxt( dlos_fpeak_envbin_fit_file, np.c_[best_slope, best_yint], fmt = data_fmt, delimiter = '\t', header = data_hdr ) except KeyError: pass return best_slope, best_yint
def file(self): """ power/bispectrum file """ specdict = (self.cat_corr)['spec'] # powerspectrum or bispectrum if self.type in ('pk'): spec_str = 'POWER_' elif self.type == 'bk': spec_str = 'BISP_' #if 'quad' not in specdict.keys(): # specdict['quad'] = False #if specdict['quad']: # spec_str += 'Q_' if (self.type == 'pk') and (self.ell != 0): spec_str += 'Q_' self.data_file = self.gal_data.file_name gal_file = (self.gal_data.file_name).split('/')[-1] self.random_file = self.rand_data.file_name spec_dir = direc('spec', self.cat_corr) if self.type == 'pk': specparam_str = ''.join([ '.grid', str(specdict['Ngrid']), '.P0', str(specdict['P0']), '.box', str(specdict['Lbox']) ]) elif self.type == 'bk': specparam_str = ''.join([ '.grid', str(specdict['Ngrid']), '.nmax40.ncut3.s3', '.P0', str(specdict['P0']), '.box', str(specdict['Lbox']) ]) else: raise NotImplementedError file_name = ''.join([ spec_dir, spec_str, gal_file, specparam_str ]) return file_name
def file(self): """ Override parent class file attribute Random catalog file """ cat_name = ((self.cat_corr)['catalog'])['name'].lower() data_dir = direc('data', self.cat_corr) if 'cmass' in cat_name: # CMASS if cat_name == 'cmass': # CMASS random catalog file_name = 'cmass-dr12v4-N-Reid.ran.dat' elif 'cmasslowz' in cat_name: # CMASS LOWZ combined random catalog if 'e2' in cat_name: cmasslowz_str = 'e2' elif 'e3' in cat_name: cmasslowz_str = 'e3' else: cmasslowz_str = '' if '_low' in cat_name: zbin_str = '_LOW' elif 'high' in cat_name: zbin_str = '_HIGH' else: raise NameError("Must specify redshift bin of CMASS LOWZ sample") file_name = ''.join([ 'random0_DR12v5_CMASSLOWZ', cmasslowz_str.upper(), zbin_str, '_North.ran.dat' ]) else: raise NotImplementedError() elif cat_name == 'nseries': # Nseries file_name = 'Nseries_cutsky_randoms_50x_redshifts_comp.dat' else: raise NotImplementedError() return ''.join([data_dir, file_name])
def file(self): """ Override parent class file() method in order to return file name of random catalog file. Everything is quite hardcoded. """ cat_name = ((self.cat_corr)["catalog"])["name"].lower() data_dir = direc("data", self.cat_corr) if "cmass" in cat_name: # CMASS if cat_name == "cmass": # CMASS random catalog file_name = "cmass-dr12v4-N-Reid.ran.dat" elif "cmasslowz" in cat_name: # CMASS LOWZ combined random catalog if "e2" in cat_name: cmasslowz_str = "e2" elif "e3" in cat_name: cmasslowz_str = "e3" else: cmasslowz_str = "" if "_low" in cat_name: zbin_str = "_LOW" elif "high" in cat_name: zbin_str = "_HIGH" else: raise NameError("Must specify redshift bin of CMASS LOWZ sample") file_name = "".join(["random0_DR12v5_CMASSLOWZ", cmasslowz_str.upper(), zbin_str, "_North.ran.dat"]) else: raise NotImplementedError() elif cat_name == "nseries": # Nseries file_name = "Nseries_cutsky_randoms_50x_redshifts_comp.dat" else: raise NotImplementedError() return "".join([data_dir, file_name])
def file(self): ''' Get file name of nbar(z) file ''' gal_data = Data('data', self.cat_corr, **self.kwargs) self.data_file = gal_data.file_name data_dir = direc('data', self.cat_corr) # data directory gal_file = (gal_data.file_name).split('/')[-1] nbar_file = ''.join([ data_dir, 'nbar_', gal_file ]) return nbar_file
def file(self): """ FFT data file name """ corrdict = (self.cat_corr)['correction'] specdict = (self.cat_corr)['spec'] fft_dir = direc('fft', self.cat_corr) if self.type == 'data': galdata = Data(self.type, self.cat_corr, **self.kwargs) # data class elif self.type == 'random': galdata = Random(self.type, self.cat_corr, **self.kwargs) # data class self.data_file = galdata.file_name # galaxy data file # FFT label fft_str = 'FFT_' if specdict['ell'] != 0: fft_str += 'Q_' fft_corr_str = '' if (corrdict['name'].lower() in ('floriansn', 'hectorsn')) & (self.type != 'random'): fft_corr_str = ''.join(['.', corrdict['name'].lower()]) # FFTs from data file fft_file = ''.join([ fft_dir, fft_str, (self.data_file).rsplit('/')[-1], fft_corr_str, '.grid', str(specdict['Ngrid']), '.P0', str(specdict['P0']), '.box', str(specdict['Lbox']) ]) return fft_file
def file(self): """ Name of line-of-sight displacement file """ catdict = self.cat_corr['catalog'] corrdict = self.cat_corr['correction'] dlos_dir = direc('data', self.cat_corr) dlos_str = 'DLOS_' dataclass = CorrCorrData(self.cat_corr, **self.kwargs) # data class data_file = dataclass.file_name # galaxy data file self.data_file = data_file # add bells and whistles here later # add bells and whistles here later # add bells and whistles here later file_name = ''.join([ dlos_dir, dlos_str, data_file.split('/')[-1] ]) return file_name
def build(self): ''' Build Fibercollided mock catalogs using specific idl routines or by using the given fiber collision weights Parameters ---------- cat_corr : catalog correction dictionary Notes ----- ''' catdict = (self.cat_corr)['catalog'] catalog_name = catdict['name'].lower() data_cols = self.datacolumns() data_fmts = self.datacols_fmt() data_hdrs = self.datacols_header() data_dir = direc('data', self.cat_corr) if catalog_name == 'nseries': # N-series mocks (high quality mocks with actual CMASS tiling) # original file orig_file = ''.join([ data_dir, 'CutskyN', str(catdict['n_mock']), '.rdzwc' ]) orig_ra, orig_dec, orig_z, orig_wfc, orig_zupw, orig_upw_index = np.loadtxt( orig_file, unpack = True, usecols = [0,1,2,4,5,6] ) # file with mask completeness mask_file = ''.join([data_dir, 'CutskyN', str(catdict['n_mock']), '.mask_info']) orig_wcomp = np.loadtxt(mask_file, unpack=True, usecols=[0]) coll = np.where(orig_wfc == 0.0) # data column list data_list = [ orig_ra, orig_dec, orig_z, orig_wfc, orig_wcomp, orig_zupw, orig_upw_index ] # handle upweighted redshift/index discrepancies by simply ignoring them. if not np.array(orig_z[orig_upw_index.astype(int)[coll]] == orig_zupw[coll]).all(): wrong_index = (coll[0])[np.where(orig_z[orig_upw_index.astype(int)[coll]] != orig_zupw[coll])[0]] warn_message = ''.join([ 'upweighted galaxy redshift and index data discrepancies in ', self.file(), ' ', str(len(wrong_index)), ' galaxies affected' ]) warnings.warn(warn_message, Warning) if len(wrong_index) > 0: for i_data, datum in enumerate(data_list): data_list[i_data] = np.delete(datum, wrong_index) elif catalog_name == 'qpm': # Quick Particle Mesh mocks from Jeremy (quantity over quality mocks) orig_file = ''.join([ '/mount/riachuelo2/rs123/BOSS/QPM/cmass/mocks/dr12d/ngc/data/', 'a0.6452_', str("%04d" % catdict['n_mock']), '.dr12d_cmass_ngc.rdz']) ra, dec, z, wfc = np.loadtxt(orig_file, unpack=True, usecols=[0,1,2,4]) orig_info_file = ''.join([ '/mount/riachuelo2/rs123/BOSS/QPM/cmass/mocks/dr12d/ngc/data/', 'a0.6452_', str("%04d" % catdict['n_mock']), '.dr12d_cmass_ngc.rdz.info']) # gal_id, comp, z_real, z_red, mass_halo, flag_sta, id_halo comp = np.loadtxt(orig_info_file, unpack=True, skiprows=3, usecols=[1]) if catdict['n_mock'] in (44, 46, 52, 53, 54, 56, 61, 707, 756, 794, 819, 831, 835, 838): orig_veto_file = ''.join([ '/mount/riachuelo1/hahn/data/QPM/dr12d/', 'a0.6452_', str("%04d" % catdict['n_mock']), '.dr12d_cmass_ngc.veto']) else: orig_veto_file = ''.join([ '/mount/riachuelo2/rs123/BOSS/QPM/cmass/mocks/dr12d/ngc/data/', 'a0.6452_', str("%04d" % catdict['n_mock']), '.dr12d_cmass_ngc.veto']) veto = np.loadtxt(orig_veto_file) n_gal = len(veto) if len(ra) != n_gal: print orig_file print orig_veto_file raise ValueError('veto mask doesnt match') vetomask = np.where(veto == 0) # data column list data_list = [ ra[vetomask], dec[vetomask], z[vetomask], wfc[vetomask], comp[vetomask] ] elif catalog_name == 'bigmd': # Big MultiDark P0 = 20000.0 # read original random catalog data_dir = '/mount/riachuelo1/hahn/data/BigMD/' if 'version' in catdict.keys(): if catdict['version'] == 'nowiggles': # simulation with no wiggles orig_file = ''.join([data_dir, 'nowiggles/BigMD-cmass-dr12v4-nowiggle-veto.dat']) else: raise NotImplementedError #orig_file = ''.join([data_dir, 'bigMD-cmass-dr12v4-wcp-veto.dat']) # hardcoded #orig_file = ''.join([data_dir, 'bigMD-cmass-dr12v4-RST-standardHAM-veto.dat']) #orig_file = ''.join([data_dir, 'bigMD-cmass-dr12v4-RST-quadru-veto.dat']) else: # default orig_file = ''.join([data_dir, 'BigMD-cmass-dr12v4-RST-standHAM-Vpeak-veto.dat']) # RA, Decl, Redhsift, veto ra, dec, z, wfkp, veto, wfc = np.loadtxt( orig_file, unpack=True, usecols=[0,1,2,3,4,5] ) n_gal = len(ra) #nbar = (1.0 / P0) * (1.0/wfkp - 1.0) vetomask = np.where(veto == 1) # impose vetomask data_list = [ ra[vetomask], dec[vetomask], z[vetomask], wfc[vetomask] ] elif catalog_name == 'tilingmock': # tiling mock input_file = ''.join([ '/mount/riachuelo1/hahn/data/tiling_mocks/', 'cmass-boss5003sector-icoll012.fidcosmo.dat']) output_file = self.file() idl_cmd = ' '.join([ 'idl', '-e', '"', "build_wcp_assign, 'tilingmock', input_file='"+input_file+"', output_file='"+output_file+"'", '"']) os.system(idl_cmd) return None elif 'cmass' in catalog_name: if catalog_name == 'cmass': # CMASS DR12v4 galaxy data data_file = ''.join([ data_dir, 'cmass-dr12v4-N-Reid.dat.fits' ]) data = mrdfits(data_file) # fits data object zlimit = np.where((data.z >= 0.43) & (data.z <= 0.7)) elif 'cmasslowz' in catalog_name: # CMASS LOWZ DR12v5 combined sample # for Ariel's sample has three separate # set of sectors '', 'e2', and 'e3' cmasslowz_str = '' if 'e2' in catalog_name: cmasslowz_str = 'E2' elif 'e3' in catalog_name: cmasslowz_str = 'E3' # Divide combined sample in two # two bins of redshift if '_low' in catalog_name: zmin, zmax = 0.2, 0.5 elif '_high' in catalog_name: zmin, zmax = 0.5, 0.75 else: raise NameError("redshift bin must be specified") # .fits data files from mk_catalog pipeline data_file = ''.join([ data_dir, 'galaxy_DR12v5_CMASSLOWZ', cmasslowz_str, '_North.fits.gz' ]) data = mrdfits(data_file) zlimit = np.where((data.z >= zmin) & (data.z < zmax)) # redshift limit else: raise NameError() data_list = [ (data.ra)[zlimit], (data.dec)[zlimit], (data.z)[zlimit], (data.nz)[zlimit], (data.weight_systot)[zlimit], (data.weight_noz)[zlimit], (data.weight_cp)[zlimit], (data.comp)[zlimit] ] # write to corrected file output_file = self.file() np.savetxt( output_file, (np.vstack(np.array(data_list))).T, fmt=data_fmts, delimiter='\t', header=data_hdrs ) return None
def build(self): ''' Build the random catalogs from original data Override parent class build attribute ''' cat_name = ((self.cat_corr)['catalog'])['name'].lower() if cat_name == 'nseries': # Nseries ---------------------------- # original random catalog data_dir = '/mount/riachuelo1/hahn/data/Nseries/' orig_rand_file = ''.join([data_dir, 'Nseries_cutsky_randoms_50x_redshifts.dat']) ra, dec, z = np.loadtxt(orig_rand_file, unpack=True, usecols=[0,1,2]) # RA, Decl, Redhsift # sector completeness catalog orig_comp_file = ''.join([data_dir, 'Nseries_cutsky_randoms_50x_maskinfo.dat']) comp = np.loadtxt(orig_comp_file, unpack=True, usecols=[0]) header_str = 'Columns : ra, dec, z, comp' data_list = [ra, dec, z, comp] data_fmt=['%10.5f', '%10.5f', '%10.5f', '%10.5f'] elif 'cmass' in cat_name: # CMASS -------------------------------- data_dir = direc('data', self.cat_corr) if cat_name == 'cmass': # random data fits file data_file = ''.join([data_dir, 'cmass-dr12v4-N-Reid.ran.fits']) cmass = mrdfits(data_file) # mask file mask_file = ''.join([data_dir, 'mask-cmass-dr12v4-N-Reid.fits']) mask = mrdfits(mask_file) ipoly = cmass.ipoly # polygon index comp = mask.weight[ipoly] # redshift limit zlimit = np.where((cmass.z >= 0.43) & (cmass.z <= 0.7)) elif 'cmasslowz' in cat_name: # CMASS LOWZ combined data # three different CMASS LOWZ if 'e2' in cat_name: cmasslowz_str = 'E2' elif 'e3' in cat_name: cmasslowz_str = 'E3' else: cmasslowz_str = '' if 'high' in cat_name: zmin, zmax = 0.5, 0.75 elif '_low' in cat_name: zmin, zmax = 0.2, 0.5 else: raise NameError("CMASSLOWZ Catalog must specify high or lowr edshift bin") # mask file mask_file = ''.join([ data_dir, 'mask_DR12v5_CMASSLOWZ', cmasslowz_str, '_North.fits.gz' ]) start_time = time.time() print 'Reading ', mask_file mask = mrdfits(mask_file) print 'took ', (time.time() - start_time)/60.0, ' minutes' # random data fits file data_file = ''.join([ data_dir, 'random0_DR12v5_CMASSLOWZ', cmasslowz_str, '_North.fits.gz' ]) start_time = time.time() print 'Reading ', data_file cmass = mrdfits(data_file) print 'took ', (time.time() - start_time)/60.0, ' minutes' ipoly = cmass.ipoly # polygon index comp = mask.weight[ipoly] # redshift limit zlimit = np.where((cmass.z >= zmin) & (cmass.z < zmax)) else: raise NotImplementedError("Only CMASS and CMASS+LOWZ combined sample implemented") header_str = 'columns : ra, dec, z, nbar, comp' #ra, dec, z, nz, comp data_list = [(cmass.ra)[zlimit], (cmass.dec)[zlimit], (cmass.z)[zlimit], (cmass.nz)[zlimit], comp[zlimit]] data_fmt=['%10.5f', '%10.5f', '%10.5f', '%.5e', '%10.5f'] else: raise NotImplementedError() # write to corrected file output_file = self.file() np.savetxt( output_file, (np.vstack(np.array(data_list))).T, fmt=data_fmt, delimiter='\t', header=header_str ) return None
def build(self): """ Completely replace parent class build attribute in order to ruild the random catalogs from original survey data. Everything is hardcoded. """ cat_name = ((self.cat_corr)["catalog"])["name"].lower() if cat_name == "nseries": # Nseries ---------------------------- # original random catalog data_dir = "/mount/riachuelo1/hahn/data/Nseries/" orig_rand_file = "".join([data_dir, "Nseries_cutsky_randoms_50x_redshifts.dat"]) ra, dec, z = np.loadtxt(orig_rand_file, unpack=True, usecols=[0, 1, 2]) # RA, Decl, Redhsift # sector completeness catalog orig_comp_file = "".join([data_dir, "Nseries_cutsky_randoms_50x_maskinfo.dat"]) comp = np.loadtxt(orig_comp_file, unpack=True, usecols=[0]) header_str = "Columns : ra, dec, z, comp" data_list = [ra, dec, z, comp] data_fmt = ["%10.5f", "%10.5f", "%10.5f", "%10.5f"] elif "cmass" in cat_name: # CMASS -------------------------------- data_dir = direc("data", self.cat_corr) if cat_name == "cmass": # random data fits file data_file = "".join([data_dir, "cmass-dr12v4-N-Reid.ran.fits"]) cmass = mrdfits(data_file) # mask file mask_file = "".join([data_dir, "mask-cmass-dr12v4-N-Reid.fits"]) mask = mrdfits(mask_file) ipoly = cmass.ipoly # polygon index comp = mask.weight[ipoly] # redshift limit zlimit = np.where((cmass.z >= 0.43) & (cmass.z <= 0.7)) elif "cmasslowz" in cat_name: # CMASS LOWZ combined data # three different CMASS LOWZ if "e2" in cat_name: cmasslowz_str = "E2" elif "e3" in cat_name: cmasslowz_str = "E3" else: cmasslowz_str = "" if "high" in cat_name: zmin, zmax = 0.5, 0.75 elif "_low" in cat_name: zmin, zmax = 0.2, 0.5 else: raise NameError("CMASSLOWZ Catalog must specify high or lowr edshift bin") # mask file mask_file = "".join([data_dir, "mask_DR12v5_CMASSLOWZ", cmasslowz_str, "_North.fits.gz"]) start_time = time.time() print "Reading ", mask_file mask = mrdfits(mask_file) print "took ", (time.time() - start_time) / 60.0, " minutes" # random data fits file data_file = "".join([data_dir, "random0_DR12v5_CMASSLOWZ", cmasslowz_str, "_North.fits.gz"]) start_time = time.time() print "Reading ", data_file cmass = mrdfits(data_file) print "took ", (time.time() - start_time) / 60.0, " minutes" ipoly = cmass.ipoly # polygon index comp = mask.weight[ipoly] # redshift limit zlimit = np.where((cmass.z >= zmin) & (cmass.z < zmax)) else: raise NotImplementedError("Only CMASS and CMASS+LOWZ combined sample implemented") header_str = "columns : ra, dec, z, nbar, comp" # ra, dec, z, nz, comp data_list = [(cmass.ra)[zlimit], (cmass.dec)[zlimit], (cmass.z)[zlimit], (cmass.nz)[zlimit], comp[zlimit]] data_fmt = ["%10.5f", "%10.5f", "%10.5f", "%.5e", "%10.5f"] else: raise NotImplementedError() # write to corrected file output_file = self.file() np.savetxt(output_file, (np.vstack(np.array(data_list))).T, fmt=data_fmt, delimiter="\t", header=header_str) return None