【问题标题】:how to set year as time coordinate using netcdf如何使用 netcdf 将年份设置为时间坐标
【发布时间】:2021-11-07 23:45:09
【问题描述】:
years = range(2011, 2020)
dataset1 = [xr.open_dataset('dataset') for year in years]
dataset1= xr.concat(dataset1, dim='time')


# set year as time coordinate

dataset1= dataset1. assign_coords(year=('time', years))

但是错误 ValueError:维度“时间”的大小冲突:“年份”的长度为 9,“时间”的长度为 1080

【问题讨论】:

    标签: python python-xarray netcdf4


    【解决方案1】:

    我猜您每年在时间维度上拥有多个数据点。解决此问题的一种方法是分配一个包含数据集中每个时间的年份的年份坐标,尽管它会包含重复值。你可以通过the DatetimeAccessor 做到这一点:

    dataset1 = dataset1.assign_coords(year=dataset1.time.dt.year)
    

    【讨论】:

    • 感谢@spencerkclark,它对我有用:)
    猜你喜欢
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多