コード例 #1
0
    def test_lookup01(self):

        raList1 = ["138.30789"]
        decList1 = ["+61.09267"]
        from HMpTy import HTM
        mesh16 = HTM(depth=16, log=log)
        print("LOOKUP")
        htmids = mesh16.lookup_id(raList1, decList1)
        for h, r, d in zip(htmids, raList1, decList1):
            print(r, d, " --> ", h)
コード例 #2
0
    def test_lookup(self):

        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]
        from HMpTy import HTM
        mesh16 = HTM(depth=16, log=log)
        print("LOOKUP")
        htmids = mesh16.lookup_id(raList1, decList1)
        for h, r, d in zip(htmids, raList1, decList1):
            print(r, d, " --> ", h)
コード例 #3
0
ファイル: test_htm.py プロジェクト: thespacedoctor/HMpTy
    def test_htm_function(self):

        from HMpTy import HTM
        mesh16 = HTM(
            depth=16,
            log=log
        )
        mesh20 = HTM(
            depth=20,
            log=log
        )
        mesh24 = HTM(
            depth=24,
            log=log
        )
        print "DEPTH24:", mesh24.depth
        print "AREA24:", mesh24.area * 60 * 60 * 60 * 60, " arcsec^2"
        print "DEPTH16:", mesh16.depth
        print "AREA16:", mesh16.area * 60 * 60 * 60 * 60, " arcsec^2"
        print "DEPTH20:", mesh20.depth
        print "AREA20:", mesh20.area * 60 * 60 * 60 * 60, " arcsec^2"

        overlappingTrixels = mesh24.intersect(
            ra="23:25:53.56",
            dec="+26:54:23.9",
            radius=0.01,
            inclusive=False
        )
        # print overlappingTrixels

        overlappingTrixels = mesh24.intersect(
            ra="23:25:53.56",
            dec="+26:54:23.9",
            radius=10 / (60 * 60),
            inclusive=True
        )
        # print overlappingTrixels

        twoArcsec = 2.0 / 3600.
        raList1 = [200.0, 200.0, 200.0, 175.23, 21.36]
        decList1 = [24.3,  24.3,  24.3,  -28.25, -15.32]
        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 = mesh16.match(
            ra1=raList1,
            dec1=decList1,
            ra2=raList2,
            dec2=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]
コード例 #4
0
ファイル: sets.py プロジェクト: thespacedoctor/HMpTy
    def _extract_one_set_from_list(
            self,
            ra,
            dec,
            radius,
            sourceList):
        """*Crossmatch the first row in the list against the remaining rows*

        **Key Arguments:**
            - ``ra`` -- a list of RAs
            - ``dec`` -- a list of DECs (same length as ``ra``)
            - ``radius`` -- the radius of the crossmatch
            - ``sourceList`` -- the list of source imformation to be divided into associated sets (same length as ``ra`` and ``dec``)

        **Return:**
            - ``matches`` -- the matches from the cross-match
            - ``ra`` -- the remaining RAs
            - ``dec`` -- the remaining DECs
        """
        self.log.info('starting the ``_extract_one_set_from_list`` method')

        matches = []

        from HMpTy import HTM
        mesh = HTM(
            depth=12,
            log=self.log
        )
        matchIndices1, matchIndices2, seps = mesh.match(
            ra1=ra[0],
            dec1=dec[0],
            ra2=ra[1:],
            dec2=dec[1:],
            radius=radius,
            maxmatch=0  # 1 = match closest 1, 0 = match all
        )

        matches = []
        matches.append(sourceList[0])

        indiciesToRemove = [0]

        for m1, m2, s in zip(matchIndices1, matchIndices2, seps):
            matches.append(sourceList[1:][m2])
            if (m2 + 1) not in indiciesToRemove:
                indiciesToRemove.append(m2 + 1)

        for index in sorted(indiciesToRemove, reverse=True):
            del ra[index]
            del dec[index]
            del sourceList[index]

        self.log.info('completed the ``_extract_one_set_from_list`` method')
        return matches, ra, dec, sourceList
コード例 #5
0
ファイル: test_htm.py プロジェクト: thespacedoctor/HMpTy
    def test_lookup(self):

        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]
        from HMpTy import HTM
        mesh16 = HTM(
            depth=16,
            log=log
        )
        print "LOOKUP"
        htmids = mesh16.lookup_id(raList1, decList1)
        for h, r, d in zip(htmids, raList1, decList1):
            print r, d, " --> ", h
