def setHdus(self, p): self.hdus = p self.table = fits_table(self.hdus[1].data)[0] T = self.table self.aa = T.aa.astype(float) self.kk = T.kk.astype(float) self.airmass = T.airmass
def readPhotoObj(self, run, camcol, field, filename=None): obj = PhotoObj(run, camcol, field) if filename is None: fn = self.getPath('photoObj', run, camcol, field) else: fn = filename obj.table = fits_table(fn) return obj
def getMaskPlane(self, name): # Mask planes are described in HDU 11 (the last HDU) if self.maskmap is None: self.maskmap = {} T = fits_table(self.hdus[-1].data) #print 'Got mask definition table' #T.about() T.cut(T.defname == 'S_MASKTYPE') for k,v in zip(T.attributename, T.value): k = k.replace('S_MASK_', '') if k == 'S_NMASK_TYPES': continue #print ' Mask', k, '=', v self.maskmap[k] = v if not name in self.maskmap: raise RuntimeError('Unknown mask plane \"%s\"' % name) return fits_table(self.hdus[1 + self.maskmap[name]].data)
def getPsfAtPoints(self, bandnum, x, y): ''' Reconstruct the SDSS model PSF from KL basis functions. x,y can be scalars or 1-d numpy arrays. Return value: if x,y are scalars: a PSF image if x,y are arrays: a list of PSF images ''' rtnscalar = np.isscalar(x) and np.isscalar(y) x = np.atleast_1d(x) y = np.atleast_1d(y) psf = fits_table(self.hdus[bandnum+1].data) psfimgs = None (outh, outw) = (None,None) # From the IDL docs: # http://photo.astro.princeton.edu/photoop_doc.html#SDSS_PSF_RECON # acoeff_k = SUM_i{ SUM_j{ (0.001*ROWC)^i * (0.001*COLC)^j * C_k_ij } } # psfimage = SUM_k{ acoeff_k * RROWS_k } for k in range(len(psf)): nrb = psf.nrow_b[k] ncb = psf.ncol_b[k] c = psf.c[k].reshape(5, 5) c = c[:nrb,:ncb] (gridi,gridj) = np.meshgrid(range(nrb), range(ncb)) if psfimgs is None: psfimgs = [np.zeros_like(psf.rrows[k]) for xy in np.broadcast(x,y)] (outh,outw) = (psf.rnrow[k], psf.rncol[k]) else: assert(psf.rnrow[k] == outh) assert(psf.rncol[k] == outw) for i,(xi,yi) in enumerate(np.broadcast(x,y)): #print 'xi,yi', xi,yi acoeff_k = np.sum(((0.001 * xi)**gridi * (0.001 * yi)**gridj * c)) if False: # DEBUG print 'coeffs:', (0.001 * xi)**gridi * (0.001 * yi)**gridj print 'c:', c for (coi,ci) in zip(((0.001 * xi)**gridi * (0.001 * yi)**gridj).ravel(), c.ravel()): print 'co %g, c %g' % (coi,ci) print 'acoeff_k', acoeff_k #print 'acoeff_k', acoeff_k.shape, acoeff_k #print 'rrows[k]', psf.rrows[k].shape, psf.rrows[k] psfimgs[i] += acoeff_k * psf.rrows[k] psfimgs = [img.reshape((outh,outw)) for img in psfimgs] if rtnscalar: return psfimgs[0] return psfimgs
def setHdus(self, p): self.hdus = p t = fits_table(p[6].data) # the table has only one row... assert(len(t) == 1) t = t[0] #self.table = t self.gain = t.gain self.dark_variance = t.dark_variance self.sky = t.sky self.skyerr = t.skyerr self.psp_status = t.status # Double-Gaussian PSF params self.dgpsf_s1 = t.psf_sigma1_2g self.dgpsf_s2 = t.psf_sigma2_2g self.dgpsf_b = t.psf_b_2g # summary PSF width (sigmas) self.psf_fwhm = t.psf_width * (2.*np.sqrt(2.*np.log(2.)))
def readFrame(self, run, camcol, field, band, filename=None): ''' http://data.sdss3.org/datamodel/files/BOSS_PHOTOOBJ/frames/RERUN/RUN/CAMCOL/frame.html ''' f = Frame(run, camcol, field, band) # ... if filename is None: fn = self.getPath('frame', run, camcol, field, band) else: fn = filename #print 'reading file', fn p = pyfits.open(fn) #print 'got', len(p), 'HDUs' # in nanomaggies f.image = p[0].data # converts counts -> nanomaggies f.calib = p[1].data # table with val,x,y -- binned; use bilinear interpolation to expand sky = p[2].data f.sky = sky.field('allsky')[0] #print 'sky shape', f.sky.shape if len(f.sky.shape) != 2: f.sky = f.sky.reshape((-1, 256)) f.skyxi = sky.field('xinterp')[0] f.skyyi = sky.field('yinterp')[0] #print 'p3:', p[3] # table -- asTrans structure tab = fits_table(p[3].data) assert(len(tab) == 1) tab = tab[0] # DR7 has NODE, INCL in radians... f.astrans = AsTrans(run, camcol, field, band, node=np.deg2rad(tab.node), incl=np.deg2rad(tab.incl), astrans=tab, cut_to_band=False) return f