Esempio n. 1
0
    def _configSourceSelector(self, camType, bscDbType, settingFileName):
        """Configue the source selector.

        Parameters
        ----------
        camType : enum 'CamType'
            Camera type.
        bscDbType : enum 'BscDbType'
            Bright star catalog (BSC) database type.
        settingFileName : str
            Setting file name.

        Returns
        -------
        SourceSelector
            Configured source selector.

        Raises
        ------
        ValueError
            WEPCalculation does not support this bscDbType yet.
        """

        sourSelc = SourceSelector(camType, bscDbType,
                                  settingFileName=settingFileName)
        sourSelc.setFilter(FilterType.REF)

        if (bscDbType == BscDbType.LocalDbForStarFile):
            dbAdress = os.path.join(getModulePath(), "tests", "testData",
                                    "bsc.db3")
            sourSelc.connect(dbAdress)
        else:
            raise ValueError("WEPCalculation does not support %s yet." % bscDbType)

        return sourSelc
Esempio n. 2
0
    def setUp(self):

        self.modulePath = getModulePath()

        # Query the database to get the star maps
        self.sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDb)
        self.sourSelc.setObsMetaData(0.0, 63, 0.0)
        self.sourSelc.configNbrCriteria(63.0, 2.5, maxNeighboringStar=99)
        self.sourSelc.setFilter(FilterType.U)

        dbAdress = os.path.join(self.modulePath, "tests", "testData",
                                "bsc.db3")
        self.sourSelc.connect(dbAdress)
        neighborStarMap, starMap, wavefrontSensors = self.sourSelc.getTargetStar(
            offset=0)
        self.sourSelc.disconnect()

        # Collect the data for the test of plot functions
        self.wavefrontSensors = wavefrontSensors
        self.starMap = starMap
        self.neighborStarMap = neighborStarMap

        # Save image files directory
        self.dataDir = os.path.join(self.modulePath, "tests", "tmp")
        self._makeDir(self.dataDir)
Esempio n. 3
0
    def _getTargetStarByFile(self, filterType):

        self.sourSelc = SourceSelector(CamType.LsstCam,
                                       BscDbType.LocalDbForStarFile)
        self.sourSelc.setObsMetaData(0, 0, 0)
        self.sourSelc.setFilter(filterType)
        self.sourSelc.connect(self.dbAdress)

        skyFilePath = os.path.join(self.modulePath, "tests", "testData",
                                   "phosimOutput", "realWfs", "output",
                                   "skyWfsInfo.txt")

        neighborStarMap, starMap, wavefrontSensors = \
                    self.sourSelc.getTargetStarByFile(skyFilePath, offset=0)

        return neighborStarMap, starMap, wavefrontSensors
Esempio n. 4
0
    def setUp(self):

        self.createBscTest()

        # Get the path of module
        self.modulePath = getModulePath()
        self.sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDb)

        # Set the survey parameters
        ra = 0.0
        dec = 63.0
        rotSkyPos = 0.0
        self.sourSelc.setObsMetaData(ra, dec, rotSkyPos)
        self.sourSelc.setFilter(FilterType.U)

        # Connect to database
        self.dbAdress = self.getPathOfBscTest()
        self.sourSelc.connect(self.dbAdress)
Esempio n. 5
0
    def setUp(self):

        # Get the path of module
        self.modulePath = getModulePath()

        self.sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDb)

        # Set the survey parameters
        ra = 0.0
        dec = 63.0
        rotSkyPos = 0.0
        self.sourSelc.setObsMetaData(ra, dec, rotSkyPos)
        self.sourSelc.setFilter(FilterType.U)

        # Address of local database
        self.dbAdress = os.path.join(self.modulePath, "tests", "testData", "bsc.db3")

        # Connect to database
        self.sourSelc.connect(self.dbAdress)
Esempio n. 6
0
    def _configSourceSelector(self, camType, bscDbType, settingFileName):
        """Configue the source selector.

        Parameters
        ----------
        camType : enum 'CamType'
            Camera type.
        bscDbType : enum 'BscDbType'
            Bright star catalog (BSC) database type.
        settingFileName : str
            Setting file name.

        Returns
        -------
        SourceSelector
            Configured source selector.
        """

        sourSelc = SourceSelector(camType, bscDbType, settingFileName=settingFileName)
        sourSelc.setFilter(FilterType.REF)

        return sourSelc