コード例 #6
0
    def test_htm_area_function(self):

        from HMpTy import HTM
        mesh24 = HTM(depth=24, log=log)
        mesh16 = HTM(depth=16, log=log)
        mesh15 = HTM(depth=15, log=log)
        mesh14 = HTM(depth=14, log=log)
        mesh13 = HTM(depth=13, log=log)
        mesh12 = HTM(depth=12, log=log)
        mesh11 = HTM(depth=11, log=log)
        mesh10 = HTM(depth=10, log=log)

        print("DEPTH24:", mesh24.depth)
        print("AREA24:", mesh24.area * 60 * 60 * 60 * 60, " arcsec^2")
        print("DEPTH16:", mesh16.depth)
        print("AREA16:", mesh16.area * 60 * 60 * 60 * 60, " arcsec^2")
        print("DEPTH15:", mesh15.depth)
        print("AREA15:", mesh15.area * 60 * 60 * 60 * 60, " arcsec^2")
        print("DEPTH14:", mesh14.depth)
        print("AREA14:", mesh14.area * 60 * 60 * 60 * 60, " arcsec^2")
        print("DEPTH13:", mesh13.depth)
        print("AREA13:", mesh13.area * 60 * 60 * 60 * 60, " arcsec^2")
        print("DEPTH12:", mesh12.depth)
        print("AREA12:", mesh12.area * 60 * 60, " arcmin^2")
        print("DEPTH11:", mesh11.depth)
        print("AREA11:", mesh11.area * 60 * 60, " arcmin^2")
        print("DEPTH10:", mesh10.depth)
        print("AREA10:", mesh10.area * 60 * 60, " arcmin^2")
コード例 #7
0
ファイル: sets.py プロジェクト: Python3pkg/HMpTy
    def _extract_all_sets_from_list(
            self):
        """*Extract all of the sets from the list of coordinates*

        **Return:**
            - ``allMatches`` -- a list of lists. All of the assocaited sets of sources
        """
        self.log.info('starting the ``_extract_all_sets_from_list`` method')

        from HMpTy import HTM
        mesh = HTM(
            depth=12,
            log=self.log
        )

        matchIndices1, matchIndices2, seps = mesh.match(
            ra1=self.ra,
            dec1=self.dec,
            ra2=self.ra,
            dec2=self.dec,
            radius=self.radius,
            maxmatch=0,  # 1 = match closest 1, 0 = match all,
            convertToArray=self.convertToArray
        )

        anchorIndicies = []
        childIndicies = []
        allMatches = []
        thisMatch = None
        for m1, m2, s in zip(matchIndices1, matchIndices2, seps):
            if m1 not in anchorIndicies and m1 not in childIndicies:
                if thisMatch:
                    allMatches.append(thisMatch)
                thisMatch = [self.sourceList[m1]]
                anchorIndicies.append(m1)
            if m2 not in anchorIndicies and m2 not in childIndicies:
                childIndicies.append(m2)
                thisMatch.append(self.sourceList[m2])
        if thisMatch:
            allMatches.append(thisMatch)

        self.log.info('completed the ``_extract_all_sets_from_list`` method')
        return allMatches
コード例 #8
0
    def test_htm_function(self):

        from HMpTy import HTM
        mesh16 = HTM(depth=16, log=log)
        mesh20 = HTM(depth=20, log=log)
        mesh24 = HTM(depth=24, log=log)
        print("DEPTH24:", mesh24.depth)
        print("AREA24:", mesh24.area * 60 * 60 * 60 * 60, " arcsec^2")
        print("DEPTH16:", mesh16.depth)
        print("AREA16:", mesh16.area * 60 * 60 * 60 * 60, " arcsec^2")
        print("DEPTH20:", mesh20.depth)
        print("AREA20:", mesh20.area * 60 * 60 * 60 * 60, " arcsec^2")

        overlappingTrixels = mesh24.intersect(ra="23:25:53.56",
                                              dec="+26:54:23.9",
                                              radius=0.01,
                                              inclusive=False)
        # print overlappingTrixels

        overlappingTrixels = mesh24.intersect(ra="23:25:53.56",
                                              dec="+26:54:23.9",
                                              radius=old_div(10, (60 * 60)),
                                              inclusive=True)
        # print overlappingTrixels

        twoArcsec = 2.0 / 3600.
        raList1 = [200.0, 200.0, 200.0, 175.23, 21.36]
        decList1 = [24.3, 24.3, 24.3, -28.25, -15.32]
        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 = mesh16.match(ra1=raList1,
                                                          dec1=decList1,
                                                          ra2=raList2,
                                                          dec2=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])
