Exemple #1
0
    def setUp(self):

        dataShare = DataShare()
        configDir = os.path.join(getModulePath(), "configData")
        dataShare.config(configDir, instName=InstName.LSST)

        optStateEstiData = OptStateEstiDataDecorator(dataShare)
        optStateEstiData.configOptStateEstiData()
        self.mixedData = OptCtrlDataDecorator(optStateEstiData)
        self.mixedData.configOptCtrlData(configFileName="optiPSSN_x00.ctrl")

        optStateEsti = OptStateEsti()
        wfsFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "lsst_wfs_error_iter0.z4c")
        sensorNameList = ["R44_S00", "R04_S20", "R00_S22", "R40_S02"]
        wfErr, fieldIdx = optStateEstiData.getWfAndFieldIdFromFile(
            wfsFilePath, sensorNameList)

        self.filterType = FilterType.REF
        self.optSt = optStateEsti.estiOptState(optStateEstiData,
                                               self.filterType, wfErr,
                                               fieldIdx)

        self.optCtrl = OptCtrl()

        state0InDof = self.mixedData.getState0FromFile()
        testState0InDof = np.ones(len(state0InDof))
        self.optCtrl.setState0(testState0InDof)
        self.optCtrl.initStateToState0()
Exemple #2
0
class TestOptStateEsti(unittest.TestCase):
    """Test the OptStateEsti class."""
    def setUp(self):

        dataShare = DataShare()
        configDir = os.path.join(getModulePath(), "configData")
        dataShare.config(configDir, instName=InstName.LSST)

        self.optStateEstiData = OptStateEstiDataDecorator(dataShare)
        self.optStateEstiData.configOptStateEstiData()

        self.optStateEsti = OptStateEsti()

        wfsFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "lsst_wfs_error_iter0.z4c")
        sensorNameList = ["R44_S00", "R04_S20", "R00_S22", "R40_S02"]
        wfErr, fieldIdx = self.optStateEstiData.getWfAndFieldIdFromFile(
            wfsFilePath, sensorNameList)
        self.wfErr = wfErr
        self.fieldIdx = fieldIdx

    def testEstiOptState(self):

        optState = self.optStateEsti.estiOptState(self.optStateEstiData,
                                                  FilterType.REF, self.wfErr,
                                                  self.fieldIdx)
        dofIdx = self.optStateEstiData.getDofIdx()

        self.assertEqual(len(optState), len(dofIdx))
        self.assertAlmostEqual(optState[0], 13.9943858)
        self.assertAlmostEqual(optState[1], 0.0303436526)
        self.assertAlmostEqual(optState[2], -0.0360475823)

    def testEstiOptStateWithDifferentZkIdxAndDofIdx(self):

        zn3Idx = np.arange(5)
        dofIdx = np.arange(10)
        self.optStateEstiData.setZkAndDofIdxArrays(zn3Idx, dofIdx)

        optState = self.optStateEsti.estiOptState(self.optStateEstiData,
                                                  FilterType.REF, self.wfErr,
                                                  self.fieldIdx)
        self.assertEqual(len(optState), len(dofIdx))
        self.assertAlmostEqual(optState[0], -645.7540849494324)
        self.assertAlmostEqual(optState[1], -10221.082801186029)
        self.assertAlmostEqual(optState[2], -758.518174)

    def testEstiOptStateWithoutEnoughZk(self):

        zn3Idx = np.arange(4)
        dofIdx = np.arange(20)
        self.optStateEstiData.setZkAndDofIdxArrays(zn3Idx, dofIdx)

        self.assertRaises(RuntimeError, self.optStateEsti.estiOptState,
                          self.optStateEstiData, FilterType.REF, self.wfErr,
                          self.fieldIdx)
Exemple #3
0
    def testEstiUkWithGainOfComCam(self):

        dataShare = DataShare()
        configDir = os.path.join(getModulePath(), "configData")
        dataShare.config(configDir, instName=InstName.COMCAM)

        optStateEstiData = OptStateEstiDataDecorator(dataShare)
        optStateEstiData.configOptStateEstiData()

        mixedData = OptCtrlDataDecorator(optStateEstiData)
        mixedData.configOptCtrlData(configFileName="optiPSSN_x00.ctrl")

        optStateEsti = OptStateEsti()
        optCtrl = OptCtrl()

        self.ztaac = ZTAAC(optStateEsti, optCtrl, mixedData)
        self.ztaac.config(filterType=FilterType.REF,
                          defaultGain=0.7,
                          fwhmThresholdInArcsec=0.2)

        self._setStateAndState0FromFile()

        gainToUse = 1
        self.ztaac.setGain(gainToUse)

        wfErr, sensorNameList = self._getWfErrAndSensorNameListFromComCamFile()
        uk = self.ztaac.estiUkWithGain(wfErr, sensorNameList)

        ansFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "comcam_pert_iter1.txt")
        ukAns = gainToUse * np.loadtxt(ansFilePath, usecols=1)

        delta = np.sum(np.abs(uk - ukAns))
        self.assertLess(delta, 0.0012)
