Esempio n. 1
0
    def setUp(self):

        self.createBscTest()

        # Set up the local database
        self.localDatabase = LocalDatabase()

        dbAdress = self.getPathOfBscTest()
        self.localDatabase.connect(dbAdress)

        # Set the filter
        self.filterType = FilterType.G

        # Set up neighboring star map
        stars = StarData(
            [123, 456, 789],
            [0.1, 0.2, 0.3],
            [2.1, 2.2, 2.3],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
        )
        stars.setRaInPixel(stars.getRA() * 10)
        stars.setDeclInPixel(stars.getDecl() * 10)
        self.neighboringStar = stars.getNeighboringStar([0], 3,
                                                        self.filterType, 99)
Esempio n. 2
0
    def setUp(self):

        # Set the database address
        modulePath = getModulePath()
        dbAdress = os.path.join(modulePath, "tests", "testData", "bsc.db3")

        # Set up local database
        self.localDatabase = LocalDatabase()
        self.localDatabase.connect(dbAdress)

        # Set the filter
        self.filterType = FilterType.G

        # Set up neighboring star map
        stars = StarData(
            [123, 456, 789],
            [0.1, 0.2, 0.3],
            [2.1, 2.2, 2.3],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
            [2.0, 3.0, 4.0],
        )
        stars.setRaInPixel(stars.getRA() * 10)
        stars.setDeclInPixel(stars.getDecl() * 10)
        self.neighboringStar = stars.getNeighboringStar([0], 3,
                                                        self.filterType, 99)
Esempio n. 3
0
 def setUp(self):
     self.stars = StarData(
         [123, 456, 789],
         [0.1, 0.2, 0.3],
         [2.1, 2.2, 2.3],
         [2.0, 3.0, 4.0],
         [2.1, 2.1, 4.1],
         [2.2, 3.2, 4.2],
         [2.3, 3.3, 4.3],
         [2.4, 3.4, 4.4],
         [2.5, 3.5, 4.5],
     )
Esempio n. 4
0
    def setUp(self):

        # Boresight (unit: degree)
        ra = 0.0  # 0 <= RA <= 360
        dec = 30.0  # -90 <= Dec <= 90
        rotSkyPos = 0.0
        self.camera = ComCam()
        self.camera.setObsMetaData(ra, dec, rotSkyPos, mjd=59580.0)

        self.stars = StarData([123, 456, 789], [0.1, 0.2, 0.3],
                              [2.1, 2.2, 2.3], [2.0, 3.0, 4.0],
                              [2.1, 2.1, 4.1], [2.2, 3.2, 4.2],
                              [2.3, 3.3, 4.3], [], [])
Esempio n. 5
0
    def setUp(self):

        stars = StarData([123, 456, 789], [0.1, 0.2, 0.3],
                         [2.1, 2.2, 2.3], [2.0, 3.0, 4.0], 
                         [2.1, 2.1, 4.1], [2.2, 3.2, 4.2],
                         [2.3, 3.3, 4.3], [2.4, 3.4, 4.4],
                         [2.5, 3.5, 4.5])
        stars.setRaInPixel(stars.getRA() * 10)
        stars.setDeclInPixel(stars.getDecl() * 10)

        self.stars = stars
        self.neighboringStar = NbrStar()
Esempio n. 6
0
    def setUp(self):

        # Boresight (unit: degree)
        ra = 0.0    # 0 <= RA <= 360
        dec = 30.0   # -90 <= Dec <= 90
        rotSkyPos = 0.0
        self.camera = ComCam()
        self.camera.setObsMetaData(ra, dec, rotSkyPos, mjd=59580.0)

        self.stars = StarData([123, 456, 789], [0.1, 0.2, 0.3],
                              [2.1, 2.2, 2.3], [2.0, 3.0, 4.0],
                              [2.1, 2.1, 4.1], [2.2, 3.2, 4.2],
                              [2.3, 3.3, 4.3], [], [])
Esempio n. 7
0
    def setUp(self):

        stars = StarData([123, 456, 789], [0.1, 0.2, 0.3],
                         [2.1, 2.2, 2.3], [2.0, 3.0, 4.0],
                         [2.1, 2.1, 4.1], [2.2, 3.2, 4.2],
                         [2.3, 3.3, 4.3], [2.4, 3.4, 4.4],
                         [2.5, 3.5, 4.5])
        stars.setRaInPixel(stars.getRA() * 10)
        stars.setDeclInPixel(stars.getDecl() * 10)

        self.stars = stars
        self.neighboringStar = NbrStar()
Esempio n. 8
0
    def setUp(self):

        # Set the database address
        modulePath = getModulePath()
        dbAdress = os.path.join(modulePath, "tests", "testData", "bsc.db3")

        # Set up local database
        self.localDatabase = LocalDatabase()
        self.localDatabase.connect(dbAdress)

        # Set the filter
        self.filterType = FilterType.G

        # Set up neighboring star map
        stars = StarData([123, 456, 789], [0.1, 0.2, 0.3], [2.1, 2.2, 2.3],
                         [2.0, 3.0, 4.0], [2.0, 3.0, 4.0], [2.0, 3.0, 4.0],
                         [2.0, 3.0, 4.0], [2.0, 3.0, 4.0], [2.0, 3.0, 4.0])
        stars.setRaInPixel(stars.getRA() * 10)
        stars.setDeclInPixel(stars.getDecl() * 10)
        self.neighboringStar = stars.getNeighboringStar(
            [0], 3, self.filterType, 99)
Esempio n. 9
0
class TestComCam(unittest.TestCase):
    """Test the ComCam class and functions of parent class."""
    def setUp(self):

        # Boresight (unit: degree)
        ra = 0.0  # 0 <= RA <= 360
        dec = 30.0  # -90 <= Dec <= 90
        rotSkyPos = 0.0
        self.camera = ComCam()
        self.camera.setObsMetaData(ra, dec, rotSkyPos)

        self.stars = StarData(
            [123, 456, 789],
            [0.1, 0.2, 0.3],
            [2.1, 2.2, 2.3],
            [2.0, 3.0, 4.0],
            [2.1, 2.1, 4.1],
            [2.2, 3.2, 4.2],
            [2.3, 3.3, 4.3],
            [],
            [],
        )

    def testGetWfsCcdList(self):

        wfsCcdList = self.camera.getWfsCcdList()

        self.assertEqual(len(wfsCcdList), 9)
        self.assertTrue("R22_S11" in wfsCcdList)
        self.assertFalse("R21_S11" in wfsCcdList)

    def testSetWfsCcdList(self):

        wfsCcdList = ["a", "b", "c"]
        self.camera.setWfsCcdList(wfsCcdList)

        self.assertEqual(self.camera.getWfsCcdList(), wfsCcdList)

    def testGetWfsCorner(self):

        wfsCorner = self.camera.getWfsCorner("R22_S11")

        self.assertEqual(len(wfsCorner), 2)
        self.assertRaises(KeyError, self.camera.getWfsCorner, "R21_S11")

    def testSetWfsCorners(self):

        wfsCorners = {"a": 1, "b": 2}
        self.camera.setWfsCorners(wfsCorners)

        self.assertEqual(self.camera.getWfsCorner("a"), wfsCorners["a"])

    def testGetCcdDim(self):

        ccdDim = self.camera.getCcdDim("R22_S11")

        self.assertEqual(ccdDim, (4096, 4004))

    def testSetCcdDims(self):

        ccdDims = {"a": (1, 1), "b": (2, 2)}
        self.camera.setCcdDims(ccdDims)

        self.assertEqual(self.camera.getCcdDim("a"), ccdDims["a"])

    def testGetWavefrontSensor(self):

        wfsData = self.camera.getWavefrontSensor()
        self.assertEqual(len(wfsData), 9)

    def testPopulatePixelFromRADecl(self):

        self.assertEqual(len(self.stars.getRaInPixel()), 0)

        populatedStar = self._populatePixelFromRADecl()

        self.assertEqual(len(self.stars.getRaInPixel()), 0)
        self.assertEqual(len(self.stars.getDeclInPixel()), 0)
        self.assertEqual(len(populatedStar.getRaInPixel()), 3)
        self.assertEqual(len(populatedStar.getDeclInPixel()), 3)
        self.assertNotEqual(id(populatedStar), id(self.stars))

    def _populatePixelFromRADecl(self):

        self.stars.setDetector("R22_S11")
        populatedStar = self.camera.populatePixelFromRADecl(self.stars)

        return populatedStar

    def testRemoveStarsNotOnDetectorWithLargeOffset(self):

        stars = self._populatePixelFromRADecl()
        starsOnDet = self.camera.getStarsOnDetector(stars, 1e7)

        self.assertEqual(len(starsOnDet.getId()), 3)
        self.assertEqual(len(starsOnDet.getRA()), 3)
        self.assertEqual(len(starsOnDet.getDecl()), 3)
        self.assertEqual(len(starsOnDet.getRaInPixel()), 3)
        self.assertEqual(len(starsOnDet.getDeclInPixel()), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.U)), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.G)), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.R)), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.I)), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.Z)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.Y)), 0)

        self.assertNotEqual(id(starsOnDet), id(stars))

    def testRemoveStarsNotOnDetectorWithZeroOffset(self):

        stars = self._populatePixelFromRADecl()
        starsOnDet = self.camera.getStarsOnDetector(stars, 0)

        self.assertEqual(len(starsOnDet.getId()), 0)
        self.assertEqual(len(starsOnDet.getRA()), 0)
        self.assertEqual(len(starsOnDet.getDecl()), 0)
        self.assertEqual(len(starsOnDet.getRaInPixel()), 0)
        self.assertEqual(len(starsOnDet.getDeclInPixel()), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.U)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.G)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.R)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.I)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.Z)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.Y)), 0)

        self.assertEqual(len(stars.getId()), 3)
        self.assertEqual(len(stars.getRA()), 3)
        self.assertEqual(len(stars.getDecl()), 3)
        self.assertEqual(len(stars.getRaInPixel()), 3)
        self.assertEqual(len(stars.getDeclInPixel()), 3)
        self.assertEqual(len(stars.getMag(FilterType.U)), 3)
        self.assertEqual(len(stars.getMag(FilterType.G)), 3)
        self.assertEqual(len(stars.getMag(FilterType.R)), 3)
        self.assertEqual(len(stars.getMag(FilterType.I)), 3)
        self.assertEqual(len(stars.getMag(FilterType.Z)), 0)
        self.assertEqual(len(stars.getMag(FilterType.Y)), 0)

        self.assertNotEqual(id(starsOnDet), id(stars))
