本文整理汇总了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 = "???"
示例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()