Exemple #1
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()
    def _generateNbrStar(self):

        nbrStar = NbrStar()
        nbrStar.starId = {523572575: [],
                          523572679: [523572671]}
        nbrStar.lsstMagG = {523572575: 14.66652,
                            523572671: 16.00000,
                            523572679: 13.25217}
        nbrStar.raDeclInPixel = {523572679: (3966.44, 1022.91),
                                 523572671: (3968.77, 1081.02),
                                 523572575: (3475.48, 479.33)}
        return nbrStar
Exemple #3
0
    def _generateNbrStar(self):

        nbrStar = NbrStar()
        nbrStar.starId = {523572575: [], 523572679: [523572671]}
        nbrStar.lsstMagG = {
            523572575: 14.66652,
            523572671: 16.00000,
            523572679: 13.25217,
        }
        nbrStar.raDeclInPixel = {
            523572679: (3966.44, 1022.91),
            523572671: (3968.77, 1081.02),
            523572575: (3475.48, 479.33),
        }
        return nbrStar
Exemple #4
0
class TestNbrStar(unittest.TestCase):
    """Test the NbrStar class."""

    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()

    def testGetId(self):

        self._addStar()

        self.assertTrue(123 in self.neighboringStar.getId())
        self.assertTrue(self.neighboringStar.getId()[123], [456])

    def _addStar(self):

        self.neighboringStar.addStar(self.stars, 0, np.array([1]),
                                     FilterType.R)

    def testGetRaDecl(self):

        self._addStar()
        self.assertEqual(self.neighboringStar.getRaDecl(),
                         {456: (0.2, 2.2), 123: (0.1, 2.1)})

    def testGetRaDeclInPixel(self):

        self._addStar()
        self.assertEqual(self.neighboringStar.getRaDeclInPixel(), 
                         {456: (2.0, 22.0), 123: (1.0, 21.0)})

    def testGetMag(self):

        self._addStar()
        self.assertEqual(len(self.neighboringStar.getMag(FilterType.R)), 2)
        self.assertEqual(self.neighboringStar.getMag(FilterType.U), {})

    def testAddStarAndGetData(self):

        self._addStar()
        self.assertNotEqual(len(self.neighboringStar.getId()), 0)
Exemple #5
0
class TestNbrStar(unittest.TestCase):
    """Test the NbrStar class."""

    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()

    def testGetId(self):

        self._addStar()

        self.assertTrue(123 in self.neighboringStar.getId())
        self.assertTrue(self.neighboringStar.getId()[123], [456])

    def _addStar(self):

        self.neighboringStar.addStar(self.stars, 0, np.array([1]),
                                     FilterType.R)

    def testGetRaDecl(self):

        self._addStar()
        self.assertEqual(self.neighboringStar.getRaDecl(),
                         {456: (0.2, 2.2), 123: (0.1, 2.1)})

    def testGetRaDeclInPixel(self):

        self._addStar()
        self.assertEqual(self.neighboringStar.getRaDeclInPixel(),
                         {456: (2.0, 22.0), 123: (1.0, 21.0)})

    def testGetMag(self):

        self._addStar()
        self.assertEqual(len(self.neighboringStar.getMag(FilterType.R)), 2)
        self.assertEqual(self.neighboringStar.getMag(FilterType.U), {})

    def testAddStarAndGetData(self):

        self._addStar()
        self.assertNotEqual(len(self.neighboringStar.getId()), 0)
