我有一个多年的 netcdf 文件。我正在尝试在每个网格点计算此数据集
(X - mean(X)) / std(X)
的归一化异常。
mean(X) = 每日气候数据,即 1 月 1 日、1 月 2 日、...12 月 31 日的平均值。最终文件有 366 个时间步。
std(X) = 数据的标准气候学。最终文件有 366 个时间步。
在计算归一化异常之前,使用滚动 95 分位数平滑平均值。
(X-mean(X))
和std(X)
的尺寸不匹配!!!!!
下面的代码,我正在使用
import xarray as xr
import pandas as pd
ds = xr.open_dataset("chirps-v2.0._merge_1981_2019.days_p05.nc")
xtime = pd.date_range("2000-01-01", periods=366)
# Calculate mean climatology and std climatology
gb = ds.groupby('time.dayofyear')
clim = gb.mean(dim='time')
std_clim = gb.std(dim='time')
# Change time dimension from dayofyear to time
good_clim = clim.rename({'dayofyear': 'time'})
good_clim["time"] = xtime
good_std = std_clim.rename({'dayofyear': 'time'})
good_std["time"] = xtime
# Rolling quantile (0.95) on mean climatology
rol_clim_P95 = good_clim.precip.rolling(time=7, center=True).construct('tmp').quantile(.95, dim='tmp')
# Change time dimension from to time to dayofyear
rol_clim_P95_dayofyear = rol_clim_P95.groupby('time.dayofyear')
rol_clim_P95_dayofyear_mean = rol_clim_P95_dayofyear.mean(dim='time')
anom = (gb - rol_clim_P95_dayofyear_mean)/std_clim