Ejemplo n.º 1
0
    def testWriteMirZkAndGridResInZemax(self):

        resFile = self._writeMirZkAndGridResInZemax()
        resFile1, resFile3 = resFile

        content1 = np.loadtxt(resFile1)
        content3 = np.loadtxt(resFile3)

        ansFilePath1 = os.path.join(getModulePath(), "tests", "testData",
                                    "testM1M3Func", "sim6_M1res.txt")
        ansFilePath3 = os.path.join(getModulePath(), "tests", "testData",
                                    "testM1M3Func", "sim6_M3res.txt")
        ansContent1 = np.loadtxt(ansFilePath1)
        ansContent3 = np.loadtxt(ansFilePath3)

        self.assertLess(np.sum(np.abs(content1[0, :]-ansContent1[0, :])), 1e-9)
        self.assertLess(np.sum(np.abs(content1[1:, 0]-ansContent1[1:, 0])),
                        1e-9)

        self.assertLess(np.sum(np.abs(content3[0, :]-ansContent3[0, :])), 1e-9)
        self.assertLess(np.sum(np.abs(content3[1:, 0]-ansContent3[1:, 0])),
                        1e-9)

        os.remove(resFile1)
        os.remove(resFile3)
Ejemplo n.º 2
0
    def setUp(self):

        self.configFilePath = os.path.join(getModulePath(), "configData",
                                           "telescopeConfig", "GT.inst")
        self.tele = TeleFacade(configFilePath=self.configFilePath)

        # Set the subsystem data directory
        camDataDir = os.path.join(getModulePath(), "configData", "camera")
        M1M3dataDir = os.path.join(getModulePath(), "configData", "M1M3")
        M2dataDir = os.path.join(getModulePath(), "configData", "M2")
        self.tele.setSubSysConfigDir(camDataDir=camDataDir,
                                     M1M3dataDir=M1M3dataDir,
                                     M2dataDir=M2dataDir)

        # Set the survey parameters
        obsId = 9006000
        filterType = FilterType.G
        boresight = (0.2, 0.3)
        zAngleInDeg = 27.0912
        rotAngInDeg = np.rad2deg(-1.2323)
        mjd = 59552.3
        self.tele.setSurveyParam(obsId=obsId, filterType=filterType,
                                 boresight=boresight, zAngleInDeg=zAngleInDeg,
                                 rotAngInDeg=rotAngInDeg, mjd=mjd)

        # Set the output dir
        self.outputDir = os.path.join(getModulePath(), "output", "temp")
        os.makedirs(self.outputDir)
Ejemplo n.º 3
0
    def _writeMirZkAndGridResInZemax(self):

        self._setSurfAlongZ()

        resFile1 = os.path.join(getModulePath(), "output", "M1res.txt")
        resFile3 = os.path.join(getModulePath(), "output", "M3res.txt")
        resFile = [resFile1, resFile3]
        self.M1M3.writeMirZkAndGridResInZemax(resFile=resFile)

        return resFile
Ejemplo n.º 4
0
    def testShowFieldMap(self):

        testDataDir = os.path.join(getModulePath(), "tests", "testData",
                                   "testOpdFunc")
        saveToFilePath = os.path.join(getModulePath(), "output", "img",
                                      "fieldMap.png")
        fieldX = np.array([0, 0])
        fieldY = np.array([0, 1])

        showFieldMap(fieldX=fieldX,
                     fieldY=fieldY,
                     folderPath2FocalPlane=testDataDir,
                     saveToFilePath=saveToFilePath)
        os.remove(saveToFilePath)
Ejemplo n.º 5
0
    def testGetAoclcOutputPathNotAssigned(self):

        with self.assertWarns(UserWarning):
            aoclcOutputPath = getAoclcOutputPath()

        self.assertEqual(aoclcOutputPath,
                         os.path.join(getModulePath(), "output"))
Ejemplo n.º 6
0
    def setUp(self):

        # Directory to the focal plane file
        folderPath2FocalPlane = os.path.join(getModulePath(), "tests",
                                             "testData", "testOpdFunc")
        self.skySim = SkySim()
        self.skySim.setFolderPath2FocalPlane(folderPath2FocalPlane)
