2014-07-15 23 views
0

我正在使用一個python 2.6腳本,我已經使用了很長一段時間了,並且我得到一個錯誤,它不應該在那裏。該Python腳本運行形成的,其中netCDF文件所在的位置,這裏是代碼Python和NetCDF sciprt不再運行

from numpy import * 
import numpy as numpy 
from netCDF4 import Dataset 
import datetime as DT 
from time import strftime 
import os 

floc ='/media/USB-HDD/NCEP_NCAP data/data_2010/' #location of directory that the file resides 
fname ='cfsr_Scotland_2010' # name of the netCDF file 
in_ext = '.nc'  # ending extentsion of the netCDF 

basetime = DT.datetime(2010,01,01,0,0,0) # Initial time (start) for the netCDF 

ncfile = Dataset(floc+fname+in_ext,'r') # netCDF assigned name 



time = ncfile.variables['time'] 
lon = ncfile.variables['lon'] 
lat = ncfile.variables['lat'] 
uwind = ncfile.variables['10u'] 
vwind = ncfile.variables['10v'] 
ht = ncfile.variables['height'] 

我得到的NCFILE命名,這是奇怪的,因爲我簽了書面的方式錯誤

Traceback (most recent call last): 
    File "CFSR2WIND.py", line 24, in <module> 
    ncfile = Dataset(floc+fname+in_ext,'r') # netCDF assigned name 
    File "netCDF4.pyx", line 1317, in netCDF4.Dataset.__init__ (netCDF4.c:14608) 
RuntimeError: No such file or directory 

有誰知道爲什麼以及是什麼原因導致這一點,以及它如何可以解決

謝謝

喬治

回答

1

嘗試使用netcdf模塊從SciPy的替代:

from scipy.io.netcdf import netcdf_file as Dataset 

夫婦的其他建議:

  1. 導入numpy。您將其導入了兩次,並且使用*來讀取所有實例有點危險。按照慣例,大多數人將numpy縮寫爲np並將其加載爲import numpy as np。然後,您可以使用np.mean()例如從numpy調用實例。

  2. 連接路徑,文件名和文件擴展名。可以使用+符號來使用字符串連接,但也可以使用join命令執行此操作。所以,總文件名就像filename = ''.join([floc, fname, in_ext])