Esempio n. 1
0
    def _configWfEstimator(self, camType):
        """Configure the wavefront estimator.

        Returns
        -------
        WfEstimator
            Configured wavefront estimator.
        """

        configDir = getConfigDir()
        instDir = os.path.join(configDir, "cwfs", "instData")
        algoDir = os.path.join(configDir, "cwfs", "algo")
        wfsEsti = WfEstimator(instDir, algoDir)

        solver = self.settingFile.getSetting("poissonSolver")
        opticalModel = self.settingFile.getSetting("opticalModel")
        defocalDistInMm = self.settingFile.getSetting("defocalDistInMm")
        donutImgSizeInPixel = self.settingFile.getSetting("donutImgSizeInPixel")

        centroidFind = self.settingFile.getSetting("centroidFindAlgo")
        centroidFindType = getCentroidFindType(centroidFind)

        wfsEsti.config(
            solver=solver,
            camType=camType,
            opticalModel=opticalModel,
            defocalDisInMm=defocalDistInMm,
            sizeInPix=donutImgSizeInPixel,
            centroidFindType=centroidFindType,
        )

        return wfsEsti
Esempio n. 2
0
    def setUp(self):

        # Get the path of module
        self.modulePath = getModulePath()

        # Define the instrument folder
        instruFolderPath = os.path.join(self.modulePath, "configData", "cwfs",
                                        "instruData")

        # Define the algorithm folder
        algoFolderPath = os.path.join(self.modulePath, "configData", "cwfs",
                                      "algo")

        # Decalre the WfEstimator
        self.wfsEst = WfEstimator(instruFolderPath, algoFolderPath)
    def _configWfEstimator(self):

        instruFolderPath = os.path.join(self.modulePath, "configData", "cwfs",
                                        "instruData")
        algoFolderPath = os.path.join(self.modulePath, "configData", "cwfs",
                                      "algo")
        wfsEsti = WfEstimator(instruFolderPath, algoFolderPath)

        # Use the comcam to calculate the LSST central raft image
        # with 1.5 mm defocal distance
        wfsEsti.config(solver="exp",
                       instName="comcam",
                       opticalModel="offAxis",
                       defocalDisInMm=1.5,
                       sizeInPix=160,
                       debugLevel=0)

        return wfsEsti
    def _configWfEstimator(self):

        cwfsConfigDir = os.path.join(getConfigDir(), "cwfs")
        instDir = os.path.join(cwfsConfigDir, "instData")
        algoDir = os.path.join(cwfsConfigDir, "algo")
        wfEsti = WfEstimator(instDir, algoDir)

        # Use the comcam to calculate the LSST central raft image
        # with 1.5 mm defocal distance
        wfEsti.config(
            solver="exp",
            camType=CamType.ComCam,
            opticalModel="offAxis",
            defocalDisInMm=1.5,
            sizeInPix=160,
            debugLevel=0,
        )

        return wfEsti
Esempio n. 5
0
    def setUp(self):

        cwfsConfigDir = os.path.join(getConfigDir(), "cwfs")
        instDir = os.path.join(cwfsConfigDir, "instData")
        algoDir = os.path.join(cwfsConfigDir, "algo")
        self.wfsEst = WfEstimator(instDir, algoDir)

        # Define the image folder and image names
        # It is noted that image.readFile inuts is based on the txt file.
        self.modulePath = getModulePath()
        imageFolderPath = os.path.join(self.modulePath, "tests", "testData",
                                       "testImages", "LSST_NE_SN25")
        intra_image_name = "z11_0.25_intra.txt"
        extra_image_name = "z11_0.25_extra.txt"

        # Path to image files
        self.intraImgFile = os.path.join(imageFolderPath, intra_image_name)
        self.extraImgFile = os.path.join(imageFolderPath, extra_image_name)

        # Field XY position
        self.fieldXY = (1.185, 1.185)
