Skip to content

Instantly share code, notes, and snippets.

@mehori
Created July 25, 2022 09:14
Show Gist options
  • Save mehori/922d23b1703ec6958369872de4623cf8 to your computer and use it in GitHub Desktop.
Save mehori/922d23b1703ec6958369872de4623cf8 to your computer and use it in GitHub Desktop.
NCLで簡単な極座標の図をつくるbashスクリプト
#!/bin/bash
function makefig (){
vmax=$1
vmin=$2
vint=$3
# color=hotcold_18lev
color=BlWhRe
cat > tmp.ncl << EOF
begin
ifile = addfile("./slp.clim.nc","r")
v = ifile->slp(0,0,{60:90},:)
; convert to hPa
v2 = v / 100.0
copy_VarCoords(v,v2)
wks = gsn_open_wks("pdf","./fig.slp")
gsn_define_colormap(wks, "${color}")
res = True
res@gsnDraw = False
res@gsnFrame = False
res@gsnPolar = "NH"
res@mpMinLatF = 60
res@mpFillOn = False
res@cnFillOn = True
res@cnLinesOn = False
res@cnMissingValFillColor = "gray90"
; contour levels
res@cnMinLevelValF = -${vmin}
res@cnMaxLevelValF = ${vmax}
res@cnLevelSpacingF = ${vint}
; res@cnLevelSelectionMode = "ManualLevels"
; lon label font size
res@gsnPolarLabelFontHeightF = 0.015
; color range
res@gsnSpreadColorStart = 2
res@gsnSpreadColorEnd = 102
; color label orientation
; res@lbOrientation = "Vertical"
res@lbOrientation = "Horizontal"
; text
res@gsnLeftString = "SLP"
res@gsnRightString = "Clim"
plot = gsn_csm_contour_map_polar(wks,v2,res)
draw(plot)
frame(wks)
end
EOF
ncl tmp.ncl
rm tmp.ncl
}
# main --------------
makefig 995 1025 2
注意点
・netCDFの変数名はslpを想定
・データの次元数は4次元で slp(時間、気圧、緯度、経度)を想定して、slp(0,0,{60:90},:) で切り出している
・これが3次元なら slp(0,:,:) のように読み出す
・gsmDrawとgsnFrameをFalseにしているのは、あとで複数の変数などを重ねやすくするため
・カラースキームはこちらから取得する
それぞれクリックすると詳細がみられる
https://www.ncl.ucar.edu/Document/Graphics/color_table_gallery.shtml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment