当前位置: 首页>>代码示例>>Python>>正文


Python numpy.fromregex函数代码示例

本文整理汇总了Python中numpy.fromregex函数的典型用法代码示例。如果您正苦于以下问题:Python fromregex函数的具体用法?Python fromregex怎么用?Python fromregex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fromregex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: readMaskRegion

def readMaskRegion(regfile):
    box = numpy.fromregex(regfile,r"box\(([0-9]*\.?[0-9]+),(-[0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)\",([0-9]*\.?[0-9]+)\",([0-9]*\.?[0-9]+)",
                          [('xc',numpy.float),('yc',numpy.float),('width',numpy.float),('height',numpy.float),('angle',numpy.float)])
    try:
        box[0]
    except IndexError:
        print 'Assuming a positive declination region.'
        box = numpy.fromregex(regfile,r"box\(([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)\",([0-9]*\.?[0-9]+)\",([0-9]*\.?[0-9]+)",[('xc',numpy.float),('yc',numpy.float),('width',numpy.float),('height',numpy.float),('angle',numpy.float)])
        
    return box[0]
开发者ID:MCTwo,项目名称:DEIMOS,代码行数:10,代码来源:obsplan.py

示例2: loadobj

def loadobj(filename, load_normals=False):
    """ load a wavefront obj file
        loads vertices into a (x,y,z) struct array and vertex indices
        into a n x 3 index array 
        only loads obj files vertex positions and also
        only works with triangle meshes """
    vertices = np.fromregex(open(filename), _vertex_regex, np.float)
    if load_normals:
        normals = np.fromregex(open(filename), _normal_regex, np.float)
    triangles = np.fromregex(open(filename), _triangle_regex, np.int) - 1 # 1-based indexing in obj file format!
    if load_normals:
        return vertices, normals, triangles
    else:
        return vertices, triangles
开发者ID:KeeganRen,项目名称:cmm,代码行数:14,代码来源:wavefront_obj.py

示例3: readheader

def readheader(catalog):
    '''
    This function extracts the #ttype indexed header of a catalog.
    Input:
    catalog = [string], Name (perhaps including path) of the catalog
        that contains all of the data (e.g. x,y,e1,e2,...). Must include
        ttype header designations for the columns e.g.:
        #ttype0 = objid
        #ttype1 = x
    Output:
    dic = dictonary that contains the {ttype string,column #}.
    '''
    import numpy
    import sys
    header = numpy.fromregex(catalog,r"ttype([0-9]+)(?:\s)?=(?:\s)?(\w+)",
                                 [('column',numpy.int64),('name','S20')])
    # Determine if the catalog is 0 or 1 indexed and if 1 indexed then change to 0
    if header['column'][0] == 1:
        header['column']-=1
    elif header['column'][0] != 0:
        print 'readheader: the catalog is not ttype indexed, please index using format ttype(column#)=(column name), exiting'
        sys.exit()
    for i in range(len(header)):
        if i == 0:
            dic = {header[i][1]:header[i][0]}
        else:
            dic[header[i][1]]=header[i][0]
    return dic
开发者ID:jmcelve2,项目名称:MCCutils,代码行数:28,代码来源:tools.py

示例4: get_stocks

def get_stocks():
    global gldict
    for name in names:
        filename = "%s.csv" % name
        if not os.path.exists(filename):
            yh_download(name)
        arr = fromregex(filename, yf_regex, yf_dtype)
        gldict[name] = arr
开发者ID:PlamenStilyianov,项目名称:Python,代码行数:8,代码来源:stocks.py

示例5: read_orca_trj

def read_orca_trj(fname):
    """return numpy 2D array
    """
    # http://stackoverflow.com/questions/14645789/
    # numpy-reading-file-with-filtering-lines-on-the-fly
    import numpy as np
    regexp = r'\s+\w+' + r'\s+([-.0-9]+)' * 3 + r'\s*\n'
    return np.fromregex(fname, regexp, dtype='f')
开发者ID:josejames00,项目名称:pytraj,代码行数:8,代码来源:qm.py

示例6: readregions

def readregions(regfile):
    '''
    regfile = (string) the ds9 region file, assumes that it was written using
              'ds9' Format and 'image' Coordinate System

    Currently this function only works on circles, ellipse, and box regions
    '''
    # find all the circle regions
    circ = numpy.fromregex(regfile,r"circle\(([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)",[('xc',numpy.float),('yc',numpy.float),('rc',numpy.float)])

    # find all the elliptical regions
    ellip = numpy.fromregex(regfile,r"ellipse\(([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)",[('xc',numpy.float),('yc',numpy.float),('a',numpy.float),('b',numpy.float),('angle',numpy.float)])

    # find all the box regions
    box = numpy.fromregex(regfile,r"box\(([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)",[('xc',numpy.float),('yc',numpy.float),('width',numpy.float),('height',numpy.float),('angle',numpy.float)])

    return circ, ellip, box
开发者ID:jmcelve2,项目名称:MCCutils,代码行数:17,代码来源:ds9tools.py

示例7: test_record_3

    def test_record_3(self):
        c = StringIO.StringIO()
        c.write('1312 foo\n1534 bar\n4444 qux')
        c.seek(0)

        dt = [('num', np.float64)]
        x = np.fromregex(c, r"(\d+)\s+...", dt)
        a = np.array([(1312,), (1534,), (4444,)], dtype=dt)
        assert_array_equal(x, a)
开发者ID:GunioRobot,项目名称:numpy-refactor,代码行数:9,代码来源:test_io.py

示例8: test_record

    def test_record(self):
        c = StringIO.StringIO()
        c.write('1.312 foo\n1.534 bar\n4.444 qux')
        c.seek(0)

        dt = [('num', np.float64), ('val', 'S3')]
        x = np.fromregex(c, r"([0-9.]+)\s+(...)", dt)
        a = np.array([(1.312, 'foo'), (1.534, 'bar'), (4.444, 'qux')], dtype=dt)
        assert_array_equal(x, a)
开发者ID:8848,项目名称:Pymol-script-repo,代码行数:9,代码来源:test_io.py

示例9: test_record_2

    def test_record_2(self):
        c = StringIO()
        c.write(asbytes("1312 foo\n1534 bar\n4444 qux"))
        c.seek(0)

        dt = [("num", np.int32), ("val", "S3")]
        x = np.fromregex(c, r"(\d+)\s+(...)", dt)
        a = np.array([(1312, "foo"), (1534, "bar"), (4444, "qux")], dtype=dt)
        assert_array_equal(x, a)
开发者ID:hector1618,项目名称:numpy,代码行数:9,代码来源:test_io.py

示例10: test_record

    def test_record(self):
        c = StringIO()
        c.write(asbytes("1.312 foo\n1.534 bar\n4.444 qux"))
        c.seek(0)

        dt = [("num", np.float64), ("val", "S3")]
        x = np.fromregex(c, r"([0-9.]+)\s+(...)", dt)
        a = np.array([(1.312, "foo"), (1.534, "bar"), (4.444, "qux")], dtype=dt)
        assert_array_equal(x, a)
开发者ID:hector1618,项目名称:numpy,代码行数:9,代码来源:test_io.py

示例11: do_once

 def do_once(self):
     self.file.seek(0)
     output = numpy.fromregex(
         self.file, 
         self.line_re, 
         [('ip', 'S20'), ('day', 'S25'), ('month', 'S20'), ('year', 'S4'), ('time', 'S20'), ('method', 'S7'), ('path', 'S100'), ('size', numpy.int32)]
         )
     total_time_by_month = defaultdict(int)
     for row in output:
         total_time_by_month[(row[2], row[1])] += row[7]
开发者ID:pfitzsimmons,项目名称:SpeedDuel,代码行数:10,代码来源:log_parser.py

示例12: test_record_2

    def test_record_2(self):
        return  # pass this test until #736 is resolved
        c = StringIO.StringIO()
        c.write("1312 foo\n1534 bar\n4444 qux")
        c.seek(0)

        dt = [("num", np.int32), ("val", "S3")]
        x = np.fromregex(c, r"(\d+)\s+(...)", dt)
        a = np.array([(1312, "foo"), (1534, "bar"), (4444, "qux")], dtype=dt)
        assert_array_equal(x, a)