Esempio n. 10
0
class TestStarData(unittest.TestCase):
    """Test the StarData class."""
    def setUp(self):
        self.stars = StarData([123, 456, 789], [0.1, 0.2, 0.3],
                              [2.1, 2.2, 2.3], [2.0, 3.0, 4.0],
                              [2.1, 2.1, 4.1], [2.2, 3.2, 4.2],
                              [2.3, 3.3, 4.3], [2.4, 3.4, 4.4],
                              [2.5, 3.5, 4.5])

    def testGetId(self):

        starId = self.stars.getId()
        self.assertEqual(starId.dtype, int)
        self.assertEqual(starId.tolist(), [123, 456, 789])

    def testGetRA(self):

        self.assertEqual(self.stars.getRA().tolist(), [0.1, 0.2, 0.3])

    def testGetDecl(self):

        self.assertEqual(self.stars.getDecl().tolist(), [2.1, 2.2, 2.3])

    def testGetMag(self):

        self.assertEqual(
            self.stars.getMag(FilterType.U).tolist(), [2.0, 3.0, 4.0])
        self.assertEqual(
            self.stars.getMag(FilterType.G).tolist(), [2.1, 2.1, 4.1])
        self.assertEqual(
            self.stars.getMag(FilterType.R).tolist(), [2.2, 3.2, 4.2])
        self.assertEqual(
            self.stars.getMag(FilterType.I).tolist(), [2.3, 3.3, 4.3])
        self.assertEqual(
            self.stars.getMag(FilterType.Z).tolist(), [2.4, 3.4, 4.4])
        self.assertEqual(
            self.stars.getMag(FilterType.Y).tolist(), [2.5, 3.5, 4.5])

    def testSetMag(self):

        mag = [1, 3, 4, 5]
        self.stars.setMag(FilterType.U, mag)

        self.assertEqual(self.stars.getMag(FilterType.U).tolist(), mag)

    def testSetAndGetDetector(self):

        detector = "CCD"
        self.stars.setDetector(detector)
        self.assertEqual(self.stars.getDetector(), detector)

    def testSetAndGetRaInPixel(self):

        raInPixel = [1.0, 2.0]
        self.stars.setRaInPixel(raInPixel)

        self.assertEqual(self.stars.getRaInPixel().tolist(), raInPixel)

    def testSetRaInPixelWithFloatValue(self):

        raInPixel = 1.0
        self.stars.setRaInPixel(raInPixel)

        self.assertEqual(self.stars.getRaInPixel().tolist(), [raInPixel])

    def testSetRaInPixelWithNpArray(self):

        raInPixel = np.array([1.0, 2.0])
        self.stars.setRaInPixel(raInPixel)

        delta = np.sum(np.abs(self.stars.getRaInPixel() - raInPixel))
        self.assertEqual(delta, 0)

    def testSetAndGetDeclInPixel(self):

        declInPixel = [2.0, 3.0]
        self.stars.setDeclInPixel(declInPixel)

        self.assertEqual(self.stars.getDeclInPixel().tolist(), declInPixel)

    def testCheckCandidateStars(self):

        indexCandidateU = self.stars.checkCandidateStars(
            FilterType.U, 1.9, 2.1)
        indexCandidateG = self.stars.checkCandidateStars(FilterType.G, 0, 5)
        indexCandidateR = self.stars.checkCandidateStars(FilterType.R, 0, 1)
        indexCandidateI = self.stars.checkCandidateStars(
            FilterType.I, 2.1, 4.0)
        indexCandidateZ = self.stars.checkCandidateStars(
            FilterType.Z, 3.0, 5.0)
        indexCandidateY = self.stars.checkCandidateStars(
            FilterType.Y, 1.0, 2.0)

        self.assertEqual(indexCandidateU, [0])
        self.assertEqual(indexCandidateG, [0, 1, 2])
        self.assertEqual(indexCandidateR, [])
        self.assertEqual(indexCandidateI, [0, 1])
        self.assertEqual(indexCandidateZ, [1, 2])
        self.assertEqual(indexCandidateY, [])

    def testGetNeighboringStar(self):

        self._populateRaDeclInPixel()

        neighboringStarU = self.stars.getNeighboringStar([0],
                                                         3,
                                                         FilterType.U,
                                                         maxNumOfNbrStar=99)
        neighboringStarG = self.stars.getNeighboringStar([0, 1],
                                                         3,
                                                         FilterType.G,
                                                         maxNumOfNbrStar=99)
        neighboringStarR = self.stars.getNeighboringStar([0],
                                                         1,
                                                         FilterType.R,
                                                         maxNumOfNbrStar=99)
        neighboringStarI = self.stars.getNeighboringStar([],
                                                         3,
                                                         FilterType.I,
                                                         maxNumOfNbrStar=99)
        neighboringStarZ = self.stars.getNeighboringStar([0, 1],
                                                         2,
                                                         FilterType.Z,
                                                         maxNumOfNbrStar=1)
        neighboringStarY = self.stars.getNeighboringStar([1],
                                                         2,
                                                         FilterType.Y,
                                                         maxNumOfNbrStar=1)

        self.assertEqual(len(neighboringStarU.getId()[123]), 2)
        self.assertEqual(len(neighboringStarU.getRaDecl()), 3)

        self.assertEqual(len(neighboringStarG.getId()), 2)

        self.assertEqual(len(neighboringStarR.getId()[123]), 0)

        self.assertEqual(neighboringStarI.getId(), {})

        self.assertEqual(len(neighboringStarZ.getId()), 1)

        self.assertEqual(neighboringStarY.getId(), {})

    def _populateRaDeclInPixel(self):

        self.stars.setRaInPixel(self.stars.getRA() * 10)
        self.stars.setDeclInPixel(self.stars.getDecl() * 10)

    def testGetNeighboringStarWithNothing(self):

        self._populateRaDeclInPixel()
        neighboringStarU = self.stars.getNeighboringStar([],
                                                         3.0,
                                                         FilterType.U,
                                                         maxNumOfNbrStar=99)

        self.assertEqual(len(neighboringStarU.getId()), 0)
