예제 #1
0
파일: htm.py 프로젝트: wangweihua/HMpTy
    def lookup_id(self, ra, dec):
        """*Lookup the ID of HTM trixel that a coordinate or lists of coordinates lie on*

        **Key Arguments**

        - ``ra`` -- list, numpy array or single ra value (first coordinate set)
        - ``dec`` -- list, numpy array or single dec value (first coordinate set - must match ra1 array length)
        

        **Return**

        - ``htmIds`` -- a list of HTM trixel ids the coordinates lie on
        

        **Usage**

        To find the trixel IDs that a set of coordinate lie on:

        ```python
        raList1 = ["13:20:00.00", 200.0, "13:20:00.00", 175.23, 21.36]
        decList1 = ["+24:18:00.00",  24.3,  "+24:18:00.00",  -28.25, -15.32]

        htmids = mesh.lookup_id(raList1, decList1)
        for h, r, d in zip(htmids, raList1, decList1):
            print(r, d, " --> ", h)
        ```
        
        """
        self.log.debug('starting the ``lookup_id`` method')

        from astrocalc.coords import coordinates_to_array
        raArray, decArray = coordinates_to_array(log=self.log, ra=ra, dec=dec)

        self.log.debug('completed the ``lookup_id`` method')
        return super(HTM, self).lookup_id(raArray, decArray)
예제 #2
0
    def test_coordinates_to_array(self):

        raList = ["13:20:00.00", 200.0, "13:20:00.00", 175.23, 21.36]
        decList = ["+24:18:00.00", 24.3, "+24:18:00.00", -28.25, -15.32]

        from astrocalc.coords import coordinates_to_array
        ra, dec = coordinates_to_array(log=log, ra=raList, dec=decList)

        print(ra, dec)

        from astrocalc.coords import coordinates_to_array
        ra, dec = coordinates_to_array(log=log,
                                       ra="13:20:00.00",
                                       dec="+24:18:00.00")

        print(ra, dec)
예제 #3
0
    def __init__(
            self,
            log,
            dbConn,
            tableName,
            columns,
            ra,
            dec,
            radiusArcsec,
            sqlWhere=False,
            raCol="raDeg",
            decCol="decDeg",
            separations=False,
            distinct=False,
            closest=False
    ):
        self.log = log
        log.debug("instansiating a new 'conesearch' object")
        self.tableName = tableName
        self.dbConn = dbConn
        self.radius = radiusArcsec
        self.raCol = raCol
        self.decCol = decCol
        self.columns = columns
        self.separations = separations
        self.distinct = distinct
        self.sqlWhere = sqlWhere
        self.closest = closest

        if not self.columns:
            self.columns = "*"

        # xt-self-arg-tmpx

        # BULK COORDINATE INTO NUMPY ARRAY
        from astrocalc.coords import coordinates_to_array
        self.ra, self.dec = coordinates_to_array(
            log=self.log,
            ra=ra,
            dec=dec
        )

        # SETUP THE MESH
        # LESS THAN 1 ARCMIN
        if self.radius < 60.:
            self.htmDepth = 16
        # LESS THAN 1 DEG BUT GREATER THAN 1 ARCMIN
        elif self.radius / (60 * 60) < 1.:
            self.htmDepth = 13
        # GREATER THAN 1 DEGREE
        else:
            self.htmDepth = 10

        # SETUP A MESH AT CHOOSEN DEPTH
        self.mesh = HTM(
            depth=self.htmDepth,
            log=self.log
        )

        return None
예제 #4
0
파일: htm.py 프로젝트: Python3pkg/HMpTy
    def __init__(
            self,
            ra,
            dec,
            depth=16,
            log=False,
            convertToArray=True):

        self.convertToArray = convertToArray

        if log == False:
            if log == False:
                from fundamentals.logs import emptyLogger
                self.log = emptyLogger()
        else:
            self.log = log

        if convertToArray == True:
            from astrocalc.coords import coordinates_to_array
            ra, dec = coordinates_to_array(
                log=log,
                ra=ra,
                dec=dec
            )

        if ra.size != dec.size:
            raise ValueError("ra size (%d) != "
                             "dec size (%d)" % (ra.size, dec.size))

        super(Matcher, self).__init__(depth, ra, dec)
예제 #5
0
파일: htm.py 프로젝트: thespacedoctor/HMpTy
    def __init__(
            self,
            ra,
            dec,
            depth=16,
            log=False):

        if log == False:
            if log == False:
                from fundamentals.logs import emptyLogger
                self.log = emptyLogger()
        else:
            self.log = log

        from astrocalc.coords import coordinates_to_array
        ra, dec = coordinates_to_array(
            log=log,
            ra=ra,
            dec=dec
        )

        if ra.size != dec.size:
            raise ValueError("ra size (%d) != "
                             "dec size (%d)" % (ra.size, dec.size))

        super(Matcher, self).__init__(depth, ra, dec)
