python中从NetCDF文件提取变量的问题
我是python新手,对matlab有一些经验。我没有从netCDF文件中获得传出长波辐射的正确值,我尝试了scipy.io.netCDF模块和Scientific.io.netCDF模块python中从NetCDF文件提取变量的问题,python,matlab,netcdf,Python,Matlab,Netcdf,我是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 th
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的想法吗?
谢谢尝试以下语法:
from scipy.io.netcdf import netcdf_file as Dataset
ncfile = Dataset('filename.nc','r')
data = ncfile.variables['var'][:,:,:]
它不应该是打印数据[0:10,42,79]吗?Python索引从0开始,Matlab索引从1开始。啊,是的。你说得对。但是,这些值仍然在-10000范围内,而它们应该在80-330范围内。今天我做了更多的工作,发现如果我使用MATLAB的“低级”netcdf包,即netcdf.getVar,那么我得到的答案与python相同。