【问题标题】:xarray: compute daily anomalies from monthly resampled average (not the climatology)xarray:从每月重新采样的平均值计算每日异常(不是气候学)
【发布时间】:2018-04-01 16:28:04
【问题描述】:

xarray 的documentation 解释了如何计算每月气候学 的异常。在这里,我试图做一些稍微不同的事情:从每日时间序列,我想计算每日异常到本月的平均值(不是从每月的气候学)。

我设法使用 groupby 和手动创建的月戳(代码如下)来做到这一点。有没有更好、更简单的方法来获得相同的结果?

import xarray as xr
import numpy as np
import pandas as pd

# Create a data array
t = pd.date_range('2001', '2003', freq='D')
da = xr.DataArray(np.arange(len(t)), coords={'time':t}, dims='time')

# Monthly time stamp for groupby
da.coords['stamp'] = ('time', [str(y) + '-' + str(m) for (y, m) in 
                               zip(da['time.year'].values, 
                                   da['time.month'].values)])

# Anomaly
da_ano = da.groupby('stamp') - da.groupby('stamp').mean()

da_ano.plot();

【问题讨论】:

    标签: python python-xarray xarray


    【解决方案1】:

    您可以明确地将每月时间序列resample 表示为每日时间序列。示例:

    monthly = da.resample(time='1MS').mean()
    upsampled_monthly = monthly.resample(time='1D').ffill()
    anomalies = da - upsampled_monthly
    

    【讨论】:

      猜你喜欢
      • 2018-07-01
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多