예제 #6
0
    def __init__(self,
                 log,
                 dbConn,
                 tableName,
                 columns,
                 ra,
                 dec,
                 radiusArcsec,
                 sqlWhere=False,
                 raCol="raDeg",
                 decCol="decDeg",
                 separations=False,
                 distinct=False,
                 closest=False):
        self.log = log
        log.debug("instansiating a new 'conesearch' object")
        self.tableName = tableName
        self.dbConn = dbConn
        self.radius = float(radiusArcsec)
        self.raCol = raCol
        self.decCol = decCol
        self.columns = columns
        self.separations = separations
        self.distinct = distinct
        self.sqlWhere = sqlWhere
        self.closest = closest

        if not self.columns:
            self.columns = "*"

        # xt-self-arg-tmpx

        # BULK COORDINATE INTO NUMPY ARRAY
        from astrocalc.coords import coordinates_to_array
        self.ra, self.dec = coordinates_to_array(log=self.log, ra=ra, dec=dec)

        # SETUP THE MESH
        # LESS THAN 1 ARCMIN
        if self.radius < 60.:
            self.htmDepth = 16
        # LESS THAN 1 DEG BUT GREATER THAN 1 ARCMIN
        elif self.radius / (60 * 60) < 1.:
            self.htmDepth = 13
        # GREATER THAN 1 DEGREE
        else:
            self.htmDepth = 10

        # SETUP A MESH AT CHOOSEN DEPTH
        self.mesh = HTM(depth=self.htmDepth, log=self.log)

        # DATETIME REGEX - EXPENSIVE OPERATION, LET"S JUST DO IT ONCE
        self.reDatetime = re.compile('^[0-9]{4}-[0-9]{2}-[0-9]{2}T')

        return None
예제 #7
0
    def test_coordinates_to_array_function_exception(self):

        from astrocalc.coords import coordinates_to_array
        try:
            this = coordinates_to_array(log=log,
                                        settings=settings,
                                        fakeKey="break the code")
            this.get()
            assert False
        except Exception as e:
            assert True
            print(str(e))
    def test_coordinates_to_array(self):

        raList = ["13:20:00.00", 200.0, "13:20:00.00", 175.23, 21.36]
        decList = ["+24:18:00.00",  24.3,  "+24:18:00.00",  -28.25, -15.32]

        from astrocalc.coords import coordinates_to_array
        ra, dec = coordinates_to_array(
            log=log,
            ra=raList,
            dec=decList
        )

        print ra, dec

        from astrocalc.coords import coordinates_to_array
        ra, dec = coordinates_to_array(
            log=log,
            ra="13:20:00.00",
            dec="+24:18:00.00"
        )

        print ra, dec
    def test_coordinates_to_array_function_exception(self):

        from astrocalc.coords import coordinates_to_array
        try:
            this = coordinates_to_array(
                log=log,
                settings=settings,
                fakeKey="break the code"
            )
            this.get()
            assert False
        except Exception, e:
            assert True
            print str(e)
예제 #10
0
파일: htm.py 프로젝트: thespacedoctor/HMpTy
    def lookup_id(
            self,
            ra,
            dec):
        """*Lookup the ID of HTM trixel that a coordinate or lists of coordinates lie on*

        **Key Arguments:**
            - ``ra`` -- list, numpy array or single ra value (first coordinate set)
            - ``dec`` -- list, numpy array or single dec value (first coordinate set - must match ra1 array length)

        **Return:**
            - ``htmIds`` -- a list of HTM trixel ids the coordinates lie on

        **Usage:**

            To find the trixel IDs that a set of coordinate lie on:

            .. code-block:: python

                raList1 = ["13:20:00.00", 200.0, "13:20:00.00", 175.23, 21.36]
                decList1 = ["+24:18:00.00",  24.3,  "+24:18:00.00",  -28.25, -15.32]

                htmids = mesh.lookup_id(raList1, decList1)
                for h, r, d in zip(htmids, raList1, decList1):
                    print r, d, " --> ", h

        """
        self.log.info('starting the ``lookup_id`` method')

        from astrocalc.coords import coordinates_to_array
        raArray, decArray = coordinates_to_array(
            log=self.log,
            ra=ra,
            dec=dec
        )

        self.log.info('completed the ``lookup_id`` method')
        return super(HTM, self).lookup_id(raArray, decArray)
