2016-01-23 29 views
-1

我對netCDF4對象的某些請求返回[[--]]值無效。一些地點的真實數值是[[someNumerical]]。 我怎樣才能抓住這個? http://matplotlib.org/basemap/api/basemap_api.htmlinterp文檔中沒有記錄該文件嗎?NetCDF4 [[ - ]]緯度值,長插值

我得到它的原因是我的經緯度超出了合理插值的範圍,但我根本不明白如何捕捉這個返回值。

這裏是我的電話吧:

value = interp(theData, longitudes, latitudes, np.asarray([[ convertLongitude(longitude)]]), np.asarray([[ convertLatitude(latitude) ]]), checkbounds=True, masked=True, order=1) 

好了,解決方法當然是做

if str(value) == '[[--]]': 
    doSomething 
+1

請爲您的問題添加更多細節。 – jhamman

回答

1

你的問題不清楚的地方,你認爲問題是 - 在獲取的值通過NetCDF4,或由interp返回的值。

但是在文檔尋找interp當我發現:

蒙面
如果真,點被屏蔽(在屏蔽數組)鑫和陰的範圍之外。如果將蒙版設置爲數字,則將xin和yin範圍之外的點設置爲該數字。默認爲False。

http://matplotlib.org/basemap/api/basemap_api.html#mpl_toolkits.basemap.interp

[--]值使得在masked array上下文感。

在屏蔽數組,蒙面值(通常是非有效的)都將顯示一個--

In [380]: x=np.ma.masked_greater(np.arange(4), 2) 
In [381]: x 
Out[381]: 
masked_array(data = [0 1 2 --], 
      mask = [False False False True], 
     fill_value = 999999) 

你需要屏蔽數組上閱讀,如果你想使用masked=True參數。

你可以做這樣的事情了fillvalue

In [387]: x.filled() 
Out[387]: array([  0,  1,  2, 999999]) 
In [388]: x.filled(-1) 
Out[388]: array([ 0, 1, 2, -1]) 

或刪除這些

In [389]: x.compressed() 
Out[389]: array([0, 1, 2]) 

您看到[[--]]表明values可能是一個二維數組的事實代替蒙面元素。如果這樣compressed可能沒有用處。

但一個關鍵點是values數組實際上沒有--值。這就是顯示的內容,作爲填充。