示例#1
0
 def testAssembly(self):
     ccdNames = ('R:0,0 S:1,0', 'R:0,0 S:0,1')
     compMap = {
         True:
         afwImage.ImageU(os.path.join(testPath,
                                      'test_comp_trimmed.fits.gz')),
         False:
         afwImage.ImageU(os.path.join(testPath, 'test_comp.fits.gz'))
     }
     for cw in self.cameraList:
         camera = cw.camera
         imList = self.assemblyList[camera.getName()]
         for ccdName in ccdNames:
             for trim, assemble in ((False, assembleAmplifierRawImage),
                                    (True, assembleAmplifierImage)):
                 det = camera[ccdName]
                 if not trim:
                     outBbox = cameraGeomUtils.calcRawCcdBBox(det)
                 else:
                     outBbox = det.getBBox()
                 outImage = afwImage.ImageU(outBbox)
                 if len(imList) == 1:
                     for amp in det:
                         assemble(outImage, imList[0], amp)
                 else:
                     for amp, im in zip(det, imList):
                         assemble(outImage, im, amp)
                 self.assertListEqual(
                     outImage.getArray().flatten().tolist(),
                     compMap[trim].getArray().flatten().tolist())
示例#2
0
def printCcd(title, ccd, trimmed=True, indent=""):
    """Print info about a ccd
    @param title: title for the ccd
    @param ccd: Detector object to interrogate
    @param trimmed: Find out information about a trimmed ccd?
    @param indent: Prefix to each output line
    """
    print(indent, title, "CCD: ", ccd.getName())
    if trimmed:
        allPixels = ccd.getBBox()
    else:
        allPixels = cameraGeomUtils.calcRawCcdBBox(ccd)
    print(indent,
          "Total size: %dx%d" % (allPixels.getWidth(), allPixels.getHeight()))
    for i, amp in enumerate(ccd):
        biasSec = amp.getRawHorizontalOverscanBBox()
        dataSec = amp.getRawDataBBox()

        print(indent, "   Amp: %s gain: %g" % (amp.getName(), amp.getGain()))

        print(
            indent, "   bias sec: %dx%d+%d+%d" %
            (biasSec.getWidth(), biasSec.getHeight(), biasSec.getMinX(),
             biasSec.getMinY()))

        print(
            indent, "   data sec: %dx%d+%d+%d" %
            (dataSec.getWidth(), dataSec.getHeight(), dataSec.getMinX(),
             dataSec.getMinY()))
        if i == 0:
            print()
示例#3
0
def printCcd(title, ccd, trimmed=True, indent=""):
    """Print info about a ccd
    @param title: title for the ccd
    @param ccd: Detector object to interrogate
    @param trimmed: Find out information about a trimmed ccd?
    @param indent: Prefix to each output line
    """
    print(indent, title, "CCD: ", ccd.getName())
    if trimmed:
        allPixels = ccd.getBBox()
    else:
        allPixels = cameraGeomUtils.calcRawCcdBBox(ccd)
    print(indent, "Total size: %dx%d" % (allPixels.getWidth(), allPixels.getHeight()))
    for i, amp in enumerate(ccd):
        biasSec = amp.getRawHorizontalOverscanBBox()
        dataSec = amp.getRawDataBBox()

        print(indent, "   Amp: %s gain: %g" % (amp.getName(),
                                               amp.getGain()))

        print(indent, "   bias sec: %dx%d+%d+%d" % (biasSec.getWidth(), biasSec.getHeight(),
                                                    biasSec.getMinX(), biasSec.getMinY()))

        print(indent, "   data sec: %dx%d+%d+%d" % (dataSec.getWidth(), dataSec.getHeight(),
                                                    dataSec.getMinX(), dataSec.getMinY()))
        if i == 0:
            print()
    def assembleCcd(self, assembleInput):
        """!Assemble a set of amps into a single CCD size image
        \param[in] assembleInput -- Either a dictionary of amp lsst.afw.image.Exposures or a single 
                                    lsst.afw.image.Exposure containing all raw
                                    amps.  If a dictionary of amp exposures, 
                                    the key should be the amp name.
        \return assembledCcd -- An lsst.afw.image.Exposure of the assembled amp sections.

        \throws TypeError with the following string:

        <DL>
          <DT> Expected either a dictionary of amp exposures or a single raw exposure
          <DD> The input exposures to be assembled do not adhere to the required format.
        </DL>

        \throws RuntimeError with the following string:

        <DL>
          <DT> No ccd detector found
          <DD> The detector set on the input exposure is not set.
        </DL>
        """
        ccd = None
        if hasattr(assembleInput, "has_key"):
            # Get a detector object for this set of amps
            ccd = assembleInput.itervalues().next().getDetector()
            # Sent a dictionary of input exposures, assume one amp per key keyed on amp name
            def getNextExposure(amp):
                return assembleInput[amp.getName()]
        elif hasattr(assembleInput, "getMaskedImage"):
            ccd = assembleInput.getDetector()
            # A single exposure was sent.  Use this to assemble.
            def getNextExposure(amp):
                return assembleInput
        else:
            raise TypeError("Expected either a dictionary of amp exposures or a single raw exposure")

        if ccd is None:
            raise RuntimeError("No ccd detector found")

        if not self.config.doTrim:
            outBox = cameraGeomUtils.calcRawCcdBBox(ccd)
        else:
            outBox = ccd.getBBox()
        outExposure = afwImage.ExposureF(outBox)
        outMI = outExposure.getMaskedImage()

        if self.config.doTrim:
            assemble = cameraGeom.assembleAmplifierImage
        else:
            assemble = cameraGeom.assembleAmplifierRawImage
        
        for amp in ccd:
            inMI = getNextExposure(amp).getMaskedImage()
            assemble(outMI, inMI, amp)
        outExposure.setDetector(ccd)
        self.postprocessExposure(outExposure=outExposure, inExposure=getNextExposure(ccd[0]))
    
        return outExposure
示例#5
0
    def assembleCcd(self, assembleInput):
        """!Assemble a set of amps into a single CCD size image
        \param[in] assembleInput -- Either a dictionary of amp lsst.afw.image.Exposures or a single 
                                    lsst.afw.image.Exposure containing all raw
                                    amps.  If a dictionary of amp exposures, 
                                    the key should be the amp name.
        \return assembledCcd -- An lsst.afw.image.Exposure of the assembled amp sections.

        \throws TypeError with the following string:

        <DL>
          <DT> Expected either a dictionary of amp exposures or a single raw exposure
          <DD> The input exposures to be assembled do not adhere to the required format.
        </DL>

        \throws RuntimeError with the following string:

        <DL>
          <DT> No ccd detector found
          <DD> The detector set on the input exposure is not set.
        </DL>
        """
        ccd = None
        if hasattr(assembleInput, "has_key"):
            # Get a detector object for this set of amps
            ccd = assembleInput.itervalues().next().getDetector()
            # Sent a dictionary of input exposures, assume one amp per key keyed on amp name
            def getNextExposure(amp):
                return assembleInput[amp.getName()]
        elif hasattr(assembleInput, "getMaskedImage"):
            ccd = assembleInput.getDetector()
            # A single exposure was sent.  Use this to assemble.
            def getNextExposure(amp):
                return assembleInput
        else:
            raise TypeError("Expected either a dictionary of amp exposures or a single raw exposure")

        if ccd is None:
            raise RuntimeError("No ccd detector found")

        if not self.config.doTrim:
            outBox = cameraGeomUtils.calcRawCcdBBox(ccd)
        else:
            outBox = ccd.getBBox()
        outExposure = afwImage.ExposureF(outBox)
        outMI = outExposure.getMaskedImage()

        if self.config.doTrim:
            assemble = cameraGeom.assembleAmplifierImage
        else:
            assemble = cameraGeom.assembleAmplifierRawImage
        
        for amp in ccd:
            inMI = getNextExposure(amp).getMaskedImage()
            assemble(outMI, inMI, amp)
        outExposure.setDetector(ccd)
        self.postprocessExposure(outExposure=outExposure, inExposure=getNextExposure(ccd[0]))
    
        return outExposure
示例#6
0
 def testAssembly(self):
     ccdNames = ('R:0,0 S:1,0', 'R:0,0 S:0,1')
     detectorImageMap = {True: afwImage.ImageU(os.path.join(testPath, 'test_comp_trimmed.fits.gz'),
                                               allowUnsafe=True),
                         False: afwImage.ImageU(os.path.join(testPath, 'test_comp.fits.gz'),
                                                allowUnsafe=True)}
     for cw in self.cameraList:
         camera = cw.camera
         imList = self.assemblyList[camera.getName()]
         for ccdName in ccdNames:
             det = camera[ccdName]
             if len(imList) == 1:
                 # There's one test image because it's the same for all
                 # amplifiers, not because there's only one amplifier.
                 imList *= len(det)
             # Test going from possibly-separate amp images to detector
             # images.
             for trim, assemble in ((False, assembleAmplifierRawImage), (True, assembleAmplifierImage)):
                 if not trim:
                     outBbox = cameraGeomUtils.calcRawCcdBBox(det)
                 else:
                     outBbox = det.getBBox()
                 outImage = afwImage.ImageU(outBbox)
                 for amp, im in zip(det, imList):
                     assemble(outImage, im, amp)
                 self.assertImagesEqual(outImage, detectorImageMap[trim])
                 # Test going from detector images back to single-amplifier
                 # images.
                 detector_exposure = afwImage.ExposureU(afwImage.MaskedImageU(detectorImageMap[trim]))
                 detector_exposure.setDetector(makeUpdatedDetector(det))
                 for amp, im in zip(det, imList):
                     amp_exposure = AmplifierIsolator.apply(detector_exposure, amp)
                     self.assertEqual(len(amp_exposure.getDetector()), 1)
                     self.assertEqual(amp_exposure.getDetector().getBBox(), amp.getBBox())
                     self.assertAmplifiersEqual(amp, amp_exposure.getDetector()[0])
                     if not trim:
                         self.assertEqual(cameraGeomUtils.calcRawCcdBBox(amp_exposure.getDetector()),
                                          amp_exposure.getBBox())
                         self.assertImagesEqual(im[amp.getRawBBox()], amp_exposure.image)
                     else:
                         self.assertEqual(amp_exposure.getDetector().getBBox(),
                                          amp_exposure.getBBox())
                         self.assertImagesEqual(im[amp.getRawDataBBox()], amp_exposure.image)
示例#7
0
 def testAssembly(self):
     ccdNames = ('R:0,0 S:1,0', 'R:0,0 S:0,1')
     compMap = {True:afwImage.ImageU('tests/test_comp_trimmed.fits.gz'), False:afwImage.ImageU('tests/test_comp.fits.gz')}
     for cw in self.cameraList:
         camera = cw.camera
         imList = self.assemblyList[camera.getName()]
         for ccdName in ccdNames:
             for trim, assemble in ((False, assembleAmplifierRawImage), (True, assembleAmplifierImage)):
                 det = camera[ccdName]
                 if not trim:
                     outBbox = cameraGeomUtils.calcRawCcdBBox(det)
                 else:
                     outBbox = det.getBBox()
                 outImage = afwImage.ImageU(outBbox)
                 if len(imList) == 1:
                     for amp in det:
                         assemble(outImage, imList[0], amp)
                 else:
                     for amp, im in zip(det, imList):
                         assemble(outImage, im, amp)
                 self.assertTrue((outImage.getArray() == compMap[trim].getArray()).all())
