def iaga2df(iaga2002_fname, D_to_radians=True):
"""
Parser the magnetometer data record stored in the IAGA-2002 format
file *iaga2002_fname*. If *D_to_radians*, declination data (D) are
converted from degrees to radians. Return the tuple with the
:class:`DataFrame` containing the data and header information
"""
with open(iaga2002_fname) as fid:
# parse header
header, cols = parse_header(fid)
keys = ['B_' + x for x in cols]
# parse data
index = []
data_map = defaultdict(list)
for line in fid:
toks = line.split()
dt = datetime.strptime(toks[0] + ' ' + toks[1], '%Y-%m-%d %H:%M:%S.%f')
index.append(dt)
data = map(convert_float, toks[3:])
for key_i, data_i in zip(keys, data):
if key_i == 'B_D' and D_to_radians:
data_i = math.radians(data_i)
data_map[key_i].append(data_i)
df = PD.DataFrame(index=index, data=data_map)
return df, header
评论列表
文章目录