如何使用python-netcdf4加速变量提取?

时间:2019-03-11 20:24:02

标签: python performance netcdf4

下面是我正在运行的代码的示例。 Here is an example是我要加载的数据类型。获取'Mean_Layer_Height'参数需要很长时间。我有一篇单独的文章考虑使用xarray来执行此操作,这可能会更快,但是我想知道是否没有某种方法可以优化python-netCDf4来更有效地提取数据。我有383个文件要加载,最多可能需要3个小时。那样还不错,只是在那之后我仍然在编写和调试代码。有什么方法可以更快地导入这些数据?

filepath = #need to put an example file in here, see above
#keep track of when code was started
runstart=pd.datetime.now()

rootgrp3 = Dataset(filepath, "r", format="NETCDF4")
#print (rootgrp3.data_model)
print(pd.datetime.now()-runstart)

#this step dats 10-19 seconds, when others only take 0.04 seconds
mlh_2 = rootgrp3.variables['Mean_Layer_Height'][:]
print(pd.datetime.now()-runstart)

#also need this but it doesn't take long (like 0.01 seconds)
ml_time = rootgrp3.variables['time'][:]
print(pd.datetime.now()-runstart)

0 个答案:

没有答案