Exemple #1
0
    # Set the ObservationMetaData
    RA = 0
    Dec = 0

    # The unit of camera rotation angle is in degree
    cameraRotation = 0
    cameraMJD = 59580.0

    obs = ObservationMetaData(pointingRA=RA,
                              pointingDec=Dec,
                              rotSkyPos=cameraRotation,
                              mjd=mjdTime)

    # Instantiate the subsystems
    phoSimCommu = PhosimCommu()
    skySim = SkySim()

    # Instantiate the telescope
    tele = TeleFacade(phoSimCommu=phoSimCommu)

    # Set the subsystem directory
    tele.setSubSysConfigFile(phosimDir=phosimDir)

    # Update the telescope degree of freedom
    # dofInUm = np.zeros(50)

    # Camera piston in um
    # dofInUm[5] = 1000

    # Camera dx in um
    def testFunc(self):
        
        # Instantiate the needed objects
        cam = CamSim()
        M1M3 = M1M3Sim()
        M2 = M2Sim()
        phoSimCommu = PhosimCommu()
        metr = OpdMetrology()
        skySim = SkySim()

        # Instantiate the telescope facade class
        tele = TeleFacade(cam=cam, M1M3=M1M3, M2=M2, phoSimCommu=phoSimCommu)

        # Set the configuration file path
        tele.setConfigFile(self.configFilePath)
        self.assertEqual(tele.configFile, self.configFilePath)

        instFilePath = "temp.inst"
        argString = tele.getPhoSimArgs(instFilePath)
        ansArgString = "%s -i lsst -e 1" % os.path.abspath(instFilePath)
        self.assertEqual(argString, ansArgString)

        instruFile = "comcam10"
        tele.setInstName(instruFile)
        self.assertEqual(tele.instName, "comcam")
        self.assertEqual(tele.defocalDisInMm, 1.0)

        dofInUm = np.random.rand(50)
        tele.setDofInUm(dofInUm)
        self.assertEqual(np.sum(np.abs(tele.dofInUm-dofInUm)), 0)

        tele.setDofInUm(np.zeros(50))
        tele.accDofInUm(dofInUm)
        self.assertEqual(np.sum(np.abs(tele.dofInUm-dofInUm)), 0)

        tele.setSubSysConfigFile(camDataDir=self.camDataDir, M1M3dataDir=self.M1M3dataDir, 
                                 M2dataDir=self.M2dataDir)
        self.assertEqual(tele.cam.camDataDir, self.camDataDir)
        self.assertEqual(tele.phoSimCommu.phosimDir, None)

        varName = "M1M3TxGrad"
        value = tele.getConfigValue(varName)
        self.assertEqual(value, -0.0894)

        dofFilePath = tele.writeAccDofFile(self.outputDir)
        self.assertLess(np.sum(np.abs(np.loadtxt(dofFilePath)-dofInUm)), 1e-7)
        os.remove(dofFilePath)

        zAngleInDeg = 27.0912
        rotAngInDeg = -1.2323/np.pi*180.0
        iSim = 6
        pertCmdFilePath = tele.writePertBaseOnConfigFile(self.outputDir, zAngleInDeg=zAngleInDeg, 
                                           rotAngInDeg=rotAngInDeg, seedNum=iSim, saveResMapFig=False)
        cmdFile = open(pertCmdFilePath, "r")
        lines = cmdFile.readlines()
        cmdFile.close()
        self.assertEqual(len(lines), 256)

        cmdFilePath = tele.writeCmdFile(self.outputDir, cmdSettingFile=self.starCmdSettingFile, 
                                        pertFilePath=pertCmdFilePath, cmdFileName="star.cmd")

        starCmdFile = open(cmdFilePath, "r")
        lines = starCmdFile.readlines()
        starCmdFile.close()
        self.assertEqual(len(lines), 267)

        metr.addFieldXYbyDeg(0, 0)
        obsId = 9006000
        aFilter = "g"
        wavelengthInNm = 500
        instFilePath = tele.writeOpdInstFile(self.outputDir, metr, obsId, aFilter, wavelengthInNm, 
                                                instSettingFile=self.opdInstSettingFile)
        opdInstFile = open(instFilePath, "r")
        lines = opdInstFile.readlines()
        opdInstFile.close()
        self.assertEqual(len(lines), 55)

        skySim.addStarByRaDecInDeg(0, 1.0, 1.0, 17.0)
        boresight = (0.2, 0.3)
        instFilePath = tele.writeStarInstFile(self.outputDir, skySim, obsId, aFilter, boresight, 
                                                wfSensorOn=True, instSettingFile=self.starInstSettingFile)

        starInstFile = open(instFilePath, "r")
        lines = starInstFile.readlines()
        starInstFile.close()
        self.assertEqual(len(lines), 62)

        shutil.rmtree(self.outputDir)