Esempio n. 11
0
    def query(self, filterType, corner1, corner2, corner3, corner4):
        """Query the database for stars within an area.

        Parameters
        ----------
        filterType : FilterType
            Filter type.
        corner1 : tuple
            The first corner of the sensor defined as (RA, Decl).
        corner2 : tuple
            The second corner of the sensor defined as (RA, Decl).
        corner3 : tuple
            The third corner of the sensor defined as (RA, Decl).
        corner4 : tuple
            The fourth corner of the sensor defined as (RA, Decl).

        Returns
        ----------
        StarData
            Star information.
        """

        ra = [corner1[0], corner2[0], corner3[0], corner4[0]]
        decl = [corner1[1], corner2[1], corner3[1], corner4[1]]
        top = max(decl)
        bottom = min(decl)
        left = min(ra)
        right = max(ra)

        # Need to change this query method that divides the area with 2 parts.
        raStddev = np.std(ra)

        # Query regions crosses the RA = 0
        if (raStddev >= self.STD_DEV_SPLIT):

            # Query the left and right regions
            left = max([x for x in ra if x < 180])
            right = min([x for x in ra if x >= 180])
            above0Set = self._queryTable(filterType, top, bottom, 0, left)
            below0Set = self._queryTable(filterType, top, bottom, right, 360)

            # Combine the query results
            starId = np.append(above0Set.getId(), below0Set.getId())
            starRa = np.append(above0Set.getRA(), below0Set.getRA())
            starDecl = np.append(above0Set.getDecl(), below0Set.getDecl())

            lsstMagU = np.append(above0Set.getMag(FilterType.U),
                                 below0Set.getMag(FilterType.U))
            lsstMagG = np.append(above0Set.getMag(FilterType.G),
                                 below0Set.getMag(FilterType.G))
            lsstMagR = np.append(above0Set.getMag(FilterType.R),
                                 below0Set.getMag(FilterType.R))
            lsstMagI = np.append(above0Set.getMag(FilterType.I),
                                 below0Set.getMag(FilterType.I))
            lsstMagZ = np.append(above0Set.getMag(FilterType.Z),
                                 below0Set.getMag(FilterType.Z))
            lsstMagY = np.append(above0Set.getMag(FilterType.Y),
                                 below0Set.getMag(FilterType.Y))

            return StarData(starId, starRa, starDecl, lsstMagU, lsstMagG,
                            lsstMagR, lsstMagI, lsstMagZ, lsstMagY)

        # Query regions does not cross the RA = 0
        else:
            return self._queryTable(filterType, top, bottom, left, right)