コード例 #9
0
ファイル: cl_utils.py プロジェクト: wangweihua/HMpTy
def main(arguments=None):
    """
    *The main function used when `cl_utils.py` is run as a single script from the cl, or when installed as a cl command*
    """
    # setup the command-line util settings
    su = tools(
        arguments=arguments,
        docString=__doc__,
        logLevel="WARNING",
        options_first=False,
        projectName="HMpTy",
        defaultSettingsFile=True
    )
    arguments, settings, log, dbConn = su.setup()

    # tab completion for raw_input
    readline.set_completer_delims(' \t\n;')
    readline.parse_and_bind("tab: complete")
    readline.set_completer(tab_complete)

    # UNPACK REMAINING CL ARGUMENTS USING `EXEC` TO SETUP THE VARIABLE NAMES
    # AUTOMATICALLY
    a = {}
    for arg, val in list(arguments.items()):
        if arg[0] == "-":
            varname = arg.replace("-", "") + "Flag"
        else:
            varname = arg.replace("<", "").replace(">", "")
        a[varname] = val
        if arg == "--dbConn":
            dbConn = val
            a["dbConn"] = val
        log.debug('%s = %s' % (varname, val,))

    hostFlag = a["hostFlag"]
    userFlag = a["userFlag"]
    passwdFlag = a["passwdFlag"]
    dbNameFlag = a["dbNameFlag"]
    tableName = a["tableName"]
    index = a["index"]
    htmid = a["htmid"]
    primaryIdCol = a["primaryIdCol"]
    raCol = a["raCol"]
    decCol = a["decCol"]
    ra = a["ra"]
    radius = a["radius"]
    level = a["level"]
    forceFlag = a["forceFlag"]
    renderFlag = a["renderFlag"]
    search = a["search"]

    ## START LOGGING ##
    startTime = times.get_now_sql_datetime()
    log.info(
        '--- STARTING TO RUN THE cl_utils.py AT %s' %
        (startTime,))

    # set options interactively if user requests
    if "interactiveFlag" in a and a["interactiveFlag"]:

        # load previous settings
        moduleDirectory = os.path.dirname(__file__) + "/resources"
        pathToPickleFile = "%(moduleDirectory)s/previousSettings.p" % locals()
        try:
            with open(pathToPickleFile):
                pass
            previousSettingsExist = True
        except:
            previousSettingsExist = False
        previousSettings = {}
        if previousSettingsExist:
            previousSettings = pickle.load(open(pathToPickleFile, "rb"))

        # x-raw-input
        # x-boolean-raw-input
        # x-raw-input-with-default-value-from-previous-settings

        # save the most recently used requests
        pickleMeObjects = []
        pickleMe = {}
        theseLocals = locals()
        for k in pickleMeObjects:
            pickleMe[k] = theseLocals[k]
        pickle.dump(pickleMe, open(pathToPickleFile, "wb"))

    if a["init"]:
        from os.path import expanduser
        home = expanduser("~")
        filepath = home + "/.config/HMpTy/HMpTy.yaml"
        try:
            cmd = """open %(filepath)s""" % locals()
            p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
        except:
            pass
        try:
            cmd = """start %(filepath)s""" % locals()
            p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
        except:
            pass
        return

    # CALL FUNCTIONS/OBJECTS
    if index:
        add_htm_ids_to_mysql_database_table(
            raColName=raCol,
            declColName=decCol,
            tableName=tableName,
            dbConn=dbConn,
            log=log,
            primaryIdColumnName=primaryIdCol,
            reindex=forceFlag,
            dbSettings=dbSettings
        )

    if search:
        cs = conesearch(
            log=log,
            dbConn=dbConn,
            tableName=tableName,
            columns=False,
            ra=ra,
            dec=dec,
            radiusArcsec=float(radius),
            separations=True,
            distinct=False,
            sqlWhere=False
        )
        matchIndies, matches = cs.search()
        if not renderFlag:
            print(matches.table())
        elif renderFlag == "json":
            print(matches.json())
        elif renderFlag == "csv":
            print(matches.csv())
        elif renderFlag == "yaml":
            print(matches.yaml())
        elif renderFlag == "md":
            print(matches.markdown())
        elif renderFlag == "table":
            print(matches.markdown())
        elif renderFlag == "mysql":
            print(matches.mysql(tableName=resultsTable))

    if level:
        from HMpTy import HTM
        mesh = HTM(
            depth=int(level),
            log=log
        )

        htmids = mesh.lookup_id(ra, dec)
        print(htmids[0])

    if "dbConn" in locals() and dbConn:
        dbConn.commit()
        dbConn.close()
    ## FINISH LOGGING ##
    endTime = times.get_now_sql_datetime()
    runningTime = times.calculate_time_difference(startTime, endTime)
    log.info('-- FINISHED ATTEMPT TO RUN THE cl_utils.py AT %s (RUNTIME: %s) --' %
             (endTime, runningTime, ))

    return