Exemple #6
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()
Exemple #7
0
    def getNeighboringStar(self,
                           idxCand,
                           maxDist,
                           filterType,
                           maxNumOfNbrStar=0):
        """Get the neighboring stars of candidate stars based on the specific
        max distance and number of neighboring star.

        Parameters
        ----------
        idxCand : list[int]
            List of index of candidate star in "stars" data.
        maxDist : float
            Maximum distance in pixel.
        filterType : FilterType
            Filter type.
        maxNumOfNbrStar : int, optional
            Maximum number of neighboring star for each candidate star (the
            default is 0)

        Returns
        -------
        NbrStar
            Information of neighboring stars.
        """

        nbrStar = NbrStar()

        # Calculate the distance in pixel between candidate stars and all stars
        numOfIdxCand = len(idxCand)
        if numOfIdxCand != 0:
            allStarXY = np.array([self.raInPixel,
                                  self.declInPixel]).transpose()
            candidateStarXY = allStarXY[np.array(idxCand), :]
            starDistances = cdist(candidateStarXY, allStarXY)

            # Decide the number of neighboring stars
            for ii in range(numOfIdxCand):
                idxNbrStar = np.where(starDistances[ii, :] < maxDist)[0]

                # Delete candidate star itself
                idxNbrStar = np.delete(idxNbrStar,
                                       np.where(idxNbrStar == idxCand[ii]))

                # Remove the candidate star if there is the neighboring star
                # brighter than itself
                if filterType == FilterType.U:
                    magSelf = self.lsstMagU[idxCand[ii]]
                    magNbrStar = self.lsstMagU[idxNbrStar]

                elif filterType == FilterType.G:
                    magSelf = self.lsstMagG[idxCand[ii]]
                    magNbrStar = self.lsstMagG[idxNbrStar]

                elif filterType == FilterType.R:
                    magSelf = self.lsstMagR[idxCand[ii]]
                    magNbrStar = self.lsstMagR[idxNbrStar]

                elif filterType == FilterType.I:
                    magSelf = self.lsstMagI[idxCand[ii]]
                    magNbrStar = self.lsstMagI[idxNbrStar]

                elif filterType == FilterType.Z:
                    magSelf = self.lsstMagZ[idxCand[ii]]
                    magNbrStar = self.lsstMagZ[idxNbrStar]

                elif filterType == FilterType.Y:
                    magSelf = self.lsstMagY[idxCand[ii]]
                    magNbrStar = self.lsstMagY[idxNbrStar]

                if (np.where(magNbrStar < magSelf)[0]).size != 0:
                    brighterNeighbor = True
                else:
                    brighterNeighbor = False

                # Restrict the maximum number of neighboring stars
                if len(idxNbrStar) > maxNumOfNbrStar:
                    highNeighboringStar = True
                else:
                    highNeighboringStar = False

                # Record the information of neighboring stars
                if brighterNeighbor is False and highNeighboringStar is False:
                    nbrStar.addStar(self, idxCand[ii], idxNbrStar, filterType)

        return nbrStar
Exemple #8
0
    def getNeighboringStar(self, idxCand, maxDist, filterType,
                           maxNumOfNbrStar=0):
        """Get the neighboring stars of candidate stars based on the specific
        max distance and number of neighboring star.

        Parameters
        ----------
        idxCand : list[int]
            List of index of candidate star in "stars" data.
        maxDist : float
            Maximum distance in pixel.
        filterType : FilterType
            Filter type.
        maxNumOfNbrStar : int, optional
            Maximum number of neighboring star for each candidate star (the
            default is 0)

        Returns
        -------
        NbrStar
            Information of neighboring stars.
        """

        nbrStar = NbrStar()

        # Calculate the distance in pixel between candidate stars and all stars
        numOfIdxCand = len(idxCand)
        if (numOfIdxCand != 0):
            allStarXY = np.array([self.raInPixel,
                                  self.declInPixel]).transpose()
            candidateStarXY = allStarXY[np.array(idxCand), :]
            starDistances = cdist(candidateStarXY, allStarXY)

            # Decide the number of neighboring stars
            for ii in range(numOfIdxCand):
                idxNbrStar = np.where(starDistances[ii, :] < maxDist)[0]

                # Delete candidate star itself
                idxNbrStar = np.delete(idxNbrStar,
                                       np.where(idxNbrStar == idxCand[ii]))

                # Remove the candidate star if there is the neighboring star
                # brighter than itself
                if (filterType == FilterType.U):
                    magSelf = self.lsstMagU[idxCand[ii]]
                    magNbrStar = self.lsstMagU[idxNbrStar]

                elif (filterType == FilterType.G):
                    magSelf = self.lsstMagG[idxCand[ii]]
                    magNbrStar = self.lsstMagG[idxNbrStar]

                elif (filterType == FilterType.R):
                    magSelf = self.lsstMagR[idxCand[ii]]
                    magNbrStar = self.lsstMagR[idxNbrStar]

                elif (filterType == FilterType.I):
                    magSelf = self.lsstMagI[idxCand[ii]]
                    magNbrStar = self.lsstMagI[idxNbrStar]

                elif (filterType == FilterType.Z):
                    magSelf = self.lsstMagZ[idxCand[ii]]
                    magNbrStar = self.lsstMagZ[idxNbrStar]

                elif (filterType == FilterType.Y):
                    magSelf = self.lsstMagY[idxCand[ii]]
                    magNbrStar = self.lsstMagY[idxNbrStar]

                if ((np.where(magNbrStar < magSelf)[0]).size != 0):
                    brighterNeighbor = True
                else:
                    brighterNeighbor = False

                # Restrict the maximum number of neighboring stars
                if (len(idxNbrStar) > maxNumOfNbrStar):
                    highNeighboringStar = True
                else:
                    highNeighboringStar = False

                # Record the information of neighboring stars
                if (brighterNeighbor is False and highNeighboringStar is False):
                    nbrStar.addStar(self, idxCand[ii], idxNbrStar, filterType)

        return nbrStar