Link Search Menu Expand Document

安裝與基本指令

Table of contents

背景

有關wrf-python

  • wrf-python顧名思義就是處理wrf相關檔案的python程式庫,包括讀寫、分析、以及繪圖等等。
  • wrf-python是NCAR下的開放源專案,有14位作者聯合的貢獻。目前版本為1.3.3.。
  • wrf-python也是NCL停止繼續發展後轉接到python的幾個專案之一,除了wrf-python,NCAR同步也持續發展PyNGL、VAPOR等等。
  • 這也意味wrf-python並不是發展完全的系統,有待持續關注、也表示如果有必要,還是必須自己使用matplotlib寫繪圖套件。
  • 程式碼:wrf-python
  • 說明、範例:官網

程式庫安裝

conda安裝

conda install -c conda-forge wrf-python

openMP重新編譯

  • 如果資料分析時能夠啟動電腦的所有核心,那是再好不過了
git clone https://github.com/NCAR/wrf-python
cd ./fortran/build_help
gfortran -o sizes -fopenmp omp_sizes.f90
python sub_sizes.py
cd ..
gfortran -E ompgen.F90 -fopenmp -cpp -o omp.f90
f2py *.f90 -m _wrffortran -h wrffortran.pyf --overwrite-signature
cd ..
python setup.py clean --all
python setup.py config_fc --f90flags="-mtune=generic -fopenmp" build_ext --libraries="gomp" build
pip install .

其他相依軟件

  • PyNGL and/or PyNIO
    • conda create --name pyn_env --channel conda-forge pynio pyngl
  • matplotlib pip install matplotlib
  • cartopy
    • brew install proj geos (macOS)
    • pip3 install --upgrade pyshp
    • pip3 install shapely --no-binary shapely
    • brew install pkg-config
    • export PKG_CONFIG_PATH=/usr/local/bin/pkgconfig
    • conda install -c conda-forge cartopy
  • Proj
    • conda install -c conda-forge proj
    • or install from source code(centos)
kuang@centos8 ~/MyPrograms/PROJ/build
$ cat cmake.kng
cmake -DTIFF_INCLUDE_DIR=/opt/anaconda3/include \
-DTIFF_LIBRARY_RELEASE=/opt/anaconda3/lib/libtiff.so \
-DSQLITE3_INCLUDE_DIR=/opt/anaconda3/envs/py37/include \
-DSQLITE3_LIBRARY=/opt/anaconda3/envs/py37/lib/sqlite3.30.1.2/libsqlite3.30.1.2.so ..
cmake --build .

變數定義

  • wrf-python最強項的功能除了繪圖之外,就屬getvar函數及其內插程式。
  • 引數:(wrfin, varname, timeidx=0, method='cat', squeeze=True, cache=None, meta=True, **kwargs)
    • wrfin: wrf檔案名稱
    • varnam: wrf-python使用的變數名稱,不是wrfout檔案的變數名稱。為區別二者,前者用小寫,後者在ncf檔案中是大寫。
    • timeidx: 時間序,0~nt-1
    • method: 時間軸是否壓縮。'cat':保持時間軸(內設);'join':聯合(壓縮)時間軸
    • squeeze: 如維度僅有一層在輸出矩陣的shape中是否予以去除?內設為True
    • cache: 將程式中反覆使用的變數暫存成矩陣名稱(varnam:ndarray),以避免反覆讀取增加執行效,內設為None
    • meta:
    • Additional Keyword Arguments: 每個變數不太相同,詳下列表格。
      • 如果只有一種單位,就不能使用units選項。
  • 輸出
    • getvar會按照新變數定義的意義輸出成帶座標系統(meta)的矩陣。
  • 原表格按照字母順序排列,以下按照變數類別分類。

Dimensions and Terran

Variable NameDescriptionAvailable UnitsAdditional Keyword Arguments
latLatitudedecimal degrees 
lonLongitudedecimal degrees 
terModel Terrain Height

m

km

dm

ft

mi

units (str) : Set to desired units. Default is ‘m’.
timesTimes in the File or Sequence  
xtimes

XTIME Coordinate

(if applicable)

minutes since

start of

model run

 

Height

Variable NameDescriptionAvailable UnitsAdditional Keyword Arguments
z/heightModel Height for Mass Grid

