def main(): plane_mask=True pmval=1 bcut=False bmin=-90 bmax=90 lcut=False lmin=-180 lmax=180 mask_ring=True inner=0 outer=30 maps_dir = '/zfs/bsafdi/data/' fermi_data_dir = '/zfs/tslatyer/fermimaps/allsky/' work_dir = '/zfs/nrodd/NPTFWorking/' emin=8 emax=9 nside=256 eventclass=5 eventtype=3 newstyle=1 ps_file = '/zfs/nrodd/NPTFWorking/data/ps_data/ps_lists/3FGL_0to15_tiny.txt' n_ps_run=10 indeg=True #loadforpsf = fp.fermi_plugin(maps_dir,fermi_data_dir=fermi_data_dir,work_dir=work_dir,CTB_en_min = emin,CTB_en_max=emax,nside=nside,eventclass=eventclass,eventtype=eventtype,newstyle=newstyle) f = sim.fake_fermi_data(maps_dir,fermi_data_dir=fermi_data_dir,work_dir=work_dir,CTB_en_min = emin,CTB_en_max=emax,nside=nside,eventclass=eventclass,eventtype=eventtype,newstyle=newstyle) f.load_psf() sigma_PSF_deg = f.sigma_PSF_deg[0:-1] print "sigma_PSF_deg:",sigma_PSF_deg print "Ebin:",emin print "Eventclass:",eventclass print "Eventtype:",eventtype print "Gaussian results:" start = time.time() the_map = np.ones(hp.nside2npix(256)) simt.draw_points(sigma_PSF_deg,1000000,0.,0.,the_map) end = time.time() #print "Time taken:",end - start f.load_king_param() print "King results:" start = time.time() the_map = np.ones(hp.nside2npix(256)) simt.draw_points_king(f.fcore_arr[0],f.score_arr[0],f.gcore_arr[0],f.stail_arr[0],f.gtail_arr[0],f.SpE_arr[0],1000000,0.,0.,the_map) end = time.time()
def main(): # Define basic vars maps_dir = '/zfs/bsafdi/data/' fermi_data_dir = '/zfs/tslatyer/fermimaps/allsky/' work_dir = '/zfs/nrodd/NPTFWorking/' emin=0 emax=4 nside=256 eventclass=5 eventtype=0 newstyle=1 ps_file = '/zfs/nrodd/NPTFWorking/data/ps_data/ps_lists/3FGL_0to15_tiny.txt' n_ps_run=10 indeg=True #loadforpsf = fp.fermi_plugin(maps_dir,fermi_data_dir=fermi_data_dir,work_dir=work_dir,CTB_en_min = emin,CTB_en_max=emax,nside=nside,eventclass=eventclass,eventtype=eventtype,newstyle=newstyle) f = sim.fake_fermi_data(maps_dir,fermi_data_dir=fermi_data_dir,work_dir=work_dir,CTB_en_min = emin,CTB_en_max=emax,nside=nside,eventclass=eventclass,eventtype=eventtype,newstyle=newstyle,use_king=True) f.load_psf() sigma_PSF_deg = f.sigma_PSF_deg[0:-1] f.load_king_param()
disk_file_name= 'thindiskmodel_ec.fits' #'simplediskmodel_ec.fits' #################### ##########Internal code ###dirs P_plots_dir = work_dir + 'plots/' + tag + '/' + run_tag_poiss + '/' NDI_plots_dir = work_dir + 'plots/' + tag + '/' + run_tag_plus_iso + '/' DI_plots_dir = work_dir + 'plots/' + tag + '/' + run_tag_disk_only + '/' ####fermi fake data f = sim.fake_fermi_data(maps_dir,CTB_en_min=CTB_start_bin,CTB_en_max=CTB_end_bin,nside=nside,data_name=data_type) f.add_diffuse(comp = 'p6') #diffuse f.add_bubbles() #bubbles f.add_iso() #iso f.add_nfw() #NFW-DM f.add_template_from_file('disk',disk_file_name) #we will call template 'disk' f.use_template_normalization_file(norm_file_path,key_suffix='-0') if prun: f_P = copy.deepcopy(f) if jdrun: f_DI = copy.deepcopy(f) if ndirun:
def setup_for_scan(): global f, b, new_template_dict, n_ps, newstyle # Load Fermi Plugin and its basic functionality f = sim.fake_fermi_data(maps_dir,fermi_data_dir=fermi_data_dir,work_dir=work_dir,CTB_en_min = emin,CTB_en_max=emax,nside=nside,eventclass=eventclass,eventtype=eventtype,newstyle=newstyle) if mask_type!='False': f.make_ps_mask(mask_type=mask_type,force_energy=force_ps_mask,energy_bin=force_ps_mask_bin) # Add appropriate templates f.add_diffuse_newstyle(comp = diff, eventclass = eventclass, eventtype = eventtype) if extraicstemp!='False': f.add_diffuse_newstyle(comp = extraicstemp, eventclass = eventclass, eventtype = eventtype) f.add_bubbles(comp = 'bubs') f.add_iso(comp = 'iso') if add_ps_model: f.add_ps_model(comp = 'ps_model') if nfw_dm: f.add_nfw(comp = 'nfw') f.add_template_from_file('disk',disk_file_name) # always add the disk here even if don't use as often needed for NPTF if norm_file!='False': if len(add_norm_file_for_comps) > 0 and add_norm_file != 'False': print 'using first normalization file: ', norm_file f.use_template_normalization_file(norm_file,key_suffix='-0',dont_use_keys=add_norm_file_for_comps) print 'using second normalization file: ', add_norm_file f.use_template_normalization_file(add_norm_file,key_suffix='-0',use_keys=add_norm_file_for_comps) else: f.use_template_normalization_file(norm_file,key_suffix='-0') # This is where things begin to vary from a normal run to make fake data medians = np.load(plots_dir + 'medians.npy') norms_dict = {} # Assumes only template that had a log prior was the NFW for i in range(len(medians)): if medians[i,0] == 'nfw-0': val = 10**float(medians[i,1]) else: val = float(medians[i,1]) norms_dict[medians[i,0]] = val #norms_dict = {'p6-0':0.5} # Now rescale the templates to the norm extracted from the fits for key in norms_dict.keys(): print 'on key ',key[:-2] print np.shape(f.template_dict[key[:-2]]) print norms_dict[key] f.template_dict[key[:-2]] = norms_dict[key]*np.array(f.template_dict[key[:-2]]) # Initiate Poissonian background templates #f.init_back(['nfw','iso','bubs','p6']) f.init_back(['p6','bubs','nfw','iso']) # Make the mask f.make_mask_total(plane_mask=plane_mask, band_mask_range = [-pmval,pmval], lcut=lcut, lmin=lmin, lmax=lmax, bcut=bcut, bmin=bmin, bmax=bmax, mask_ring=mask_ring, inner=inner, outer=outer) # Make the fake data f.make_fake_data() # Save the fake data and the location of the point sources (called keys) f.save_fake_data(plots_dir + 'FD_ap.txt.gz') f.save_fake_data_key(plots_dir + 'FD_ap_key.txt.gz')
def setup_for_scan(): global f, b, new_template_dict, n_ps, newstyle # Load Fermi Plugin and its basic functionality f = sim.fake_fermi_data(maps_dir,fermi_data_dir=fermi_data_dir,work_dir=work_dir,CTB_en_min = emin,CTB_en_max=emax,nside=nside,eventclass=eventclass,eventtype=eventtype,newstyle=newstyle) if mask_type!='False': f.make_ps_mask(mask_type=mask_type,force_energy=force_ps_mask,energy_bin=force_ps_mask_bin) # Add appropriate templates f.add_diffuse_newstyle(comp = diff, eventclass = eventclass, eventtype = eventtype) if extraicstemp!='False': f.add_diffuse_newstyle(comp = extraicstemp, eventclass = eventclass, eventtype = eventtype) f.add_bubbles(comp = 'bubs') f.add_iso(comp = 'iso') if add_ps_model: f.add_ps_model(comp = 'ps_model') if nfw_dm: f.add_nfw(comp = 'nfw') f.add_template_from_file('disk',disk_file_name) # always add the disk here even if don't use as often needed for NPTF if norm_file!='False': if len(add_norm_file_for_comps) > 0 and add_norm_file != 'False': print 'using first normalization file: ', norm_file f.use_template_normalization_file(norm_file,key_suffix='-0',dont_use_keys=add_norm_file_for_comps) print 'using second normalization file: ', add_norm_file f.use_template_normalization_file(add_norm_file,key_suffix='-0',use_keys=add_norm_file_for_comps) else: f.use_template_normalization_file(norm_file,key_suffix='-0') # This is where things begin to vary from a normal run to make fake data medians = np.load(plots_dir + 'medians.npy') norms_dict = {} # Assumes only template that had a log prior was the NFW for i in range(len(medians)): if medians[i,0] == 'nfw-0': val = 10**float(medians[i,1]) else: val = float(medians[i,1]) norms_dict[medians[i,0]] = val # Now rescale the templates to the norm extracted from the fits for key in norms_dict.keys(): print 'on key ',key[:-2] print np.shape(f.template_dict[key[:-2]]) print norms_dict[key] f.template_dict[key[:-2]] = norms_dict[key]*np.array(f.template_dict[key[:-2]]) # Initiate Poissonian background templates f.init_back(['nfw','iso','bubs','p6']) # Make the mask f.make_mask_total(plane_mask=plane_mask, band_mask_range = [-pmval,pmval], lcut=lcut, lmin=lmin, lmax=lmax, bcut=bcut, bmin=bmin, bmax=bmax, mask_ring=mask_ring, inner=inner, outer=outer) def load_ps_template(ps_path): with open(ps_path, 'rb') as F: the_list = pickle.load(F) return the_list list_disk = load_ps_template(plots_dir + 'disk_ps.txt') list_iso = load_ps_template(hl_plots_dir + 'iso_ps.txt') if not just_disk: list_nfw = load_ps_template(plots_dir + 'nfw_ps.txt') # Use spectrum norms bins = emax - emin if not just_disk: nfw_norm_reduced=np.array([np.mean(f.template_dict['nfw'][en]) for en in range(bins)]) # Make e-dep breaks - I calculated these in Mathematica Sb_iso_list = np.array([0.804978, 0.838517, 0.873453, 0.909845, 0.947752, 0.98724, 1.02837, 1.07122, 1.11585, 1.16234]) if not just_disk: Sb_nfw_list = list_nfw[0][3]*nfw_norm_reduced / np.sum(nfw_norm_reduced) else: Sb_disk_list = np.array([1.84547, 1.1267, 0.68787, 0.419958, 0.256393, 0.156533, 0.0955661, 0.058345, 0.0356207, 0.0217471]) # Make theta lists theta_ps_iso=list_iso[0][0:3]+list(Sb_iso_list) if not just_disk: theta_ps_nfw=list_nfw[0][0:3]+list(Sb_nfw_list) else: theta_ps_disk=list_disk[0][0:3]+list(Sb_disk_list) # Load PSF f.load_king_param() # Now add the NPTF models f.init_ps_king(list_iso[1],theta_ps_iso,f.fcore_arr,f.score_arr,f.gcore_arr,f.stail_arr,f.gtail_arr,f.SpE_arr,n_ps=n_ps_max,smin=0.1) if not just_disk: f.init_ps_king(list_nfw[1],theta_ps_nfw,f.fcore_arr,f.score_arr,f.gcore_arr,f.stail_arr,f.gtail_arr,f.SpE_arr,n_ps=n_ps_max,smin=0.1) else: f.init_ps_king(list_disk[1],theta_ps_disk,f.fcore_arr,f.score_arr,f.gcore_arr,f.stail_arr,f.gtail_arr,f.SpE_arr,n_ps=n_ps_max,smin=0.1) # Make the fake data f.make_fake_data() # Save the fake data and the location of the point sources (called keys) f.save_fake_data(plots_dir + 'FD.txt.gz') f.save_fake_data_key(plots_dir + 'FD_key.txt.gz')
disk_file_name= 'thindiskmodel_ec.fits' #'simplediskmodel_ec.fits' #################### ##########Internal code ###dirs P_plots_dir = work_dir + 'plots/' + tag + '/' + run_tag_poiss + '/' NDI_plots_dir = work_dir + 'plots/' + tag + '/' + run_tag_plus_iso + '/' DI_plots_dir = work_dir + 'plots/' + tag + '/' + run_tag_disk_only + '/' ####fermi fake data f = sim.fake_fermi_data(maps_dir,fermi_data_dir=fermi_data_dir,work_dir=work_dir,CTB_en_min=CTB_start_bin,CTB_en_max=CTB_end_bin+1,nside=nside,eventclass=eventclass,eventtype=eventtype,newstyle=newstyle f.add_diffuse_newstyle(comp = 'p6', eventclass = eventclass, eventtype = eventtype) f.add_bubbles() #bubbles f.add_iso() #iso f.add_nfw() #NFW-DM f.add_template_from_file('disk',disk_file_name) #we will call template 'disk' f.use_template_normalization_file(norm_file_path,key_suffix='-0') if prun: f_P = copy.deepcopy(f) if jdrun: f_DI = copy.deepcopy(f) if ndirun: f_NDI = copy.deepcopy(f)