在Python中从NetCDF文件提取变量的问题
我刚开始学习python,之前有一些matlab的经验。我从netCDF文件中获取的 outgoing longwave radiation(向外长波辐射)值不正确,我尝试过scipy.io.netcdf模块和Scientific.IO.NetCDF模块。
import Scientific.IO.NetCDF as S
fileobj = S.NetCDFFile('filename.nc', mode='r')
data = fileobj.variables['var'].getValue() # I tried both with and w/o the .getValue()
print data[0:10,43,80] #first ten points in time at a specific lat/lon
[ -5124 -5335 -5121 -5499 -5508 -8930 -10111 -9435 -8534 -8487]
我用scipy.io.netcdf写的代码基本一样,只是没有使用.getValue()。然后我在matlab中尝试了这个练习。
data = ncread('filename.nc','var');
data[80,43,1:10] %note matlab orders the data lon, lat, time
ans(:,:,1) =
275.0400
ans(:,:,2) =
279.0800
ans(:,:,3) =
279.6800
ans(:,:,4) =
277.8700
ans(:,:,5) =
275.5900
ans(:,:,6) =
241.4700
ans(:,:,7) =
223.1900
ans(:,:,8) =
235.5700
ans(:,:,9) =
239.8200
ans(:,:,10) =
249.5400
我知道matlab生成的值是正确的。这个变量的值应该在80到330(每平方米瓦特)之间。你们觉得python出了什么问题呢?谢谢!
1 个回答
0
试试这个写法:
from scipy.io.netcdf import netcdf_file as Dataset
ncfile = Dataset('filename.nc','r')
data = ncfile.variables['var'][:,:,:]