Esempio n. 7
0
    def _getTargetStarByFile(self, filterType):

        self.sourSelc = SourceSelector(CamType.LsstCam,
                                       BscDbType.LocalDbForStarFile)
        self.sourSelc.setObsMetaData(0, 0, 0)
        self.sourSelc.setFilter(filterType)
        self.sourSelc.connect(self.dbAdress)

        skyFilePath = os.path.join(self.modulePath, "tests", "testData",
                                   "phosimOutput", "realWfs", "output",
                                   "skyWfsInfo.txt")

        neighborStarMap, starMap, wavefrontSensors = \
            self.sourSelc.getTargetStarByFile(skyFilePath, offset=0)

        return neighborStarMap, starMap, wavefrontSensors
Esempio n. 8
0
    def setUp(self):

        # Get the path of module
        self.modulePath = getModulePath()

        self.sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDb)

        # Set the survey parameters
        ra = 0.0
        dec = 63.0
        rotSkyPos = 0.0
        self.sourSelc.setObsMetaData(ra, dec, rotSkyPos)
        self.sourSelc.setFilter(FilterType.U)

        # Address of local database
        self.dbAdress = os.path.join(self.modulePath, "tests", "testData",
                                     "bsc.db3")

        # Connect to database
        self.sourSelc.connect(self.dbAdress)
    def _configSourceSelector(self):

        sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDbForStarFile)

        # Set the criteria of neighboring stars
        starRadiusInPixel = 63
        spacingCoefficient = 2.5
        maxNeighboringStar = 1
        sourSelc.configNbrCriteria(
            starRadiusInPixel, spacingCoefficient, maxNeighboringStar=maxNeighboringStar
        )

        # Connest the database
        dbAdress = os.path.join(self.modulePath, "tests", "testData", "bsc.db3")
        sourSelc.connect(dbAdress)

        return sourSelc
    def _configSourceSelector(self):

        sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDbForStarFile)

        # Set the criteria of neighboring stars
        starRadiusInPixel = 63
        spacingCoefficient = 2.5
        maxNeighboringStar = 1
        sourSelc.configNbrCriteria(
            starRadiusInPixel, spacingCoefficient, maxNeighboringStar=maxNeighboringStar
        )

        # Connect the database
        dbAdress = self.getPathOfBscTest()
        sourSelc.connect(dbAdress)

        return sourSelc
Esempio n. 11
0
    def setUp(self):

        self.modulePath = getModulePath()

        # Query the database to get the star maps
        self.sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDb)
        self.sourSelc.setObsMetaData(0.0, 63, 0.0)
        self.sourSelc.configNbrCriteria(63.0, 2.5, maxNeighboringStar=99)
        self.sourSelc.setFilter(FilterType.U)

        dbAdress = os.path.join(self.modulePath, "tests", "testData", "bsc.db3")
        self.sourSelc.connect(dbAdress)
        neighborStarMap, starMap, wavefrontSensors = \
            self.sourSelc.getTargetStar(offset=0)
        self.sourSelc.disconnect()

        # Collect the data for the test of plot functions
        self.wavefrontSensors = wavefrontSensors
        self.starMap = starMap
        self.neighborStarMap = neighborStarMap

        # Save image files directory
        self.dataDir = os.path.join(self.modulePath, "tests", "tmp")
        self._makeDir(self.dataDir)
Esempio n. 12
0
    def _configSourceSelector(self):
        """Configue the source selector.

        Returns
        -------
        SourceSelector
            Configured source selector.
        """

        sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDbForStarFile)

        # Set the criteria of neighboring stars
        sourSelc.configNbrCriteria(
            self.STAR_RADIUS_IN_PIXEL,
            self.SPACING_COEFFICIENT,
            maxNeighboringStar=self.MAX_NEIGHBORING_STAR)

        # Connest the database
        dbAdress = os.path.join(aoclcUtil.getModulePath(), "tests", "testData",
                                "bsc.db3")
        sourSelc.connect(dbAdress)

        return sourSelc
