def make_3panel(self, center, size=10, pixelsize=0.02, galactic=False, scale=1, label_1FGL=True, labels=None, separate_figures=False, fignum_base=10): import pylab as P from matplotlib.colorbar import ColorbarBase from matplotlib.colors import Normalize from uw.utilities.image import ZEA cmap = P.cm.jet cmap.set_bad('white') if separate_figures: axes = [] for i in xrange(1, 4): P.figure(i + fignum_base) axes += [P.gca()] else: axes = [P.subplot(1, 3, i) for i in xrange(1, 4)] zeas = [ ZEA(center, size=size, pixelsize=pixelsize, galactic=galactic, axes=ax) for ax in axes ] mods = [1, 2, 0] for i in xrange(0, 3): self.set_mode(mods[i]) zeas[i].fill(PySkyFunction(self)) zeas[i].grid() axes[i].imshow(zeas[i].image**(0.5 if scale else 1), cmap=cmap) if label_1FGL: names, skydirs = self.get_1FGL_sources(zeas[0]) for na, sd in zip(names, skydirs): for z in zeas: z.plot_source(na, sd, color='white') if labels is not None: names, skydirs = labels for na, sd in zip(names, skydirs): for z in zeas: z.plot_source(na, sd, color='white') if separate_figures: # basically a "show" for i in xrange(1, 4): P.figure(i + fignum_base) axes[i - 1].set_autoscale_on(True) cb = ColorbarBase(axes[i - 1], orientation='vertical', cmap=cmap) #P.colorbar() return axes, zeas
def get_ZEA(self, axes=None, nticks=None): """ axes and nticks can be created by this object's constructor, but are more logically specified here. If they are not specified, get values from initial object creation. """ # get out of the object all parameters which should be passed to ZEA. if hasattr(self.size, '__iter__'): raise Exception("Can only create ZEA object for square objects.") zea_dict = dict((d[0],self.__dict__[d[0]]) for d in ZEA.defaults if hasattr(d,'__iter__') and \ hasattr(self,d[0])) if axes is not None: zea_dict['axes'] = axes if nticks is not None: zea_dict['nticks'] = nticks from uw.utilities.image import ZEA zea = ZEA(self.center, **zea_dict) zea.skyimage = self.skyimage # recalculate, in case the sky image has changed zea.image = ROIImage.skyimage2numpy(self.skyimage) # The old one gets removed by python's garbage collector (when zea.skyimage is replaced). zea.projector = zea.skyimage.projector() zea.vmin, zea.vmax = zea.skyimage.minimum(), zea.skyimage.maximum() return zea
def make_comp(roi, outstem, size=15, pixelsize=0.02, galactic=True, ebands=[100, 500, 2200, 10000], double_back=True): from uw.utilities.image import ZEA multi = 1. + double_back counter = 1 for emin, emax in zip(ebands[:-1], ebands[1:]): print 'Working on image %d of %d' % (counter, len(ebands) - 1) rko = ROI_KDEMap_OTF(roi, emin=[emin, multi * emin], emax=[emax, multi * emax]) z = ZEA(roi.roi_dir, size=size, pixelsize=pixelsize, galactic=galactic, fitsfile='%s_%d_%d.fits' % (outstem, emin, emax)) im = z.fill(rko.pyskyfun()) del (z)
def make_zea(self, center, size=10, pixelsize=0.02, galactic=False): z = ZEA(center, size=size, pixelsize=pixelsize, galactic=galactic) z.fill(PySkyFunction(self)) self.z = z
def make_map(self, center, size=10, pixelsize=0.02, galactic=False, axes=None, scale=1, thresh_low=0, thresh_high=np.inf, label_1FGL=True, mode=1, cmap=None, log_transform=False, labels=None): """ scale : 0 == linear, 1 == sqrt """ import pylab as P from uw.utilities.image import ZEA from matplotlib.colorbar import ColorbarBase from matplotlib.colors import Normalize self.set_mode(mode) if axes is None: axes = P.gca() cmap = cmap or P.cm.jet cmap.set_bad('white') z = ZEA(center, size=size, pixelsize=pixelsize, galactic=galactic, axes=axes) z.fill(PySkyFunction(self)) im = z.image.copy() print 'Max Value: %.2f' % (im.max()) im[im < thresh_low] = np.nan im[im > thresh_high] = thresh_high z.grid() im = im**(0.5 if scale else 1) if log_transform: im[im < 1] = 1 im = np.log10(im) P.imshow(im, cmap=cmap) #P.colorbar(ax=axes,cmap=cmap,orientation='horizontal') #P.contour(im,np.asarray([9,16,25,50,100,1000])**(0.5 if scale else 1)) #P.contour(im,10) #contours = np.asarray([9,16,25,36,49,64,81,100,225,400,625,900,1225,1600])**(0.5 if scale else 1) #if log_transform: contours = np.log10(contours) #P.contour(im,contours) if label_1FGL: names, skydirs = self.get_1FGL_sources(z) for na, sd in zip(names, skydirs): z.plot_source(na, sd, color='gray' if thresh_low > 0 else 'white') if labels is not None: try: names, skydirs = labels except: skydirs = labels names = ['S%d' % (i) for i in xrange(len(labels))] for na, sd in zip(names, skydirs): z.plot_source(na, sd, color='gray' if thresh_low > 0 else 'white') return z
def make_zea(self, center, size=10, pixelsize=0.02, galactic=False): from uw.utilities.image import ZEA z = ZEA(center, size=size, pixelsize=pixelsize, galactic=galactic) z.fill(PySkyFunction(self)) self.z = z