【发布时间】:2021-05-19 04:54:51
【问题描述】:
我需要使用 Dask 和 Xarray 计算两个数据集(每月重新采样的两个每日变量)之间的差异。这是我的代码:
def diff(path_1,path_2):
import xarray as xr
max_v=xr.open_mfdataset(path_1, combine='by_coords', concat_dim="time", parallel=True)['variable_1'].resample({'time': '1M'}).max()
min_v=xr.open_mfdataset(path_2, combine='by_coords', concat_dim="time", parallel=True)['variable_2'].resample({'time': '1M'}).min()
return (max_v-min_v).compute()
future = client.submit(diff,path_1,path_2)
diff = client.gather(future)
我也试过这个:
%%time
def max_var(path):
import xarray as xr
multi_file_dataset = xr.open_mfdataset(path, combine='by_coords', concat_dim="time", parallel=True)
max_v=multi_file_dataset['variable_1'].resample(time='1M').max(dim='time')
return max_v.compute()
def min_var(path):
import xarray as xr
multi_file_dataset = xr.open_mfdataset(path, combine='by_coords', concat_dim="time", parallel=True)
min_v=multi_file_dataset['variable_2'].resample(time='1M').min(dim='time')
return min_v.compute()
futures=[]
future = client.submit(max_temp,path1)
futures.append(future)
future = client.submit(min_temp,path2)
futures.append(future)
results = client.gather(futures)
diff = results[0]-results[1]
但我注意到在 getitem-nanmax 和 getitem-nanmin 的最后一步中计算变得非常缓慢(例如 1974 年到 1980 年)。
这里是集群配置:
cluster = SLURMCluster(walltime='1:00:00',cores=5,memory='5GB')
cluster.scale(jobs=10)
每个数据集由几个文件组成:总大小=7GB
有没有更好的方法来实现这种计算?
谢谢
【问题讨论】:
-
次要问题,但变量和函数使用相同的名称并不是一个好主意,因此在您的第一个 sn-p 中考虑区分
diffvar/function。 -
@SultanOrazbayev 感谢您的建议。除此之外,您认为实现还可以吗?
标签: dask python-xarray dask-distributed