python - xarray : calculate time-series of daily anomalies from *local* monthly means

标签 python time-series python-xarray cdo-climate

我目前正在处理每日气候数据 (ERA5) 并使用 xarray 对其进行分析。

da

<xarray.DataArray (time: 8036)>
dask.array<stack, shape=(8036,), dtype=float32, chunksize=(1,), chunktype=numpy.ndarray>
Coordinates:
  * time     (time) datetime64[ns] 1979-01-01 1979-01-02 ... 2000-12-31

我想根据时间序列的本地月平均值计算该数据的每日异常。也就是说,我想从 1979 年 1 月的所有日子中去掉(例如)1979 年 1 月的平均值。并且我想对数组中每年的每个月都执行此操作。

我认为目前没有一种简单的方法可以使用 xarray 来做到这一点,但我会很感激人们能找到的任何解决方法! :)

最佳答案

一个稍微漂亮的方法可以让您了解如何将事物扩展到其他类型的异常:

da = da.assign_coords(year_month=da.time.dt.strftime("%Y-%m"))
result = da.groupby("year_month") - da.groupby("year_month").mean("time")

关于python - xarray : calculate time-series of daily anomalies from *local* monthly means,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61370684/

相关文章:

python - 使用数组作为列填充预定义的 numpy 数组

r - 绘制 2x2x2 时间序列的原始值和预测值

r - plot.ts - 更改标签和 axis.labels 的字体大小

python - 两次调用 GetListFeed 失败 (gdata.spreadsheet.service.SpreadsheetsService())

Python:数组中的条件元素

python - dask-distributed 中计算 NetCDF 数据集滚动总和的内存问题

python - 循环遍历数据框字典

python - 如何将色阶标签移动到 matplotlib/xarray 中彩色字段的中间?

python - 如何有效地将函数应用于 Pandas Panel 的每个 DataFrame

Python - 时间序列对齐和 "to date"函数