當前位置: 首頁>>代碼示例>>Python>>正文


Python IO.readheader方法代碼示例

本文整理匯總了Python中MOSFIRE.IO.readheader方法的典型用法代碼示例。如果您正苦於以下問題:Python IO.readheader方法的具體用法?Python IO.readheader怎麽用?Python IO.readheader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MOSFIRE.IO的用法示例。


在下文中一共展示了IO.readheader方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: open

# 需要導入模塊: from MOSFIRE import IO [as 別名]
# 或者: from MOSFIRE.IO import readheader [as 別名]
    os.remove('filelist.txt')
fl = open('filelist.txt', 'w')


files = []
for i in range(1, len(sys.argv)):
    files.extend(glob.iglob(sys.argv[i]))

masks = {}


info('Examining {} files'.format(len(files)))
for fname in files:

    try:
        header = IO.readheader(fname)
    except IOError:#, err:
        fl.write("Couldn't IO %s\n" % fname)
        continue
    except:
        fl.write("%s is unreadable\n" % fname)
        continue

    lamps = ""
    try:
        if header["pwstata7"] == 1:
            lamps += header["pwloca7"][0:2]
        if header["pwstata8"] == 1:
            lamps += header["pwloca8"][0:2]
    except KeyError:
        lamps = "???"
開發者ID:Keck-DataReductionPipelines,項目名稱:MosfireDRP,代碼行數:33,代碼來源:handle.py

示例2: make

# 需要導入模塊: from MOSFIRE import IO [as 別名]
# 或者: from MOSFIRE.IO import readheader [as 別名]
def make():
    """Make the database"""

    db = load_db()
    c = db.cursor()
    create(c)
    dirs = os.walk(Options.indir)

    Options.indir = Options.indir.rstrip("/")

    for root, dirs, files in dirs:
        if root == Options.indir: continue
        ignore, path = root.split(Options.indir)

        if len(path.split("/")) != 2: continue

        try: date = int(path.split("/")[1][0:4])
        except: continue

        if (date < 2012) or (date > 2030): continue

        for file in files:
            if len(file) != 17: continue
            p = os.path.join(root, file)

            num = db.execute('select count(*) from files where path = "%s"' %
                    p).fetchall()
            if num[0][0] > 0: 
                print("Skipping: " + p + " [already in db]")
                continue
            print(p)

            hdr = IO.readheader(p)

            try:
                fdate = file.split("_")[0][1:]
                number = file.split("_")[1][:-5]
            except:
                print("Skipping: " + p)
                continue

            insert_sql = "insert into files(path,fdate,number,"
            vals = "?,?,?,"
            values = [p, fdate, number]

            for key in list(hdr.keys()):

                if key == 'COMMENT': continue

                value = hdr[key]
                T = type(value)
                key = key.replace("-","_")

                insert_sql += key + ","
                vals += "?,"
                values.append(value)

                if key in keys: continue
                keys.append(key)
            


                if T == int: typename = 'integer'
                if T == float: typename = 'real'
                else: typename = 'text'
                append_column(c, key, typename)


            insert_sql = insert_sql[:-1] + ") values (" + vals[:-1] + ")"
            try:
                c.execute(insert_sql, tuple(values))
            except:
                print("Query failed on:")
                print(insert_sql)
                traceback.print_exc()
                #sys.exit()
                 

    db.commit()
開發者ID:Keck-DataReductionPipelines,項目名稱:MosfireDRP,代碼行數:81,代碼來源:mospy_db.py


注:本文中的MOSFIRE.IO.readheader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。