开发者ID:hadesain,项目名称:robothon,代码行数:10,代码来源:test_io.py

示例13: test_record_2

    def test_record_2(self):
        c = StringIO.StringIO()
        c.write('1312 foo\n1534 bar\n4444 qux')
        c.seek(0)

        dt = [('num', np.int32), ('val', 'S3')]
        x = np.fromregex(c, r"(\d+)\s+(...)", dt)
        a = np.array([(1312, 'foo'), (1534, 'bar'), (4444, 'qux')],
                     dtype=dt)
        assert_array_equal(x, a)
开发者ID:GunioRobot,项目名称:numpy-refactor,代码行数:10,代码来源:test_io.py

示例14: combine_history_statsfiles

def combine_history_statsfiles(cnavgdir):
    statsfiles = glob.glob(cnavgdir + "/" + "HISTORY_STATS*")
    sys.stderr.write("statsfiles: %s\n" % (str(statsfiles)))
    mystats = np.array([])
    mysims = []
    runlens = []
    for statsfile in statsfiles:
        sim = int(re.match(".*HISTORY_STATS_(\d+)", statsfile).group(1))
        mysims.append(sim)
        historystats = np.fromregex(statsfile, r"\((\d+), (\d+)\)\t(\d+)\t(\d+)\t(\d+)\t(\d+)", dtype=int)
        runlens.append(historystats.shape[0])
    runlen = max(runlens)
    for sim in mysims:
        statsfile = os.path.join(cnavgdir, "HISTORY_STATS_%d" % sim)
        historystats = np.fromregex(statsfile, r"\((\d+), (\d+)\)\t(\d+)\t(\d+)\t(\d+)\t(\d+)", dtype=int)
        if mystats.size == 0:
            mystats = np.zeros(((max(mysims) + 1) * runlen, historystats.shape[1] + 1), dtype=int)
        hids = np.array(range(historystats.shape[0])) + sim * Global_BINWIDTH
        i = sim * runlen
        mystats[i : i + runlen, :] = np.hstack((np.atleast_2d(hids).T, historystats))
    return mystats
开发者ID:TracyBallinger,项目名称:cnavgpost,代码行数:21,代码来源:event_cycles_module.py

示例15: parse

    def parse(self,xmlHeaderFile,quick=True):
        """
Parse the usefull part of the xml header,
stripping time stamps and non ascii characters
"""
        lightXML = StringIO.StringIO()
        #to strip the non ascii characters
        t = "".join(map(chr, range(256)))
        d = "".join(map(chr, range(128,256)))
        
        if not quick:
            #store all time stamps in a big array
            timestamps = np.fromregex(
                xmlHeaderFile,
                r'<TimeStamp HighInteger="(\d+)" LowInteger="(\d+)"/>',
                float
                )
            xmlHeaderFile.seek(0)
            relTimestamps = np.fromregex(
                xmlHeaderFile,
                r'<RelTimeStamp Time="(\f+)" Frame="(\d+)"/>|<RelTimeStamp Frame="[0-9]*" Time="[0-9.]*"/>',
                float
                )
            xmlHeaderFile.seek(0)
            for line in xmlHeaderFile:
                lightXML.write(line.translate(t,d))
            
        else:
            #to strip the time stamps
            m = re.compile(
                r'''<TimeStamp HighInteger="[0-9]*" LowInteger="[0-9]*"/>|'''
                +r'''<RelTimeStamp Time="[0-9.]*" Frame="[0-9]*"/>|'''
                +r'''<RelTimeStamp Frame="[0-9]*" Time="[0-9.]*"/>'''
                )
            
            for line in xmlHeaderFile:
                lightXML.write(''.join(m.split(line)).translate(t,d))
        lightXML.seek(0)
        self.xmlHeader = parse(lightXML)
开发者ID:MathieuLeocmach,项目名称:colloids,代码行数:39,代码来源:lif.py


注:本文中的numpy.fromregex函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。