netcdf.py 文件源码

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

项目:sympl 作者: mcgibbon 项目源码 文件源码
def append_times_to_dataset(times, dataset, time_units):
    """Appends the given list of times to the dataset. Assumes the time units
    in the NetCDF4 dataset correspond to the string time_units."""
    it_start = dataset.dimensions['time'].size
    it_end = it_start + len(times)
    if isinstance(times[0], timedelta):
        times_list = []
        for time in times:
            times_list.append(time.total_seconds())
        time_array = from_unit_to_another(
            np.array(times_list), 'seconds', time_units)
        dataset.variables['time'][it_start:it_end] = time_array[:]
    else:  # assume datetime
        dataset.variables['time'][it_start:it_end] = nc4.date2num(
            times, dataset.variables['time'].units,
            calendar='proleptic_gregorian'
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号