def makeCameraFromPolicy(filename, writeRepo=False, outputDir=None, doClobber=False, ccdToUse=None, shortNameMethod=lambda x: x): """ Make a Camera from a paf file @param filename: name of policy file to read @param writeRepo: write out repository files? @param outputDir: output directory to write files into @param doClobber: clobber any files existing in the repository? @param ccdToUse: Type of ccd to use, otherwise use ccd specified in the paf @param shortNameMethod: Method to compactify ccd names into names easily used in paths @return Camera object """ #This is all fragile as the CameraGeomDictionary.paf will go away. policyFile = pexPolicy.DefaultPolicyFile("afw", "CameraGeomDictionary.paf", "policy") defPolicy = pexPolicy.Policy.createPolicy(policyFile, policyFile.getRepositoryPath(), True) polFile = pexPolicy.DefaultPolicyFile("obs_cfht", filename) geomPolicy = pexPolicy.Policy.createPolicy(polFile) geomPolicy.mergeDefaults(defPolicy.getDictionary()) ampParams = makeAmpParams(geomPolicy) ccdParams = makeCcdParams(geomPolicy, ampParams) ccdInfoDict = parseCcds(geomPolicy, ccdParams, ccdToUse) camConfig = parseCamera(geomPolicy) camConfig.detectorList = dict([(i, ccdInfo) for i, ccdInfo in enumerate(ccdInfoDict['ccdInfo'])]) if writeRepo: if outputDir is None: raise ValueError("Need output directory for writting") def makeDir(dirPath, doClobber=False): """Make a directory; if it exists then clobber or fail, depending on doClobber @param[in] dirPath: path of directory to create @param[in] doClobber: what to do if dirPath already exists: if True and dirPath is a dir, then delete it and recreate it, else raise an exception @throw RuntimeError if dirPath exists and doClobber False """ if os.path.exists(dirPath): if doClobber and os.path.isdir(dirPath): print "Clobbering directory %r" % (dirPath,) shutil.rmtree(dirPath) else: raise RuntimeError("Directory %r exists" % (dirPath,)) print "Creating directory %r" % (dirPath,) os.makedirs(dirPath) # write data products makeDir(dirPath=outputDir, doClobber=doClobber) camConfigPath = os.path.join(outputDir, "camera.py") with open(camConfigPath, 'w') as outfile: outfile.write("#!!!!This file is auto generated.----Do not edit!!!!\n"+\ "#!!!!Edit input file and regenerate with $OBS_CFHT_DIR/bin/genCameraRepository.py\n") camConfig.saveToStream(outfile) for detectorName, ampTable in ccdInfoDict['ampInfo'].iteritems(): shortDetectorName = shortNameMethod(detectorName) ampInfoPath = os.path.join(outputDir, shortDetectorName + ".fits") ampTable.writeFits(ampInfoPath) return makeCameraFromCatalogs(camConfig, ccdInfoDict['ampInfo'])
def ReturnCamera(baseDir): """ This method reads in the files baseDir/focalplanelayout.txt baseDir/segmentation.txt and returns an afw.cameraGeom object Below is the original documentation of the function this code was copied from: Create the configs for building a camera. This runs on the files distributed with PhoSim. Currently gain and saturation need to be supplied as well. The file should have three columns: on disk amp id (R22_S11_C00), gain, saturation. For example: DetectorLayoutFile -- https://dev.lsstcorp.org/cgit/LSST/sims/phosim.git/plain/data/lsst/focalplanelayout.txt?h=dev SegmentsFile -- https://dev.lsstcorp.org/cgit/LSST/sims/phosim.git/plain/data/lsst/segmentation.txt?h=dev """ defaultOutDir = 'scratch' DetectorLayoutFile = os.path.join(baseDir, 'focalplanelayout.txt') SegmentsFile = os.path.join(baseDir, 'segmentation.txt') GainFile = None phosimVersion='1.0' ampTableDict = makeAmpTables(SegmentsFile, GainFile) detectorConfigList = makeDetectorConfigs(DetectorLayoutFile, phosimVersion) #Build the camera config. camConfig = CameraConfig() camConfig.detectorList = dict([(i,detectorConfigList[i]) for i in range(len(detectorConfigList))]) camConfig.name = 'LSST' camConfig.plateScale = 2.0 #arcsec per mm pScaleRad = afwGeom.arcsecToRad(camConfig.plateScale) pincushion = 0.925 # Don't have this yet ticket/3155 #camConfig.boresiteOffset_x = 0. #camConfig.boresiteOffset_y = 0. tConfig = afwGeom.TransformConfig() tConfig.transform.name = 'inverted' radialClass = afwGeom.xyTransformRegistry['radial'] tConfig.transform.active.transform.retarget(radialClass) # According to Dave M. the simulated LSST transform is well approximated (1/3 pix) # by a scale and a pincusion. #this is ultimately used to convert from focal plane coordinates to pupil coordinates #see the asgnment below to tmc.transforms tConfig.transform.active.transform.coeffs = [0., 1./pScaleRad, 0., pincushion/pScaleRad] #tConfig.transform.active.boresiteOffset_x = camConfig.boresiteOffset_x #tConfig.transform.active.boresiteOffset_y = camConfig.boresiteOffset_y tmc = afwGeom.TransformMapConfig() tmc.nativeSys = FOCAL_PLANE.getSysName() tmc.transforms = {PUPIL.getSysName():tConfig} camConfig.transformDict = tmc myCamera = makeCameraFromCatalogs(camConfig, ampTableDict) return myCamera
def ReturnCamera(baseDir): """ This method reads in the files baseDir/focalplanelayout.txt baseDir/segmentation.txt and returns an afw.cameraGeom object Below is the original documentation of the function this code was copied from: Create the configs for building a camera. This runs on the files distributed with PhoSim. Currently gain and saturation need to be supplied as well. The file should have three columns: on disk amp id (R22_S11_C00), gain, saturation. For example: DetectorLayoutFile -- https://dev.lsstcorp.org/cgit/LSST/sims/phosim.git/plain/data/lsst/focalplanelayout.txt?h=dev SegmentsFile -- https://dev.lsstcorp.org/cgit/LSST/sims/phosim.git/plain/data/lsst/segmentation.txt?h=dev """ defaultOutDir = 'scratch' DetectorLayoutFile = os.path.join(baseDir, 'focalplanelayout.txt') SegmentsFile = os.path.join(baseDir, 'segmentation.txt') GainFile = None phosimVersion='1.0' ampTableDict = makeAmpTables(SegmentsFile, GainFile) detectorConfigList = makeDetectorConfigs(DetectorLayoutFile, phosimVersion) #Build the camera config. camConfig = CameraConfig() camConfig.detectorList = dict([(i,detectorConfigList[i]) for i in xrange(len(detectorConfigList))]) camConfig.name = 'LSST' camConfig.plateScale = 2.0 #arcsec per mm pScaleRad = afwGeom.arcsecToRad(camConfig.plateScale) pincushion = 0.925 # Don't have this yet ticket/3155 #camConfig.boresiteOffset_x = 0. #camConfig.boresiteOffset_y = 0. tConfig = afwGeom.TransformConfig() tConfig.transform.name = 'inverted' radialClass = afwGeom.xyTransformRegistry['radial'] tConfig.transform.active.transform.retarget(radialClass) # According to Dave M. the simulated LSST transform is well approximated (1/3 pix) # by a scale and a pincusion. #this is ultimately used to convert from focal plane coordinates to pupil coordinates #see the asgnment below to tmc.transforms tConfig.transform.active.transform.coeffs = [0., 1./pScaleRad, 0., pincushion/pScaleRad] #tConfig.transform.active.boresiteOffset_x = camConfig.boresiteOffset_x #tConfig.transform.active.boresiteOffset_y = camConfig.boresiteOffset_y tmc = afwGeom.TransformMapConfig() tmc.nativeSys = FOCAL_PLANE.getSysName() tmc.transforms = {PUPIL.getSysName():tConfig} camConfig.transformDict = tmc myCamera = makeCameraFromCatalogs(camConfig, ampTableDict) return myCamera
def makeCameraFromPolicy(filename, cameraname, writeRepo=False, outputDir=None, doClobber=False, shortNameMethod=lambda x: x): """Make a camera repository suitable for reading by the butler using a policy file @param[in] filename Name of the policy file to open. @param[in] cameraname Name of the camera being used @param[in] writeRepo Write the repository to disk? Default is False @param[in] outputDir Directory to write to. @param[in] doClobber Clobber existing repository? @param[in] shortNameMethod Method to generate short, filename-like names for sensors @return a Camera object. """ policyFile = pexPolicy.DefaultPolicyFile("afw", "CameraGeomDictionary.paf", "policy") defPolicy = pexPolicy.Policy.createPolicy(policyFile, policyFile.getRepositoryPath(), True) polFile = pexPolicy.DefaultPolicyFile("obs_subaru", filename) geomPolicy = pexPolicy.Policy.createPolicy(polFile) geomPolicy.mergeDefaults(defPolicy.getDictionary()) ampParams = makeAmpParams(geomPolicy) ccdParams = makeCcdParams(geomPolicy, ampParams) ccdToUse = None ccdInfoDict = parseCcds(geomPolicy, ccdParams, ccdToUse) camConfig = parseCamera(geomPolicy, cameraname) camConfig.detectorList = dict([ (i, ccdInfo) for i, ccdInfo in enumerate(ccdInfoDict['ccdInfo']) ]) if writeRepo: if outputDir is None: raise ValueError("Need output directory for writting") # write data products makeDir(dirPath=outputDir, doClobber=doClobber) camConfigPath = os.path.join(outputDir, "camera.py") camConfig.save(camConfigPath) for detectorName, ampTable in ccdInfoDict['ampInfo'].iteritems(): shortDetectorName = shortNameMethod(detectorName) ampInfoPath = os.path.join(outputDir, shortDetectorName + ".fits") ampTable.writeFits(ampInfoPath) return makeCameraFromCatalogs(camConfig, ccdInfoDict['ampInfo'])
def makeCamera(name="SDSS", outputDir=None): """Make a camera @param name: name of the camera @param outputDir: If not None, write the objects used to make the camera to this location @return a camera object """ camConfig = CameraConfig() camConfig.name = name camConfig.detectorList = {} camConfig.plateScale = 16.5 # arcsec/mm pScaleRad = afwGeom.arcsecToRad(camConfig.plateScale) radialDistortCoeffs = [0.0, 1.0 / pScaleRad] tConfig = afwGeom.TransformConfig() tConfig.transform.name = 'inverted' radialClass = afwGeom.xyTransformRegistry['radial'] tConfig.transform.active.transform.retarget(radialClass) tConfig.transform.active.transform.coeffs = radialDistortCoeffs tmc = afwGeom.TransformMapConfig() tmc.nativeSys = FOCAL_PLANE.getSysName() tmc.transforms = {PUPIL.getSysName(): tConfig} camConfig.transformDict = tmc ccdId = 0 ampInfoCatDict = {} for i in range(6): dewarName = str(i + 1) filters = "riuzg" for j, c in enumerate(reversed(filters)): ccdName = "%s%s" % (c, dewarName) offsetPoint = afwGeom.Point2D(25.4 * 2.5 * (2.5 - i), 25.4 * 2.1 * (2.0 - j)) ccdInfo = makeCcd(ccdName, ccdId, offsetPoint) ampInfoCatDict[ccdName] = ccdInfo['ampInfo'] camConfig.detectorList[ccdId] = ccdInfo['ccdConfig'] ccdId += 1 if outputDir is not None: camConfig.save(os.path.join(outputDir, 'camera.py')) for k in ampInfoCatDict: ampInfoCatDict[k].writeFits( os.path.join(outputDir, "%s.fits" % (k))) return makeCameraFromCatalogs(camConfig, ampInfoCatDict)
def makeCamera(name="SDSS", outputDir=None): """Make a camera @param name: name of the camera @param outputDir: If not None, write the objects used to make the camera to this location @return a camera object """ camConfig = CameraConfig() camConfig.name = name camConfig.detectorList = {} camConfig.plateScale = 16.5 # arcsec/mm pScaleRad = afwGeom.arcsecToRad(camConfig.plateScale) radialDistortCoeffs = [0.0, 1.0/pScaleRad] tConfig = afwGeom.TransformConfig() tConfig.transform.name = 'inverted' radialClass = afwGeom.transformRegistry['radial'] tConfig.transform.active.transform.retarget(radialClass) tConfig.transform.active.transform.coeffs = radialDistortCoeffs tmc = TransformMapConfig() tmc.nativeSys = FOCAL_PLANE.getSysName() tmc.transforms = {FIELD_ANGLE.getSysName(): tConfig} camConfig.transformDict = tmc ccdId = 0 ampInfoCatDict = {} for i in range(6): dewarName = str(i+1) filters = "riuzg" for j, c in enumerate(reversed(filters)): ccdName = "%s%s" % (c, dewarName) offsetPoint = afwGeom.Point2D(25.4*2.5*(2.5-i), 25.4*2.1*(2.0 - j)) ccdInfo = makeCcd(ccdName, ccdId, offsetPoint) ampInfoCatDict[ccdName] = ccdInfo['ampInfo'] camConfig.detectorList[ccdId] = ccdInfo['ccdConfig'] ccdId += 1 if outputDir is not None: camConfig.save(os.path.join(outputDir, 'camera.py')) for k in ampInfoCatDict: ampInfoCatDict[k].writeFits(os.path.join(outputDir, "%s.fits"%(k))) return makeCameraFromCatalogs(camConfig, ampInfoCatDict)
def makeCameraFromPolicy(filename, cameraname, writeRepo=False, outputDir=None, doClobber=False, shortNameMethod=lambda x: x): """Make a camera repository suitable for reading by the butler using a policy file @param[in] filename Name of the policy file to open. @param[in] cameraname Name of the camera being used @param[in] writeRepo Write the repository to disk? Default is False @param[in] outputDir Directory to write to. @param[in] doClobber Clobber existing repository? @param[in] shortNameMethod Method to generate short, filename-like names for sensors @return a Camera object. """ policyFile = pexPolicy.DefaultPolicyFile("afw", "CameraGeomDictionary.paf", "policy") defPolicy = pexPolicy.Policy.createPolicy(policyFile, policyFile.getRepositoryPath(), True) polFile = pexPolicy.DefaultPolicyFile("obs_subaru", filename) geomPolicy = pexPolicy.Policy.createPolicy(polFile) geomPolicy.mergeDefaults(defPolicy.getDictionary()) ampParams = makeAmpParams(geomPolicy) ccdParams = makeCcdParams(geomPolicy, ampParams) ccdToUse = None ccdInfoDict = parseCcds(geomPolicy, ccdParams, ccdToUse) camConfig = parseCamera(geomPolicy, cameraname) camConfig.detectorList = dict([(i, ccdInfo) for i, ccdInfo in enumerate(ccdInfoDict['ccdInfo'])]) if writeRepo: if outputDir is None: raise ValueError("Need output directory for writting") # write data products makeDir(dirPath=outputDir, doClobber=doClobber) camConfigPath = os.path.join(outputDir, "camera.py") camConfig.save(camConfigPath) for detectorName, ampTable in ccdInfoDict['ampInfo'].iteritems(): shortDetectorName = shortNameMethod(detectorName) ampInfoPath = os.path.join(outputDir, shortDetectorName + ".fits") ampTable.writeFits(ampInfoPath) return makeCameraFromCatalogs(camConfig, ccdInfoDict['ampInfo'])