def roi_circle(roi_index, galactic=True, radius=5.0): """ return (lon,lat,radius) tuple for given nside=12 position """ from skymaps import Band sdir = Band(12).dir(roi_index) return (sdir.l(), sdir.b(), radius) if galactic else (sdir.ra(), sdir.dec(), radius)
def setup(self, **kwargs): self.plotfolder = 'rois' self.title = 'ROI summary' self.source_name = 'observed' # default for base class self.plots_kw = {} filename = 'rois.pickle' refresh = kwargs.pop( 'refresh', not os.path.exists(filename) or os.path.getmtime(filename) < os.path.getmtime('pickle.zip')) if refresh: files, pkls = self.load_pickles('pickle') assert len( files ) == 1728, 'Expected to find 1728 files, found %d' % len(files) rdict = dict() exclude = ('sources', 'name') for i, pkl in enumerate(pkls): skydir = Band(12).dir(i) tdict = dict((key, item) for key, item in pkl.items() if key not in exclude) tdict.update(sources=pkl['sources'].keys()) glon = skydir.l() if glon > 180: glon -= 360. glat = skydir.b() ra = skydir.ra() dec = skydir.dec() tdict.update(glon=glon, glat=glat, ra=ra, dec=dec) rdict[i] = tdict self.df = pd.DataFrame(rdict).transpose() self.df.to_pickle(filename) print 'saved %s' % filename else: print 'loading %s' % filename self.df = pd.read_pickle(filename) # move this into refresh? rois = self.df rx = rois['ra dec glat glon'.split()].copy() try: rx['chisq'] = [r['chisq'] for r in rois['counts']] except: print '***Failed to find counts, skip creating rois.csv' return rx['npar'] = [len(p) for p in rois.parameters] rx.index.name = 'name' ### ?? #rx['ring'] = [10**p[0] for p in rois.parameters] #rx['iso'] = [10**p[1] for p in rois.parameters] rx.to_csv('rois.csv') print 'saved rois.csv' self.energy = self.df.ix[0]['counts']['energies'] self.funcs = [] self.fnames = []
def fill_zea(self, index, fignum=12, axes=None, show_kw=None, **kwargs): """ index: integer, or a SkyDir the HP12 index if integer figmun: integer used if axes is None show_kw : dict override imshow keywords kwargs size pixelsize galactic """ if axes is None: plt.close(fignum) fig = plt.figure(fignum, figsize=(6, 6)) axes = fig.gca() if type(index) == types.IntType: sdir = Band(12).dir(index) title = 'HP12_%4d' % index else: sdir = index title = 'l = %.1f, b=%.1f' % (sdir.l(), sdir.b()) title = kwargs.pop('title', title) kw = self.ZEA_kw kw.update(kwargs) zea = image.ZEA(sdir, **kw) zea.grid() zea.fill(self.get_pyskyfun()) zea.imshow(**(show_kw if show_kw is not None else self.imshow_kw)) zea.colorbar() if title is not None: axes.set_title(title) if self.sources is not None: count = 0 for s in self.sources: sdir = SkyDir(s.ra, s.dec) if not zea.inside(sdir): continue count += 1 inside = self.band.index(sdir) == index zea.plot_source(s.name, sdir, symbol='*' if inside else 'd', markersize=14 if inside else 8, color='w') print 'found %d sources to plot' % count if self.map_path is not None: fout = os.path.join(self.map_path, hpname(index) + '.png') plt.savefig(fout, bbox_inches='tight') print 'saved figure to %s' % fout plt.draw_if_interactive() return zea