Exemple #4
0
    def setUp(self):

        dataShare = DataShare()
        configDir = os.path.join(getModulePath(), "configData")
        dataShare.config(configDir, instName=InstName.LSST)

        optStateEstiData = OptStateEstiDataDecorator(dataShare)
        optStateEstiData.configOptStateEstiData()

        mixedData = OptCtrlDataDecorator(optStateEstiData)
        mixedData.configOptCtrlData(configFileName="optiPSSN_x00.ctrl")

        optStateEsti = OptStateEsti()
        optCtrl = OptCtrl()

        self.ztaac = ZTAAC(optStateEsti, optCtrl, mixedData)
        self.ztaac.config(filterType=FilterType.REF,
                          defaultGain=0.7,
                          fwhmThresholdInArcsec=0.2)

        self.ztaac.setState0FromFile(state0InDofFileName="state0inDof.txt")
        self.ztaac.setStateToState0()

        self.camRot = CamRot()
        self.camRot.setRotAng(0)

        iterDataDir = os.path.join(getModulePath(), "tests", "testData",
                                   "iteration")
        self.iterDataReader = IterDataReader(iterDataDir)
Exemple #5
0
    def setUp(self):

        dataShare = DataShare()
        configDir = os.path.join(getModulePath(), "configData")
        dataShare.config(configDir, instName=InstName.LSST)

        self.optStateEstiData = OptStateEstiDataDecorator(dataShare)
        self.optStateEstiData.configOptStateEstiData()

        self.optStateEsti = OptStateEsti()

        wfsFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "lsst_wfs_error_iter0.z4c")
        sensorNameList = ["R44_S00", "R04_S20", "R00_S22", "R40_S02"]
        wfErr, fieldIdx = self.optStateEstiData.getWfAndFieldIdFromFile(
            wfsFilePath, sensorNameList)
        self.wfErr = wfErr
        self.fieldIdx = fieldIdx
Exemple #6
0
def setup():

    # Set up the object of data share class. This contains the
    # information of indexes of zk and degree of freedom (DOF)
    # to use.
    dataShare = DataShare()
    configDir = os.path.join(getModulePath(), "configData")
    dataShare.config(configDir, instName=InstName.LSST)

    # Decorate the DataShare object to get the data needed
    # for the OptStateEsti object.
    optStateEstiData = OptStateEstiDataDecorator(dataShare)
    optStateEstiData.configOptStateEstiData()

    # Decorate the DataShare object to get the data needed
    # for the OptCtrl object.
    mixedData = OptCtrlDataDecorator(optStateEstiData)
    mixedData.configOptCtrlData(configFileName="optiPSSN_x00.ctrl")

    # Instantiate the objects of OptStateEsti and OptCtrl classes.
    optStateEsti = OptStateEsti()
    optCtrl = OptCtrl()

    # Instantiate the ZTAAC object with the configured objects.
    ztaac = ZTAAC(optStateEsti, optCtrl, mixedData)

    # Do the configuration of ZTAAC object.
    ztaac.config(filterType=FilterType.REF,
                 defaultGain=0.7,
                 fwhmThresholdInArcsec=0.2)

    # Set the state 0 from file. This is only used in the simulation.
    # In the real control, the state 0 should come from the subsystem
    # by SAL (software abstracion layer). But the algorithm for this
    # needs to be developed.
    ztaac.setState0FromFile(state0InDofFileName="state0inDof.txt")

    # Initialize the state to state 0.
    ztaac.setStateToState0()

    # Instantiate the camera rotation object.
    camRot = CamRot()

    # Set up the rotation angle.
    # The angle is zero degree in the test data.
    camRot.setRotAng(0)

    # Read the test iteration data by the IM closed-loop simulation.
    iterDataDir = os.path.join(getModulePath(), "tests", "testData",
                               "iteration")
    iterDataReader = IterDataReader(iterDataDir)

    return ztaac, camRot, iterDataReader
Exemple #7
0
    def setUp(self):

        dataShare = DataShare()
        configDir = os.path.join(getModulePath(), "configData")
        dataShare.config(configDir, instName=InstName.LSST)

        optStateEstiData = OptStateEstiDataDecorator(dataShare)
        optStateEstiData.configOptStateEstiData()

        mixedData = OptCtrlDataDecorator(optStateEstiData)
        mixedData.configOptCtrlData(configFileName="optiPSSN_x00.ctrl")

        optStateEsti = OptStateEsti()
        optCtrl = OptCtrl()

        self.ztaac = ZTAAC(optStateEsti, optCtrl, mixedData)
        self.ztaac.config(filterType=FilterType.REF,
                          defaultGain=0.7,
                          fwhmThresholdInArcsec=0.2)
Exemple #8
0
    def _configZTAAC(self, instName):
        """Configurate the ZTAAC.

        ZTAAC: Zernike to actuator adjustment calculator.

        Parameters
        ----------
        instName : InstName
            Instrument name.

        Returns
        -------
        ZTAAC
            configurated ZTAAC object.
        """

        # Prepare the data object for the ZTAAC to use
        dataShare = DataShare()
        configDataPath = self._getConfigDataPath()
        dataShare.config(configDataPath, instName=instName)

        optStateEstiData = OptStateEstiDataDecorator(dataShare)
        optStateEstiData.configOptStateEstiData()

        mixedData = OptCtrlDataDecorator(optStateEstiData)
        mixedData.configOptCtrlData(configFileName="optiPSSN_x00.ctrl")

        # Instantiate the ZTAAC object with the configured objects.
        ztaac = ZTAAC(OptStateEsti(), OptCtrl(), mixedData)

        # Set the state 0 and state
        ztaac.setState0FromFile(state0InDofFileName="state0inDof.txt")
        ztaac.setStateToState0()

        # Configure the parameters
        ztaac.config(filterType=FilterType.REF,
                     defaultGain=self.DEFAULT_GAIN,
                     fwhmThresholdInArcsec=self.FWHM_THRESHOLD_IN_ARCSEC)

        return ztaac