Esempio n. 12
0
    def _queryTable(self, filterType, top, bottom, left, right):
        """Queries the database for stars within an area.

        Parameters
        ----------
        filterType : FilterType
            Filter type.
        top : float
            The top edge of the box (Decl).
        bottom : float
            The bottom edge of the box (Decl).
        left : float
            The left edge of the box (RA).
        right : float
            The right edge of the box (RA).

        Returns
        ----------
        StarData
            Star information.
        """

        # Do the query
        tableName = self._getTableName(filterType)
        command = "SELECT simobjid, ra, decl, " + \
                  filterType.name.lower() + "mag" + \
                  " FROM " + tableName + \
                  " WHERE decl <= %f AND decl >= %f AND ra >= %f AND ra <= %f"
        query = command % (top, bottom, left, right)
        self.cursor.execute(query)

        # Collect the data
        simobjid = []
        ra = []
        decl = []
        lsstMagU = []
        lsstMagG = []
        lsstMagR = []
        lsstMagI = []
        lsstMagZ = []
        lsstMagY = []
        for item in self.cursor.fetchall():

            # It is noted that the data type of simobjid is big interger
            # in UW database 
            simobjid.append(item[0])
            ra.append(item[1])
            decl.append(item[2])

            if (filterType == FilterType.U):              
                lsstMagU.append(item[3])    

            elif (filterType == FilterType.G):              
                lsstMagG.append(item[3])

            elif (filterType == FilterType.R):
                lsstMagR.append(item[3])

            elif (filterType == FilterType.I):
                lsstMagI.append(item[3])

            elif (filterType == FilterType.Z):
                lsstMagZ.append(item[3])

            elif (filterType == FilterType.Y):
                lsstMagY.append(item[3])

        return StarData(simobjid, ra, decl, lsstMagU, lsstMagG, lsstMagR,  
                        lsstMagI, lsstMagZ, lsstMagY)
