【发布时间】:2014-06-28 05:14:51
【问题描述】:
我是 python 新手,对 matlab 有一些经验。我没有从 netCDF 文件中获得输出长波辐射的正确值,我尝试了 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发生了什么的任何想法? 谢谢
【问题讨论】:
-
不应该是
print data[0:10,42,79]吗? Python 索引从 0 开始,Matlab 从 1 开始。 -
啊,是的。你是对的。但是,这些值仍然在 -10,000 范围内,而它们应该在 80-330 范围内。我今天做了更多的工作,发现如果我使用 MATLAB 的“低级”netcdf 包,只是称为 netcdf.getVar ,那么我会得到与 python 相同的答案。