Esempio n. 1
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
Esempio n. 2
0
class TestSkySim(unittest.TestCase):
    """ Test the SkySim class."""
    def setUp(self):

        # Directory to the focal plane file
        folderPath2FocalPlane = os.path.join(getModulePath(), "tests",
                                             "testData", "testOpdFunc")
        self.skySim = SkySim()
        self.skySim.setFolderPath2FocalPlane(folderPath2FocalPlane)

    def testAddStarByRaDecInDeg(self):

        self.skySim.addStarByRaDecInDeg(1, 2, 3, 4)
        self.assertEqual(len(self.skySim.starId), 1)

        self.skySim.addStarByRaDecInDeg(2, 2.1, 3, 4)
        self.assertEqual(len(self.skySim.starId), 2)
        self.assertEqual(self.skySim.starId[0], 1)
        self.assertEqual(self.skySim.starId[1], 2)

        # Try to add the same star Id again
        self.skySim.addStarByRaDecInDeg(2, 2.1, 3, 4)
        self.assertEqual(len(self.skySim.starId), 2)

    def testResetSky(self):

        self.skySim.addStarByRaDecInDeg(1, 2, 3, 4)
        self.skySim.resetSky()
        self.assertEqual(len(self.skySim.starId), 0)

    def testSetStarRaDecInDeg(self):

        self.skySim.setStarRaDecInDeg(np.array([0]), np.array([1]),
                                      np.array([2]), np.array([3]))
        self.assertEqual(len(self.skySim.starId), 1)

    def testAddStarByFile(self):

        self._addStarByFile()
        self.assertEqual(len(self.skySim.starId), 8)
        self.assertEqual(self.skySim.ra[2], -1.176)
        self.assertEqual(self.skySim.decl[2], 1.196)
        self.assertEqual(self.skySim.mag[2], 17.0)

    def _addStarByFile(self):

        skyFile = os.path.join(getModulePath(), "tests", "testData", "sky",
                               "wfsStar.txt")
        self.skySim.addStarByFile(skyFile)

    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)

    def testAddStarByChipPos(self):

        self._setObservationMetaData()

        # Add the star
        sensorName = "R22_S11"
        starId = 0
        xInpixelInCam = 2000
        yInPixelInCam = 2036
        starMag = 17
        self.skySim.addStarByChipPos(sensorName, starId, xInpixelInCam,
                                     yInPixelInCam, starMag)

        # Test the result
        self.assertAlmostEqual(self.skySim.ra[0], 359.99971038)
        self.assertAlmostEqual(self.skySim.decl[0], 0.0001889)

    def _setObservationMetaData(self):

        ra = 0
        decl = 0
        rotSkyPos = 0
        mjd = 59580.0
        self.skySim.setObservationMetaData(ra, decl, rotSkyPos, mjd)
def main(phosimDir):

    # Settings
    outputDir = os.path.join(getModulePath(), "output")
    outputImgDir = os.path.join(outputDir, "img")

    cmdSettingFile = os.path.join(getModulePath(), "configData", "cmdFile",
                                  "starDefault.cmd")
    instSettingFile = os.path.join(getModulePath(), "configData", "instFile",
                                   "starSingleExp.inst")

    # Survey information
    obsId = 9006000
    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 = [
        "R44_S00_C0", "R00_S22_C1", "R44_S00_C1", "R00_S22_C0", "R04_S20_C1",
        "R40_S02_C0", "R04_S20_C0", "R40_S02_C1"
    ]
    xInpixelInCam = [500, 800]
    yInPixelInCam = [1000, 1300]
    starMag = [15, 15]
    starId = 0
    for sensor in sensorName:
        for ii in range(len(starMag)):
            skySim.addStarByChipPos(sensor, starId, xInpixelInCam[ii],
                                    yInPixelInCam[ii], starMag[ii])
            starId += 1

    # Export sky information
    outputSkyFilePath = os.path.join(getModulePath(), "output",
                                     "skyWfsInfo.txt")
    skySim.exportSkyToFile(outputSkyFilePath)

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

    # Write the accumulated DOF file
    tele.writeAccDofFile(outputDir)

    # Write the star physical command file
    cmdFilePath = tele.writeCmdFile(outputDir,
                                    cmdSettingFile=cmdSettingFile,
                                    cmdFileName="star.cmd")

    # Write the instance file
    instFilePath = tele.writeStarInstFile(outputDir,
                                          skySim,
                                          instSettingFile=instSettingFile,
                                          instFileName="star.inst")

    # Get the argument to run the PhoSim
    logFilePath = os.path.join(outputImgDir, "phosimStar.log")
    argString = tele.getPhoSimArgs(instFilePath,
                                   extraCommandFile=cmdFilePath,
                                   numPro=8,
                                   outputDir=outputImgDir,
                                   e2ADC=0,
                                   logFilePath=logFilePath)

    # Run the PhoSim
    tele.runPhoSim(argString)
Esempio n. 4
0
def main(phosimDir):

    # Settings
    outputDir = os.path.join(getModulePath(), "output")
    outputImgDir = os.path.join(outputDir, "img")

    cmdSettingFile = os.path.join(getModulePath(), "configData", "cmdFile",
                                  "starDefault.cmd")
    instSettingFile = os.path.join(getModulePath(), "configData", "instFile",
                                   "starDefault.inst")

    # Survey information
    obsId = 9006000
    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]
    xInpixelInCam = [3200]
    yInPixelInCam = [3800]
    starMag = [15]
    for ii in range(len(starId)):
        skySim.addStarByChipPos(sensorName, starId[ii], xInpixelInCam[ii],
                                yInPixelInCam[ii], starMag[ii])

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

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

    # Camera piston in um
    dofInUm[5] = 1000

    tele.accDofInUm(dofInUm)

    # Write the accumulated DOF file
    tele.writeAccDofFile(outputDir)

    # Write the star physical command file
    cmdFilePath = tele.writeCmdFile(outputDir,
                                    cmdSettingFile=cmdSettingFile,
                                    cmdFileName="star.cmd")

    # Write the instance file
    instFilePath = tele.writeStarInstFile(outputDir,
                                          skySim,
                                          instSettingFile=instSettingFile,
                                          instFileName="star.inst")

    # Get the argument to run the PhoSim
    logFilePath = os.path.join(outputImgDir, "phosimStar.log")
    argString = tele.getPhoSimArgs(instFilePath,
                                   extraCommandFile=cmdFilePath,
                                   numPro=1,
                                   outputDir=outputImgDir,
                                   e2ADC=0,
                                   logFilePath=logFilePath)

    # Run the PhoSim
    tele.runPhoSim(argString)