Xarray to_netcdf非常慢并且在python中崩溃了大型数据集

时间:2018-02-26 10:37:08

标签: python dask python-xarray netcdf4 xarray

我正在尝试使用Python中的xarray从每小时到6小时重新采样降水数据,PET数据和温度数据。完成此步骤后,我们的想法是将这三个数据集合并为一个netCDF4文件。在此合并之前,xarray执行速度相当快(大约40秒),但保存到netcdf需要两天然后崩溃。 数据在一起~25GB。

我看到这个问题经常发生,但我还没有找到任何解决方案..

提前感谢您的帮助!

在我用过的代码下面:

import xarray 
import datetime 
from datetime import * 
import time


start = time.time()`


# Rhine 
P = xarray.open_dataset("D:\P_Rhine_total.nc", decode_times=True, chunks={'time':500}) 
P = P.sel(time=slice(datetime(2010, 1, 1, 1), datetime(2015, 12, 31, 0))) 
Pnew = P.precipitation_thickness.rename("P") 
Pagg = Pnew.resample('6H','time',how='sum', closed='right', label='right')  
PET = xarray.open_dataset("D:\PET_Rhine_total.nc", decode_times=True, chunks={'time':500}) 
PET = PET.sel(time=slice(datetime(2010, 1, 1, 1), datetime(2015, 12, 31, 0))) 
PETnew = PET.makkink_potential_evaporation.rename("PET") 
PETagg = PETnew.resample('6H','time',how='sum', closed='right', label='right') 

T = xarray.open_dataset("D: \T_Rhine_total.nc", decode_times=True, chunks={'time':500}) 
T = T.sel(time=slice(datetime(2010, 1, 1, 1), datetime(2015, 12, 31, 0))) 
Tnew = T.air_temperature.rename("TEMP") 
Tagg = Tnew.resample('6H','time',how='mean', closed='right', label='right') 

New = xarray.merge((Pagg,PETagg,Tagg)) 
New.chunk(chunks={'time':500}) 
New.to_netcdf(path="D:\\forcing_Rhine.nc",mode="w",format="NETCDF4", encoding={'P': {'dtype': 'float32', 'scale_factor': 0.001, '_FillValue': -9999}, 'PET': {'dtype': 'float32', 'scale_factor': 0.001, '_FillValue': -9999}, 'TEMP': {'dtype': 'float32', 'scale_factor': 0.001, '_FillValue': -9999}}) 
End = time.time() 
print End-start 

0 个答案:

没有答案
相关问题