コード例 #10
0
def main(arguments=None):
    """
    *The main function used when ``cl_utils.py`` is run as a single script from the cl, or when installed as a cl command*
    """
    # setup the command-line util settings
    su = tools(arguments=arguments,
               docString=__doc__,
               logLevel="DEBUG",
               options_first=False,
               projectName="HMpTy")
    arguments, settings, log, dbConn = su.setup()

    # unpack remaining cl arguments using `exec` to setup the variable names
    # automatically
    for arg, val in arguments.items():
        if arg[0] == "-":
            varname = arg.replace("-", "") + "Flag"
        else:
            varname = arg.replace("<", "").replace(">", "")
        if isinstance(val, str) or isinstance(val, str):
            exec(varname + " = '%s'" % (val, ))
        else:
            exec(varname + " = %s" % (val, ))
        if arg == "--dbConn":
            dbConn = val
        log.debug('%s = %s' % (
            varname,
            val,
        ))

    ## START LOGGING ##
    startTime = times.get_now_sql_datetime()
    log.info('--- STARTING TO RUN THE cl_utils.py AT %s' % (startTime, ))

    # CALL FUNCTIONS/OBJECTS
    if index:
        add_htm_ids_to_mysql_database_table(raColName=raCol,
                                            declColName=decCol,
                                            tableName=tableName,
                                            dbConn=dbConn,
                                            log=log,
                                            primaryIdColumnName=primaryIdCol,
                                            reindex=forceFlag)

    if search:
        cs = conesearch(log=log,
                        dbConn=dbConn,
                        tableName=tableName,
                        columns=False,
                        ra=ra,
                        dec=dec,
                        radiusArcsec=float(radius),
                        separations=True,
                        distinct=False,
                        sqlWhere=False)
        matchIndies, matches = cs.search()
        if not renderFlag:
            print(matches.table())
        elif renderFlag == "json":
            print(matches.json())
        elif renderFlag == "csv":
            print(matches.csv())
        elif renderFlag == "yaml":
            print(matches.yaml())
        elif renderFlag == "md":
            print(matches.markdown())
        elif renderFlag == "table":
            print(matches.markdown())
        elif renderFlag == "mysql":
            print(matches.mysql(tableName=resultsTable))

    if level:
        from HMpTy import HTM
        mesh = HTM(depth=int(level), log=log)

        htmids = mesh.lookup_id(ra, dec)
        print(htmids[0])

    if "dbConn" in locals() and dbConn:
        dbConn.commit()
        dbConn.close()
    ## FINISH LOGGING ##
    endTime = times.get_now_sql_datetime()
    runningTime = times.calculate_time_difference(startTime, endTime)
    log.info(
        '-- FINISHED ATTEMPT TO RUN THE cl_utils.py AT %s (RUNTIME: %s) --' % (
            endTime,
            runningTime,
        ))

    return
コード例 #11
0
            log=log,
            sqlQuery=sqlQuery,
            dbConn=thisConn,
        )

    potSources = len(orbFitRows)

    raOrb = []
    raOrb[:] = [r["ra_deg"] for r in orbFitRows]
    decOrb = []
    decOrb[:] = [r["dec_deg"] for r in orbFitRows]

    raOrb = np.array(raOrb)
    decOrb = np.array(decOrb)

    mesh = HTM(depth=12, log=log)
    matchIndices1, matchIndices2, seps = mesh.match(
        ra1=ra,
        dec1=dec,
        ra2=raOrb,
        dec2=decOrb,
        radius=matchRadius / 3600.,
        convertToArray=False,
        maxmatch=0  # 1 = match closest 1, 0 = match all
    )

    # FREE MEMORY
    raOrb = None
    decOrb = None

    dophotRows = []