![](/img/trans.png)
[英]Extracting a name from a NETCDF file with Python using netCDF4
[英]Issues with extracting variables from NetCDF file in python
我是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]
除了不使用.getValue()之外,我使用scipy.io.netcdf的代碼是相同的。 然后我在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'][:,:,:]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.