m

km

dm

ft

mi

msl (boolean): Set to False to return AGL values. True is for MSL. Default is True.

units (str) : Set to desired units. Default is ‘m’.

height_aglModel Height for Mass Grid (AGL)

m

km

dm

ft

mi

units (str) : Set to desired units. Default is ‘m’.
zstagModel Height for Vertically Staggered Grid

m

km

dm

ft

mi

msl (boolean): Set to False to return AGL values. True is for MSL. Default is True.

units (str) : Set to desired units. Default is ‘m’.

Temperatures

Variable NameDescriptionAvailable UnitsAdditional Keyword Arguments
eth/theta_eEquivalent Potential Temperature

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.
cttCloud Top Temperature

degC

K

degF

fill_nocloud (boolean): Set to True to use fill values for cloud free regions rather than surface temperature. Default is False.

missing (float): The fill value to use when fill_nocloud is True.

opt_thresh (float): The optical depth required to trigger the cloud top temperature calculation. Default is 1.0.

units (str) : Set to desired units. Default is ‘degC’.

T22m TemperatureK 
td22m Dew Point Temperature

degC

K

degF

units (str) : Set to desired units. Default is ‘degC’.
tdDew Point Temperature

degC

K

degF

units (str) : Set to desired units. Default is ‘degC’.
tcTemperature in CelsiusdegC 
th/thetaPotential Temperature

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.
tempTemperature (in specified units)

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.
tkTemperature in KelvinK 
tvVirtual Temperature

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.
twbWet Bulb Temperature

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.

Pressures

Variable NameDescriptionAvailable UnitsAdditional Keyword Arguments
p/pres

Full Model Pressure

(in specified units)

Pa

hPa

mb

torr

mmhg

atm

units (str) : Set to desired units. Default is ‘Pa’.
pressureFull Model Pressure (hPa)hPa 
slpSea Level Pressure

hPa

hPa

mb

torr

mmhg

atm

units (str) : Set to desired units. Default is ‘hPa’.

Velocities

Variable NameDescriptionAvailable UnitsAdditional Keyword Arguments
omg/omegaOmega(wiki, earthscience)Pa s-1 
uaU-component of Wind on Mass Points

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
vaV-component of Wind on Mass Points

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
waW-component of Wind on Mass Points

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
uvmet10

10 m U and V Components of Wind

Rotated to Earth Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
uvmet

U and V Components of Wind

Rotated to Earth Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
wspd_wdir

Wind Speed and Direction (wind_from_direction)

in Grid Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
wspd_wdir10

10m Wind Speed and Direction (wind_from_direction)

in Grid Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
uvmet_wspd_wdir

Wind Speed and Direction (wind_from_direction)

Rotated to Earth Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
uvmet10_wspd_wdir

10m Wind Speed and Direction (wind_from_direction)

Rotated to Earth Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.

Energy

Variable NameDescriptionAvailable UnitsAdditional Keyword Arguments
cape_2d2D CAPE, Convective Available Potential Energy, Convective Inhibition, Lifted condensation level, level of free convection (MCAPE/MCIN/LCL/LFC)J kg-1 ; J kg-1 ; m ; mmissing (float): Fill value for output only
cape_3d3D CAPE and CIN (Convective INhibition, wiki)J kg-1missing (float): Fill value for output only
geopt/geopotentialGeopotential for the Mass Gridm2 s-2 
geopt_stagGeopotential for the Vertically Staggered Gridm2 s-2 

High Order Dynamics

Variable NameDescriptionAvailable UnitsAdditional Keyword Arguments
avoAbsolute Vorticity10-5 s-1 
pvoPotential VorticityPVU 
helicityStorm Relative Helicity(see ref.)m2 s-2top (float): The top level for the calculation in meters. Default is 3000.0.
updraft_helicityUpdraft Helicitym2 s-2

bottom (float): The bottom level for the calculation in meters. Default is 2000.0.

top (float): The top level for the calculation in meters. Default is 5000.0.

Vapors, Cloudness and Precipitation

Variable NameDescriptionAvailable UnitsAdditional Keyword Arguments
pwPrecipitable Waterkg m-2 
rhRelative Humidity% 
rh22m Relative Humidity% 
cloudfracCloud Fraction%

