def parseCamera(policy, cameraname):
    """ Parse a policy file for a Camera object
    @param[in] policy  pexPolicy.Policy object to parse
    @param[in] cameraname  name of camerea being used
    @return afw.CameraGeom.CameraConfig object
    """
    camPolicy = policy.get('Camera')
    camConfig = CameraConfig()
    camConfig.name = camPolicy.get('name')
    camConfig.plateScale = PIXELSIZE

    #Need to invert because this is stored with FOCAL_PLANE to PUPIL as the
    #forward transform: only for HSC
    if cameraname.lower() == 'hsc':
        tConfig = afwGeom.TransformConfig()
        tConfig.transform.name = 'hsc'
    else:
        #I don't know what the PUPIL transform is for non-HSC cameras is
        tConfig = afwGeom.TransformConfig()
        tConfig.transform.name = 'identity'
    tpConfig = afwGeom.TransformConfig()
    tpConfig.transform.name = 'affine'
    tpConfig.transform.active.linear = [1/PIXELSIZE, 0, 0, 1/PIXELSIZE]

    tmc = afwGeom.TransformMapConfig()
    tmc.nativeSys = FOCAL_PLANE.getSysName()
    tmc.transforms = {PUPIL.getSysName():tConfig, FOCAL_PLANE_PIXELS.getSysName():tpConfig}
    camConfig.transformDict = tmc
    return camConfig
def parseCamera(policy):
    """
    Make a CameraConfig from a policy
    @param policy: Policy object to parse
    @return CameraConfig parsed from the policy
    """
    camPolicy = policy.get('Camera')
    camConfig = CameraConfig()
    camConfig.name = camPolicy.get('name')
    # Using pixel scale 0.185 arcsec/pixel from:
    # http://arxiv.org/pdf/0908.3808v1.pdf
    camConfig.plateScale = 13.70 #arcsec/mm

    # Radial distortion correction polynomial coeff.
    conv_1 = 14805.4
    conv_2 = 13619.3
    conv_3 = 426637.0
    
    tConfig = afwGeom.TransformConfig()
    tConfig.transform.name = 'inverted'
    radialClass = afwGeom.xyTransformRegistry['radial']
    tConfig.transform.active.transform.retarget(radialClass)

    coeffs = [0., conv_1, conv_2, conv_3]
    tConfig.transform.active.transform.coeffs = coeffs

    tmc = afwGeom.TransformMapConfig()
    tmc.nativeSys = FOCAL_PLANE.getSysName()
    tmc.transforms = {PUPIL.getSysName():tConfig}
    camConfig.transformDict = tmc
    return camConfig
示例#3
0
def parseCamera(policy, cameraname):
    """ Parse a policy file for a Camera object
    @param[in] policy  pexPolicy.Policy object to parse
    @param[in] cameraname  name of camerea being used
    @return afw.CameraGeom.CameraConfig object
    """
    camPolicy = policy.get('Camera')
    camConfig = CameraConfig()
    camConfig.name = camPolicy.get('name')
    camConfig.plateScale = PIXELSIZE

    #Need to invert because this is stored with FOCAL_PLANE to PUPIL as the
    #forward transform: only for HSC
    if cameraname.lower() == 'hsc':
        tConfig = afwGeom.TransformConfig()
        tConfig.transform.name = 'hsc'
    else:
        #I don't know what the PUPIL transform is for non-HSC cameras is
        tConfig = afwGeom.TransformConfig()
        tConfig.transform.name = 'identity'
    tpConfig = afwGeom.TransformConfig()
    tpConfig.transform.name = 'affine'
    tpConfig.transform.active.linear = [1 / PIXELSIZE, 0, 0, 1 / PIXELSIZE]

    tmc = afwGeom.TransformMapConfig()
    tmc.nativeSys = FOCAL_PLANE.getSysName()
    tmc.transforms = {
        PUPIL.getSysName(): tConfig,
        FOCAL_PLANE_PIXELS.getSysName(): tpConfig
    }
    camConfig.transformDict = tmc
    return camConfig
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
示例#6
0
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)
示例#7
0
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)
    #From DECam calibration doc
    camConfig.plateScale = 17.575
    pScaleRad = afwGeom.arcsecToRad(camConfig.plateScale)
    tConfig = afwGeom.TransformConfig()
    tConfig.transform.name = 'radial'
    nomWavelen =  0.625 #nominal wavelen in microns
    coeff0 = 0
    coeff1 = 1 - 2.178e-4 - 2.329e-4/nomWavelen + 4.255e-5/nomWavelen**2
    coeff2 = 0
    coeff3 = -6.174e-8 + 5.569e-9/nomWavelen
    tConfig.transform.active.coeffs = [pScaleRad*coeff0, pScaleRad*coeff1, pScaleRad*coeff2,
                                       pScaleRad*coeff3]
    tmc = afwGeom.TransformMapConfig()
    tmc.nativeSys = FOCAL_PLANE.getSysName()
    tmc.transforms = {PUPIL.getSysName():tConfig}
    camConfig.transformDict = tmc

    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,))
    # From DECam calibration doc
    camConfig.plateScale = 17.575
    pScaleRad = afwGeom.arcsecToRad(camConfig.plateScale)
    tConfig = afwGeom.TransformConfig()
    tConfig.transform.name = 'radial'
    nomWavelen = 0.625  # nominal wavelen in microns
    coeff0 = 0
    coeff1 = 1 - 2.178e-4 - 2.329e-4/nomWavelen + 4.255e-5/nomWavelen**2
    coeff2 = 0
    coeff3 = -6.174e-8 + 5.569e-9/nomWavelen
    tConfig.transform.active.coeffs = [pScaleRad*coeff0, pScaleRad*coeff1, pScaleRad*coeff2,
                                       pScaleRad*coeff3]
    tmc = afwGeom.TransformMapConfig()
    tmc.nativeSys = FOCAL_PLANE.getSysName()
    tmc.transforms = {PUPIL.getSysName(): tConfig}
    camConfig.transformDict = tmc

    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,))