我正在尝试向xarray教程数据集添加霜天数。扩展xarray数据集
airtemps = xr.tutorial.load_dataset('air_temperature')
# The set spans more than a year, let's take only one
airtemps = airtemps.sel(time=slice('2013-01-01', '2013-12-31'))
airtemps['air'] = airtemps.air - 273.15
的数据是相当高解析度时间明智这样更容易处理我重新取样他们 air_day = airtemps.resample(“维”,“时间”,如何=“平均”) air_month = air_day。 resample('1M','time',how ='mean')
因为我的结果,我想在air_month
有一个额外的变量,所有三个维度的平均值低于零的天数。
我非常天真的尝试是......。像这样
air_month['frost'] = sum(air_day.air < 0)
但是通过sum()
ing,我在这里松开了时间维度。我被困在这里,仍然没有在我头上包裹着xarray的概念。
感谢您的帮助!
不知道这*的*方式是否做到这一点,但它似乎工作: 'air_day [ '霜'] = air_day.air <0' 'air_day.frost.groupby( 'time.month')。总和( '时间')。情节(COL = '月',col_wrap = 3)' – TomTom101