def get_record(omni_path,
d1,
d2,
template='omni_min{year:04d}{month:02d}.asc',
inclusive=True):
"""
Gather an OMNI data record spanning *d1* to *d2* and return a
:class:`PD.DataFrame`. Use file OMNI data record file names
specified by *template*. If *inclusive*, the range is *d1* to *d2*
with equality on both bounds.
"""
df_list = []
for year in range(d1.year, d2.year + 1):
for month in range(1, 13):
date1 = datetime(year, month, 1)
date2 = date1 + timedelta(days=monthrange(year, month)[1])
if not (date1 <= d1 <= date2 or date1 <= d2 <= date2):
continue
omni_fname = os.path.join(omni_path,
template.format(year=year,
month=month))
if not os.path.isfile(omni_fname):
logger.warning('could not find {} --- skipping'.format(omni_fname))
continue
logger.info('parsing {}'.format(omni_fname))
df_list.append(parse(omni_fname))
df = PD.concat(df_list)
if inclusive:
return df[d1:d2]
else:
return df[d1:d2].iloc[:-1]
评论列表
文章目录