def altdiff_followup(self, hypothesis, dist, halo, TS): name = self.name print dist, halo, TS # Note, Gulli's alt diffuse models only go to 100GeV! roi = self.reload_roi(hypothesis, fit_emax=1e5) roi.print_summary() print roi.get_source(name) for source in get_background(roi): roi.del_source(source) print 'Loading alternate diffuse models' diff = get_gulli_diffuse(dist=dist, halo=halo, TS=TS, version=2, event_class='source', verbosity=True) print 'Adding alternate diffuse models to ROI' for source in diff: roi.add_source(source) print 'Freezing insignificant diffuse models' freeze_insignificant_diffuse(roi,allowed_fraction=0.03, verbosity=True) print 'Printing ROI' roi.print_summary() print 'Doing gtlike analysis' results=gtlike_analysis(roi, name=name, max_free = self.max_free, seddir=self.seddir, datadir=self.datadir, plotdir=self.plotdir, hypothesis='%s_altdiff_dist_%s_halo_%s_TS_%s' % (hypothesis,dist,halo,TS), upper_limit=False, do_bandfitter=False, do_sed=True, ) savedict(results,'results_%s_altdiff_dist_%s_halo_%s_TS_%s_%s.yaml' % (name,dist,halo,TS,hypothesis))
def altdiff_followup(self, hypothesis, dist, halo, TS): name = self.name print dist, halo, TS # Note, Gulli's alt diffuse models only go to 100GeV! roi = self.reload_roi(hypothesis, fit_emax=1e5) roi.print_summary() print roi.get_source(name) for source in get_background(roi): roi.del_source(source) print 'Loading alternate diffuse models' diff = get_gulli_diffuse(dist=dist, halo=halo, TS=TS, version=2, event_class='source', verbosity=True) print 'Adding alternate diffuse models to ROI' for source in diff: roi.add_source(source) print 'Freezing insignificant diffuse models' freeze_insignificant_diffuse(roi, allowed_fraction=0.03, verbosity=True) print 'Printing ROI' roi.print_summary() print 'Doing gtlike analysis' results = gtlike_analysis( roi, name=name, max_free=self.max_free, seddir=self.seddir, datadir=self.datadir, plotdir=self.plotdir, hypothesis='%s_altdiff_dist_%s_halo_%s_TS_%s' % (hypothesis, dist, halo, TS), upper_limit=False, do_bandfitter=False, do_sed=True, ) savedict( results, 'results_%s_altdiff_dist_%s_halo_%s_TS_%s_%s.yaml' % (name, dist, halo, TS, hypothesis))
def update_roi(self): roi = self.roi if self.verbosity: print "Replacing current diffuse file with Gulli's diffuse files" if self.verbosity: print 'Deleting previous background sources:' for source in get_background(roi): if self.verbosity: print ' .. Deleting source %s' % source roi.del_source(source) if self.verbosity: print 'Getting Gulli Diffuse:' diffuse_sources = get_gulli_diffuse(verbosity=self.verbosity, **self.diffuse_kwargs) if self.verbosity: print 'Adding Gulli Diffuse files to ROI:' for source in diffuse_sources: if self.verbosity: print ' .. adding file %s to the ROI' % source.name roi.add_source(source) galatic_sources = [i for i in diffuse_sources if isinstance(i.dmodel[0],DiffuseFunction)] assert len(galatic_sources) == len(diffuse_sources) - 1, "Exactly one isotropic diffue source" free_galatic_sources = [i for i in diffuse_sources if np.any(i.smodel.free)] if self.verbosity: print 'Testing significance of free Galactic sources (to see if they need to be merged):' insignificant = [i for i in free_galatic_sources if not is_significant(roi, i.name, self.fraction, self.verbosity)] if len(insignificant) == 0: print 'No insignificant sources, returning!' return elif len(insignificant) == 0: print 'Only one insignificant source (%s). Freezing it and returning' % insignificant[0].name roi.modify(which=insignificant[0].name, free=False) return else: if self.verbosity: print 'Multiple insignificant sources in ROI. Merging them!' print 'Insignificant free Galactic diffuse sources are:' for i in insignificant: print ' .. %s' % i.name if self.verbosity: print 'Deleting (and the merging) the insignificant free Galactic sources' for source in insignificant: if self.verbosity: print ' .. Deleting (and then merging) %s' % source.name roi.del_source(source.name) merged = merge_diffuse(insignificant, mergefile=self.mergefile, verbosity=self.verbosity, short_name=self.short_name , compress=self.compress) if self.verbosity: print 'Adding merged Galactic diffuse source %s to ROI:' % (merged.name) roi.add_source(merged) if self.verbosity: print 'Testing if the merged Galactic diffuse source is significant' if is_significant(roi, merged.name, self.fraction, self.verbosity): if self.verbosity: print 'Keeping free the merged Galactic diffuse sources!' else: if self.verbosity: print 'Freezing the insignificant merged Galactic diffuse sources!' roi.modify(which=merged.name, free=False)