def main(): # Set up logging logging.basicConfig( level=logging.INFO, format='%(asctime)s %(message)s', datefmt='%Y-%d-%m %I:%M:%S %p') # Get parameters from the provided parameter file param_file_path = sys.argv[1] params = parameters.get_params(param_file_path) zkey = params['zkey'] mkey = params['mkey'] rkey = params['ra_key'] dkey = params['dec_key'] t0 = time.time() if params['bins']['bin_in_lookback_time'] == True: z_pref = 'lookt' else: z_pref = 'z' # Stack in Slices or ALL AT ONCE Choice made here if params['bins']['stack_all_z_at_once'] == True: n_slices = 1 else: n_slices = len(params['bins']['z_nodes']) - 1 #Save Parameter file in folder save_paramfile(params) for i in range(n_slices): if params['bins']['stack_all_z_at_once'] == True: j = None stacked_flux_density_key = 'all_'+z_pref else: j = i if params['bins']['bin_in_lookback_time'] == True: stacked_flux_density_key = '{:.2f}'.format(params['bins']['t_nodes'][j])+'-'+'{:.2f}'.format(params['bins']['t_nodes'][j+1]) else: stacked_flux_density_key = str(params['bins']['t_nodes'][j])+'-'+str(params['bins']['t_nodes'][j+1]) print stacked_flux_density_key # From parameter file read maps, psfs, cats, and divide them into bins sky_library = get_maps(params) cats = get_catalogs(params) if params['bootstrap'] == True: pcat = Bootstrap(cats.table) # Bootstrap Loop Starts here for iboot in np.arange(params['number_of_boots'])+params['boot0']: #stacked_flux_densities = {} if params['bootstrap'] == True: print 'Running ' +str(int(iboot))+' of '+ str(int(params['boot0'])) +'-'+ str(int(params['boot0']+params['number_of_boots']-1)) + ' bootstraps' pcat.perturb_catalog(perturb_z = params['perturb_z']) bootcat = Field_catalogs(pcat.pseudo_cat,zkey=zkey,mkey=mkey,rkey=rkey,dkey=dkey) binned_ra_dec = get_bin_radec(params, bootcat, single_slice = j) if params['save_bin_ids'] == False: bin_ids = None else: bin_ids = get_bin_ids(params, bootcat, single_slice = j) out_file_path = params['io']['output_folder']+'/bootstrapped_fluxes/'+params['io']['shortname'] out_file_suffix = '_'+stacked_flux_density_key+'_boot_'+str(int(iboot)) else: binned_ra_dec = get_bin_radec(params, cats, single_slice = j) if params['save_bin_ids'] == False: bin_ids = None else: bin_ids = get_bin_ids(params, cats, single_slice = j) out_file_path = params['io']['output_folder'] + '/simstack_fluxes/' + params['io']['shortname'] out_file_suffix = '_'+stacked_flux_density_key # Do simultaneous stacking if params['float_background'] == True: stacked_flux_densities = stack_libraries_in_layers_w_background(sky_library,binned_ra_dec) else: stacked_flux_densities = stack_libraries_in_layers(sky_library,binned_ra_dec) save_stacked_fluxes(stacked_flux_densities,params, out_file_path,out_file_suffix, IDs=bin_ids) #pdb.set_trace() # Summarize timing t1 = time.time() tpass = t1-t0 logging.info("Done!") logging.info("") logging.info("Total time : {:.4f} minutes\n".format(tpass/60.))