Esempio n. 13
0
class TestSourceSelector(unittest.TestCase):
    """Test the source selector class."""

    def setUp(self):

        # Get the path of module
        self.modulePath = getModulePath()

        self.sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDb)

        # Set the survey parameters
        ra = 0.0
        dec = 63.0
        rotSkyPos = 0.0
        self.sourSelc.setObsMetaData(ra, dec, rotSkyPos)
        self.sourSelc.setFilter(FilterType.U)

        # Address of local database
        self.dbAdress = os.path.join(self.modulePath, "tests", "testData", "bsc.db3")

        # Connect to database
        self.sourSelc.connect(self.dbAdress)

    def tearDown(self):

        self.sourSelc.disconnect()

    def testInit(self):

        self.assertEqual(self.sourSelc.maxDistance, 157.5)
        self.assertEqual(self.sourSelc.maxNeighboringStar, 1)

    def testConfigNbrCriteria(self):

        starRadiusInPixel = 100
        spacingCoefficient = 2
        maxNeighboringStar = 3
        self.sourSelc.configNbrCriteria(
            starRadiusInPixel, spacingCoefficient, maxNeighboringStar=maxNeighboringStar
        )

        self.assertEqual(
            self.sourSelc.maxDistance, starRadiusInPixel * spacingCoefficient
        )
        self.assertEqual(self.sourSelc.maxNeighboringStar, maxNeighboringStar)

    def testSetAndGetFilter(self):

        filterType = FilterType.Z
        self.sourSelc.setFilter(filterType)

        self.assertEqual(self.sourSelc.getFilter(), filterType)

    def testGetTargetStarWithZeroOffset(self):

        self.sourSelc.configNbrCriteria(63.0, 2.5, maxNeighboringStar=99)
        neighborStarMap, starMap, wavefrontSensors = self.sourSelc.getTargetStar(
            offset=0
        )

        self.assertEqual(len(wavefrontSensors), 8)

    def testGetTargetStarWithNotZeroOffset(self):

        self.sourSelc.configNbrCriteria(63.0, 2.5, maxNeighboringStar=99)
        neighborStarMap, starMap, wavefrontSensors = self.sourSelc.getTargetStar(
            offset=-1000
        )

        self.assertEqual(len(wavefrontSensors), 3)

    def testGetTargetStarByFileWithWrongDbType(self):

        self.assertRaises(TypeError, self.sourSelc.getTargetStarByFile, "skyFile")

    def testGetTargetStarByFileForFilterG(self):

        neighborStarMap, starMap, wavefrontSensors = self._getTargetStarByFile(
            FilterType.G
        )

        self.assertEqual(len(wavefrontSensors), 8)

        for detector in wavefrontSensors:
            self.assertEqual(len(starMap[detector].getId()), 2)
            self.assertEqual(len(neighborStarMap[detector].getId()), 2)

    def testGetTargetStarByFileForFilterRef(self):

        neighborStarMap, starMap, wavefrontSensors = self._getTargetStarByFile(
            FilterType.REF
        )

        self.assertEqual(len(wavefrontSensors), 8)

        for detector in wavefrontSensors:
            self.assertEqual(len(starMap[detector].getId()), 2)
            self.assertEqual(len(neighborStarMap[detector].getId()), 2)

    def _getTargetStarByFile(self, filterType):

        self.sourSelc = SourceSelector(CamType.LsstCam, BscDbType.LocalDbForStarFile)
        self.sourSelc.setObsMetaData(0, 0, 0)
        self.sourSelc.setFilter(filterType)
        self.sourSelc.connect(self.dbAdress)

        skyFilePath = os.path.join(
            self.modulePath,
            "tests",
            "testData",
            "phosimOutput",
            "realWfs",
            "output",
            "skyWfsInfo.txt",
        )

        neighborStarMap, starMap, wavefrontSensors = self.sourSelc.getTargetStarByFile(
            skyFilePath, offset=0
        )

        return neighborStarMap, starMap, wavefrontSensors