Ejemplo n.º 7
0
    def _writeMirZkAndGridResInZemax(self):

        self._setSurfAlongZ()
        resFile = os.path.join(getModulePath(), "output", "M2res.txt")
        self.M2.writeMirZkAndGridResInZemax(resFile=resFile)

        return resFile
Ejemplo n.º 8
0
def precondition(phosimDir):

    # Survey information
    instName = "lsst"
    filterType = FilterType.REF
    ra = 20
    decl = 30
    rotSkyPos = 10
    mjd = 59580.0

    # Declare the SkySim()
    skySim = SkySim()

    # Set the focal plane information
    folderPath2FocalPlane = os.path.join(phosimDir, "data", instName)
    skySim.setFolderPath2FocalPlane(folderPath2FocalPlane)

    # Set the observation information
    skySim.setObservationMetaData(ra, decl, rotSkyPos, mjd)

    # Add the interested stars
    sensorName = "R22_S11"
    starId = [0, 1]
    xInpixelInCam = [3200, 400]
    yInPixelInCam = [3800, 700]
    starMag = [15, 16]
    for ii in range(len(starId)):
        skySim.addStarByChipPos(sensorName, starId[ii], xInpixelInCam[ii],
                                yInPixelInCam[ii], starMag[ii])

    # Output the sky information
    outputFilePath = os.path.join(getModulePath(), "output",
                                  "skyLsstFamInfo.txt")
    skySim.exportSkyToFile(outputFilePath)

    # Set the Telescope facade class
    configFilePath = os.path.join(getModulePath(), "configData",
                                  "telescopeConfig", "GT.inst")
    tele = TeleFacade(configFilePath=configFilePath)
    tele.setSubSysConfigDir(phosimDir=phosimDir)
    tele.setSurveyParam(filterType=filterType,
                        boresight=(ra, decl),
                        rotAngInDeg=rotSkyPos,
                        mjd=mjd)
    tele.setInstName(instName)

    return tele, skySim
Ejemplo n.º 9
0
    def _generateOpd(self):

        metr = OpdMetrology()
        metr.addFieldXYbyDeg(0, 0)
        opdInstSettingFile = os.path.join(getModulePath(), "configData",
                                          "instFile", "opdDefault.inst")

        return metr, opdInstSettingFile
Ejemplo n.º 10
0
    def testGetTempCorr(self):

        tempCorrInUm = self._getTempCorrInUm()

        ansFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "testM1M3Func", "M1M3tempCorr.txt")
        ansTempCorrInUm = np.loadtxt(ansFilePath)
        self.assertLess(np.sum(np.abs(tempCorrInUm-ansTempCorrInUm)), 2*1e-8)
Ejemplo n.º 11
0
    def testGetMirrorData(self):

        M2DataDir = os.path.join(getModulePath(), "configData", "M2")
        self.mirror.setMirrorDataDir(M2DataDir)

        dataFileName = "M2_GT_FEA.txt"
        data = self.mirror.getMirrorData(dataFileName, skiprows=1)
        self.assertEqual(data.shape, (9084, 6))
Ejemplo n.º 12
0
    def testGetPrintthz(self):

        zAngleInDeg = 27.0912
        printthzInM = self._getPrintthzInM(zAngleInDeg)

        ansFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "testM1M3Func", "M1M3printthz.txt")
        ansPrintthzInM = np.loadtxt(ansFilePath)
        self.assertLess(np.sum(np.abs(printthzInM-ansPrintthzInM)), 1e-10)
Ejemplo n.º 13
0
    def testExportSkyToFile(self):

        self._addStarByFile()
        outputFilePath = os.path.join(getModulePath(), "output",
                                      "testSkyOutput.txt")

        self.skySim.exportSkyToFile(outputFilePath)
        self.assertTrue(os.path.isfile(outputFilePath))
        os.remove(outputFilePath)
Ejemplo n.º 14
0
    def _generateFakeSky(self):

        skySim = SkySim()
        skySim.addStarByRaDecInDeg(0, 1.0, 1.0, 17.0)

        starInstSettingFile = os.path.join(getModulePath(), "configData",
                                           "instFile", "starDefault.inst")

        return skySim, starInstSettingFile
