예제 #1
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)
예제 #2
0
def _prepareSkySimBySkyFile(inputSkyFilePath):

    skySim = SkySim()

    absSkyFilePath = os.path.abspath(inputSkyFilePath)
    skySim.addStarByFile(absSkyFilePath)

    return skySim
예제 #3
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
예제 #4
0
def _prepareSkySim(opdMetr, starMag):

    skySim = SkySim()

    starId = 0
    raInDegList, declInDegList = opdMetr.getFieldXY()
    for raInDeg, declInDeg in zip(raInDegList, declInDegList):
        # It is noted that the field position might be < 0. But it is not the
        # same case for ra (0 <= ra <= 360).
        if (raInDeg < 0):
            raInDeg += 360.0
        skySim.addStarByRaDecInDeg(starId, raInDeg, declInDeg, starMag)
        starId += 1

    return skySim
예제 #5
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
예제 #6
0
def get_opd_ra_dec(instrument, raField, decField, rotskypos):
    ''' Provide phoSim with ra,dec locations to evaluate OPD.
    The OPD expects field location, not sky location.
    '''
    if instrument == 'comCam':
        sensorNames, xCenter, yCenter = get_all_sensor_names_xy(
            LsstComCam().getCamera())

    elif instrument == 'lsstCam':
        sensorNames, xCenter, yCenter = get_all_sensor_names_xy(
            LsstCam().getCamera())

    elif instrument == 'wfs':
        sensorNames, xCenter, yCenter = get_wfs_sensor_names_xy()

    # Declare the SkySim()
    skySim = SkySim()

    # Set the observation information
    skySim.setObservationMetaData(raField, decField, rotskypos)

    xPx = xCenter
    yPx = yCenter
    starMag = 15

    starId = 0
    # we have only one x,y point per sensor
    for i in range(len(sensorNames)):
        skySim.addStarByChipPos(sensorNames[i], starId, xCenter[i], yCenter[i],
                                starMag)
        starId += 1

    raList, decList = skySim.getRaDecInDeg()

    # Note:  ra for phosim is (0 <= ra <= 360). But the
    # field position might be < 0 (-180 <= field_ra <= 180).
    # So here I change
    # the (0,360) range to (-180,180) range:
    m = raList > 180
    raList[m] = raList[m] - 360

    mags = skySim.getStarMag()
    coords = Table(data=[raList, decList, xCenter, yCenter, mags],
                   names=['ra', 'dec', 'xPx', 'yPx', 'r'])

    # add a column with object id
    coords['objid'] = np.arange(len(coords))

    panda_cat = coords.to_pandas()

    return panda_cat
예제 #7
0
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
예제 #8
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)
예제 #9
0
    def _addSglStarToSkySim(self):

        skySim = SkySim()
        skySim.addStarByRaDecInDeg(0, 0.1, 0.2, 5.0)

        return skySim
예제 #10
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)
예제 #11
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",
                                   "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)
예제 #12
0
def main(phosimDir):

    # 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
    zAngleInDeg = 27.0912
    rotSkyPos = np.rad2deg(-1.2323)

    # Set the Telescope facade class
    tele = TeleFacade()
    tele.addSubSys(addCam=True, addM1M3=True, addM2=True)
    tele.setPhoSimDir(phosimDir)
    tele.setSurveyParam(obsId=obsId,
                        filterType=filterType,
                        boresight=(ra, decl),
                        zAngleInDeg=zAngleInDeg,
                        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, 300]
    yInPixelInCam = [3800, 1000]
    starMag = [15, 12]
    for ii in range(len(starId)):
        skySim.addStarByChipPos(sensorName, starId[ii], xInpixelInCam[ii],
                                yInPixelInCam[ii], starMag[ii])

    # Generate the perturbation
    iSim = 6
    pertCmdFilePath = tele.writePertBaseOnConfigFile(outputDir,
                                                     seedNum=iSim,
                                                     saveResMapFig=True)

    # Update the telescope degree of freedom with camera piston in um
    dofInUm = np.zeros(50)
    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,
                                    pertFilePath=pertCmdFilePath,
                                    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)
예제 #13
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)
예제 #14
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)
예제 #15
0
    def setUp(self):

        self.skySim = SkySim()