Example #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
def _prepareTeleAndSky(phosimDir):

    # Survey information
    filterType = FilterType.REF
    ra = 20
    decl = 30
    rotSkyPos = 10

    # Set the Telescope facade class
    tele = TeleFacade()
    tele.setPhoSimDir(phosimDir)
    tele.setSurveyParam(filterType=filterType,
                        boresight=(ra, decl),
                        rotAngInDeg=rotSkyPos)
    tele.setInstName(CamType.LsstFamCam)

    # Declare the SkySim()
    skySim = SkySim()

    # Set the observation information
    mjd = tele.getCamMjd()
    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(getAoclcOutputPath(), "skyLsstFamInfo.txt")
    skySim.exportSkyToFile(outputFilePath)

    return tele, skySim
Example #3
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)
Example #4
0
def main(phosimDir, numPro):

    # Settings
    outputDir = getAoclcOutputPath()
    outputImgDir = os.path.join(outputDir, "img")
    os.makedirs(outputImgDir, exist_ok=True)

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

    # Survey information
    obsId = 9006000
    filterType = FilterType.REF
    ra = 20
    decl = 30
    rotSkyPos = 10

    # Set the Telescope facade class
    tele = TeleFacade()
    tele.setPhoSimDir(phosimDir)
    tele.setSurveyParam(obsId=obsId,
                        filterType=filterType,
                        boresight=(ra, decl),
                        rotAngInDeg=rotSkyPos)
    tele.setInstName(CamType.LsstCam)

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

    # Declare the SkySim()
    skySim = SkySim()

    # Set the observation information
    mjd = tele.getCamMjd()
    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(outputDir, "skyWfsInfo.txt")
    skySim.exportSkyToFile(outputSkyFilePath)

    # 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=numPro,
                                   outputDir=outputImgDir,
                                   e2ADC=0,
                                   logFilePath=logFilePath)

    # Run the PhoSim
    tele.runPhoSim(argString)
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)
Example #6
0
class TestSkySim(unittest.TestCase):
    """ Test the SkySim class."""
    def setUp(self):

        self.skySim = SkySim()

    def testGetStarId(self):

        starId = self.skySim.getStarId()
        self.assertEqual(len(starId), 0)
        self.assertTrue(isinstance(starId, np.ndarray))

    def testGetRaDecInDeg(self):

        ra, decl = self.skySim.getRaDecInDeg()

        self.assertEqual(len(ra), 0)
        self.assertTrue(isinstance(ra, np.ndarray))

        self.assertEqual(len(decl), 0)
        self.assertTrue(isinstance(decl, np.ndarray))

    def testGetStarMag(self):

        mag = self.skySim.getStarMag()
        self.assertEqual(len(mag), 0)
        self.assertTrue(isinstance(mag, np.ndarray))

    def testAddStarByRaDecInDeg(self):

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

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

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

    def testResetSky(self):

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

    def testSetStarRaDecInDeg(self):

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

    def testAddStarByFile(self):

        self._addStarByFile("wfsStar.txt")

        self.assertEqual(len(self.skySim.getStarId()), 8)

        ra, decl = self.skySim.getRaDecInDeg()
        self.assertEqual(ra[2], -1.176)
        self.assertEqual(decl[2], 1.196)

        self.assertEqual(self.skySim.getStarMag()[2], 17.0)

    def _addStarByFile(self, skyFileName):

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

    def testAddStarByFileWithSglStar(self):

        self._addStarByFile("wfsSglStar.txt")

        self.assertEqual(len(self.skySim.getStarId()), 1)

        ra, decl = self.skySim.getRaDecInDeg()
        self.assertEqual(ra[0], 1.196)
        self.assertEqual(decl[0], 1.176)

        self.assertEqual(self.skySim.getStarMag()[0], 17.0)

    def testExportSkyToFile(self):

        self._addStarByFile("wfsStar.txt")
        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
        ra, decl = self.skySim.getRaDecInDeg()
        self.assertAlmostEqual(ra[0], 359.99971038)
        self.assertAlmostEqual(decl[0], 0.0001889)

    def _setObservationMetaData(self):

        ra = 0
        decl = 0
        rotSkyPos = 0
        mjd = 59580.0
        self.skySim.setObservationMetaData(ra, decl, rotSkyPos, mjd)