def makeLinearizerDecam(fromFile, force=False, verbose=False): """Convert the specified DECam linearity FITS table to standard LSST format Details: - Input format is one table per CCD, HDU is amplifier number, the table has 3 columns: ADU, ADU_LINEAR_A, ADU_LINEAR_B. The values of ADU contiguous (0, 1, 2...) but check and error out if not. The values of the latter two are replacements (0+delta0, 1+delta1, 2+delta2...) and this is converted to offsets for the LSST linearization tables (delta0, delta1, delta2...) - Output is a set of LinearizeLookupTable instances, one per CCD, saved as dataset type "linearizer" - The row indices for the linearization lookup table are (row index=amp name): 0=A, 1=B @param[in] fromFile path to DECam linearity table (a FITS file with one HDU per amplifier) """ print("Making DECam linearizers from %r" % (fromFile, )) butler = Butler(mapper=DecamMapper) linearizerDir = DecamMapper.getLinearizerDir() if os.path.exists(linearizerDir): if not force: print("Output directory %r exists; use --force to replace" % (linearizerDir, )) sys.exit(1) print("Replacing data in linearizer directory %r" % (linearizerDir, )) else: print("Creating linearizer directory %r" % (linearizerDir, )) os.makedirs(linearizerDir) camera = DecamMapper().camera fromHDUs = fits.open(fromFile)[1:] # HDU 0 has no data assert len(fromHDUs) == len(camera) for ccdind, (detector, hdu) in enumerate(zip(camera, fromHDUs)): ccdnum = ccdind + 1 if verbose: print("ccdnum=%s; detector=%s" % (ccdnum, detector.getName())) fromData = hdu.data assert len(fromData.dtype) == 3 lsstTable = np.zeros((2, len(fromData)), dtype=np.float32) uncorr = fromData["ADU"] if not np.allclose(uncorr, np.arange(len(fromData))): raise RuntimeError( "ADU data not a range of integers starting at 0") for i, ampName in enumerate("AB"): # convert DECam replacement table to LSST offset table if verbose: print("DECam table for %s=%s..." % ( ampName, fromData["ADU_LINEAR_" + ampName][0:5], )) lsstTable[i, :] = fromData["ADU_LINEAR_" + ampName] - uncorr if verbose: print("LSST table for %s=%s..." % ( ampName, lsstTable[i, 0:5], )) linearizer = LinearizeLookupTable(table=lsstTable, detector=detector) butler.put(linearizer, "linearizer", dataId=dict(ccdnum=ccdnum)) print("Wrote %s linearizers" % (ccdind + 1, ))
def getSourcesAndCoeffsFile(self, filename='DECam_xtalk_20130606.txt'): """File containing DECam crosstalk coefficients. This text file is provided by NOAO in a particular format with information about the DECam crosstalk coefficients. It is available at http://www.ctio.noao.edu/noao/content/DECam-Calibration-Files Parameters ---------- filename : `str`, optional File containing the decam crosstalk coefficients, from NOAO. Returns ------- result : `str` Full path to filename. """ mapper = DecamMapper() packageName = mapper.getPackageName() packageDir = getPackageDir(packageName) return os.path.join(packageDir, 'decam', filename)
def getButler(datadir): bf = dafPersist.ButlerFactory( mapper=DecamMapper(root=os.path.join(datadir, "DATA"), calibRoot=os.path.join(datadir, "CALIB"))) return bf.create()
def setUp(self): self.bf = dafPersist.ButlerFactory(mapper=DecamMapper(root=".")) self.butler = self.bf.create()