Esempio n. 13
0
class TestComCam(unittest.TestCase):
    """Test the ComCam class and functions of parent class."""

    def setUp(self):

        # Boresight (unit: degree)
        ra = 0.0    # 0 <= RA <= 360
        dec = 30.0   # -90 <= Dec <= 90
        rotSkyPos = 0.0
        self.camera = ComCam()
        self.camera.setObsMetaData(ra, dec, rotSkyPos, mjd=59580.0)

        self.stars = StarData([123, 456, 789], [0.1, 0.2, 0.3],
                              [2.1, 2.2, 2.3], [2.0, 3.0, 4.0],
                              [2.1, 2.1, 4.1], [2.2, 3.2, 4.2],
                              [2.3, 3.3, 4.3], [], [])

    def testGetWfsCcdList(self):

        wfsCcdList = self.camera.getWfsCcdList()

        self.assertEqual(len(wfsCcdList), 9)
        self.assertTrue("R:2,2 S:1,1" in wfsCcdList)
        self.assertFalse("R:2,1 S:1,1" in wfsCcdList)

    def testSetWfsCcdList(self):

        wfsCcdList = ["a", "b", "c"]
        self.camera.setWfsCcdList(wfsCcdList)

        self.assertEqual(self.camera.getWfsCcdList(), wfsCcdList)

    def testGetWfsCorner(self):

        wfsCorner = self.camera.getWfsCorner("R:2,2 S:1,1")

        self.assertEqual(len(wfsCorner), 2)
        self.assertRaises(KeyError, self.camera.getWfsCorner, "R:2,1 S:1,1")

    def testSetWfsCorners(self):

        wfsCorners = {"a": 1, "b": 2}
        self.camera.setWfsCorners(wfsCorners)

        self.assertEqual(self.camera.getWfsCorner("a"), wfsCorners["a"])

    def testGetCcdDim(self):

        ccdDim = self.camera.getCcdDim("R:2,2 S:1,1")

        self.assertEqual(ccdDim, (4072, 4000))

    def testSetCcdDims(self):

        ccdDims = {"a": (1, 1), "b": (2, 2)}
        self.camera.setCcdDims(ccdDims)

        self.assertEqual(self.camera.getCcdDim("a"), ccdDims["a"])

    def testGetWavefrontSensor(self):

        wfsData = self.camera.getWavefrontSensor()
        self.assertEqual(len(wfsData), 9)

    def testPopulatePixelFromRADecl(self):

        self.assertEqual(len(self.stars.getRaInPixel()), 0)

        populatedStar = self._populatePixelFromRADecl()

        self.assertEqual(len(self.stars.getRaInPixel()), 0)
        self.assertEqual(len(self.stars.getDeclInPixel()), 0)
        self.assertEqual(len(populatedStar.getRaInPixel()), 3)
        self.assertEqual(len(populatedStar.getDeclInPixel()), 3)
        self.assertNotEqual(id(populatedStar), id(self.stars))

    def _populatePixelFromRADecl(self):

        self.stars.setDetector("R:2,2 S:1,1")
        populatedStar = self.camera.populatePixelFromRADecl(self.stars)

        return populatedStar

    def testRemoveStarsNotOnDetectorWithLargeOffset(self):

        stars = self._populatePixelFromRADecl()
        starsOnDet = self.camera.getStarsOnDetector(stars, 1e7)

        self.assertEqual(len(starsOnDet.getId()), 3)
        self.assertEqual(len(starsOnDet.getRA()), 3)
        self.assertEqual(len(starsOnDet.getDecl()), 3)
        self.assertEqual(len(starsOnDet.getRaInPixel()), 3)
        self.assertEqual(len(starsOnDet.getDeclInPixel()), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.U)), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.G)), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.R)), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.I)), 3)
        self.assertEqual(len(starsOnDet.getMag(FilterType.Z)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.Y)), 0)

        self.assertNotEqual(id(starsOnDet), id(stars))

    def testRemoveStarsNotOnDetectorWithZeroOffset(self):

        stars = self._populatePixelFromRADecl()
        starsOnDet = self.camera.getStarsOnDetector(stars, 0)

        self.assertEqual(len(starsOnDet.getId()), 0)
        self.assertEqual(len(starsOnDet.getRA()), 0)
        self.assertEqual(len(starsOnDet.getDecl()), 0)
        self.assertEqual(len(starsOnDet.getRaInPixel()), 0)
        self.assertEqual(len(starsOnDet.getDeclInPixel()), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.U)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.G)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.R)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.I)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.Z)), 0)
        self.assertEqual(len(starsOnDet.getMag(FilterType.Y)), 0)

        self.assertEqual(len(stars.getId()), 3)
        self.assertEqual(len(stars.getRA()), 3)
        self.assertEqual(len(stars.getDecl()), 3)
        self.assertEqual(len(stars.getRaInPixel()), 3)
        self.assertEqual(len(stars.getDeclInPixel()), 3)
        self.assertEqual(len(stars.getMag(FilterType.U)), 3)
        self.assertEqual(len(stars.getMag(FilterType.G)), 3)
        self.assertEqual(len(stars.getMag(FilterType.R)), 3)
        self.assertEqual(len(stars.getMag(FilterType.I)), 3)
        self.assertEqual(len(stars.getMag(FilterType.Z)), 0)
        self.assertEqual(len(stars.getMag(FilterType.Y)), 0)

        self.assertNotEqual(id(starsOnDet), id(stars))