Esempio n. 6
0
    def _configWfEstimator(self):
        """Configure the wavefront estimator.

        Returns
        -------
        WfEstimator
            Configured wavefront estimator.
        """

        instruFolderPath = os.path.join(self._getConfigDataPath(), "cwfs",
                                        "instruData")
        algoFolderPath = os.path.join(self._getConfigDataPath(), "cwfs",
                                      "algo")
        wfsEsti = WfEstimator(instruFolderPath, algoFolderPath)

        # Use the comcam to calculate the LSST central raft image
        wfsEsti.config(solver="exp",
                       instName="comcam",
                       opticalModel="offAxis",
                       defocalDisInMm=self.DEFOCAL_DIS_IN_MM,
                       sizeInPix=self.DONUT_IMG_SIZE_IN_PIXEL,
                       debugLevel=0)

        return wfsEsti
Esempio n. 7
0
    def _configWfEstimator(self, camType):
        """Configure the wavefront estimator.

        Returns
        -------
        WfEstimator
            Configured wavefront estimator.
        """

        configDir = getConfigDir()
        instDir = os.path.join(configDir, "cwfs", "instData")
        algoDir = os.path.join(configDir, "cwfs", "algo")
        wfsEsti = WfEstimator(instDir, algoDir)

        solver = self.settingFile.getSetting("poissonSolver")
        opticalModel = self.settingFile.getSetting("opticalModel")
        defocalDisInMm = self.settingFile.getSetting("dofocalDistInMm")
        donutImgSizeInPixel = self.settingFile.getSetting("donutImgSizeInPixel")
        wfsEsti.config(solver=solver, camType=camType,
                       opticalModel=opticalModel,
                       defocalDisInMm=defocalDisInMm,
                       sizeInPix=donutImgSizeInPixel)

        return wfsEsti
Esempio n. 8
0
    def setUp(self):

        cwfsConfigDir = os.path.join(getConfigDir(), "cwfs")
        instDir = os.path.join(cwfsConfigDir, "instData")
        algoDir = os.path.join(cwfsConfigDir, "algo")
        self.wfsEst = WfEstimator(instDir, algoDir)

        # Define the image folder and image names
        # It is noted that image.readFile inuts is based on the txt file.
        self.modulePath = getModulePath()
        imageFolderPath = os.path.join(self.modulePath, "tests", "testData",
                                       "testImages", "LSST_NE_SN25")
        intra_image_name = "z11_0.25_intra.txt"
        extra_image_name = "z11_0.25_extra.txt"

        # Path to image files
        self.intraImgFile = os.path.join(imageFolderPath, intra_image_name)
        self.extraImgFile = os.path.join(imageFolderPath, extra_image_name)

        # Field XY position
        self.fieldXY = (1.185, 1.185)
Esempio n. 9
0
class TestWfEsitmator(unittest.TestCase):
    """Test the wavefront estimator class."""
    def setUp(self):

        cwfsConfigDir = os.path.join(getConfigDir(), "cwfs")
        instDir = os.path.join(cwfsConfigDir, "instData")
        algoDir = os.path.join(cwfsConfigDir, "algo")
        self.wfsEst = WfEstimator(instDir, algoDir)

        # Define the image folder and image names
        # It is noted that image.readFile inuts is based on the txt file.
        self.modulePath = getModulePath()
        imageFolderPath = os.path.join(self.modulePath, "tests", "testData",
                                       "testImages", "LSST_NE_SN25")
        intra_image_name = "z11_0.25_intra.txt"
        extra_image_name = "z11_0.25_extra.txt"

        # Path to image files
        self.intraImgFile = os.path.join(imageFolderPath, intra_image_name)
        self.extraImgFile = os.path.join(imageFolderPath, extra_image_name)

        # Field XY position
        self.fieldXY = (1.185, 1.185)

    def testCalWfsErrOfExp(self):

        # Setup the images
        self.wfsEst.setImg(self.fieldXY,
                           DefocalType.Intra,
                           imageFile=self.intraImgFile)
        self.wfsEst.setImg(self.fieldXY,
                           DefocalType.Extra,
                           imageFile=self.extraImgFile)

        # Test the images are set.
        self.assertEqual(self.wfsEst.getIntraImg().getDefocalType(),
                         DefocalType.Intra)
        self.assertEqual(self.wfsEst.getExtraImg().getDefocalType(),
                         DefocalType.Extra)

        # Setup the configuration
        # If the configuration is reset, the images are needed to be set again.
        self.wfsEst.config(
            solver="exp",
            camType=CamType.LsstCam,
            opticalModel="offAxis",
            defocalDisInMm=1.0,
            sizeInPix=120,
            debugLevel=0,
        )

        # Evaluate the wavefront error
        wfsError = [
            2.593,
            14.102,
            -8.470,
            3.676,
            1.467,
            -9.724,
            8.207,
            -192.839,
            0.978,
            1.568,
            4.197,
            -0.391,
            1.551,
            1.235,
            -1.699,
            2.140,
            -0.296,
            -2.113,
            1.188,
        ]
        zer4UpNm = self.wfsEst.calWfsErr()
        self.assertAlmostEqual(np.sum(np.abs(zer4UpNm - np.array(wfsError))),
                               0.66984026,
                               places=7)

    def testCalWfsErrOfFft(self):

        # Reset the wavefront images
        self.wfsEst.setImg(self.fieldXY,
                           DefocalType.Intra,
                           imageFile=self.intraImgFile)
        self.wfsEst.setImg(self.fieldXY,
                           DefocalType.Extra,
                           imageFile=self.extraImgFile)

        # Change the algorithm to fft
        self.wfsEst.config(
            solver="fft",
            camType=CamType.LsstCam,
            opticalModel="offAxis",
            defocalDisInMm=1.0,
            sizeInPix=120,
            debugLevel=0,
        )

        # Evaluate the wavefront error
        wfsError = [
            12.484,
            10.358,
            -6.674,
            -0.043,
            -1.768,
            -15.593,
            12.511,
            -192.382,
            0.195,
            4.074,
            9.577,
            -1.930,
            3.538,
            3.420,
            -3.610,
            3.547,
            -0.679,
            -2.943,
            1.101,
        ]
        zer4UpNm = self.wfsEst.calWfsErr()
        self.assertAlmostEqual(np.sum(np.abs(zer4UpNm - np.array(wfsError))),
                               6.95092306,
                               places=7)

        # Test to reset the data
        self.wfsEst.reset()
        self.assertEqual(np.sum(self.wfsEst.getAlgo().getZer4UpInNm()), 0)
Esempio n. 10
0
    def estimateZernikes(self, donutStampsExtra, donutStampsIntra):
        """
        Take the donut postage stamps and estimate the Zernike coefficients.

        Parameters
        ----------
        donutStampsExtra: DonutStamps
            Extra-focal donut postage stamps.
        donutStampsIntra: DonutStamps
            Intra-focal donut postage stamps.

        Returns
        -------
        numpy.ndarray
            Zernike coefficients for the exposure. Will return one set of
            coefficients per set of stamps, not one set of coefficients
            per detector so this will be a 2-D numpy array with
            the number of rows equal to the number of donut stamps and
            the number of columns equal to the number of Zernike coefficients.
        """

        zerArray = []

        configDir = getConfigDir()
        instDir = os.path.join(configDir, "cwfs", "instData")
        algoDir = os.path.join(configDir, "cwfs", "algo")
        wfEsti = WfEstimator(instDir, algoDir)
        camType = getCamType(self.instName)
        defocalDisInMm = getDefocalDisInMm(self.instName)

        wfEsti.config(
            sizeInPix=self.donutStampSize,
            camType=camType,
            opticalModel=self.opticalModel,
            defocalDisInMm=defocalDisInMm,
        )

        for donutExtra, donutIntra in zip(donutStampsExtra, donutStampsIntra):

            # Transpose field XY because CompensableImages below are transposed
            # so this gets the correct mask orientation in Algorithm.py
            fieldXYExtra = donutExtra.calcFieldXY()[::-1]
            fieldXYIntra = donutIntra.calcFieldXY()[::-1]

            camera = donutExtra.getCamera()
            detectorExtra = camera.get(donutExtra.detector_name)
            detectorIntra = camera.get(donutIntra.detector_name)

            # Rotate any sensors that are not lined up with the focal plane.
            # Mostly just for the corner wavefront sensors. The negative sign
            # creates the correct rotation based upon closed loop tests
            # with R04 and R40 corner sensors.
            eulerZExtra = -detectorExtra.getOrientation().getYaw().asDegrees()
            eulerZIntra = -detectorIntra.getOrientation().getYaw().asDegrees()

            # NOTE: TS_WEP expects these images to be transposed
            # TODO: Look into this
            wfEsti.setImg(
                fieldXYExtra,
                DefocalType.Extra,
                image=rotate(donutExtra.stamp_im.getImage().getArray(),
                             eulerZExtra).T,
            )
            wfEsti.setImg(
                fieldXYIntra,
                DefocalType.Intra,
                image=rotate(donutIntra.stamp_im.getImage().getArray(),
                             eulerZIntra).T,
            )
            wfEsti.reset()
            zer4UpNm = wfEsti.calWfsErr()
            zer4UpMicrons = zer4UpNm * 1e-3

            zerArray.append(zer4UpMicrons)

        return np.array(zerArray)
