def projmap(self, map, vec2pix_func, vmin=None, vmax=None, badval=UNSEEN, cmap=None, norm=None, rot=None, coord=None, **kwds): """Project a map. Input: - map: a map - vec2pix_func: the function describing the pixelisation - vmin, vmax: min and max value to use instead of min max of the map - badval: the value of the bad pixels - cmapname: the name of the color map to use (see cm.datad.keys()) - rot: =(a,b,c) map is centered on (a,b) and rotated by angle c, in deg. - coord: the coordinate system of the map ('G','E' or 'C'), rotate the map if different from the axes coord syst. other keywords given to Axes.imshow """ img = self.proj.projmap(map, vec2pix_func, rot=rot, coord=coord) w = ~(npy.isnan(img) | npy.isinf(img) | pixelfunc.mask_bad(img, badval=badval)) try: if vmin is None: vmin = img[w].min() except ValueError: vmin = 0. try: if vmax is None: vmax = img[w].max() except ValueError: vmax = 0. if vmin > vmax: vmin = vmax if vmin == vmax: vmin -= 1. vmax += 1. cm, nn = get_color_table(vmin, vmax, img[w], cmap=cmap, norm=norm) ext = self.proj.get_extent() img = npy.ma.masked_values(img, badval) aximg = self.imshow(img, extent=ext, cmap=cm, norm=nn, interpolation='nearest', origin='lower', vmin=vmin, vmax=vmax, **kwds) xmin, xmax, ymin, ymax = self.proj.get_extent() self.set_xlim(xmin, xmax) self.set_ylim(ymin, ymax)
def projmap(self,map,vec2pix_func,vmin=None,vmax=None,badval=UNSEEN, cmap=None,norm=None,rot=None,coord=None,**kwds): """Project a map on the SphericalProjAxes. Parameters ---------- map : array-like The map to project. vec2pix_func : function The function describing the pixelisation. vmin, vmax : float, scalars min and max value to use instead of min max of the map badval : float The value of the bad pixels cmap : a color map The colormap to use (see matplotlib.cm) rot : sequence In the form (lon, lat, psi) (unit: degree):the center of the map is at (lon, lat) and rotated by angle psi around that direction. coord : {'G', 'E', 'C', None} The coordinate system of the map ('G','E' or 'C'), rotate the map if different from the axes coord syst. Notes ----- Other keywords are transmitted to :func:`matplotlib.Axes.imshow` """ img = self.proj.projmap(map,vec2pix_func,rot=rot,coord=coord) w = ~( np.isnan(img) | np.isinf(img) | pixelfunc.mask_bad(img, badval = badval) ) try: if vmin is None: vmin = img[w].min() except ValueError: vmin = 0. try: if vmax is None: vmax = img[w].max() except ValueError: vmax = 0. if vmin > vmax: vmin = vmax if vmin == vmax: vmin -= 1. vmax += 1. cm,nn = get_color_table(vmin,vmax,img[w],cmap=cmap,norm=norm) ext = self.proj.get_extent() img = np.ma.masked_values(img, badval) aximg = self.imshow(img,extent = ext,cmap=cm,norm=nn, interpolation='nearest',origin='lower', vmin=vmin,vmax=vmax,**kwds) xmin,xmax,ymin,ymax = self.proj.get_extent() self.set_xlim(xmin,xmax) self.set_ylim(ymin,ymax) return img
def projmap(self,map,vec2pix_func,vmin=None,vmax=None,badval=UNSEEN, cmap=None,norm=None,rot=None,coord=None,**kwds): """Project a map on the SphericalProjAxes. Parameters ---------- map : array-like The map to project. vec2pix_func : function The function describing the pixelisation. vmin, vmax : float, scalars min and max value to use instead of min max of the map badval : float The value of the bad pixels cmap : a color map The colormap to use (see matplotlib.cm) rot : sequence In the form (lon, lat, psi) (unit: degree):the center of the map is at (lon, lat) and rotated by angle psi around that direction. coord : {'G', 'E', 'C', None} The coordinate system of the map ('G','E' or 'C'), rotate the map if different from the axes coord syst. Notes ----- Other keywords are transmitted to :func:`matplotlib.Axes.imshow` """ img = self.proj.projmap(map,vec2pix_func,rot=rot,coord=coord) w = ~( np.isnan(img) | np.isinf(img) | pixelfunc.mask_bad(img, badval = badval) ) try: if vmin is None: vmin = img[w].min() except ValueError: vmin = 0. try: if vmax is None: vmax = img[w].max() except ValueError: vmax = 0. if vmin > vmax: vmin = vmax if vmin == vmax: vmin -= 1. vmax += 1. cm,nn = get_color_table(vmin,vmax,img[w],cmap=cmap,norm=norm) ext = self.proj.get_extent() img = np.ma.masked_values(img, badval) aximg = self.imshow(img,extent = ext,cmap=cm,norm=nn, interpolation='nearest',origin='lower', vmin=vmin,vmax=vmax,**kwds) xmin,xmax,ymin,ymax = self.proj.get_extent() self.set_xlim(xmin,xmax) self.set_ylim(ymin,ymax)
def projmap(self,map,vec2pix_func,vmin=None,vmax=None,badval=UNSEEN, cmap=None,norm=None,rot=None,coord=None,**kwds): """Project a map. Input: - map: a map - vec2pix_func: the function describing the pixelisation - vmin, vmax: min and max value to use instead of min max of the map - badval: the value of the bad pixels - cmapname: the name of the color map to use (see cm.datad.keys()) - rot: =(a,b,c) map is centered on (a,b) and rotated by angle c, in deg. - coord: the coordinate system of the map ('G','E' or 'C'), rotate the map if different from the axes coord syst. other keywords given to Axes.imshow """ img = self.proj.projmap(map,vec2pix_func,rot=rot,coord=coord) w = ~( npy.isnan(img) | npy.isinf(img) | pixelfunc.mask_bad(img, badval = badval) ) try: if vmin is None: vmin = img[w].min() except ValueError: vmin = 0. try: if vmax is None: vmax = img[w].max() except ValueError: vmax = 0. if vmin > vmax: vmin = vmax if vmin == vmax: vmin -= 1. vmax += 1. cm,nn = get_color_table(vmin,vmax,img[w],cmap=cmap,norm=norm) ext = self.proj.get_extent() img = npy.ma.masked_values(img, badval) aximg = self.imshow(img,extent = ext,cmap=cm,norm=nn, interpolation='nearest',origin='lower', vmin=vmin,vmax=vmax,**kwds) xmin,xmax,ymin,ymax = self.proj.get_extent() self.set_xlim(xmin,xmax) self.set_ylim(ymin,ymax)
def read_map(filename,field=0,dtype=np.float64,nest=False,hdu=1,h=False, verbose=False): """Read an healpix map from a fits file. Parameters ---------- filename : str the fits file name field : int or tuple of int, optional The column to read. Default: 0. By convention 0 is temperature, 1 is Q, 2 is U. Field can be a tuple to read multiple columns (0,1,2) dtype : data type, optional Force the conversion to some type. Default: np.float64 nest : bool, optional If True return the map in NEST ordering, otherwise in RING ordering; use fits keyword ORDERING to decide whether conversion is needed or not If None, no conversion is performed. hdu : int, optional the header number to look at (start at 0) h : boo, optional If True, return also the header. Default: False. verbose : bool, optional If True, print a number of diagnostic messages Returns ------- m | (m0, m1, ...) [, header] : array or a tuple of arrays, optionally with header appended The map(s) read from the file, and the header if *h* is True. """ hdulist=pf.open(filename) #print hdulist[1].header nside = hdulist[hdu].header.get('NSIDE') if nside is None: warnings.warn("No NSIDE in the header file : will use length of array", HealpixFitsWarning) else: nside = int(nside) if verbose: print 'NSIDE = %d'%nside if not pixelfunc.isnsideok(nside): raise ValueError('Wrong nside parameter.') ordering = hdulist[hdu].header.get('ORDERING','UNDEF').strip() if ordering == 'UNDEF': ordering = (nest and 'NESTED' or 'RING') warnings.warn("No ORDERING keyword in header file : " "assume %s"%ordering) if verbose: print 'ORDERING = %s in fits file'%ordering sz=pixelfunc.nside2npix(nside) if not hasattr(field, '__len__'): field = (field,) ret = [] for ff in field: m=hdulist[hdu].data.field(ff).astype(dtype).ravel() if (not pixelfunc.isnpixok(m.size) or (sz>0 and sz != m.size)) and verbose: print 'nside=%d, sz=%d, m.size=%d'%(nside,sz,m.size) raise ValueError('Wrong nside parameter.') if not nest is None: # no conversion with None if nest and ordering == 'RING': idx = pixelfunc.nest2ring(nside,np.arange(m.size,dtype=np.int32)) m = m[idx] if verbose: print 'Ordering converted to NEST' elif (not nest) and ordering == 'NESTED': idx = pixelfunc.ring2nest(nside,np.arange(m.size,dtype=np.int32)) m = m[idx] if verbose: print 'Ordering converted to RING' try: m[pixelfunc.mask_bad(m)] = UNSEEN except OverflowError, e: pass ret.append(m)
def read_map(filename, field=0, dtype=npy.float64, nest=False, hdu=1, h=False, verbose=False): """Read an healpix map from a fits file. Input: - filename: the fits file name Parameters: - field: the column to read Default: 0 by convention 0 is temperature, 1 is Q, 2 is U field can be a tuple to read multiple columns (0,1,2) - dtype: force the conversion to some type. Default: npy.float64 - nest=False: if True return the map in NEST ordering, otherwise in RING ordering; use fits keyword ORDERING to decide whether conversion is needed or not if None, no conversion is performed - hdu=1: the header number to look at (start at 0) - h=False: if True, return also the header - verbose=False: if True, print a number of diagnostic messages Return: - an array, a tuple of array, possibly with the header at the end if h is True """ hdulist = pyf.open(filename) # print hdulist[1].header nside = int(hdulist[hdu].header.get("NSIDE")) if nside is None: warnings.warn("No NSIDE in the header file : will use length of array", HealpixFitsWarning) if verbose: print "NSIDE = %d" % nside if not pixelfunc.isnsideok(nside): raise ValueError("Wrong nside parameter.") ordering = hdulist[hdu].header.get("ORDERING", "UNDEF").strip() if ordering == "UNDEF": ordering = nest and "NESTED" or "RING" warnings.warn("No ORDERING keyword in header file : " "assume %s" % ordering) if verbose: print "ORDERING = %s in fits file" % ordering sz = pixelfunc.nside2npix(nside) if not hasattr(field, "__len__"): field = (field,) ret = [] for ff in field: m = hdulist[hdu].data.field(ff).astype(dtype).ravel() if (not pixelfunc.isnpixok(m.size) or (sz > 0 and sz != m.size)) and verbose: print "nside=%d, sz=%d, m.size=%d" % (nside, sz, m.size) raise ValueError("Wrong nside parameter.") if nest != None: # no conversion with None if nest and ordering == "RING": idx = pixelfunc.nest2ring(nside, npy.arange(m.size, dtype=npy.int32)) m = m[idx] if verbose: print "Ordering converted to NEST" elif (not nest) and ordering == "NESTED": idx = pixelfunc.ring2nest(nside, npy.arange(m.size, dtype=npy.int32)) m = m[idx] if verbose: print "Ordering converted to RING" try: m[pixelfunc.mask_bad(m)] = UNSEEN except OverflowError, e: pass ret.append(m)
def read_map(filename, field=0, dtype=npy.float64, nest=False, hdu=1, h=False, verbose=False): """Read an healpix map from a fits file. Input: - filename: the fits file name Parameters: - field: the column to read Default: 0 by convention 0 is temperature, 1 is Q, 2 is U field can be a tuple to read multiple columns (0,1,2) - dtype: force the conversion to some type. Default: npy.float64 - nest=False: if True return the map in NEST ordering, otherwise in RING ordering; use fits keyword ORDERING to decide whether conversion is needed or not if None, no conversion is performed - hdu=1: the header number to look at (start at 0) - h=False: if True, return also the header - verbose=False: if True, print a number of diagnostic messages Return: - an array, a tuple of array, possibly with the header at the end if h is True """ hdulist = pyf.open(filename) #print hdulist[1].header nside = int(hdulist[hdu].header.get('NSIDE')) if nside is None: warnings.warn("No NSIDE in the header file : will use length of array", HealpixFitsWarning) if verbose: print 'NSIDE = %d' % nside if not pixelfunc.isnsideok(nside): raise ValueError('Wrong nside parameter.') ordering = hdulist[hdu].header.get('ORDERING', 'UNDEF').strip() if ordering == 'UNDEF': ordering = (nest and 'NESTED' or 'RING') warnings.warn("No ORDERING keyword in header file : " "assume %s" % ordering) if verbose: print 'ORDERING = %s in fits file' % ordering sz = pixelfunc.nside2npix(nside) if not hasattr(field, '__len__'): field = (field, ) ret = [] for ff in field: m = hdulist[hdu].data.field(ff).astype(dtype).ravel() if (not pixelfunc.isnpixok(m.size) or (sz > 0 and sz != m.size)) and verbose: print 'nside=%d, sz=%d, m.size=%d' % (nside, sz, m.size) raise ValueError('Wrong nside parameter.') if nest != None: # no conversion with None if nest and ordering == 'RING': idx = pixelfunc.nest2ring(nside, npy.arange(m.size, dtype=npy.int32)) m = m[idx] if verbose: print 'Ordering converted to NEST' elif (not nest) and ordering == 'NESTED': idx = pixelfunc.ring2nest(nside, npy.arange(m.size, dtype=npy.int32)) m = m[idx] if verbose: print 'Ordering converted to RING' try: m[pixelfunc.mask_bad(m)] = UNSEEN except OverflowError, e: pass ret.append(m)