Esempio n. 14
0
class TestStarData(unittest.TestCase):
    """Test the StarData class."""

    def setUp(self):
        self.stars = StarData([123, 456, 789], [0.1, 0.2, 0.3],
                              [2.1, 2.2, 2.3], [2.0, 3.0, 4.0],
                              [2.1, 2.1, 4.1], [2.2, 3.2, 4.2],
                              [2.3, 3.3, 4.3], [2.4, 3.4, 4.4],
                              [2.5, 3.5, 4.5])

    def testGetId(self):

        starId = self.stars.getId()
        self.assertEqual(starId.dtype, int)
        self.assertEqual(starId.tolist(), [123, 456, 789])

    def testGetRA(self):

        self.assertEqual(self.stars.getRA().tolist(), [0.1, 0.2, 0.3])

    def testGetDecl(self):

        self.assertEqual(self.stars.getDecl().tolist(), [2.1, 2.2, 2.3])

    def testGetMag(self):

        self.assertEqual(self.stars.getMag(FilterType.U).tolist(),
                         [2.0, 3.0, 4.0])
        self.assertEqual(self.stars.getMag(FilterType.G).tolist(),
                         [2.1, 2.1, 4.1])
        self.assertEqual(self.stars.getMag(FilterType.R).tolist(),
                         [2.2, 3.2, 4.2])
        self.assertEqual(self.stars.getMag(FilterType.I).tolist(),
                         [2.3, 3.3, 4.3])
        self.assertEqual(self.stars.getMag(FilterType.Z).tolist(),
                         [2.4, 3.4, 4.4])
        self.assertEqual(self.stars.getMag(FilterType.Y).tolist(),
                         [2.5, 3.5, 4.5])

    def testSetMag(self):

        mag = [1, 3, 4, 5]
        self.stars.setMag(FilterType.U, mag)

        self.assertEqual(self.stars.getMag(FilterType.U).tolist(), mag)

    def testSetAndGetDetector(self):

        detector = "CCD"
        self.stars.setDetector(detector)
        self.assertEqual(self.stars.getDetector(), detector)

    def testSetAndGetRaInPixel(self):

        raInPixel = [1.0, 2.0]
        self.stars.setRaInPixel(raInPixel)

        self.assertEqual(self.stars.getRaInPixel().tolist(), raInPixel)

    def testSetRaInPixelWithFloatValue(self):

        raInPixel = 1.0
        self.stars.setRaInPixel(raInPixel)

        self.assertEqual(self.stars.getRaInPixel().tolist(), [raInPixel])

    def testSetRaInPixelWithNpArray(self):

        raInPixel = np.array([1.0, 2.0])
        self.stars.setRaInPixel(raInPixel)

        delta = np.sum(np.abs(self.stars.getRaInPixel() - raInPixel))
        self.assertEqual(delta, 0)

    def testSetAndGetDeclInPixel(self):

        declInPixel = [2.0, 3.0]
        self.stars.setDeclInPixel(declInPixel)

        self.assertEqual(self.stars.getDeclInPixel().tolist(), declInPixel)

    def testCheckCandidateStars(self):

        indexCandidateU = self.stars.checkCandidateStars(
            FilterType.U, 1.9, 2.1)
        indexCandidateG = self.stars.checkCandidateStars(
            FilterType.G, 0, 5)
        indexCandidateR = self.stars.checkCandidateStars(
            FilterType.R, 0, 1)
        indexCandidateI = self.stars.checkCandidateStars(
            FilterType.I, 2.1, 4.0)
        indexCandidateZ = self.stars.checkCandidateStars(
            FilterType.Z, 3.0, 5.0)
        indexCandidateY = self.stars.checkCandidateStars(
            FilterType.Y, 1.0, 2.0)

        self.assertEqual(indexCandidateU, [0])
        self.assertEqual(indexCandidateG, [0, 1, 2])
        self.assertEqual(indexCandidateR, [])
        self.assertEqual(indexCandidateI, [0, 1])
        self.assertEqual(indexCandidateZ, [1, 2])
        self.assertEqual(indexCandidateY, [])

    def testGetNeighboringStar(self):

        self._populateRaDeclInPixel()

        neighboringStarU = self.stars.getNeighboringStar(
            [0], 3, FilterType.U, maxNumOfNbrStar=99)
        neighboringStarG = self.stars.getNeighboringStar(
            [0, 1], 3, FilterType.G, maxNumOfNbrStar=99)
        neighboringStarR = self.stars.getNeighboringStar(
            [0], 1, FilterType.R, maxNumOfNbrStar=99)
        neighboringStarI = self.stars.getNeighboringStar(
            [], 3, FilterType.I, maxNumOfNbrStar=99)
        neighboringStarZ = self.stars.getNeighboringStar(
            [0, 1], 2, FilterType.Z, maxNumOfNbrStar=1)
        neighboringStarY = self.stars.getNeighboringStar(
            [1], 2, FilterType.Y, maxNumOfNbrStar=1)

        self.assertEqual(len(neighboringStarU.getId()[123]), 2)
        self.assertEqual(len(neighboringStarU.getRaDecl()), 3)

        self.assertEqual(len(neighboringStarG.getId()), 2)

        self.assertEqual(len(neighboringStarR.getId()[123]), 0)

        self.assertEqual(neighboringStarI.getId(), {})

        self.assertEqual(len(neighboringStarZ.getId()), 1)

        self.assertEqual(neighboringStarY.getId(), {})

    def _populateRaDeclInPixel(self):

        self.stars.setRaInPixel(self.stars.getRA() * 10)
        self.stars.setDeclInPixel(self.stars.getDecl() * 10)

    def testGetNeighboringStarWithNothing(self):

        self._populateRaDeclInPixel()
        neighboringStarU = self.stars.getNeighboringStar(
            [], 3.0, FilterType.U, maxNumOfNbrStar=99)

        self.assertEqual(len(neighboringStarU.getId()), 0)
Esempio n. 15
0
 def setUp(self):
     self.stars = StarData([123, 456, 789], [0.1, 0.2, 0.3],
                           [2.1, 2.2, 2.3], [2.0, 3.0, 4.0],
                           [2.1, 2.1, 4.1], [2.2, 3.2, 4.2],
                           [2.3, 3.3, 4.3], [2.4, 3.4, 4.4],
                           [2.5, 3.5, 4.5])