安裝及使用 NCL,以 GFS 的氣壓初始場及對 Δp(972) 及 Δp(S) 的預測為例

NCL 全名為 NCAR Command Language,為一解釋型語言,專門分析及視覺化地球科學等數據,支援 netCDF、GRIB 等氣象格式。

安裝 NCL
1. 到 http://www.ncl.ucar.edu/ 按指示下載最新的 NCL 版本。最簡單的方法為下載其已編譯的 Binary 版本。這裡列出了可供下載的版本,建議為 OPeNDAP-enabled binaries,而我的伺服器選用了 "64-bit binary for x86_64 chips for Debian LINUX , compiled with gcc 4.4.5",另有其他 Linux、AIX、Mac OS X 和 Cygwin 版本。
2. 下載其 .tar.gz 檔後,以 root 權限解壓到相應的系統目錄:
sudo tar -xvf ~/ncl_ncarg-6.0.0.Linux_Debian_x86_64_gcc445.tar.gz

3. 在執行之前,將 NCL 的目錄加進環境變數中,此處以 bash 為例:
export NCARG_ROOT=/usr/local

4. 輸入 ncl,應該可見類似下面的訊息:
 Copyright (C) 1995-2011 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.0.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
ncl 0>
這即代表安裝成功。

製作 GFS 的氣壓初始場
由於我所需的資料來自 Unidata 的 motherlode server,故可先上 這裡這裡 查看有什麼資料可供使用。就本例而言,我選用了美國國家海洋和大氣管理局的全球預測模型解析度為 0.5 度的數據,經 OPeNDAP 下載。
用文字編輯器輸入以下指令,檔案名稱、經緯度、日期等可按需要更改:

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin
        filename = "http://motherlode.ucar.edu:8080/thredds/dodsC/fmrc/NCEP/GFS/Global_0p5deg/runs/NCEP-GFS-Global_0p5deg_RUN_2011-12-25T00:00:00Z"
        f1 = addfile(filename,"r")
        fsd=f1->Pressure_reduced_to_MSL(time|2,{lat|8:42},{lon|90:146})
        lat  = fsd&lat
        lon  = fsd&lon
        fsd = fsd/100
        fsd@units     = "hPa"

        wks_type = "png"
        wks_type@wkWidth = 1000
        wks_type@wkHeight = 800
        wks  = gsn_open_wks(wks_type, "msl")

        gsn_define_colormap(wks,"BlGrYeOrReVi200")
        i = NhlNewColor(wks,0.8,0.8,0.8)

        res                             = True
        res@gsnMaximize                 = True
        res@cnFillOn                    = False
        res@cnLinesOn                   = True
        res@cnLevelSpacingF             = 1
        res@cnSmoothingOn               = True
        res@gsnSpreadColors             = True
        res@gsnSpreadColorEnd           = -3 
        res@mpDataBaseVersion           = "Ncarg4_1"
        res@pmTickMarkDisplayMode       = "Always"
        res@gsnAddCyclic                = False
        res@mpProjection                = "mercator"
        res@mpLimitMode                 = "Corners"
        res@mpLeftCornerLatF            = min(lat)
        res@mpLeftCornerLonF            = min(lon)
        res@mpRightCornerLatF           = max(lat)
        res@mpRightCornerLonF           = max(lon)
        res@tfDoNDCOverlay              = True

        plot = gsn_csm_contour_map (wks,fsd,res)    ; create plot

end
儲存為 msl.ncl,再執行
ncl msl.nsl

則可得到 msl.png:
msl
製作 GFS 對 Δp(972) 及 Δp(S) 的預測
根據香港地下天文台的介紹,Δp(972) 及 Δp(S) 為香港天文台制定之氣壓指數,用來預測影響香港之冬季季候風到達時間及強度。當 Δp(972) 升至 7 百帕或以上時,北風潮即將到達香港。而 Δp(S) 升至 8 百帕或以上時,東風潮可能於晚上為香港離岸地區帶來強風。

用文字編輯器輸入以下指令,檔案名稱及日期等可按需要更改:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin
        filename = "http://motherlode.ucar.edu:8080/thredds/dodsC/fmrc/NCEP/GFS/Global_0p5deg/runs/NCEP-GFS-Global_0p5deg_RUN_2011-12-25T00:00:00Z"
        f1 = addfile(filename,"r")

        time = f1->time
        ;time = time - time(0)

        hkmsl = f1->Pressure_reduced_to_MSL(time|:,{lat|22.15},{lon|114.1})
        hkmsl = hkmsl / 100

        s972msl = f1->Pressure_reduced_to_MSL(time|:,{lat|25.8},{lon|113})
        s972msl = s972msl / 100


        s362msl = f1->Pressure_reduced_to_MSL(time|:,{lat|31.4},{lon|121.5})
        s362msl = s362msl / 100

        wks_type = "png"
        wks_type@wkWidth = 600
        wks_type@wkHeight = 600
        wks  = gsn_open_wks(wks_type, "delta")

        data_all = new((/2,dimsizes(hkmsl)/),"float")
        data_all(0,:)=s362msl - hkmsl
        data_all(1,:)=s972msl - hkmsl

        res               = True
        res@tiMainString  = ":F8:D:F0:p(972) & :F8:D:F0:p(S)"
        res@tiYAxisString = ":F8:D:F0:p"

        axisString = time@units
        res@tiXAxisString = axisString
        res@tiXAxisFuncCode = "!"

        res@xyLineColors      = (/"black","red"/)


        res@pmLegendDisplayMode    = "Always"
        res@pmLegendParallelPosF   = .50
        res@pmLegendOrthogonalPosF = -0.2

        res@pmLegendWidthF         = 0.12
        res@pmLegendHeightF        = 0.05
        res@xyExplicitLegendLabels = (/":F8:D:F0:p(S)",":F8:D:F0:p(972)"/)
        res@pmLegendSide           = "Top"
        res@lgLabelFontHeightF     = .03
        plot = gsn_xy(wks,time,data_all,res)
end

儲存為 delta.ncl,再執行
ncl delta.nsl

則可得到 delta.png:
delta

從此圖表可以見到,於 2011 年 12 月 25 日之後的 210 小時,Δp(972) 多數在 7 以下,而 Δp(S) 則偏高,顯示香港會受東風影響。

參考資料:
NCL
NCL Documentation
unidata
香港地下天文台


本文連結