Esempio n. 11
0
class TestWfEsitmator(unittest.TestCase):
    """Test the wavefront estimator class."""

    def setUp(self):

        cwfsConfigDir = os.path.join(getConfigDir(), "cwfs")
        instDir = os.path.join(cwfsConfigDir, "instData")
        algoDir = os.path.join(cwfsConfigDir, "algo")
        self.wfsEst = WfEstimator(instDir, algoDir)

        # Define the image folder and image names
        # It is noted that image.readFile inuts is based on the txt file.
        self.modulePath = getModulePath()
        imageFolderPath = os.path.join(self.modulePath, "tests", "testData",
                                       "testImages", "LSST_NE_SN25")
        intra_image_name = "z11_0.25_intra.txt"
        extra_image_name = "z11_0.25_extra.txt"

        # Path to image files
        self.intraImgFile = os.path.join(imageFolderPath, intra_image_name)
        self.extraImgFile = os.path.join(imageFolderPath, extra_image_name)

        # Field XY position
        self.fieldXY = (1.185, 1.185)

    def testCalWfsErrOfExp(self):

        # Setup the images
        self.wfsEst.setImg(self.fieldXY, DefocalType.Intra,
                           imageFile=self.intraImgFile)
        self.wfsEst.setImg(self.fieldXY, DefocalType.Extra,
                           imageFile=self.extraImgFile)

        # Test the images are set.
        self.assertEqual(self.wfsEst.getIntraImg().getDefocalType(),
                         DefocalType.Intra)
        self.assertEqual(self.wfsEst.getExtraImg().getDefocalType(),
                         DefocalType.Extra)

        # Setup the configuration
        # If the configuration is reset, the images are needed to be set again.
        self.wfsEst.config(solver="exp", camType=CamType.LsstCam,
                           opticalModel="offAxis", defocalDisInMm=1.0,
                           sizeInPix=120, debugLevel=0)

        # Evaluate the wavefront error
        wfsError = [2.593, 14.102, -8.470, 3.676, 1.467, -9.724, 8.207,
                    -192.839, 0.978, 1.568, 4.197, -0.391, 1.551, 1.235,
                    -1.699, 2.140, -0.296, -2.113, 1.188]
        zer4UpNm = self.wfsEst.calWfsErr()
        self.assertAlmostEqual(np.sum(np.abs(zer4UpNm-np.array(wfsError))), 0,
                               places=1)

    def testCalWfsErrOfFft(self):

        # Reset the wavefront images
        self.wfsEst.setImg(self.fieldXY, DefocalType.Intra,
                           imageFile=self.intraImgFile)
        self.wfsEst.setImg(self.fieldXY, DefocalType.Extra,
                           imageFile=self.extraImgFile)

        # Change the algorithm to fft
        self.wfsEst.config(solver="fft", camType=CamType.LsstCam,
                           opticalModel="offAxis", defocalDisInMm=1.0,
                           sizeInPix=120, debugLevel=0)

        # Evaluate the wavefront error
        wfsError = [12.484, 10.358, -6.674, -0.043, -1.768, -15.593, 12.511,
                    -192.382, 0.195, 4.074, 9.577, -1.930, 3.538, 3.420,
                    -3.610, 3.547, -0.679, -2.943, 1.101]
        zer4UpNm = self.wfsEst.calWfsErr()
        self.assertAlmostEqual(np.sum(np.abs(zer4UpNm-np.array(wfsError))), 0,
                               places=1)

        # Test to reset the data
        self.wfsEst.reset()
        self.assertEqual(np.sum(self.wfsEst.getAlgo().getZer4UpInNm()), 0)
