python-xarray - 尝试计算时小 xarray 对象杀死 Dask 工作人员
问题描述
我正在使用每小时温度数据集,并试图将其减少到给定国家在给定年份的每日最大值/最小值/平均值。我的代码如下:
def daily_temps_year(country, year, utc_offset):
'''
Takes in a country and a year and creates daily totals for that country (assuming the country spans a single time zone).
'''
full_year = xr.open_mfdataset(FILEPATH + year + '_*.nc')
full_year = full_year.rename({'longitude': 'lon',
'latitude': 'lat'})
full_year = full_year.assign_coords({"lon": (((full_year.lon + 180) % 360) - 180)})
mask_3d = regionmask.defined_regions.natural_earth.countries_110.mask_3D(full_year)
country = mask_3d.isel(region=(mask_3d.names == country))
country = country.drop(['region', 'names', 'abbrevs'])
country = country.squeeze(dim='region', drop=True)
country_temp_full = full_year.where(country, drop=True)
country_temp_full = country_temp_full.assign_coords({'time': country_temp_full.time+pd.Timedelta(utc_offset, unit='h')})
daily_avg = country_temp_full.resample(time='1D').mean()
daily_max = country_temp_full.resample(time='1D').max()
daily_min = country_temp_full.resample(time='1D').min()
daily_avg = daily_avg.rename({'t2m': 'mean_temp'})
daily_max = daily_max.rename({'t2m': 'max_temp'})
daily_min = daily_min.rename({'t2m': 'min_temp'})
merged_temp_full = xr.merge([daily_avg, daily_max, daily_min])
return merged_temp_full
我在 2017 年运行了 Mali 的代码,它返回了一个大小为 5.69 MB 的数组。当我尝试显示最大值、在数组上调用 .compute() 或将文件保存为 netCDF 时,dask 工作人员会被杀死。xr.open_mfdataset 打开的完整 2017 数据集大约 40 GB,我在分布式计算集群上运行代码。当我打印出客户端对象时,它确认有 40 个工作人员和 160 GB 内存,所以我不确定它为什么会过载。任何建议都会很棒!
解决方案
推荐阅读
- sql - 列之间的 SQL 字符串匹配并返回结果
- linux - 用于 Microsoft Office365 的命令行电子邮件,用于请求跟踪器(BasicAuth 停用后)
- regex - WordPress - 重写规则多段
- bash - 如何使用 Launcher 应用程序文件 .desktop 打开我的应用程序
- r - 使用 R 中的 cut() 函数将日期转换为 15 分钟间隔的不可预测的结果
- sql - 插入..在重复键更新时重复值
- matlab - 梯度下降后向量 Theta 无符号
- javascript - 2020 年 AJAX 最佳实践(成功与完成)
- android - 在干净架构的上下文中,用例和交互器意味着什么?
- linux - 在现代 Linux x86-64 中,用户空间覆盖 GS 寄存器是否安全?