示例#8
0
    def assembleCcd(self, assembleInput):
        """!Assemble a set of amps into a single CCD size image
        @param[in] assembleInput -- Either a dictionary of amp lsst.afw.image.Exposures or a single
                                    lsst.afw.image.Exposure containing all raw
                                    amps.  If a dictionary of amp exposures,
                                    the key should be the amp name.
        @return assembledCcd -- An lsst.afw.image.Exposure of the assembled amp sections.

        @throws TypeError with the following string:

        <DL>
          <DT> Expected either a dictionary of amp exposures or a single raw exposure
          <DD> The input exposures to be assembled do not adhere to the required format.
        </DL>

        @throws RuntimeError with the following string:

        <DL>
          <DT> No ccd detector found
          <DD> The detector set on the input exposure is not set.
        </DL>
        """
        ccd = None
        if isinstance(assembleInput, dict):
            # assembleInput is a dictionary of amp name: amp exposure

            # Assume all amps have the same detector, so get the detector from an arbitrary amp
            ccd = next(iter(assembleInput.values())).getDetector()

            def getNextExposure(amp):
                return assembleInput[amp.getName()]
        elif hasattr(assembleInput, "getMaskedImage"):
            # assembleInput is a single exposure
            ccd = assembleInput.getDetector()

            def getNextExposure(amp):
                return assembleInput
        else:
            raise TypeError(
                "Expected either a dictionary of amp exposures or a single raw exposure"
            )

        if ccd is None:
            raise RuntimeError("No ccd detector found")

        if not self.config.doTrim:
            outBox = cameraGeomUtils.calcRawCcdBBox(ccd)
        else:
            outBox = ccd.getBBox()
        outExposure = afwImage.ExposureF(outBox)
        outMI = outExposure.getMaskedImage()

        if self.config.doTrim:
            assemble = cameraGeom.assembleAmplifierImage
        else:
            assemble = cameraGeom.assembleAmplifierRawImage

        for amp in ccd:
            inMI = getNextExposure(amp).getMaskedImage()
            assemble(outMI, inMI, amp)
        #
        # If we are returning an "untrimmed" image (with overscans and extended register) we
        # need to update the ampInfo table in the Detector as we've moved the amp images into
        # place in a single Detector image
        #
        if not self.config.doTrim:
            ccd = cameraGeom.makeUpdatedDetector(ccd)

        outExposure.setDetector(ccd)
        self.postprocessExposure(outExposure=outExposure,
                                 inExposure=getNextExposure(ccd[0]))

        return outExposure
    def assembleCcd(self, assembleInput):
        """!Assemble a set of amps into a single CCD size image
        @param[in] assembleInput -- Either a dictionary of amp lsst.afw.image.Exposures or a single
                                    lsst.afw.image.Exposure containing all raw
                                    amps.  If a dictionary of amp exposures,
                                    the key should be the amp name.
        @return assembledCcd -- An lsst.afw.image.Exposure of the assembled amp sections.

        @throws TypeError with the following string:

        <DL>
          <DT> Expected either a dictionary of amp exposures or a single raw exposure
          <DD> The input exposures to be assembled do not adhere to the required format.
        </DL>

        @throws RuntimeError with the following string:

        <DL>
          <DT> No ccd detector found
          <DD> The detector set on the input exposure is not set.
        </DL>
        """
        ccd = None
        if isinstance(assembleInput, dict):
            # assembleInput is a dictionary of amp name: amp exposure

            # Assume all amps have the same detector, so get the detector from an arbitrary amp
            ccd = next(iter(assembleInput.values())).getDetector()

            def getNextExposure(amp):
                return assembleInput[amp.getName()]
        elif hasattr(assembleInput, "getMaskedImage"):
            # assembleInput is a single exposure
            ccd = assembleInput.getDetector()

            def getNextExposure(amp):
                return assembleInput
        else:
            raise TypeError("Expected either a dictionary of amp exposures or a single raw exposure")

        if ccd is None:
            raise RuntimeError("No ccd detector found")

        if not self.config.doTrim:
            outBox = cameraGeomUtils.calcRawCcdBBox(ccd)
        else:
            outBox = ccd.getBBox()
        outExposure = afwImage.ExposureF(outBox)
        outMI = outExposure.getMaskedImage()

        if self.config.doTrim:
            assemble = cameraGeom.assembleAmplifierImage
        else:
            assemble = cameraGeom.assembleAmplifierRawImage

        for amp in ccd:
            inMI = getNextExposure(amp).getMaskedImage()
            assemble(outMI, inMI, amp)
        #
        # If we are returning an "untrimmed" image (with overscans and extended register) we
        # need to update the ampInfo table in the Detector as we've moved the amp images into
        # place in a single Detector image
        #
        if not self.config.doTrim:
            ccd = cameraGeom.makeUpdatedDetector(ccd)

        outExposure.setDetector(ccd)
        self.postprocessExposure(outExposure=outExposure, inExposure=getNextExposure(ccd[0]))

        return outExposure