Esempio n. 12
0
class TestWfEsitmator(unittest.TestCase):
    """Test the wavefront estimator class."""
    def setUp(self):

        # Get the path of module
        self.modulePath = getModulePath()

        # Define the instrument folder
        instruFolderPath = os.path.join(self.modulePath, "configData", "cwfs",
                                        "instruData")

        # Define the algorithm folder
        algoFolderPath = os.path.join(self.modulePath, "configData", "cwfs",
                                      "algo")

        # Decalre the WfEstimator
        self.wfsEst = WfEstimator(instruFolderPath, algoFolderPath)

    def testFunc(self):

        # Define the image folder and image names
        # Image data -- Don't know the final image format.
        # It is noted that image.readFile inuts is based on the txt file.
        imageFolderPath = os.path.join(self.modulePath, "tests", "testData",
                                       "testImages", "LSST_NE_SN25")
        intra_image_name = "z11_0.25_intra.txt"
        extra_image_name = "z11_0.25_extra.txt"

        # Path to image files
        intraImgFile = os.path.join(imageFolderPath, intra_image_name)
        extraImgFile = os.path.join(imageFolderPath, extra_image_name)

        # Field XY position
        fieldXY = [1.185, 1.185]

        # Setup the images
        self.wfsEst.setImg(fieldXY,
                           imageFile=intraImgFile,
                           defocalType="intra")
        self.wfsEst.setImg(fieldXY,
                           imageFile=extraImgFile,
                           defocalType="extra")

        # Test the images are set.
        self.assertEqual(self.wfsEst.ImgIntra.atype,
                         self.wfsEst.ImgIntra.INTRA)
        self.assertEqual(self.wfsEst.ImgExtra.atype,
                         self.wfsEst.ImgExtra.EXTRA)

        # Setup the configuration

        # Try to catch the error
        try:
            self.wfsEst.config(solver="exp", defocalDisInMm=3, debugLevel=0)
        except ValueError:
            print("Catch the wrong instrument.")

        # If the configuration is reset, the images are needed to be set again.
        self.wfsEst.config(solver="exp",
                           instName="lsst",
                           sizeInPix=120,
                           opticalModel="offAxis",
                           debugLevel=0)

        # Test the setting of algorithm and instrument
        self.assertEqual(self.wfsEst.inst.instName, "lsst")
        self.assertEqual(self.wfsEst.algo.algoName, "exp")

        # Evaluate the wavefront error
        wfsError = [
            2.593, 14.102, -8.470, 3.676, 1.467, -9.724, 8.207, -192.839,
            0.978, 1.568, 4.197, -0.391, 1.551, 1.235, -1.699, 2.140, -0.296,
            -2.113, 1.188
        ]
        zer4UpNm = self.wfsEst.calWfsErr()
        self.assertAlmostEqual(np.sum(np.abs(zer4UpNm - np.array(wfsError))),
                               0,
                               places=1)

        # Reset the wavefront images
        self.wfsEst.setImg(fieldXY,
                           imageFile=intraImgFile,
                           defocalType="intra")
        self.wfsEst.setImg(fieldXY,
                           imageFile=extraImgFile,
                           defocalType="extra")

        # Change the algorithm to fft
        self.wfsEst.config(solver="fft")
        self.assertEqual(self.wfsEst.algo.algoName, "fft")

        # Evaluate the wavefront error
        wfsError = [
            12.484, 10.358, -6.674, -0.043, -1.768, -15.593, 12.511, -192.382,
            0.195, 4.074, 9.577, -1.930, 3.538, 3.420, -3.610, 3.547, -0.679,
            -2.943, 1.101
        ]
        zer4UpNm = self.wfsEst.calWfsErr()
        self.assertAlmostEqual(np.sum(np.abs(zer4UpNm - np.array(wfsError))),
                               0,
                               places=1)

        # Test to output the parameters
        filename = "outputParameter"
        self.wfsEst.outParam(filename=filename)
        self.assertTrue(os.path.isfile(filename))
        os.remove(filename)

        # Test to reset the data
        self.wfsEst.reset()
        self.assertEqual(np.sum(self.wfsEst.algo.zer4UpNm), 0)