Ejemplo n.º 15
0
    def _copyComCamFiles(self):

        intraFocalDirName = self.phosimCmpt.getIntraFocalDirName()
        extraFocalDirName = self.phosimCmpt.getExtraFocalDirName()
        for imgType in (intraFocalDirName, extraFocalDirName):
            imgDirPath = os.path.join(getModulePath(), "tests", "testData",
                                      "comcamPhosimData", imgType)
            dst = os.path.join(self.phosimCmpt.getOutputImgDir(), imgType)
            shutil.copytree(imgDirPath, dst)
Ejemplo n.º 16
0
    def testGetTempCorr(self):

        M2TzGrad = -0.0675
        M2TrGrad = -0.1416
        tempCorrInUm = self.M2.getTempCorr(M2TzGrad, M2TrGrad)

        ansFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "testM2Func", "M2tempCorr.txt")
        ansTempCorrInUm = np.loadtxt(ansFilePath)
        self.assertLess(np.sum(np.abs(tempCorrInUm - ansTempCorrInUm)), 1e-10)
Ejemplo n.º 17
0
    def testGenMirSurfRandErr(self):

        iSim = 6
        zAngleInDeg = 27.0912
        randSurfInM = self._getRandSurfInM(iSim, zAngleInDeg)

        ansFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "testM1M3Func", "M1M3surfRand.txt")
        ansRandSurfInM = np.loadtxt(ansFilePath)
        self.assertLess(np.sum(np.abs(randSurfInM-ansRandSurfInM)), 1e-10)
Ejemplo n.º 18
0
    def testGetPrintthz(self):

        zAngleInDeg = 27.0912
        zAngleInRadian = np.deg2rad(zAngleInDeg)
        printthzInUm = self.M2.getPrintthz(zAngleInRadian)

        ansFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "testM2Func", "M2printthz.txt")
        ansPrintthzInUm = np.loadtxt(ansFilePath)
        self.assertLess(np.sum(np.abs(printthzInUm - ansPrintthzInUm)), 1e-10)
Ejemplo n.º 19
0
    def testShowMirResMap(self):

        resFile = self._writeMirZkAndGridResInZemax()
        resFile1, resFile3 = resFile

        writeToResMapFilePath1 = os.path.join(getModulePath(), "output",
                                              "M1resMap.png")
        writeToResMapFilePath3 = os.path.join(getModulePath(), "output",
                                              "M3resMap.png")
        writeToResMapFilePath = [writeToResMapFilePath1,
                                 writeToResMapFilePath3]
        self.M1M3.showMirResMap(resFile,
                                writeToResMapFilePath=writeToResMapFilePath)
        self.assertTrue(os.path.isfile(writeToResMapFilePath1))
        self.assertTrue(os.path.isfile(writeToResMapFilePath3))

        os.remove(resFile1)
        os.remove(resFile3)
        os.remove(writeToResMapFilePath1)
        os.remove(writeToResMapFilePath3)
Ejemplo n.º 20
0
    def _getConfigDataPath(self):
        """Get the configuration data path.

        Returns
        -------
        str
            Configuration data path
        """

        configDataPath = os.path.join(getModulePath(), "configData")

        return configDataPath
Ejemplo n.º 21
0
    def testShowMirResMap(self):

        resFile = self._writeMirZkAndGridResInZemax()
        writeToResMapFilePath = os.path.join(getModulePath(), "output",
                                             "M2resMap.png")

        self.M2.showMirResMap(resFile,
                              writeToResMapFilePath=writeToResMapFilePath)
        self.assertTrue(os.path.isfile(writeToResMapFilePath))

        os.remove(resFile)
        os.remove(writeToResMapFilePath)
Ejemplo n.º 22
0
    def testWriteCmdFile(self):

        starCmdSettingFile = os.path.join(getModulePath(), "configData",
                                          "cmdFile", "starDefault.cmd")

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

        numOfLineInFile = self._getNumOfLineInFile(cmdFilePath)
        self.assertEqual(numOfLineInFile, 267)