vert_type (str): The vertical coordinate type for the cloud thresholds. Must be ‘height_agl’, ‘height_msl’, or ‘pres’. Default is ‘height_agl’.

low_thresh (float): The low cloud threshold (meters for ‘height_agl’ and ‘height_msl’, pascals for ‘pres’). Default is 300 m (97000 Pa)

mid_thresh (float): The mid cloud threshold (meters for ‘height_agl’ and ‘height_msl’, pascals for ‘pres’). Default is 2000 m (80000 Pa)

high_thresh (float): The high cloud threshold (meters for ‘height_agl’ and ‘height_msl’, pascals for ‘pres’). Default is 6000 m (45000 Pa)

dbzReflectivitydBZ

do_variant (boolean): Set to True to enable variant calculation. Default is False.

do_liqskin (boolean): Set to True to enable liquid skin calculation. Default is False.

mdbzMaximum ReflectivitydBZ

do_variant (boolean): Set to True to enable variant calculation. Default is False.

do_liqskin (boolean): Set to True to enable liquid skin calculation. Default is False.

色標

  • wrf-python適用所有matplotlib選項

    所有選項

  • cmap選項常用有:”jet”、”rainbow”等
  • 分為7大類
    • plot_color_gradients(‘Perceptually Uniform Sequential’, [‘viridis’, ‘plasma’, ‘inferno’, ‘magma’, ‘cividis’])
    • plot_color_gradients(‘Sequential’, [‘Greys’, ‘Purples’, ‘Blues’, ‘Greens’, ‘Oranges’, ‘Reds’, ‘YlOrBr’, ‘YlOrRd’, ‘OrRd’, ‘PuRd’, ‘RdPu’, ‘BuPu’, ‘GnBu’, ‘PuBu’, ‘YlGnBu’, ‘PuBuGn’, ‘BuGn’, ‘YlGn’])
    • plot_color_gradients(‘Sequential (2)’, [‘binary’, ‘gist_yarg’, ‘gist_gray’, ‘gray’, ‘bone’, ‘pink’, ‘spring’, ‘summer’, ‘autumn’, ‘winter’, ‘cool’, ‘Wistia’, ‘hot’, ‘afmhot’, ‘gist_heat’, ‘copper’])
    • plot_color_gradients(‘Diverging’, [‘PiYG’, ‘PRGn’, ‘BrBG’, ‘PuOr’, ‘RdGy’, ‘RdBu’, ‘RdYlBu’, ‘RdYlGn’, ‘Spectral’, ‘coolwarm’, ‘bwr’, ‘seismic’])
    • plot_color_gradients(‘Cyclic’, [‘twilight’, ‘twilight_shifted’, ‘hsv’])
    • plot_color_gradients(‘Qualitative’, [‘Pastel1’, ‘Pastel2’, ‘Paired’, ‘Accent’, ‘Dark2’, ‘Set1’, ‘Set2’, ‘Set3’, ‘tab10’, ‘tab20’, ‘tab20b’, ‘tab20c’])
    • plot_color_gradients(‘Miscellaneous’, [‘flag’, ‘prism’, ‘ocean’, ‘gist_earth’, ‘terrain’, ‘gist_stern’, ‘gnuplot’, ‘gnuplot2’, ‘CMRmap’, ‘cubehelix’, ‘brg’, ‘gist_rainbow’, ‘rainbow’, ‘jet’, ‘turbo’, ‘nipy_spectral’, ‘gist_ncar’])
  • 反轉色標:XXX_r。
    • 如rainbow -> rainbow_r

選擇考量

  • 性質迥異之整數純量,如土地使用、行政區別等,可以考慮使用Qualitative
    • 即使為連續場,如數量差異很大,如dB、或有標準上下考量,亦可以嘗試Qualitative
  • Sequential雙色漸層色彩較為不純,可以考慮用 Sequential (2) 的四季
  • Cyclic容易誤解,慎重使用
  • 如果圖面太偏低值或高值,不必重選顏色,而用不等間距的interval來取代等間距
    • 圖面偏向低值(如NO2/SO2/煙流濃度)→取log值、等分、再取exp返回
    • 圖面偏向高值(如位溫垂直變化)→取exp值、等分、再取log返回
  • color list的使用,詳見公版模式後製工具等值圖的問題

Reference