首页 > 解决方案 > 尝试计算时小 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 内存,所以我不确定它为什么会过载。任何建议都会很棒!

标签: python-xarray

解决方案


推荐阅读