omni.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:pyrsss 作者: butala 项目源码 文件源码
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]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号