Ejemplo n.º 23
0
    def setUp(self):

        self.phosimCmpt = PhosimCmpt(self.tele)

        # Set the output directories
        self.outputDir = os.path.join(getModulePath(), "tests", "tmp")
        self.outputImgDir = os.path.join(self.outputDir, "img")

        self.phosimCmpt.setOutputDir(self.outputDir)
        self.phosimCmpt.setOutputImgDir(self.outputImgDir)

        # Set the file name of analyzed OPD data
        self.zkFileName = "opd.zer"
        self.pssnFileName = "PSSN.txt"
Ejemplo n.º 24
0
    def testGetLUTforce(self):

        M1M3DataDir = os.path.join(getModulePath(), "configData", "M1M3")

        zangleInDeg = 1.5
        LUTfileName = "M1M3_LUT.txt"

        self.mirror.setMirrorDataDir(M1M3DataDir)
        self.mirror.config(LUTfileName=LUTfileName)
        LUTforce = self.mirror.getLUTforce(zangleInDeg)

        oriLutForce = self.mirror.getMirrorData(LUTfileName, skiprows=1)
        ansLutForce = (oriLutForce[:, 1] + oriLutForce[:, 2]) / 2
        self.assertLess(np.sum(np.abs(LUTforce - ansLutForce)), 1e-10)
Ejemplo n.º 25
0
    def testWriteToFile(self):

        filePath = os.path.join(getModulePath(), "tests", "temp.inst")
        self.assertFalse(os.path.exists(filePath))

        content = "temp"
        self.phosimCom.writeToFile(filePath, content=content, mode="w")
        self.assertTrue(os.path.exists(filePath))

        with open(filePath, "r") as file:
            contentInFile = file.read()
        self.assertEqual(contentInFile, content)

        os.remove(filePath)
Ejemplo n.º 26
0
    def testGetMirrorResInMmInZemax(self):

        numTerms = 28
        self._setSurfAlongZ()
        zcInMmInZemax = self.M2.getMirrorResInMmInZemax()[3]

        ansFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "testM2Func", "sim6_M2zlist.txt")
        ansZcInUmInZemax = np.loadtxt(ansFilePath)
        ansZcInMmInZemax = ansZcInUmInZemax * 1e-3

        delta = np.sum(
            np.abs(zcInMmInZemax[0:numTerms] - ansZcInMmInZemax[0:numTerms]))
        self.assertLess(delta, 1e-9)
Ejemplo n.º 27
0
    def testWriteMirZkAndGridResInZemax(self):

        resFile = self._writeMirZkAndGridResInZemax()
        content = np.loadtxt(resFile)

        ansFilePath = os.path.join(getModulePath(), "tests", "testData",
                                   "testM2Func", "sim6_M2res.txt")
        ansContent = np.loadtxt(ansFilePath)

        self.assertLess(np.sum(np.abs(content[0, :] - ansContent[0, :])), 1e-9)
        self.assertLess(np.sum(np.abs(content[1:, 0] - ansContent[1:, 0])),
                        1e-9)

        os.remove(resFile)
Ejemplo n.º 28
0
    def testGetCamDistortionInMm(self):

        self.camSim.setBodyTempInDegC(6.5650)
        self.camSim.setRotAngInRad(-1.2323)

        zenithAngleInDeg = 27.0912
        zAngleInRad = np.deg2rad(zenithAngleInDeg)
        distortionInMn = self.camSim.getCamDistortionInMm(
            zAngleInRad, CamDistType.L1S1zer)

        dataFilePath = os.path.join(getModulePath(), "tests", "testData",
                                    "testOpdFunc", "sim6_iter0_pert.cmd")
        distData = np.loadtxt(dataFilePath, skiprows=88, usecols=(1, 2, 3))
        idx = (distData[:, 0] == 3)
        absDiff = np.sum(np.abs(distortionInMn - distData[idx, -1]))

        self.assertTrue(absDiff < 1e-10)
Ejemplo n.º 29
0
    def setUp(self):

        self.testM2Data = os.path.join(getModulePath(), "tests", "testData",
                                       "testM2Func")
        self.outputDir = os.path.join(getModulePath(), "output")
Ejemplo n.º 30
0
    def setUp(self):

        self.testDataDir = os.path.join(getModulePath(), "tests", "testData",
                                        "testOpdFunc")
        self.metr = OpdMetrology()