예제 #11
0
파일: htm.py 프로젝트: wangweihua/HMpTy
    def match(self, ra, dec, radius, maxmatch=1):
        """*match a corrdinate set against this Matcher object's coordinate set*

        **Key Arguments**

        - ``ra`` -- list, numpy array or single ra value
        - ``dec`` -- --list, numpy array or single dec value (must match ra array length)
        - ``radius`` -- radius of circle in degrees
        - ``maxmatch`` -- maximum number of matches to return. Set to `0` to match all points. Default *1* (i.e. closest match)
        

        **Return**

        - None
        

        **Usage**

        Once we have initialised a Matcher coordinateSet object we can match other coordinate sets against it:

        ```python
        twoArcsec = 2.0 / 3600.
        raList2 = [200.0, 200.0, 200.0, 175.23, 55.25]
        decList2 = [24.3 + 0.75 * twoArcsec, 24.3 + 0.25 * twoArcsec,
            24.3 - 0.33 * twoArcsec, -28.25 + 0.58 * twoArcsec, 75.22]

        matchIndices1, matchIndices2, seps = coordinateSet.match(
            ra=raList2,
            dec=decList2,
            radius=twoArcsec,
            maxmatch=0
        )

        for m1, m2, s in zip(matchIndices1, matchIndices2, seps):
            print(raList1[m1], decList1[m1], " -> ", s * 3600., " arcsec -> ", raList2[m2], decList2[m2])
        ```

        Or to return just the nearest matches:

        ```python
        matchIndices1, matchIndices2, seps = coordinateSet.match(
            ra=raList2,
            dec=decList2,
            radius=twoArcsec,
            maxmatch=1
        )
        ```

        Note from the print statement, you can index the arrays ``raList1``, ``decList1`` with the ``matchIndices1`` array values and  ``raList2``, ``decList2`` with the ``matchIndices2`` values.
        
        """

        if self.convertToArray == True:
            from astrocalc.coords import coordinates_to_array
            ra, dec = coordinates_to_array(log=self.log, ra=ra, dec=dec)

        radius = numpy.array(radius, dtype='f8', ndmin=1, copy=False)

        if ra.size != dec.size:
            raise ValueError("ra size (%d) != "
                             "dec size (%d)" % (ra.size, dec.size))

        if radius.size != 1 and radius.size != ra.size:
            raise ValueError("radius size (%d) != 1 and"
                             " != ra,dec size (%d)" % (radius.size, ra.size))

        return super(Matcher, self).match(ra, dec, radius, maxmatch, False)
예제 #12
0
파일: htm.py 프로젝트: thespacedoctor/HMpTy
    def match(self, ra, dec, radius, maxmatch=1):
        """*match a corrdinate set against this Matcher object's coordinate set*

        **Key Arguments:**
            - ``ra`` -- list, numpy array or single ra value
            - ``dec`` -- --list, numpy array or single dec value (must match ra array length)
            - ``radius`` -- radius of circle in degrees
            - ``maxmatch`` -- maximum number of matches to return. Set to `0` to match all points. Default *1* (i.e. closest match)

        **Return:**
            - None

        **Usage:**

            Once we have initialised a Matcher coordinateSet object we can match other coordinate sets against it:

            .. code-block:: python

                twoArcsec = 2.0 / 3600.
                raList2 = [200.0, 200.0, 200.0, 175.23, 55.25]
                decList2 = [24.3 + 0.75 * twoArcsec, 24.3 + 0.25 * twoArcsec,
                    24.3 - 0.33 * twoArcsec, -28.25 + 0.58 * twoArcsec, 75.22]

                matchIndices1, matchIndices2, seps = coordinateSet.match(
                    ra=raList2,
                    dec=decList2,
                    radius=twoArcsec,
                    maxmatch=0
                )

                for m1, m2, s in zip(matchIndices1, matchIndices2, seps):
                    print raList1[m1], decList1[m1], " -> ", s * 3600., " arcsec -> ", raList2[m2], decList2[m2]

            Or to return just the nearest matches:

            .. code-block:: python

                matchIndices1, matchIndices2, seps = coordinateSet.match(
                    ra=raList2,
                    dec=decList2,
                    radius=twoArcsec,
                    maxmatch=1
                )

            Note from the print statement, you can index the arrays ``raList1``, ``decList1`` with the ``matchIndices1`` array values and  ``raList2``, ``decList2`` with the ``matchIndices2`` values.
        """

        from astrocalc.coords import coordinates_to_array
        ra, dec = coordinates_to_array(
            log=self.log,
            ra=ra,
            dec=dec
        )

        radius = numpy.array(radius, dtype='f8', ndmin=1, copy=False)

        if ra.size != dec.size:
            raise ValueError("ra size (%d) != "
                             "dec size (%d)" % (ra.size, dec.size))

        if radius.size != 1 and radius.size != ra.size:
            raise ValueError("radius size (%d) != 1 and"
                             " != ra,dec size (%d)" % (radius.size, ra.size))

        return super(Matcher, self).match(ra, dec, radius, maxmatch, False)