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()
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)
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)
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
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)
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
class TestOptCtrl(unittest.TestCase): """Test the OptCtrl class.""" 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() def testEstiUkWithoutGainWithX0(self): self.mixedData.xRef = "x0" uk = self.optCtrl.estiUkWithoutGain(self.mixedData, self.filterType, self.optSt) self.assertEqual(len(uk), len(self.mixedData.getDofIdx())) self.assertAlmostEqual(uk[0], -16.036665624673333) self.assertAlmostEqual(uk[1], -1.349544022857101) self.assertAlmostEqual(uk[2], 2.6511005518054187) def testEstiUkWithoutGainWith0(self): self.mixedData.xRef = "0" uk = self.optCtrl.estiUkWithoutGain(self.mixedData, self.filterType, self.optSt) self.assertEqual(len(uk), len(self.mixedData.getDofIdx())) self.assertAlmostEqual(uk[0], 69.00565727180765) self.assertAlmostEqual(uk[1], -6.579374120758578) self.assertAlmostEqual(uk[2], -39.21488331771004) def testEstiUkWithoutGainWithX00(self): self.mixedData.xRef = "x00" uk = self.optCtrl.estiUkWithoutGain(self.mixedData, self.filterType, self.optSt) self.assertEqual(len(uk), len(self.mixedData.getDofIdx())) self.assertAlmostEqual(uk[0], -16.036665624673333) self.assertAlmostEqual(uk[1], -1.349544022857101) self.assertAlmostEqual(uk[2], 2.6511005518054187) def testEstiUkWithoutGainAndXref(self): self.mixedData.xRef = None self.assertRaises(ValueError, self.optCtrl.estiUkWithoutGain, self.mixedData, self.filterType, self.optSt)