def gtlike_analysis(pipeline, roi, name, hypothesis, upper_limit): print 'Performing Gtlike crosscheck for %s' % hypothesis gtlike = Gtlike(roi, savedir='savedir' if pipeline.cachedata else None) like = gtlike.like print 'About to fit gtlike ROI' print summary(like, maxdist=10) paranoid_gtlike_fit(like, verbosity=4) print 'Done fiting gtlike ROI' print summary(like, maxdist=10) like.writeXml("%s/srcmodel_gtlike_%s_%s.xml" % (pipeline.dirdict['data'], hypothesis, name)) r = source_dict(like, name) upper_limit_kwargs = dict() if upper_limit: pul = GtlikePowerLawUpperLimit(like, name, cl=.95, verbosity=4) r['powerlaw_upper_limit'] = pul.todict() def sed(kind, **kwargs): print 'Making %s SED' % kind s = GtlikeSED(like, name, always_upper_limit=True, verbosity=4, upper_limit_kwargs=upper_limit_kwargs, **kwargs) s.plot('%s/sed_gtlike_%s_%s.png' % (pipeline.dirdict['seds'], kind, name)) s.save('%s/sed_gtlike_%s_%s.yaml' % (pipeline.dirdict['seds'], kind, name)) sed('1bpd_%s' % hypothesis, bin_edges=[10**2, 10**3, 10**4, 10**5.5]) sed('2bpd_%s' % hypothesis, bin_edges=np.logspace(2, 5.5, 8)) if not pipeline.fast: sed('4bpd_%s' % hypothesis, bin_edges=np.logspace(2, 5.5, 15)) return r
def gtlike_analysis(pipeline, roi, name, hypothesis, upper_limit): print "Performing Gtlike crosscheck for %s" % hypothesis gtlike = Gtlike(roi, savedir="savedir" if pipeline.cachedata else None) like = gtlike.like print "About to fit gtlike ROI" print summary(like, maxdist=10) paranoid_gtlike_fit(like, verbosity=4) print "Done fiting gtlike ROI" print summary(like, maxdist=10) like.writeXml("%s/srcmodel_gtlike_%s_%s.xml" % (pipeline.dirdict["data"], hypothesis, name)) r = source_dict(like, name) upper_limit_kwargs = dict() if upper_limit: pul = GtlikePowerLawUpperLimit(like, name, cl=0.95, verbosity=4) r["powerlaw_upper_limit"] = pul.todict() def sed(kind, **kwargs): print "Making %s SED" % kind s = GtlikeSED(like, name, always_upper_limit=True, verbosity=4, upper_limit_kwargs=upper_limit_kwargs, **kwargs) s.plot("%s/sed_gtlike_%s_%s.png" % (pipeline.dirdict["seds"], kind, name)) s.save("%s/sed_gtlike_%s_%s.yaml" % (pipeline.dirdict["seds"], kind, name)) sed("1bpd_%s" % hypothesis, bin_edges=[10 ** 2, 10 ** 3, 10 ** 4, 10 ** 5.5]) sed("2bpd_%s" % hypothesis, bin_edges=np.logspace(2, 5.5, 8)) if not pipeline.fast: sed("4bpd_%s" % hypothesis, bin_edges=np.logspace(2, 5.5, 15)) return r
def gtlike_analysis(roi, name, hypothesis, max_free, seddir, datadir, plotdir, upper_limit=False, cutoff=False, cutoff_model=None, do_bandfitter=False, do_sed=False, ): print 'Performing Gtlike crosscheck for %s' % hypothesis frozen = freeze_far_away(roi, roi.get_source(name).skydir, max_free) gtlike=Gtlike(roi, extended_dir_name=datadir) unfreeze_far_away(roi, frozen) global like like=gtlike.like like.tol = 1e-1 # I found that the default tol '1e-3' would get the fitter stuck in infinite loops import pyLikelihood as pyLike like.setFitTolType(pyLike.ABSOLUTE) emin, emax = get_full_energy_range(like) print 'About to fit gtlike ROI' print summary(like, maxdist=10) paranoid_gtlike_fit(like, verbosity=4) print 'Done fiting gtlike ROI' print summary(like, maxdist=10) spectrum_name = like.logLike.getSource(name).spectrum().genericName() like.writeXml("%s/srcmodel_gtlike_%s_%s_%s.xml"%(datadir, hypothesis, spectrum_name, name)) r=source_dict(like, name) #upper_limit_kwargs=dict(delta_log_like_limits=10) upper_limit_kwargs=dict() if upper_limit: pul = GtlikePowerLawUpperLimit(like, name, emin=emin, emax=emax, cl=.95, upper_limit_kwargs=upper_limit_kwargs, verbosity=4, xml_name=join("%s/srcmodel_gtlike_%s_%s_%s.xml" % (datadir, hypothesis, 'PowerLaw_Upper_Limit', name))) r['powerlaw_upper_limit'] = pul.todict() cul = GtlikeCutoffUpperLimit(like, name, Index=1.7, Cutoff=3e3, b=1, cl=.95, upper_limit_kwargs=upper_limit_kwargs, verbosity=4, xml_name=join("%s/srcmodel_gtlike_%s_%s_%s.xml" % (datadir, hypothesis, 'PLSuperExpCutoff_Upper_Limit', name))) r['cutoff_upper_limit'] = cul.todict() if do_bandfitter: if all_energy(emin,emax): try: bf = GtlikeBandFitter(like, name, bin_edges=one_bin_per_dec(emin,emax), upper_limit_kwargs=upper_limit_kwargs, verbosity=4) bf.plot('%s/bandfits_gtlike_%s_%s.png' % (plotdir,hypothesis,name)) r['bandfits'] = bf.todict() except Exception, ex: print 'ERROR computing bandfit:', ex traceback.print_exc(file=sys.stdout)
fit(fit_bg_first=True) fit() if localize: paranoid_localize(roi, name, verbosity=4) if fit_extension: roi.fit_extension(which=name) paranoid_localize(roi, name) fit() print 'Making pointlike SED for hypothesis %s' % hypothesis sed = PointlikeSED(roi, name, verbosity=4) sed.save('%s/sed_pointlike_4bpd_%s_%s.yaml' % (pipeline.dirdict['seds'],hypothesis,name)) sed.plot('%s/sed_pointlike_4bpd_%s_%s.png' % (pipeline.dirdict['seds'],hypothesis,name)) print_summary() p = source_dict(roi, name) if upper_limit: pul = PointlikePowerLawUpperLimit(roi, name, cl=.95, verbosity=4) p['powerlaw_upper_limit']=pul.todict() roi.toXML(filename="%s/srcmodel_pointlike_%s_%s.xml"%(pipeline.dirdict['data'], hypothesis, name)) roi.save('roi_%s_%s.dat' % (hypothesis,name)) return p
if localize: paranoid_localize(roi, name, verbosity=4) if fit_extension: roi.fit_extension(which=name) paranoid_localize(roi, name) fit() print 'Making pointlike SED for hypothesis %s' % hypothesis sed = PointlikeSED(roi, name, verbosity=4) sed.save('%s/sed_pointlike_4bpd_%s_%s.yaml' % (pipeline.dirdict['seds'], hypothesis, name)) sed.plot('%s/sed_pointlike_4bpd_%s_%s.png' % (pipeline.dirdict['seds'], hypothesis, name)) print_summary() p = source_dict(roi, name) if upper_limit: pul = PointlikePowerLawUpperLimit(roi, name, cl=.95, verbosity=4) p['powerlaw_upper_limit'] = pul.todict() roi.toXML(filename="%s/srcmodel_pointlike_%s_%s.xml" % (pipeline.dirdict['data'], hypothesis, name)) roi.save('roi_%s_%s.dat' % (hypothesis, name)) return p