【发布时间】:2020-05-18 21:27:47
【问题描述】:
我尝试使用xarray 对气候数据实施移动百分位。
我有一个包含每日最低和最高温度的数据集,如下所示:
<xarray.Dataset>
Dimensions: (latitude: 60, longitude: 20, time: 14456)
Coordinates:
* latitude (latitude) float64 39.05 39.05 39.15 39.15 ... 41.85 41.95 41.95
* longitude (longitude) float64 8.05 8.15 8.25 8.35 ... 9.65 9.75 9.85 9.95
* time (time) datetime64[ns] 1980-01-01 1980-01-02 ... 2019-07-30
Data variables:
tn (time, latitude, longitude) float32 nan nan nan ... nan nan nan
tx (time, latitude, longitude) float32 nan nan nan ... nan nan nan
Attributes:
E-OBS_version: 20.0e
Conventions: CF-1.4
References: http://surfobs.climate.copernicus.eu/dataaccess/access_eo...
history: Wed May 13 17:26:55 2020: ncrcat tn_ens_mean_0.1deg_reg_1...
NCO: netCDF Operators version 4.8.1 (Homepage = http://nco.sf....
对于一年中的每一天,我想计算一个移动分位数,移动窗口为 5 天。 为了更好地理解,请参阅此 pic,窗口每年需要 5 天计算分位数(绿色、红色和蓝色方框表示移动的分位数滤波器)。
我没有找到rolling 和groupby 运算符的正确组合来达到我的目的。
所以我使用(慢)for循环解决了它。我创建了一个日期列表,并使用sel 运算符来选择和计算分位数,例如:
# all_days_lists is a list of lists
for days_list in all_days_lists:
# select days of interest
tmp_ds = xdataset.sel(time=days_list)
# compute 90th percentile
p90 = tmp_ds.quantile(0.9,dim='time')
有解决这个问题的想法吗? 非常感谢。
【问题讨论】:
-
我有同样的问题,看看我的帖子和这里的答案:stackoverflow.com/questions/62698837/…>
-
我找到了一个很好的解决方案。可以使用 pandas multiidex 创建自定义索引。因此可以使用任意标准进行分组
标签: python-xarray