Esempio n. 14
0
class TestSourceSelector(unittest.TestCase):
    """Test the source selector class."""

    def setUp(self):

        # Get the path of module
        self.modulePath = getModulePath()

        self.sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDb)

        # Set the survey parameters
        ra = 0.0
        dec = 63.0
        rotSkyPos = 0.0
        self.sourSelc.setObsMetaData(ra, dec, rotSkyPos)
        self.sourSelc.setFilter(FilterType.U)

        # Address of local database
        self.dbAdress = os.path.join(self.modulePath, "tests", "testData",
                                     "bsc.db3")

        # Connect to database
        self.sourSelc.connect(self.dbAdress)

    def tearDown(self):

        self.sourSelc.disconnect()

    def testInit(self):

        self.assertEqual(self.sourSelc.maxDistance, 157.5)
        self.assertEqual(self.sourSelc.maxNeighboringStar, 1)

    def testConfigNbrCriteria(self):

        starRadiusInPixel = 100
        spacingCoefficient = 2
        maxNeighboringStar = 3
        self.sourSelc.configNbrCriteria(starRadiusInPixel, spacingCoefficient,
                                        maxNeighboringStar=maxNeighboringStar)

        self.assertEqual(self.sourSelc.maxDistance,
                         starRadiusInPixel * spacingCoefficient)
        self.assertEqual(self.sourSelc.maxNeighboringStar, maxNeighboringStar)

    def testSetAndGetFilter(self):

        filterType = FilterType.Z
        self.sourSelc.setFilter(filterType)

        self.assertEqual(self.sourSelc.getFilter(), filterType)

    def testGetTargetStarWithZeroOffset(self):

        self.sourSelc.configNbrCriteria(63.0, 2.5, maxNeighboringStar=99)
        neighborStarMap, starMap, wavefrontSensors = \
            self.sourSelc.getTargetStar(offset=0)

        self.assertEqual(len(wavefrontSensors), 8)

    def testGetTargetStarWithNotZeroOffset(self):

        self.sourSelc.configNbrCriteria(63.0, 2.5, maxNeighboringStar=99)
        neighborStarMap, starMap, wavefrontSensors = \
            self.sourSelc.getTargetStar(offset=-1000)

        self.assertEqual(len(wavefrontSensors), 3)

    def testGetTargetStarByFileWithWrongDbType(self):

        self.assertRaises(TypeError, self.sourSelc.getTargetStarByFile,
                          "skyFile")

    def testGetTargetStarByFileForFilterG(self):

        neighborStarMap, starMap, wavefrontSensors = \
            self._getTargetStarByFile(FilterType.G)

        self.assertEqual(len(wavefrontSensors), 8)

        for detector in wavefrontSensors:
            self.assertEqual(len(starMap[detector].getId()), 2)
            self.assertEqual(len(neighborStarMap[detector].getId()), 2)

    def testGetTargetStarByFileForFilterRef(self):

        neighborStarMap, starMap, wavefrontSensors = \
            self._getTargetStarByFile(FilterType.REF)

        self.assertEqual(len(wavefrontSensors), 8)

        for detector in wavefrontSensors:
            self.assertEqual(len(starMap[detector].getId()), 2)
            self.assertEqual(len(neighborStarMap[detector].getId()), 2)

    def _getTargetStarByFile(self, filterType):

        self.sourSelc = SourceSelector(CamType.LsstCam,
                                       BscDbType.LocalDbForStarFile)
        self.sourSelc.setObsMetaData(0, 0, 0)
        self.sourSelc.setFilter(filterType)
        self.sourSelc.connect(self.dbAdress)

        skyFilePath = os.path.join(self.modulePath, "tests", "testData",
                                   "phosimOutput", "realWfs", "output",
                                   "skyWfsInfo.txt")

        neighborStarMap, starMap, wavefrontSensors = \
            self.sourSelc.getTargetStarByFile(skyFilePath, offset=0)

        return neighborStarMap, starMap, wavefrontSensors
