這裏我都是經過源碼包安裝的,你們也能夠再終端裏經過pip install 命令來安裝 spa
一、安裝nose.net
解壓縮後,進入命令提示符 運行
1 python3 setup.py install
二、安裝numpy
解壓縮後,進入命令提示符 運行
1 python3 setup.py install
三、安裝pyparsing
解壓縮後,進入命令提示符 運行
1 python3 setup.py install
四、安裝python-dateutil
解壓縮後,進入命令提示符 運行
1 python3 setup.py install
五、安裝cycler
解壓縮後,進入命令提示符 運行
1 python3 setup.py install
六、安裝pkg-config
1 ./configure --with-intermal-glib 2 make && date 3 sudo make install && date
七、安裝freetype
1 ./configure 2 make && date 3 sudo make install && date
八、安裝libpng
1 ./configure 2 make && date 3 sudo make install && date
九、安裝matplotlib-1.5.0
解壓縮後,進入命令提示符 運行
1 python3 setup.py install
(二)basemap安裝
一、安裝GEOS
1 ./configure 2 make && date 3 sudo make install && date
二、安裝pyproj
1 python3 setup.py install
三、安裝basemap
1 python3 setup.py install
因爲以前已經安裝了numpy和pyproj,這裏只需安裝Jasper和GRIB API便可安裝pygrib
一、安裝Jasper
1 ./configure 2 make && date 3 sudo make install && date
二、安裝GRIB API
1 ./configure --with-jasper='/usr/local/' 2 make && date 3 sudo make install && date
三、安裝pygrib
安裝pygrib以前首先要根據本身的實際狀況修改文件目錄下的setup.cfg文件,最主要的就是修改grib_api_dir和jasper_dir,這兩個是剛剛安裝的Jasper和GRIB API的路徑,若是這兩個地址不正確安裝會報錯
1 # Rename this file to setup.cfg to set pygrib's 2 # build options. 3 # Follow instructions below for editing. 4 [directories] 5 # uncomment and set to grib_api install location. 6 # Include files should be located in grib_api_dir/include and 7 # the library should be located in grib_api_dir/lib. 8 # If the libraries and include files are installed in separate locations, 9 # use grib_api_libdir and grib_api_incdir to specify the locations 10 # separately. 11 grib_api_dir = /usr/local 12 # if grib_api was built with jasper support for JPEG200, 13 # uncomment and set to jasper lib install location. 14 # If the libraries and include files are installed in separate locations, 15 # use jasper_libdir and jasper_incdir. 16 jasper_dir = /usr/local 17 # if grib_api was built with openjpeg support for JPEG200, 18 # uncomment and set to openjpeg lib install location. 19 # If the libraries and include files are installed in separate locations, 20 # use openjpeg_libdir and openjpeg_incdir. 21 #openjpeg_dir = /opt/local 22 # if grib_api was built with png support, 23 # uncomment and set to png lib install location. 24 # If the libraries and include files are installed in separate locations, 25 # use png_libdir and png_incdir. 26 png_dir = /usr 27 # if grib_api was built with png support, 28 # uncomment and set to zlib install location. 29 zlib_dir = /usr 30 # install man pages for command line utilities here 31 #man_dir = /usr/local/man
修改好就能夠正常安裝了
1 python3 setup.py install
雖然我作的東西和睦象沾邊,可是我自己並非氣象專業出身,全部這些東西都是我慢慢研究琢磨出來的,因此有些方面可能講的比較外行,有不對的地方歡迎你們留言指正。
1 >>> import pygrib
1 >>> grbs = pygrib.open('/Users/Kallan/Documents/data/echhae50.082')
1 >>> grbs.seek(0) 2 >>> for grb in grbs: 3 grb 4 1:Geopotential Height:gpm (instant):regular_ll:isobaricInhPa:level 500:fcst time 24 :from 201507081200
1 :數據列表的行號,有的文件可能包括多個數據
Geopotential Height:數據的名稱
gpm (instant):數據的單位
regular_ll:常規數據,其實這個字段我也不清楚
isobaricInhPa:這個字段表示的是數據屬性,此處表示是以hPa爲單位的等壓面
level 500:這個字段表示的是高度層
fcst time 24 :預報時效
from 201507081200 :起報時間
綜合上面的信息能夠得出,這個文件是從2015年7月8日12時開始的24小時後500hPa等壓面高度場數據
1 >>> grb = grbs.select(name='Geopotential Height')[0] 2 >>> data = grb.values 3 >>> print(data.shape,data.min(),data.max()) 4 (37, 37) 5368.6796875 5941.0390625 5 >>> lat,lon=grb.latlons() 6 >>> print(lat,'\n',lon) 7 [[ 0. 0. 0. ..., 0. 0. 0. ] 8 [ 2.5 2.5 2.5 ..., 2.5 2.5 2.5] 9 [ 5. 5. 5. ..., 5. 5. 5. ] 10 ..., 11 [ 85. 85. 85. ..., 85. 85. 85. ] 12 [ 87.5 87.5 87.5 ..., 87.5 87.5 87.5] 13 [ 90. 90. 90. ..., 90. 90. 90. ]] 14 [[-90. -87.5 -85. ..., -5. -2.5 0. ] 15 [-90. -87.5 -85. ..., -5. -2.5 0. ] 16 [-90. -87.5 -85. ..., -5. -2.5 0. ] 17 ..., 18 [-90. -87.5 -85. ..., -5. -2.5 0. ] 19 [-90. -87.5 -85. ..., -5. -2.5 0. ] 20 [-90. -87.5 -85. ..., -5. -2.5 0. ]]
1 >>> import matplotlib.pyplot as plt 2 >>> from mpl_toolkits.basemap import Basemap 3 >>> import numpy as np
1 >>> plt.figure() 2 <matplotlib.figure.Figure object at 0x107e65198>
1 >>> m=Basemap(projection='mill',lat_ts=10,llcrnrlon=lon.min(), \ 2 urcrnrlon=lon.max(),llcrnrlat=lat.min(),urcrnrlat=lat.max(), \ 3 resolution='c') 4 >>> m.drawcoastlines(linewidth=0.25) 5 <matplotlib.collections.LineCollection object at 0x1091c1f28> 6 >>> m.drawcountries(linewidth=0.25) 7 <matplotlib.collections.LineCollection object at 0x10621d0f0> 8 >>> m.fillcontinents(color='coral',lake_color='aqua') 9 >>> m.drawmapboundary(fill_color='aqua') 10 <matplotlib.patches.Rectangle object at 0x10918b3c8> 11 >>> m.drawmeridians(np.arange(0,360,30)) 12 >>> m.drawparallels(np.arange(-90,90,30))
1 >>> x, y = m(lon,lat)
1 >>> cs = m.contour(x,y,data,15,linewidths=1.5)
1 >>> plt.title('Geopotential Height Contour from Grib') 2 <matplotlib.text.Text object at 0x10918bda0> 3 >>> plt.show()
本文版權歸做者和博客園共有,歡迎轉載,但未經做者贊成必須保留此段聲明,且在文章頁面明顯位置給出原文鏈接,不然保留追究法律責任的權利。
想觀看Matplotlib教學視頻,瞭解更多Matplotlib實用技巧可關注
微信公衆帳號: MatplotlibClass
今日頭條號:Matplotlib小講堂