Esempio n. 15
0
class TestPlotStarFunc(unittest.TestCase):
    """Test the functions of PlotStarFunc."""
    def setUp(self):

        self.modulePath = getModulePath()

        # Query the database to get the star maps
        self.sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDb)
        self.sourSelc.setObsMetaData(0.0, 63, 0.0)
        self.sourSelc.configNbrCriteria(63.0, 2.5, maxNeighboringStar=99)
        self.sourSelc.setFilter(FilterType.U)

        dbAdress = os.path.join(self.modulePath, "tests", "testData",
                                "bsc.db3")
        self.sourSelc.connect(dbAdress)
        neighborStarMap, starMap, wavefrontSensors = self.sourSelc.getTargetStar(
            offset=0)
        self.sourSelc.disconnect()

        # Collect the data for the test of plot functions
        self.wavefrontSensors = wavefrontSensors
        self.starMap = starMap
        self.neighborStarMap = neighborStarMap

        # Save image files directory
        self.dataDir = os.path.join(self.modulePath, "tests", "tmp")
        self._makeDir(self.dataDir)

    def _makeDir(self, directory):

        if not os.path.exists(directory):
            os.makedirs(directory)

    def tearDown(self):

        shutil.rmtree(self.dataDir)

    def testPlotRaDecl(self):

        saveFilePath = os.path.join(self.dataDir, "starInRaDecl.png")
        plotRaDecl(
            self.wavefrontSensors,
            self.starMap,
            self.neighborStarMap,
            self.sourSelc.db.STD_DEV_SPLIT,
            saveFilePath=saveFilePath,
        )

        self.assertTrue(os.path.exists(saveFilePath))

    def testPlotStarInPixelOnDetector(self):

        detector = list(self.neighborStarMap.keys())[0]
        stars = self.starMap[detector]
        neighboringStar = self.neighborStarMap[detector]
        saveFilePath = os.path.join(self.dataDir, "starInPixel.png")
        plotStarInPixelOnDetector(stars,
                                  neighboringStar,
                                  xyDim=(4000, 4000),
                                  saveFilePath=saveFilePath)

        self.assertTrue(os.path.exists(saveFilePath))
Esempio n. 16
0
class TestPlotStarFunc(unittest.TestCase):
    """Test the functions of PlotStarFunc."""

    def setUp(self):

        self.modulePath = getModulePath()

        # Query the database to get the star maps
        self.sourSelc = SourceSelector(CamType.ComCam, BscDbType.LocalDb)
        self.sourSelc.setObsMetaData(0.0, 63, 0.0)
        self.sourSelc.configNbrCriteria(63.0, 2.5, maxNeighboringStar=99)
        self.sourSelc.setFilter(FilterType.U)

        dbAdress = os.path.join(self.modulePath, "tests", "testData", "bsc.db3")
        self.sourSelc.connect(dbAdress)
        neighborStarMap, starMap, wavefrontSensors = \
            self.sourSelc.getTargetStar(offset=0)
        self.sourSelc.disconnect()

        # Collect the data for the test of plot functions
        self.wavefrontSensors = wavefrontSensors
        self.starMap = starMap
        self.neighborStarMap = neighborStarMap

        # Save image files directory
        self.dataDir = os.path.join(self.modulePath, "tests", "tmp")
        self._makeDir(self.dataDir)

    def _makeDir(self, directory):

        if (not os.path.exists(directory)):
            os.makedirs(directory)

    def tearDown(self):

        shutil.rmtree(self.dataDir)

    def testPlotRaDecl(self):

        saveFilePath = os.path.join(self.dataDir, "starInRaDecl.png")
        plotRaDecl(self.wavefrontSensors, self.starMap, self.neighborStarMap,
                   self.sourSelc.db.STD_DEV_SPLIT, saveFilePath=saveFilePath)

        self.assertTrue(os.path.exists(saveFilePath))

    def testPlotStarInPixelOnDetector(self):

        detector = list(self.neighborStarMap.keys())[0]
        stars = self.starMap[detector]
        neighboringStar = self.neighborStarMap[detector]
        saveFilePath = os.path.join(self.dataDir, "starInPixel.png")
        plotStarInPixelOnDetector(stars, neighboringStar, xyDim=(4000, 4000),
                                  saveFilePath=saveFilePath)

        self.assertTrue(os.path.exists(saveFilePath))