Windbar (wks, lat, lon, u, v) - 大氣科學系

Transcription

Windbar (wks, lat, lon, u, v) - 大氣科學系
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Introduction(day 1)
Language Basics(day 1)
Input / Output(day 1)
11/02,
11/02,2004@NCU
11/04,
11/04,2004@CCU
3/143/14-16,
16,2005@CWB
10/01 ,2005@NTU
7/27,
7/27,2009@CCU
Functions and Statistical methods(day 2)
Graphics(day 3)
Update:2009.07.23
Function
average、
average、summary、
summary、rootroot-meanmean-square
standard deviation、
deviation、variance、
variance、 running average
climatology、
climatology、seasonal mean
Statistic method
Correlation、
Correlation、Regression、
Regression、Spectral、
Spectral、FFT、
FFT、EOF
SVD、
SVD、Wavelets、
Wavelets、Filter、
Filter、T-Test、
Test、Taylor Diagrams
Special
vertical integral、
integral、interpolation、
interpolation、gradient、
gradient、dtrend
、moisture、
moisture、Laplacian、
Laplacian、9 point smoothing、
smoothing、Vorticity
、Divergence、
Divergence、stream function、
function、velocity potential
Why Learn NCL
※ Integrated processing environment
pdf png
(Data)
(Figures)
jpg gif
(Datas)
Datas)
※ freeware: supported public domain software
※ portable: Linux/Unix, Windows, MacOSX
※ excellent graphics
Tu@CCU
1/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Software and Paths
● Binaries … Free (Download)
※ http://www.earthsystemgrid.org/
● NCAR PATH ( C-Shell )
※ setenv NCARG_ROOT /usr/local/lib/ncarg_4.3.1
※ set path = ( /usr/local/lib/ncarg_4.3.1/bin )(自訂)
Useful NCL related URLs
● CSM and NCL links
http://www.ncl.ucar.edu
http://www.ncl.ucar.edu
● NCL functions and procedures
http://www.ncl.ucar.edu/Document/Functions/list_alpha.shtml
http://www.ncl.ucar.edu/Document/Functions/list_alpha.shtml
● NCL Graphics Example Pages
http://www.ncl.ucar.edu/Applications/index.shtml
http://www.ncl.ucar.edu/Applications/index.shtml
Tu@CCU
2/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Functions and Procedures
NCL commitment to help !
Color Table
Tu@CCU
[email protected]
[cc: [email protected] , [email protected]]
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
3/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
NCL
Fortran {C}
• interpreted language
– no optimization
• compiled language
– high optimization {good}
• subscripts are 0 based
• subscripts are 1 based {0}
• row major
• column major {row}
• right index fastest varying
• left index fastest varying {right}
• \ continue next line
• col 6 [f77]; ; & [f90] continue
• ; comment
• c [f77]; ![f90] comment { ; }
• + string concatenation
• // char concatenation {strcat}
• built in file handling for nc,
grb, ccm, hdf, (hdfeos )
Demo Script: Input/Function/Graphics
ODM!ᄃ GPSUSBO!შॾळᇾमள
NCL
load
load
load
load
Fortran {C}
dat ( lev , lat , lon ) <=map=> dat ( lon , lat , lev )
dat ( N , M )
<==>
dat ( M , N )
dat ( 0 , 0 )
<==>
dat ( 1 , 1 )
dat ( 0 , 1 )
<==>
dat ( 2 , 1 )
dat ( 0 , 2 )
<==>
dat ( 3 , 1 )
dat ( 1 , 0 )
<==>
dat ( 1 , 2 )
dat ( 1 , 1 )
<==>
dat ( 2 , 2 )
dat ( 1 , 2 )
<==>
dat ( 3 , 2 )
begin
input = addfile("/ptmp/shea/TMP_1958-1997.nc", "r") ; open netCDF file
dat = input->T
; dat (time,lev,lat,lon)
wks = gsn_open_wks("pdf", "demo")
gsn_define_colormap(wks,"gui_default")
; open a graphic file
; color map
hov = dim_avg(dat ( lev|: , lat|: , lon|: , time|: ))
; function
res
= True
res@cnFillOn
= True
res@gsnSpreadColors = True
res@gsnMaximize
= True
res@cnLineLabelFont = 21
; change default plot
; use colors
; use entire color map
; max plot size
; Label font
(屬性設定)
plot = gsn_csm_contour_map_ce(wks, hov(3 , {-60:60} , {100:300} ), res )
end
Executing NCL
Symbols
• Interactive Mode (Command line)
;
prompt> ncl <return>
ncl> enter commands (no begin/end)
ncl> quit
<return>
– can save interactive commands
ncl> record (“file_name”)
ncl> stop record
@
設定參數屬性或大小( ex:
ex:res@
res@vpXF = 0.12 )
沿用先前已設定過的字串( var = $vname+
$vname+””-”+$vyr)
+$vyr)
設定陣列大小( hov = new((/ny,nx
/),"float"))
)
new((/ny,nx/),"float")
!
設定陣列維度名稱(ex
:hov!
設定陣列維度名稱(ex:
ov!0 = “lat”
lat” , hov!
hov!1 = “lon”
lon”)
&
設定座標系統下各個維度相對應的數值。(ex
:hov&
設定座標系統下各個維度相對應的數值。(ex:
ov&lat = rlat)
{...}
4/41
註解符號(等同於fortran77
註解符號(等同於fortran77 的 C 或 fortran90 的 !)
$
(/.../)
• Batch Mode [ < and .ncl are optional ]
– prompt> ncl < script.ncl
– prompt> ncl script.ncl [also acceptable]
– prompt> ncl < script.ncl > &! script.out
– prompt> ncl < script.ncl > &! script.out &
※ scripts require begin………end statements
※ appending "&" means put in background
※ note: the >&! & are appropriate for csh and tcsh
Tu@CCU
" $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl "
" $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl "
" $NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl“
" $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
在座標系統下設定座標範圍 (ex: hov=hov({
hov=hov({--20:20},{90:200}))
:
設定陣列中每個維度的範圍與間隔 ( hov(
hov(20:90:2 , ::5) )
|
用於區隔維度名稱與維度 ( hov(:)=
dim_avg(dt(lat|:,lon|:))
|:)) )
hov(:)=dim_avg(dt(lat|:,lon
\
連續符號(相當於fortran
第六格的作用,置於最尾端)
連續符號(相當於fortran第六格的作用,置於最尾端)
->
用於資料的 I/O ( dtmp = input).
input->olr ) (前後不能有空格
(前後不能有空格).
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Manual Array Creation
• array
Automatic Array Creation
constructor characters (/…/) 【類似 fortran的data宣告 】
•
– a_integer
= (/1,2,3/)
= (/1.0, 2.0, 3.0/)
,
a_double = (/1., 2, 3.2d0 /)
– a_string
= (/"a","b","c"/)
– a_logical = (/True, False,True/)
– a_2Darray = (/ (/1,2,3/), (/4,5,6/), (/7,8,9/) /) = 3 x 3的矩陣
variable to variable assignment
–
– a_float
–
•
data importation via supported format
–
• new function [Fortran dimension, allocate]
–
– x = new (array_size, type, missing value)(missing value is optional)
– a = new(3, float)
•
– b = new(10, double, 1d+20)
– c = new( (/ 5, 6, 7 /), integer)
y=x
y => same size, type as x plus meta data
no need to preallocate space for y
u = input->U
same for subset of data: u = f->U(:, 3:9:2, :, 10:20)
– meta data (coordinate will reflect subset)
functions
return array: no need to preallocate space
T42 = f2gsh ( gridi, (/ 64,128/), 42)
– gridi(10,30,73,144) Î T42(10,30,64,128)
–
– d = new(dimsizes(U), string)
–
– e = new(dimsizes(ndtooned(U)), logical)
• new and (/…/) can appear anywhere in script
ƒ
delete
T42 = f2gsh_Wrap ( gridi, (/ 64,128/), 42) ; contributed.ncl
Attributes
Deletes variables,
variables, attributes, and coordinate variables.
•
delete ( data )
assign/access with 「@」 character
T@long_name
T@wgts
– T@x3d
–
–
Example 1 (integer to float)
float)
= “temperature”
= (/ 0.25, 0.5, 0.25 /)
= x3D
x = (/1,2,3,4,5/)
res@vpWidthF
res@vpHeightF
res@cnMinLevelValF
res@cnMaxLevelValF
res@cnLevelSpacingF
delete(x
delete(x)) ; The delete is necessary because
x = (/1.,2.,3.,4.,5./) ; was originally an integer array.
Example 2 (size remodel)
remodel)
=
=
=
=
=
delx
dely
cmin
cmax
cint
x = (/1,2,3,4,5/)
•
delete(x
delete(x)) ; The delete is necessary because
x = (/1,2,3,4/) ; was originally an array of 5 elements.
delete can eliminate an attribute
–
Dimensions ( GrADS )
delete(T@long_name)
Name Dimensions ( NCL)
XDEF 128 LINEAR 0 2.8125
• May be “named”
YDEF 64 LEVELS -87.864 -85.097 -82.313 -79.526 -76.737 -73.948
-71.158 -68.368 -65.578 -62.787 -59.997 -57.207
-54.416 -51.626 -48.835 -46.045 -43.254 -40.464
-37.673 -34.883 -32.092 -29.301 -26.511 -23.720
-20.930 -18.139 -15.348 -12.558 -9.767 -6.977
-4.186 -1.395 1.395 4.186 6.977 9.767
12.558 15.348 18.139 20.930
20.930 23.720 26.511
29.301 32.092 34.883 37.673
37.673 40.464 43.254
46.045 48.835 51.626 54.416
54.416 57.207 59.997
62.787 65.578 68.368 71.158
71.158 73.948 76.737
79.526 82.313 85.097 87.864
87.864
陣列的維度由左至右從零開始(0、1、2、……… )依序編號
ex:T (nz,ny,nx) 【 T(nx,ny,nz) → fortran】
• 設定維度名稱需採用符號「!」 {let T(nz,ny,nx)}
定義完各個座標名稱之後,我們就可以將陣列的維度
– T!0 = "lev"
編排方式依照個人需求重新排列,而座標變數也可以
– T!1 = "lat "
用來代表座標軸的index,例如:
reordered_T = T(lon|:,lat|:,lev|:)
– T!2 = "lon"
• assign dimension name(s) → functions
dd= nameDim(dd , dimNames[*] , longName , units)
【T = nameDim (T, (/ "lev" , "lat " , "lon" /), "Temperature", "C") 】
【u = nameDim (u, (/"time","lev","lat","lon"/), "zonal wind","m/s"】
ZDEF 12 LEVELS 1000 925 850 700 600 500 400 300 250 200 150 100
TDEF 5000 LINEAR 15jan1860 1mon
Tu@CCU
5/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Longitude Manipulators གྷ‫ޘ‬Ҝཉ
T ( nz , ny , nx ) -> Tnew ( nx , ny , nz )
經度
rlon = lonGlobeF (nx,
", "longitude", "degrees_east
")
nx, "lon
"lon",
"degrees_east")
lon will run from 0 to (360-
360-rint)
rint)
Fortran
【註】如果nx
如果nx = 144,那麼經度範圍將會介於
144,那麼經度範圍將會介於 0 到 357.5 之間
rlon = lonGlobeFo (nx,
", "longitude", "degrees_east
")
nx, "lon
"lon",
"degrees_east")
lon will run from(
from(rint/2)
rint/2)to(
to(360-
360-rint/2)
rint/2)
【註】如果nx
1.25 到 358.75 之間
如果nx = 144,那麼經度範圍將會介於
144,那麼經度範圍將會介於1.25
rlon = fspan(0 , 360 *(nx*(nx-1) /nx
/nx , nx)
nx)
NCL
rlon = (/ rlonrlon-180. /)
; grid goes DateLine eastward
Lon /Lat/Weights གྷቛშॾᝋࢦ
Latitude Manipulators ቛ‫ޘ‬Ҝཉ
緯度
權重
rlat = latGlobeF (ny,
")
ny, "lat", "latitude", "degrees_north
"degrees_north")
gwts = latGauWgt (ny,
")
ny, "lat", "gaussian
"gaussian weights", "dimension_less
"dimension_less")
lat will run from 90S to 90N
Generate gaussian weights and meta data
【註】如果nx
如果nx = 73,那麼緯度範圍將會介於
73,那麼緯度範圍將會介於 90S 到 90N 之間
gwts = NormCosWgtGlobe(rlat)
NormCosWgtGlobe(rlat)
rlat = latGlobeFo(ny,
")
latGlobeFo(ny, "lat", "latitude", "degrees_north
"degrees_north")
normalize the cosine wgts
lat will run from (-90
+rint/2)
(-90+
rint/2)to(
to(90-
90-rint/2)
rint/2)
gwts = SqrtCosWgtGlobe(rlat)
SqrtCosWgtGlobe(rlat)
【註】如果nx
如果nx = 72,那麼緯度範圍將會介於
72,那麼緯度範圍將會介於 88.75S 到 88.75N 之間
rlat = latGau
也可以使用
gau_info = gaus(ny/2)
(ny,
")
ny, "lat", "latitude", "degrees_north
"degrees_north")
Generates gaussian latitudes and associated meta data.
rlat
rlat = rlat(::rlat(::-1)
; divide by 2 to get "per hemisphere"
或 gau_info = doubletofloat(gaus(nlat/2));
doubletofloat(gaus(nlat/2)); convert double the float
; grid goes from North → South
= gau_info(:,0
gau_info(:,0)
; gaussian latitudes ( 1st dimension of gau_info)
gau_info)
gwts = gau_info(:,1
gau_info(:,1)
; gaussian weights ( 2nd dimension of gau_info)
gau_info)
Create and Assign Coordinate Variables
geographical coordinate arrays with
named dimensions and units
•
U = new ((/ 12 , 73 , 144 /) , " float " , U@_FillValue)
rlon = lonGlobeF (nx, "lon", "longitude", "degrees_east")
rlat = latGlobeF (ny, "lat", "latitude", "degrees_north")
plev = (/1000,925,850,700,600,500,400,300,250,200,150,100/)
plev皆需給定單位)
plev@units = "hPa" (rlon、rlat、plev皆需給定單位)
named dimensions
Latitude
Longitude
LATITUDE
LONGITUDE
lat
lon
Lat
Lon
LAT
LON
hlat
hlon
lat_u
lat_t
lon_u
lon_t
Tu@CCU
create vector array
units
degrees_north
degrees_east
degrees-north
degrees-east
degree-north
degree-east
degrees north
degrees east
degrees_N
degrees_E
–
Degrees_east
Degrees_east
–
•
assign dimension name(s) → functions
U = nameDim (U , (/ "lev " , "lat " , "lon" /), "zonal wind", "m/s")
•
assign coordinate variables to U → via『&』
U&lon = rlon
U&lat = rlat
– U&lev = plev
6/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Variable Subscripting (1 of 2)
Create and Assign Coordinate Variables
假設 SST 是一個二維陣列,大小為(nlat
是一個二維陣列,大小為(nlat,, nlon),那麼
nlon),那麼
要定義維度的名稱,可以使用符號「!
要定義維度的名稱,可以使用符號「!」,如果要將座標
軸相對應的數值帶入,則可使用符號「&
軸相對應的數值帶入,則可使用符號「&」。
SST!0
SST!1
=
=
※ Standard subscripting(標準網格註腳, similar to f90 and f77)
每個註腳的維度開始值從0 到 ( N-1 ) ,由右至左 ( nt, ny, nx ) ,維度之間用逗號
( , )區隔。標準的註腳寫法 → 【開始值 : 結束值 : 間隔大小】亦可簡化成【:】
"lat"
"lon"
lon"
rlon
rlat
=
=
fspan(0.,355.,72)
fspan(
fspan(-90.,90.,37)
rlon@units
rlat@units
=
=
"degrees_east"
degrees_east"
"degrees_north"
degrees_north"
SST&lon
SST&lat
=
=
dat = T( : , {-30:30} , : )
Î 取所有時間和經度,緯度從30S到30N的資料。
dat = T( : , {-20:20} , {90:290:2} ) Î 取所有時間, 緯度從20S到20N
經度從90到290,每間隔2取一筆資料。
Array Dimension Reduction
•
indicated by 「 | 」(維度名稱與座標位置間的區隔符號)
T
= nameDim (T , (/ "lev
")
"lev " , "lat " , "lon
"lon"" /), “Temperature", "m/s
"m/s")
rlon
= lonGlobeF(nx,"lon","longitude","degrees_east")
lonGlobeF(nx,"lon","longitude","degrees_east")
rlat
= latGlobeF(ny,"lat","latitude","degrees_north")
latGlobeF(ny,"lat","latitude","degrees_north")
plev
= (/1000,925,850,700,600,500,400,300,250,200,150,100/)
0, : , : )
Î Tjan(64,128)
– Tjan automatically becomes 2D
– all applicable meta data copied
•
plev@units = "hPa
"hPa""
T&lat = rlat , T&lon = rlon , T&lev=
lev=plev
Î makes dd (lat,lon,lev)
lat,lon,lev)
dd = T(lev|:
90∘E~120∘
120∘E , 20∘
20∘S~20∘
20∘N
T(lev|:,,{lon|
lon|90:120}
90:120},{lat|
lat|-20:20}
20:20}) Î all levels , 90∘
can override dimension reduction
Î Tjan(
Tjan( 1 , 64 , 128 )
– Tjan
= T( 0 : 0 , : , : )
– Tjan
= new(
/),, typeof(T
), T@_FillValue)
new( (/1,64,128
(/1,64,128/)
typeof(T),
T@_FillValue)
ƒTjan(0,:,:)
jan(0,:,:) = T(0,:,:)
Î all levels , 90∘
90∘E~120∘
120∘E , 20∘
20∘S~20∘
20∘N
_FillValue
Standard and Coordinate Subscripting
Latitude coordinate variable (1D)
let T ( 12 , 64 , 128 )
– Tjan = T(
假設一個陣列 T(nz,ny,nx)
T(nz,ny,nx)
• most NCL functions ignore _FillValue
named/coordinate subscripting can be mixed
Standard
T(8:15,1:12)
– “missing_value”
missing_value” has no special status to NCL
Coordinate
– if “T” has “missing_value”
missing_value” but no “_FillValue ”
T({-30:30},{-180:-90})
• T@_FillValue = T@missing_value
Combined
Tu@CCU
Î 1st time index, reverse lat order,1st 51 lon
資料陣列中,每個維度都可用一個一維陣列加以表示,數值大小可以依序增加,
也可逐漸減小,座標標註可用 『 {...}』加以表示。假設T(nt,ny,nx)
rlon
rlat
Longitude coordinate variable (1D)
Î 1st time index, all lat, every 5th lon
T(0 , : : -1 , : 50 )
※ Coordinate subscripting(加註座標軸的註腳,similar to GrADS)
※ Named / Coordinate subscripting(加註座標名稱)
dd = T(:
T(:,29:
,29:45,{
45,{lon|
lon|90:120}
90:120})
Î entire array [ don't use T(:,:,:) ]
T( 0 , : , : : 5 )
T( : 1 , 45 , 10 : 20 ) Î 1st 2 time indices, 46th index of lat, 10-20 indicies of lon
Variable Subscripting (2 of 2)
dd = T(lat|:
lev|:))
T(lat|:,, lon|:
lon|:,, lev|:
T
– T@_FillValue = -99.99
T({-30:30}, 1:12)
7/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Expressions
Data Types
Algebraic operators
+
-
*
/
^
>, <
加(除了數字加減外,也可用於文字)
減
乘
除(除法的運算速度較慢,所以建議改用乘)
指數(10^2 = 102)
大於, 小於
algebraic operator
5.3 + 7.95 Î 13.25
5.0 * 3.0 Î 15.0
string concatenator
"alpha" + (5.3 + 7)Îalpha12.3
"A="+3+" B="+5 ÎA=3 B=5
Do Loops
.lt.
.le.
.gt.
.ne.
.eq.
.and.
.xor.
.or.
.not.
Logical
小於
小於等於
大於
不等於
等於
and
exclusive-or
or
Not
if (scalar_logical_expression) then
[statements]
end if
do while (expression)
[statements]
end do
if (scalar_logical_expression) then
[statements]
else
[statements]
end if
break: jump to first statement
after end do [f90: exit]
2
2
T (i , j ) = 100 − (8 i ) + (8 j )
do j= 1,ny
do i= 1,nx
T( j-1 , i-1 ) = 100.0 - sqrt((8.0*i)^2 + (8.0*j)^2)
end do
; 88 seconds
end do
do j= 1 , ny
do i= 1 , nx
T(j-1,i-1) = i^2 + j^2
end do
end do
T = 100.0 - sqrt((8.0^2) * T)
※ no if (logical_expression) [statements]
print (1 of 3)
Minimize Use of Loops (2 of 2)
; <1 sec----------
•
Prints out all variable information including
–
–
ispn = ispan( 1 , nx , 1 )^2
jspn = ispan( 1 , ny , 1 )^2
do i= 0,dimsizes(ispn)-1
T(:,i) = ispn(i) + jspn
end do
T = 100.0 - sqrt((8.0^2) *T )
meta data, values
T(lat,lon): print (T)
Fortran?
Variable: T
Type: float
Total Size: 32768 bytes
8192 values
Number of Dimensions: 2
Dimensions / Sizes: [lat | 64] x [lon | 128]
Coordinates:
lat:
[-87.86379 .. 87.86379]
lon: [ 0. 0 .. 357.1875]
Number of Attributes: 2
long_name: Temperature
units:
C
(0,0) -31.7
(0,1) -31.4
(0,2) -32.3
(0,3) -33.4
(0,4) -31.3 etc. [entire T array will be printed]
T = onedtond(ispan(1,nx,1),(/ny,nx/))
T!0 = "x"
T!1 = "y"
T = 100.0 - sqrt((8.0*T(:,:))^2 + (8.0*T(y | :, x | :))^2)
Tu@CCU
complex NOT supported
; 136 seconds
※ “end if ”, “end do”
※ do loop 運算速度非常緩慢,盡量避免使用。
; <1 sec
•
• parameters for each example:
– nx=1000, ny=1000
– T=new( (/ny,nx/),float)
※ no “else if ”
continue: proceed to next
iteration [f90: cycle]
character
float (32 bit)
integer (32 bit)
double (64 bit)
long (32 bit) [SGI 64]
short (16 bit)
byte ( 8 bit, 0-255)
Minimize Use of Loops (1 of 2)
If Statements
do n = start , end , skip
[statements]
end do
•
•
•
•
•
•
•
8/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
print (2 of 3)
•
print (3 of 3)
can be used to print a subset of array
–
–
•
meta data, values
T(nlat,nlon): print( T(:,103) ) or print( T(:,{110}) )
print with embedded strings
–
–
no meta data
print ( "min(T)="+min(T)+" max(T)="+max(T) )
(0) min(T)=-53.8125 max(T)=25.9736
Variable: T (subsection)
Type: float
Total Size: 256 bytes
64 values
Number of Dimensions: 1
Dimensions / Sizes: [lat | 64]
Coordinates:
lat:
[-87.86379 .. 87.86379]
Number of Attributes: 3
long_name: Temperature
units:
C
lon:
109.6875 [ added ]
(0) -40.7
(1) -33.0
(2) -25.1
(3) -20.0
(4) -15.3 etc.
• sprintf
and sprinti provide formatting
- often used in graphics
- print ( "min(T) = "+ sprintf("%5.2f ", min(T)) )
• sprinti can left fill with zeros
(ex: let n=3)
- fnam = "h" + sprinti ("%0.5i", n) + ".nc"
- print("file name = "+fnam)
printVarSummary
• Print out variable (data object) information
–
–
–
–
type
dimension information
coordinate information (if present)
attributes (if present)
• printVarSummary (u)
Variable: u
Type: double
Total Size: 1179648 bytes
147456 values
Number of Dimensions: 4
Dimensions / Sizes: [time | 1] x [lev | 18] x [lat | 64] x [lon | 128]
Coordinates:
time: [4046..4046]
lev: [4.809 .. 992.5282]
lat: [-87.86379 .. 87.86379]
lon: [ 0. 0 .. 357.1875]
Number of Attributes: 2
long_name: zonal wind component
units:
m/s
Supported formats in NCL
● ASCⅡ
ASCⅡ
● Fortran Binary ( sequential / direct )
[open(11,form="unformatted", access="sequential")]
[open(11,form="unformatted",access
=direct",recl=_)]
[open(11,form="unformatted",access=
direct",recl=_)]
● NetCDF (Network
Network Common Data Format)
● GRIB (Grid
Grid in Binary; WMO standard)
● HDF (Hierarchical Data Format (Scientific Data Set only) )
● HDFHDF-EOS (Earth Observing System)
● CCMHT (CCM History
History Tape)
Tu@CCU
9/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Reading / Writing ASCII files
Reading
head = readAsciiHead (fname:string , opt:numeric)
opt:numeric)
data = asciiread (fname:string , dimensions , datatype:string)
datatype:string)
remove any previously exist file
data = readAsciiTable (fname:string , ncol:integer , datatype:string , opt)
system (path+"/rm "+ofn)
Writing
asciiwrite (fname:string , dat)
dat)
write_matrix → 2D
number of rows and columns
行
列
nrow = numAsciiRow ( ifn : string)
ncol = numAsciiCol ( ifn : string)
ASCII file:Time Series Data
Assume you have the file "test.dat
"
"test.dat"
DARWIN SEA LEVEL PRESS
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
行
列
YEAR
JAN FEB MAR
1951
1952
1953
1954
1955
……
[snip]
5.3 5.1
6.7 7.1
0.4 -1.6
1.0 -1.2
-1.1 2.9
APR
MAY JUN
JUL
AUG
SEP
SEP
7.0 9.4 11.9 11.2 13.3 13.2
13.2 12.5
8.3 10.3 10.3 12.5 13.0 12.6 12.1
-1.4 -0.1 -3.6 -0.5 -0.2 -3.1 -2.4
-0.5 0.6 0.4 -0.5 0.4 1.3 0.3
0.1 -0.8 1.4 1.7 2.7 2.0 2.5
OCT NOV
11.4
9.9
-0.3
0.1
2.5
DEC
9.5
7.7
-0.7
0.2
2.2
8.9
8.4
-1.1
2.4
1.7
【方法一】
方法一】
【方法二】
方法二】
ncol = numAsciiCol("test.dat
")
numAsciiCol("test.dat")
soi
nm = 13
head = readAsciiHead(
readAsciiHead( ifn , 2 )
soi = new((/nt,
nm/),"float")
/),"float")
new((/nt,nm
nrow = numAsciiRow("test.dat")
numAsciiRow("test.dat")
head = readAsciiHead(
")
readAsciiHead( ifn , "YEAR
"YEAR"
SOI = readAsciiTable(ifn,
readAsciiTable(ifn, nm,
nm, "float", 2 )
SOI = asciiread(ifn , (/nt,nm
/),"float" )
(/nt,nm/),"float"
SOI = readAsciiTable(ifn,
YEAR")
")
readAsciiTable(ifn, nm,"float","
nm,"float","YEAR
= new((/nt,
nm/),"float")
/),"float")
new((/nt,nm
由於不需要使用do
由於不需要使用do loop讀取資料,所以必須給定剛好的時間筆數
loop讀取資料,所以必須給定剛好的時間筆數
઄నᇾᐝΒӣᇴф
YEAR MON NINO1+2
NINO1+2 ANOM NINO3
NINO3
ANOM NINO4
NINO4
ANOM NINO3.4
NINO3.4
ANOM
2004 1
2004 2
2004 3
2004 4
2004 5
2004 6
2004 7
2004 8
2004 9
2004 10
2004 11
2004 12
-1.64
-1.85
-0.43
-0.76
-1.14
-0.74
-0.41
-0.44
-0.71
-0.57
-1.15
-0.64
-0.73
-1.24
-1.09
-1.28
-0.92
-0.79
-0.73
-0.91
-1.37
-0.77
-1.23
-1.01
-1.50
-1.77
-0.73
-0.94
-1.47
-0.70
-0.48
-0.59
-1.09
-0.57
-1.09
-0.93
23.49
24.56
25.59
23.84
23.41
21.70
20.74
20.52
19.82
20.19
20.46
21.92
-1.00
-1.49
-0.89
-1.62
-0.93
-1.32
-1.11
-0.30
-0.65
-0.72
-1.22
-0.92
23.97
24.51
26.65
26.65
25.91
25.64
25.17
24.51
24.12
24.32
23.80
24.44
27.41
26.77
27.00
27.12
27.72
27.85
27.84
27.54
27.12
27.64
27.13
27.27
25.01
24.92
26.41
26.75
26.30
26.79
26.59
26.11
25.56
26.03
25.42
25.54
(0,0)
1
(0,1)
2
(0,2)
3
SST
(0,3)
4
head = readAsciiHead( ifn , 1 )
(0,4) 3.4
(0,6)
SST = asciiread(ifn , (/nm,nn/),"float" )
1
SST = readAsciiTable(ifn, nn, "float", 1)
(0,7) 23.49
(0,8) -1
(0,9) 23.97
【方法二】
(1,0) -1.64
nn
nn
= 10
(1,1) 27.41
SST = new((/nm,nn/),"float")
nm = 12
(1,2) -0.73
head = readAsciiHead( ifn , 1 )
SST = new((/nm,nn/),"float")
head = readAsciiHead( ifn , "YEAR" )
SST = readAsciiTable(ifn, nn, "float", 1)
SST = asciiread(ifn , (/nm,nn/),"float" )
SST = readAsciiTable(ifn, nn,"float","YEAR")
Tu@CCU
= new((/nt,nn/),"float")
(0,5) 2004
【方法一】
= 10
【方法一】
(1,3) 25.01
(1,4) -1.5
10/41
YEAR MON NINO1+2 ANOM NINO3
ANOM NINO4
ANOM NINO3.4
ANOM
2004 1
2004 2
2004 3
2004 4
2004 5
2004 6
2004 7
2004 8
2004 9
2004 10
2004 11
2004 12
-1.64
-1.85
-0.43
-0.76
-1.14
-0.74
-0.41
-0.44
-0.71
-0.57
-1.15
-0.64
-0.73
-1.24
-1.09
-1.28
-0.92
-0.79
-0.73
-0.91
-1.37
-0.77
-1.23
-1.01
-1.50
-1.77
-0.73
-0.94
-1.47
-0.70
-0.48
-0.59
-1.09
-0.57
-1.09
-0.93
23.49
24.56
25.59
23.84
23.41
21.70
20.74
20.52
19.82
20.19
20.46
21.92
-1.00
-1.49
-0.89
-1.62
-0.93
-1.32
-1.11
-0.30
-0.65
-0.72
-1.22
-0.92
23.97
24.51
26.65
26.65
25.91
25.64
25.17
24.51
24.12
24.32
23.80
24.44
27.41
26.77
27.00
27.12
27.72
27.85
27.84
27.54
27.12
27.64
27.13
27.27
25.01
24.92
26.41
26.75
26.30
26.79
26.59
26.11
25.56
26.03
25.42
25.54
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Writing ASCII files
ifn
ofn
nx
ny
dat
write_matrix(dat
[*][*], format,
write_matrix(dat[*][*],
format, opt)
prettypretty-print 2D array to standard out
integer, float, double
= "/glacier2/tu/data/xy.asc"
= "new.asc
"new.asc""
= 144
= 73
= asciiread ( ifn , (/ny,nx
/) , " float " )
(/ny,nx/)
user format control (format)
T(7,5): write_matrix (T, " 5f7.2 ", False) Æ 在螢幕上顯示結果
4.35
4.36
9.73
4.91
0.17
-0.63
-4.29
asciiwrite (ofn,
ofn, dat)
dat)
0.8400397
0.55219
0.2622927
-0.02875445
………
4.39
4.66
-5.84
4.59
3.68
-4.12
0.07
0.27
3.77
0.89
-3.09
5.08
-2.51
5.85
-3.35
-1.66
8.46
7.55
0.14
1.76
0.87
-6.90
4.06
10.39
4.56
-5.63
-1.43
8.65
• can also create an ASCII file
Example
Reading/Writing Binary files
(STAND TAHITI - STAND DARWIN) SEA LEVEL PRESS
YEAR JAN FEB MAR APR MAY JUN JUL AUG
1951
2.7 1.0 -1.3 -1.1 -1.7 -0.5 -2.3 -1.2
1952 -2.0 -1.8
0.0 -0.9
1.0 0.8 0.7 -0.7
1953
0.4 -1.6 -1.4 -0.1 -3.6 -0.5 -0.2 -3.1
1954
1.0 -1.2 -0.5
0.6
0.4 -0.5 0.4
1.3
1955 -1.1 2.9
0.1 -0.8
1.4 1.7 2.7
2.0
Direct
SEP
-2.1
-0.4
-2.4
0.3
2.5
OCT
-2.3
0.3
-0.3
0.1
2.5
NOV
-1.6
-0.3
-0.7
0.2
2.2
DEC
-1.6
-2.6
-1.1
2.4
1.7
specified direct record
Sequential
multiple unformatted
sequential records
Cray Sequential
; #################################################
load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
; ##################################################
begin
0.00 -0.90
ifn = "aa.asc"
nm = 13
-1.40 -0.10
nt = 5
-0.50 0.60
soi = new((/nt,nm/),"float")
single unformatted
sequential record
Cray(C block IO write)
1.00 0.80 0.70
-3.60 -0.50 -0.20
0.40 -0.50 0.40
mimics a C block IO write
※ “rec” which start at 「
soi = readAsciiTable(ifn,nm,"float",2)
data = fbindirread (ifn,rec,dim,type)
fbindirwrite (ofn,data)
data = fbinrecread (ifn,rec,dim,type)
fbinrecwrite (ofn,rec,data)
data = craybinrecread (ifn,rec,dim,type)
fbinwrite (ofn,data)
data = cbinread (ifn,dim,type)
cbinwrite (ofn,data)
」
※ “type” : double、float、integer、byte…………….
※ 文字或資料型態設定採用雙引號。(var=“sst” , “float” , ……………)
※ sequential中的“rec”如果設為「
end
」,表依個人所要求之陣列大小輸出。
Reading NetCDF & Grib & HDF files
sequential binary format
fbinrecwrite (path+ofn,-1, lat)
fbinrecwrite (path+ofn,-1, lon)
fbinrecwrite (path+ofn,-1, sst)
lat=fbinrecread(ifn,0, ny, "float")
lon=fbinrecread(ifn,1, nx, "float")
sst=fbinrecread(ifn,2,(/ny,nx/),"float")
real rlon(nx), rlat(ny), sst(nx,ny)
open (11,file=ofn,form="unformatted"
,access="sequential")
read (11) rlat
read (11) rlon
read (11) sst
Fortran
; output subsection (lat,lon) only
do m=0,nm-1
fbinrecwrite(ofn,-1,dd(m,:,:))
end do
do m=1,nm
read(11)((dd(i,j,m),i=1,nx),j=1,ny)
enddo
Tu@CCU
direct binary format
SST
dat
ifn
ofn
=
=
=
=
※ 資料的副檔名必須依檔案類型作設定。
「NetCDF」→「nc」 或「cdf」
「GRIB」 →「grb」或「grib」
「HDF 」 →「hdf」或「hdfeos」
new ((/nt,nm,ny,nx/),"float" )
new ((/nm,ny,nx/),"float" )
"OIMSST_V2_1982_2003_mon.bin"
"OIMSST_V2_1982_2003_cli.bin"
do l=0,nt-1
do m=0,nm-1
【 read / write】
【 read only】
【 read / write】
※ 讀取相關類型資料之function
input = addfile (fname:string , status:string)→ 讀取單個檔
input = addfiles(fname:string , status:string)→ 讀取多個檔
rec = m + l*nm
SST( l , m , : , : )
=fbindirread(ifn,rec,(/ny,nx/),"float")
end do
end do
status = “r” (表示 read, 適用於所有格式之資料)
status = “c” (表示 create,適用於NetCDF和HDF4)
status = “w” (表示 write, 適用於NetCDF和HDF4)
do m=0,nm-1
fbindirwrite (ofn,dat( m , : , : ))
end do
open (11,file=ofn, form="unformatted“
,access="direct", recl=nx*ny)
可以利用「print (input)」
※ 範例
input= addfile("oisst.nc"," r ")
確認變數名稱
dims= filevardimsizes(input,"sst")
dd = new((/dims(0),dims(1),dims(2)/),float)
dd = input->sst
do m=1,nm
read (11,rec=m)
&
((dat(i,j,m),i=1,nx),j=1,ny)
end do
11/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
ncdump
Reading NetCDF files
ncl
dimensions:
lon = 144 ;
lat = 73 ;
time = UNLIMITED ; // (12 currently)
variables:
float lon(lon) ;
lon:units = "degrees_east" ;
lon:long_name = "Longitude" ;
lon:actual_range = 0.f, 360.f ;
float lat(lat) ;
lat:units = "degrees_north" ;
lat:actual_range = 90.f, -90.f ;
lat:long_name = "Latitude" ;
double time(time) ;
time:units = "hours since 1-1-1 00:00:0.0" ;
time:long_name = "Time" ;
time:actual_range = 0., 8016. ;
time:delta_t = "0000-01-00 00:00:00" ;
time:avg_period = "0000-01-00 00:00:00" ;
time:ltm_range = 17338824., 17487096. ;
short olr(time, lat, lon) ;
olr:long_name = "OLR monthly means" ;
olr:valid_range = 0.f, 500.f ;
olr:actual_range = 134.9129f, 293.3665f ;
olr:units = "W/m^2" ;
olr:add_offset = 327.65f ;
olr:scale_factor = 0.01f ;
olr:missing_value = 32766s ;
olr:var_desc="Outgoing Longwave Radiation\n", "O"
olr:dataset = "NOAA Interpolated OLR\n",
input = addfile("olr.mon.ltm.nc","r")
【抓取資料維度(dimensions)】
dims = filevardimsizes(input,"olr") ;
nlat = filevardimsizes(input,"lat")
mlon = filevardimsizes(input,"lon")
print(dims)
; #######
Variable: dims
Type: integer
Total Size: 12 bytes
3 values
Number of Dimensions: 1
Dimensions and sizes: [3]
Coordinates:
(0) 12
(1) 73
(2) 144
【讀variables之資料】
data = input->olr(0,:,:)
rlon = input->lon
rlat = input->lat
time = input->time
【讀variables內之參數】
unit = input->olr@units
add = input->olr@add_offset
scale = input->olr@scale_factor
spv = input->olr@missing_value
begin
; ##############
path
= " /glacier1/ECMWF/ERA15/PRS/PRS_1990/ "
ifn
= "ERA15_T106_PRS_1990_mon.grb "
input
= addfile(path+ifn,"r")
; ##############
printVarSummary(input)
end
; #######
begin
unit = input->olr@units
add = input->olr@add_offset
scale = input->olr@scale_factor
spv = input->olr@missing_value
path = "/glacier1/OLR/src/"
ifn = "OLR"OLR-197406197406-200411200411-mon.nc"
ofn = "NOAA_OLR_1979_2004.bin"
ifn = path+ifn
; #######
input = addfile(ifn,"r")
; #######
dd = inputinput->olr
; #######
dims = filevardimsizes(input,"olr")
nt = dims(0)
ny = dims(1)
nx = dims(2)
print(dims)
print(dims)
dd = new((/dims(0),dims(1),dims(2)/),"float")
; #######
do m=0,dims(0)-1
fbindirwrite(ofn,dd(m,:,:))
end do
; #######
end
begin
(reading
; #######
ifn
= "ERA15_T106_PRS_1990_mon.grb"
ofn
= "ERA15_T106_T_1990_mon.bin"
input = addfile(ifn,"r")
; #######
system("/bin/rm "+ofn)
; #######
dims = filevardimsizes(input," T_GDS4_ISBL_10 ")
print(dims)
; #######
dd = new((/dims(0),dims(1),dims(2)/),"float")
; #######
dd = input->T_GDS4_ISBL_10
; #######
do m=0,dims(0)-1
fbindirwrite(ofn,dd(m,:,:))
end do
; #######
end
GRIB
HDF
Variable: input
(0)
filename:
ERA15_T106_PRS_1990_mon
path: /glacier1/ECMWF/ERA15/PRS/PRS_1990/ERA15_T106_PRS_1990_mon.grb
file global attributes:
dimensions:
initial_time0 = 12
lv_ISBL1 = 17
g4_lat_2 = 160
g4_lon_3 = 320
initial_time4 = 12
variables:
float T_GDS4_ISBL_10 ( initial_time0, lv_ISBL1, g4_lat_2, g4_lon_3 )
center :
European Center for Medium-Range Weather Forecasts - Reading
long_name : Temperature
units :
K
_FillValue : -999
level_indicator :
100
grid_number : 255
parameter_number : 130
forecast_time :
19
grib)
get dimension sizes
Numerous functions to query contents of supported file
−
getfilevarnames
dpath = "/fs/cgd/data0/shea/ccm/"
file = "H200503"
getfilevardims
−
getfilevaratts
−
getfilevardimsizes
−
getfilevartypes
−
isfilevar
−
isfilevaratt
−
isfilevardim
−
isfilevarcoord
−
ext
ifn
• returns the dimension sizes of a variable
• will return 1D array of integers if the array queried
is multi-dimensional.
= ".ccm"
= addfile(dpath+file+ext , " r ")
dimsizes
(針對陣列)
vname = getfilevarnames (ifn)
if (isfilevarcoord(ifn, "U", "lat")) then
…
end if
Tu@CCU
filevardimsizes
(針對變數檔案)
12/41
begin
input=addfile("OLR.nc", "r")
; #######
dd =input->olr
dims = dimsizes(dd)
; #######
dims = filevardimsizes(input,"olr")
; #######
print(dims)
end
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
get dimension sizes
begin
input = addfile(“R2.nc”,”r”)
Type: integer
fnames = (/ "reAnal1","reAnal2","reAnal3","reAnal4"/)
Total Size: 16 bytes
•
t
4 values
= input->T
Number of dimensions: 1
Dimensions and sizes:(4)
print(dims)
(1) 25
(2) 116
print ("rank="+rank)
(3) 100
end
(0) rank=4
addfiles
•
input = addfiles (fnames, "r")
− fnames is a 1D array of file names (strings)
− can be used for any supported format
T = input[:]->T
− read T [values only] from each file in list 'input'
ƒ T will not have any meta data
− T must exist in each file and be same shape
[rank]
− a list is used to sequence results of addfiles
− normal file variable selection is used with "[…]"
(0) 12
rank = dimsizes(dims)
•
(1 of 2)
• spans multiple files
Variable: dims
dims = dimsizes(t)
•
addfiles
addfiles
(2 of 2)
begin
2 options on variable merging
−
ListSetType (a, "cat")
−
ListSetType (a, "join”)
fnames = (/ "reAnal1","reAnal2","reAnal3","reAnal4"/)
input = addfiles (path+fnames, "r")
[default; “cat” => concatenation]
ListSetType (input, "cat")
ListSetType (input, "join")
when to use "cat" and "join" [rule of thumb]
−
cat : continuous record
−
join : creating ensembles
a record dimension will be added
T
= input[:]->T
Number of Dimensions:
ListSetType (a, "join”) creating ensembles
cat
Dimensions and sizes:
Number of Dimensions:
meta data to variable
Tu@CCU
2 options on variable merging
ListSetType (a, "cat") continuous record
end
suggest using addfiles_GetVar [contributed.ncl]
−attaches
•
T1(time,lev.lat,lon)
join
Dimensions and sizes:
13/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Conversion between data types
function integertobyte
(int_val : integer)
function doubletobyte
(double_val : double)
function integertocharacter
(int_val : integer)
function doubletocharacter
(double_val : double)
function integertoshort
(int_val : integer)
function doubletoshort
(double_val : double)
function shorttobyte
(short_val : short)
function doubletointeger
(double_val : double)
function shorttocharacter
(short_val : short)
function doubletolong
(double_val : double)
function longtobyte
(long_val : long)
function longtocharacter
(long_val : long)
function doubletofloat
(double_val : double)
function longtoshort
(long_val : long)
function charactertodouble
(char_val : character)
function longtointeger
(long_val : long)
function charactertofloat
(char_val : character)
function floattobyte
(float_val : float)
function charactertolong
(char_val : character)
function floattocharacter
(float_val : float)
function charactertoshort
(char_val : character)
function floattoshort
(float_val : float)
function charactertostring
(char_val : character)
function floattointeger
(float_val : float)
function charactertointeger
(char_val : character)
function floattolong
(float_val : float)
function stringtocharacter
(char_val : string)
function stringtodouble
(char_val : string)
function stringtofloat
(char_val : string)
function stringtointeger
(char_val : string)
function stringtolong
(char_val : string)
function stringtoshort
(char_val : string)
abs( value:integer)
→ computes absolute value for integer input ( abs(-2) = 2)
fabs(value:numeric)
→ computes absolute value for numeric input (fabs(-1.2) = 1.2)
sin(value:numeric)
→ computes sin from radian input (sin(3.1415/180*45)=0.707)
asin(value:numeric)
→ computes inverse sin in radians
cos(value:numeric)
→ computes cosine from radian input
acos(value:numeric)
→ computes inverse cosine in radians
tan(value:numeric)
→computes tangent from radian input(tan(3.1415/180*45)=1.0)
atan(value:numeric)
→ computes inverse tangent in radians
atan2(y:numeric,x:numeric)
→ returns the arctangent of y/x in radians
tanh(value:numeric)
→ computes hyperbolic tangent from radian input
exp(value:numeric)
→ computes e to the power of the input(exp(1)=2.718282)
log(value:numeric)
→ computes natural log (log(10)=2.302585)
log10(value:numeric)
→ computes log base 10 (log10(10)=1.0)
sqrt(value:numeric)
→ computes square root of input (sqrt(2)=1.414)
max(arg:numeric)
→ returns the maximum value of an array
min(arg:numeric)
→ returns the minimum value of an array
從長字串中擷取出某個片段字串
假設有一個字串 "2005120800Z"
若欲取出 “1208”
1208” 則可按照下面的方式
time = "2005120800Z"
word = stringtocharacter(time)
stringtocharacter(time)
nwod = charactertostring(word(4:7))
nwod 就會等於 1208
求餘數
val = 182
print(val%3)
Î 2
Scalar regridding routines
假設原本資料之陣列維度為 dd(
dd(nlat,nlon)
nlat,nlon),轉換後之新資料維度為 gnew(
gnew(ny,nx)
ny,nx)
【Example 1】
=73, nlon=144
)轉換不同解析度之固定網格(ny
ny=181
=181 , nx=360
)
1】由固定網格(nlat
由固定網格(nlat=73,
nlon=144)轉換不同解析度之固定網格(
nx=360)
f2fosh
f2fsh
from one fixed grid to another using spherical harmonics
f2gsh
from one fixed grid to a Gaussian grid using spherical harmonics
fo2fsh
gnew = f2fsh(
f2fsh(dd ,(/ny,nx/
ny,nx/))
from one fixed grid (including pole points) to a fixed-offset grid using spherical harmonics
【Example 2】
=73, nlon=144
)轉換不同解析度之固定網格(ny
ny=72
=72 , nx=144
)
2】由固定網格(nlat
由固定網格(nlat=73,
nlon=144)轉換不同解析度之固定網格(
nx=144)
gnew = f2fosh(
f2fosh(dd)
dd)
【Example 3】
=72, nlon=144
)轉換不同解析度之固定網格(ny
ny=73
=73 , nx=144
)
3】由固定網格(nlat
由固定網格(nlat=72,
nlon=144)轉換不同解析度之固定網格(
nx=144)
gnew = fo2fsh(
fo2fsh(dd)
dd)
from one fixed-offset grid (including pole points) to a fixed grid using spherical harmonics
【Example 4】
=73, nlon=144
)轉換到高斯網格(T42
T42)(
)(ny
ny=64
=64 , nx=128
)
4】由固定網格(nlat
由固定網格(nlat=73,
nlon=144)轉換到高斯網格(
nx=128)
g2fsh
from one Gaussian grid to a fixed grid using spherical harmonics
g2gsh
from one Gaussian grid to another using spherical harmonics
gnew = f2gsh(
f2gsh(dd ,(/ny,nx/
ny,nx/), 42)
42)
【Example 5】
) (nlat=96,
)
5】由高斯網格(T63
由高斯網格(T63)
nlat=96, nlon=192)
nlon=192) 轉換到固定網格 (ny=73
ny=73 , nx=144
nx=144)
gnew = g2fsh(
g2fsh(dd ,(/ny,nx/
ny,nx/))
【Example 6】
)轉換到高斯網格((T42)(
)
6】由高斯網格(
由高斯網格(T63)(
T63)(nlat=96,
nlat=96, nlon=192
nlon=192)轉換到高斯網格
T42)(ny=64
ny=64 , nx=128
nx=128)
f:包含極點。fo:不包含極點。g:gaussian grid points
Tu@CCU
gnew = g2gsh(
g2gsh(dd ,(/ny,nx/
ny,nx/), 42)
42)
14/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
linint2
Vector regridding routines
Interpolates from one grid to another grid using bilinear interpolation.
interpolation.
f2foshv
function linint2 ( xold,
xold, yold,
yold, data, CyclicX , xnew,
xnew, ynew,
ynew, opt0 )
if the rightmost dimension of data is cyclic. Set CyclicX to True
interpolates a vector pair on a fixed grid to a Gaussian grid using
spherical harmonics
fo2fshv
interpolates a vector pair on a fixed-offset grid (including pole points) to
a fixed grid using spherical harmonics
interpolates a vector pair on a Gaussian grid to a fixed grid using
g2fshv
spherical harmonics
g2gshv
interpolates a vector pair from one Gaussian grid to another using
spherical harmonics
Compute Wind field - Global
假設原本資料之陣列維度為 → u(nt,
nt,nlat,nlon)、
nlat,nlon)、 v(nt,
nt,nlat,nlon)
nlat,nlon)
轉換後之新資料維度為
harmonics
f2gshv
sst (time,lat,lon)
time,lat,lon) 1x2degree grid , @_FillValue
@_FillValue is assigned
lats go from 64N to 74S , lons from 1 to 359E...
latnew = ispan (-74,64,2)
lonnew = ispan (1,359,2)
sstr = linint2_Wrap (sst&lon,sst&lat,sst
(sst&lon,sst&lat,sst,, True, lonnew,latnew,
lonnew,latnew, 0)
fixed-offset grid using spherical harmonics
interpolates a vector pair from one fixed grid to another using spherical
f2fshv
xi = (30,33,35,39,....., 80) [does not have to be equally spaced]
spaced]
yi = (0,1,2,3,....,28,29)
xo = (any coordinates between 30 and 80) [inclusive]
yo = (any coordinates between 0 and 29) [inclusive]
fo = linint2 (xi,yi,fi
(xi,yi,fi,, False, xo,yo,
xo,yo, 0)
interpolates a vector pair on a fixed grid (including pole points) to a
→ unew(
unew(nt,
nt,ny,nx)、
ny,nx)、 vnew(
vnew(nt,
nt,ny,nx)
ny,nx)
uv2dvf (u,v,div)
uv2dvg (u,v,div)
uv2vrf (u,v,vor)
uv2vrg (u,v,vor)
uv2vrdvf (u,v,vor,div)
uv2vrdvg (u,v,vor,div)
uv2sfvpf (u,v, sf, vp)
uv2sfvpg (u,v, sf, vp)
dv2uvf (div, udiv,vdiv)
dv2uvg (div, udiv,vdiv)
vr2uvf (vor,urot,vrot)
vr2uvg (vor,urot,vrot)
vrdv2uvf(vor,div,uu,vv)
vrdv2uvg(vor,div,uu,vv)
sfvp2uvf(sf,vp,uu,vv)
sfvp2uvg(sf,vp,uu,vv)
【Example 1】
=73, nlon=144
)轉換不同解析度之固定網格(ny
ny=181
=181 , nx=360
)
1】由固定網格(nlat
由固定網格(nlat=73,
nlon=144)轉換不同解析度之固定網格(
nx=360)
f2fshv(
f2fshv( u , v , unew , vnew)
vnew)
【Example 2】
=73, nlon=144
)轉換不同解析度之固定網格(ny
ny=72
=72 , nx=144
)
2】由固定網格(nlat
由固定網格(nlat=73,
nlon=144)轉換不同解析度之固定網格(
nx=144)
f2foshv(
f2foshv( u , v , unew , vnew)
vnew)
【Example 3】
=72, nlon=144
)轉換不同解析度之固定網格(ny
ny=73
=73 , nx=144
)
3】由固定網格(nlat
由固定網格(nlat=72,
nlon=144)轉換不同解析度之固定網格(
nx=144)
fo2fshv(
fo2fshv( u , v , unew , vnew )
【Example 4】
=73, nlon=144
)轉換到高斯網格(T42
T42)(
)(ny
ny=64
=64 , nx=128
)
4】由固定網格(nlat
由固定網格(nlat=73,
nlon=144)轉換到高斯網格(
nx=128)
f2gshv(
f2gshv( u , v , unew , vnew , 42)
42)
【Example 5】
) (nlat=96,
)
5】由高斯網格(T63
由高斯網格(T63)
nlat=96, nlon=192)
nlon=192) 轉換到固定網格 (ny=73
ny=73 , nx=144
nx=144)
g2fshv(
g2fshv( u , v , unew , vnew )
【Example 6】
)轉換到高斯網格((T42)(
)
6】由高斯網格(
由高斯網格(T63)(
T63)(nlat=96,
nlat=96, nlon=192
nlon=192)轉換到高斯網格
T42)(ny=64
ny=64 , nx=128
nx=128)
g2gshv(
g2gshv( u , v , unew , vnew , 42)
42)
; u,v ==> divergence
; u,v ==> relative vorticity
; u,v ==> divergence and vorticity
; u,v ==> stream function
+ velocity potential
; div ==> divergent wind components
; vor ==> rotational wind components
; vor,div =>reconstruct original wind
; sf,vp ==> reconstruct original wind
Variable Shaping
Compute Wind field - Regional
vor = uv2vr_cfd (u,v,lat,lon
(u,v,lat,lon,, opt) ==> vor (nlat,mlon)
nlat,mlon)
div = uv2dv_cfd (u,v,lat,lon
(u,v,lat,lon,, opt) ==> div (nlat,mlon
(nlat,mlon))
•
can and should be done without loops
–
opt =0 :boundary point are set to the missing value
(=u
(=u@_FillValue)
@_FillValue)
–
use NCL syntax or functions
very fast for variables in memory
Fortran : 3DÆ1D
=1 :the u and v arrays are cyclic in longitude.
longitude. The arrays
should NOT include the cyclic point. The upper and
lower boundaries will be set to missing
(=u
(=u@_FillValue)
@_FillValue)
dd(nx,ny,nz) Æ dd1(nn)
=2 :boundary points are estimated using oneone-sided difference
schemes normal to the boundary.
=3 :the u and v arrays are cyclic in longitude. The arrays
should NOT include the cyclic point. The upper and lower
boundaries are estimated using a oneone-sided difference
scheme normal to the boundary.
boundary.
Tu@CCU
15/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
• returns a 1D array of integers or floating
– beginning with start and ending with finish.
ndtooned ( val )
onedtond ( val , dims : integer )
ispan ( start:integer,
start:integer, finish:integer,
finish:integer, stride:integer )
a = (/ (/1,2,3/) , (/4,5,6/) , (/7,8,9/) /) → 3 x 3
print (ndtooned(a
))
(ndtooned(a))
→ (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /)
1
4
7
2
5
8
建立一組等間隔的整數序列
3
6
9
time = ispan(1990,2001,2)
print (time)
a = (/1, 2, 3, 4, 5, 6, 7, 8/)
print (onedtond(a
,(/ 2 , 4 /)))
(onedtond(a,(/
time=ispan(1990,2001,2)*1.0
→ a = ( / (/1,2,3,4/) , (/5,6,7,8/) / ) → 4 x 2
time would be Type: float
any、all、num
fspan ( start:float,
start:float, finish:float,
finish:float, num:integer )
常用於 「if statement」
statement」
建立一組等間隔的實數序列
any :Returns True if any of the values of its input evaluate as True.
all :Returns True if all the elements of the input evaluate as True.
num :Counts the number of True values in the input.
returns a 1D array of
evenly spaced floating
point numbers
• num is the number of
points including start and
finish
•
begin
b = fspan( 2, 6, 11 )
print(b)
end
Example 2
Example 3
x = new(5,float,new(5,float,-999)
x = new(5,float,new(5,float,-999)
a = (/1,2,3,4,5/)
x = (/1.,2.,(/1.,2.,-999,4.,5./)
x = (/1.,2.,(/1.,2.,-999,4.,5./)
print(num(a.gt.3)) → 2
print(any(x.ge.4))
print(all(x.ge.5)
print(all(x.ge.5)
N = num(.not.ismissing
(x))
))
num(.not.ismissing(x
; should be True
; should be False
print(any(x.lt.0))
if(all(ismissing
(x)))
))) then
if(all(ismissing(x
; should be False
print("x
print("x contains all missing values, cannot
print(any(x.gt.2.and.x.lt.4))
continue.")
; should be False
return
end if
mask
mask
use mask function to mask out a range of the data
sets values to _FillValue that DO NOT equal mask array
range_only = sst
range_only = mask( sst , (sst.ge.26) , True )
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
begin
; read in netCDF file
in = addfile("/wp/cgd/murphys/Data/ATMOS/atmos.nc","r")
ts = in->TS(0,:,:)
oro = in->ORO(0,:,:)
; mask out ocean or land data
; ocean=0, land=1, sea_ice=2
land_only = ts
ocean_only = ts
land_only = mask(ts,oro,1)
ocean_only = mask(ts,oro,0)
end
Tu@CCU
Example 1
range_only = mask( sst , (sst.ge.15.and.sst.le.26) , True )
16/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
ঈ෪૱ϡᇴጯࢍზё
ঈ෪૱ϡᇴጯࢍზё
Fortran
do I = 1 , nn
…..
enddo
A(nz,ny,nx)、B(nz,ny,nx)
C(nz,ny,nx)
C = A+B 或 C=A-B 或 C=A*B 或 C=2A+B
T(nz,ny,nx)、P(nz,ny,nx)
θ(nz,ny,nx)
T(nt,nz,ny,nx)、P(nz)
θ(nt,nz,ny,nx)
sum
θ= T * ( 1000/P ) ^0.286
function conform (A:numeric , B:numeric , ndim:integer)
【例】dd = conform (x(time|:,lat|:,lon|:,lev|:), dp, (/0,3/))
→ x(time,lev,lat,lon)、dp(ntim,klvl)、dd(ntim,nlat,mlon,klvl)
【例】dd = dim_sum(q*conform(q,dz,3))
→ q(nt,ny,nx,nz)、dz(nz) → dd(nt,ny,nx)
avg
→ 得到一個數值大小
stddev
ex : val = avg(dd)
avg(dd) 、 val = sum(dd)
sum(dd)
variance
θ= T * (1000/conform(T,P,1))^0.286
不同維度陣列的對應
計算所有資料的總和、平均、標準差、變異數。
【註】如果陣列中有特殊值,可以利用下面的方式避開
設定欲忽略之特殊值 → dd@_FillValue = - 99.99
min
計算實際運算之點數 → N = num(.not.ismissing(dd))
num(.not.ismissing(dd))
max
x = (/3., 2., 5., 1., 5., 2., 5., 1., 3., 2./)
minind
i = maxind(x
maxind(x))
maxind
j = minind(x
minind(x))
let SST be (100,72,144) and SICE = -1.8 (scalar)
SST = SST > SICE [f90: where (sst.lt.sice) sst = sice]
Compute n dimension index
Compute the rightmost dimension index
dim_avg
dim_sum
dim_stddev
dim_min
dim_max
dim_median
dim_num
dim_rmsd
dim_rmvmean
dim_rmvmed
dim_variance
dim_stat4
dim_standardize
dim_avg_n
dim_sum_n
dim_stddev_n
dim_min_n
dim_max_n
dim_median_n
dim_num_n
dim_rmsd_n
dim_rmvmean_n
dim_rmvmed_n
dim_variance_n
dim_stat4_n
compute the rightmost (n(n-1 th)
th) dimension at all other indices
計算最後一個維度
的平均、總和、標準差、去除平均值…
…等。
計算最後一個維度的平均、總和、標準差、去除平均值
【例】dd1 = new((/nt,nm
/),"float") → 定義陣列大小
new((/nt,nm/),"float")
dd3 = new((/3,nt/),"float") → 定義陣列大小
dd1!0 = "yy
"yy"" → 定義第一個維度的名稱為 “yy”
yy”
dd1!1 = "mm" → 定義第二個維度的名稱為 “mm”
mm”
dd3(0,:) = dim_avg(dd1(yy|:,mm|5:7)) → 計算JJA
的平均
計算JJA的平均
dd3(1,:) = dim_sum(dd1(yy|:,mm|5:7))→
的總和
dim_sum(dd1(yy|:,mm|5:7))→ 計算JJA
計算JJA的總和
dd3(2,:) = dim_rmvmean(dd3(0,:))
→ 去掉平均值
計算平均時,如果採用一般的點數作計算,則裡面所使用的維
度範圍需用整數,如果已用實際經緯度作對應則無此限制。
wgt_runave(dat, wgt [*], opt) → pass filter
wgt_areaave
wgt_areaave(dat, wgty[*], wgtx[*], opt)
wgt_areaave2
wgt_areaave2(dat, wgt [*][*], opt)
wgt_areasum2
wgt_areasum2(dat, wgt [*][*], opt)
wgt_arearmse
wgt_arearmse(dat1,dat2,wgty[*],wgtx[*],opt)
qAvgTime = dim_avg_n(
dim_avg_n( q, 0) ))
qAvgLon = dim_avg_n(
dim_avg_n( q, 2 )
【例】 Let q be defined q( time , lev , lat , lon ).
qSum = dim_sum_n(x
dim_sum_n(x,, (/ 0 , 1 /))
ঈ෪૱ϡᇴጯࢍზё
; ##########################################
rlon = lonGlobeF(nx, "lon", "longitude", "degrees_east")
rlat = latGau (ny, "lat", "latitude", "degrees_north")
wgty = latGauWgt(ny, "lat", "gaussian weights", "dimension_less")
; ###########################################
dd = nameDim (dd, (/"time","lat","lon"/), “Temp", “K")
dd&lat = rlat
dd&lon = rlon
wgty!0 = "lat"
wgty&lat = rlat
; #############################################
gb = wgt_areaave(dd( : ,{-90:90}, : ) , wgty({-90:90}), 1.0, 0)
nh = wgt_areaave(dd( : ,{ 0:90}, : ) , wgty({ 0:90}), 1.0, 0)
sh = wgt_areaave(dd( : ,{-90: 0}, : ) , wgty({-90: 0}), 1.0, 0)
; #############################################
wgt_arearmse2(dat1,dat2, wgt[*][*],opt)
wgt_volave(dat1,dat2,wgtz[*],wgty[*],wgtx[*],opt)
wgt_volrmse
dimensions "time", "latitude" and "longitude",
Available in version 5.1.1 or later.
wgt_runave
wgt_volave
【例】Let q be of size ( nt,
nt, ny,
ny, nx)
nx) and with named
dim_standardize_n qSum = dim_sum_n(x
,(/ 2 , 3 /))
dim_sum_n(x,(/
ঈ෪૱ϡᇴጯࢍზё
wgt_arearmse2
計算某個維度的平均、總和、標準差、去除平均值…
計算某個維度的平均、總和、標準差、去除平均值…等。
zonalAve
wgt_volrmse(dat1,dat2,wgtz[*],wgty[*],wgtx[*],opt)
zonalAve
opt = 0, the area average is calculated using available non-missing data.
opt = 1, then if any point in dat is missing, the area average is not computed.
Tu@CCU
Computes a zonal average of the input array.
zonalAve ( x : numeric )
reture_val : typeof (x)
17/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
̂ঈ‫ۏ‬நณ
angmom_atm
Compute gradient、detrend、Laplacian
計算大氣的相對角動量(relative angular momentum,單位=kg * m^2/s)
angmom_atm(u, dp,lat[*],wgt[*])
( containing gaussian weights if u is on a gaussian grid. Otherwise, set to a scalar (typically 1.0). )
ram_NH = angmom_atm (u(:,:,{0:90},:), dp, lat({0:90}), 1.0) ; ==> ram_NH(time)
fluxEddy
fluxEddy(x,y) → x‘y’ = ave{x*y} - X*Y(其中x=X+x‘ and y=Y+y’)
The rightmost dimension must be "time". Missing values should be indicated by x@_FillValue
【例】upvp = fluxEddy (u(lev|:,lat|:,lon|:,time|:), v(lev|:,lat|:,lon|:,time|:))
upvp will be a 3-dimensional array dimensioned klev x nlat x mlon.
lclvl
Calculates the pressure of the lifting condensation level(LCL).
dtrend
dtrend (y:numeric , return_info: logical)
gradsf (dat , grad_x , grad_y)
【例】yDtrend = dtrend_msg (y&time, y(lat|:,lon|:,time|:), True, False)
lclvl(P , T , Td)(units=hPa and K)
Given a scalar z, compute its Laplacian via Spherepack.
lapsF
lapsG
lapsf
lapsg
lapvf
lapvg
computing the geopotential height using the hydrostatic equation
hydro( P: numeric, Tv : numeric, Zsfc : numeric)
P:pressure (hPa) (last dimension is nlvl and Pressure must start at the surface)
Tv:virtual temperature (K) at each P(Tv= (T+273.15)*(1.+q*0.61))
Zsfc:surface geopotential height (gpm) (same dimensions as P)
【例】Tnew = T(time|:,lat|:,lon|:,lev|:)zh=hydro(conform(Tnew,P,3),Tnew, Zsfc)
(ntim,nlat,mlon,klev)
prcwater_dp
計算球面座標下x和y方向的梯度(gradient)
dtrend_msg(x[*],y,remove_mean:logical,return_info: logical)
dtrend_msg
【例】yDtrend = dtrend (y(lat|:,lon|:,time|:), False)
dtrend_quadratic
【例】plcl = lclvl (1000, 15+273.15, 4+273.15) ; plcl = 848.6
【例】plcl = lclvl (P, T, Td) ; P&T&Td(nt,ny,nx)、plcl(nt,ny,nx)
hydro
gradsf
gradsg
computing column precipitable water(unit= [kg/m2])
prcwater_dp(q : numeric, dp : numeric)
q :specific humidity (kg/kg). The rightmost dimension must be “level".
dp :pressure layer thickness (Pascals).
【例】q = (/ 20.8,19.4,16.5, ... , 1.7 ,1.0 /) ; [g/kg]
dp = (/ 10., 30. , 50., ... , 100., 50. /); [hPa]
pw = prcwater_dp(q*0.001,dp*100.)
; [kg/m2]
lapsF( z : numeric )
lapsG( z : numeric )
lapsf ( z : numeric, zlap : float ; or double )
lapsg ( z : numeric, zlap : float ; or double )
Given vector quantity (u,v), compute the vector Laplacian via Spherepack
lapvf ( u : numeric, v : numeric, ulap : float, vlap : float )
lapvg ( u : numeric, v : numeric, ulap : float, vlap : float)
z :scalar function array (input, two or more dimensions, last two dimensions
must be nlat x nlon and input values must be in ascending latitude order).
ilapsF
ilapsG
zlap:Laplacian array (output, same dimensions as z, values will be in ascending
latitude order)
Running average
function runave(
runave( dat : numeric, nave : integer, kopt : integer)
Model
dat :1或N維資料陣列。可利用 「dat@_FillValue」設定陣列之
dat@_FillValue」設定陣列之
特殊值。若沒設定,於計算過程中將被當作真實值計算。
nave :Number of points to be included in the running average
(一般使用奇數)
一般使用奇數)
kopt :邊界條件
kopt < 0 : utilize cyclic conditions
kopt = 0 : set unsmoothed beginning and end pts to x@_FillValue
kopt > 0 : utilize reflective (symmetric) conditions
Dtrend
dd3(3,:) = runave(dd3(0,:),12,0) → 計算12
個月的滑動平均
計算12個月的滑動平均
linear interpolation and smoothing
int2p
int2p(prsin , dat , prsout , linlog[1] : integer)
linear interpolation (=1) or linear interpolation in ln (≠1)
【Example】
plev@units = "hPa"
plev = (/1000,925,850,700,600,500,400,300,250,200,150,100/)
plevn = ispan(100,1000,50)
ddt = int2p(plev,tmp,plevn(::-1),2)
vertical average: v2p = dim_avg(int2p(plev({lev1:lev2}),dat(:,:,{lev1:lev2}),plevn(::-1),linlog))
smth9
1------8------7
|
|
|
2------0------6
|
|
|
3------4------5
Tu@CCU
18/41
performing nine point local smoothing on a 2D grid
smth9 (x[*][*] : numeric , p : numeric , q : numeric , wrap : logical)
f0 = f0 + (p/4)*(f2+f4+f6+f8-4*f0) + (q/4)*(f1+f3+f5+f7-4*f0)
x :二維或以上之網格資料陣列。平滑只取最右邊兩個維度
若有特殊值需先作x@_FillValue的設定。
p,q:權重。(通常p設為0.5,q則設為0.25)
【註】 q = -0.25 → results in "light" smoothing
q = 0.25 → results in "heavy" smoothing.
q = 0.0 → results in a 5-point local smoother.
wrap :True when the rightmost dimension is treated as cyclic.
False if the rightmost dimension is not to be treated as a cyclic.
【Example】xsmth = smth9 (x , 0.50, 0.25, True) ; heavy local smooth
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
triple2grid2d
將非網格點資料內差成二維網格點資料
grid
= triple2grid2d(xlon,ylat,zVal, lon,lat,
lon,lat, False)
triple2grid ( x [*], y [*], data [*], xgrid [*], ygrid [*], option)
opt
= True ; setting options
opt@mopt = 1
grid
= triple2grid2d(xlon,ylat,zVal, lon,lat,
lon,lat, opt)
triple2grid2d ( x [*], y [*], data [*], xgrid [*][*], ygrid [*][*], option)
option=False,
option=False, the function will operate under default mode
that is, all grid points will be assigned a value.
option=
option= True, this variable may have associated with it
the attributes mopt and/or distmx.
distmx.
Setting the option@
option@distmx option will result in any
observation greater than distmx to be not used:
option@mopt - an integer value of 0 or 1
option@
option@mopt=0
mopt=0 (default)
- use a quick approximation to determine the distance of an x/y location to a grid point.
option@
option@mopt=1
mopt=1
- calculate the distance using the great circle distance formula. ( in slower execution times.)
opt@distmx = 1.2
; observation more than 1.2 will not be used
option@distmx
grid = triple2grid(xlon,ylat,zVal,
triple2grid(xlon,ylat,zVal, lon,lat,
lon,lat, opt)
Any observation greater than option@
option@distmx from a grid point will not be used.
If this option is used, it is possible for some grid points to be
be returned as missing
Compute climatology and anomaly
opt
= True
opt@mopt = 0
opt@distmx = 10.0
res@sfXArray
= rlon
hov = triple2grid(rlon,rlat,rain,rlon1,rlat1,opt)
res@sfYArray
= rlat
plot = gsn_csm_contour_map(wks,rain,res)
gsn_csm_contour_map(wks,rain,res) hov = smth9(hov,0.5,0.25,False)
plot = gsn_csm_contour_map(wks,rain,res)
gsn_csm_contour_map(wks,rain,res)
clmMon
計算氣候平均值,時間需為12的倍數。(計算速度慢,所需計算時間大約是
dim_avg的三倍)
mean = clmMonLLT (x[*][*][*]:numeric)
(lat,lon,time)
mean = clmMonLLLT (x[*][*][*][*]:numeric) (lev,lat,lon,time)
mean = clmMonTLL (x[*][*][*]:numeric)
(time,lat,lon)
mean = clmMonTLLL (x[*][*][*][*]:numeric) (time,lev,lat,lon)
【註】執行前需先設定陣列中每個維度的名稱,例如:
x!0 = "time"
x!1 = "lat"
x!2 = "lon"
calcMonAnom
計算距平值
anom = calcMonAnomLLT(x[*][*][*], xAve[*][*][12])
anom = calcMonAnomLLLT(x[*][*][*][*],xAve[*][*][12])
anom = calcMonAnomTLL(x[*][*][*], xAve[12][*][*])
stdMon
計算均方根
x = stdMonLLT (x[*][*][*]:numeric)
x = stdMonTLL (x[*][*][*]:numeric)
x = stdMonLLLT (x[*][*][*][*]:numeric)
x = stdMonTLLL (x[*][*][*][*]:numeric)
rmMonAnnCyc
; x(lat,lon,time)
; x(time,lat,lon)
; x(lev,lat,lon,time)
; x(time,lev,lat,lon)
Removes thae Annual Cycle from monthly (nmos=12) data.
x = rmMonAnnCycLLT(x) ; input dim. x(lat,lon,time)
x = rmMonAnnCycTLL(x) ; input dim. x(time,lat,lon)
x = rmMonAnnCycLLLT(x) ; input dim. x(lev,lat,lon,time)
【結果與下面計算式相同】
xAve = clmMonLLT(x)
xAnom = calcMonAnomLLT(x,xAve)
Compute seasonal mean
month_to_season
Vertical integration
計算季節平均
Function for doing vertical integration in pressure using beta factors
[ DJF , JFM , FMA , MAM , AMJ , MJJ , JJA , JAS , ASO , SON , OND , NDJ ]
執行前需先設定陣列中每個維度的名稱,資料比數必須被12整除。資料必須從一月
開始擺放,計算時頭尾兩筆資料實際上是兩個月的平均(DJF=JF , NDJ=ND)
function vibeta( p : numeric , x: numeric , linlog : integer , psfc:
numeric , pbot: numeric , ptop: numeric)
usage
result = month_to_season (xMon:numeric, SEASON:string)
vibeta
example
for : xMon(time,lat,lon) , result : xJJA(time/12,lat,lon)
xJJA = month_to_season (xMon, "JJA")
計算n個季節平均值
【Example】:Let dat(nt,nz,ny,nx) , psfc(nt,ny,nx) , p(nz) → vint(nt,ny,nx)
vint = vibeta (p ,dat(time|:,lat|:,lon|:,lev|:) , linlog , psfc , pbot , ptop)
[ DJF , JFM , FMA , MAM , AMJ , MJJ , JJA , JAS , ASO , SON , OND , NDJ ]
month_to_seasonN
usage
result = month_to_seasonN (xMon:numeric, SEASONS[*]:string)
ftcurvi
example
for : xMon(time,lat,lon) , result : xJJA(n,time/12,lat,lon)
xJJA = month_to_seasonN (xMon, (/"JJA","JFM"/))
integrates a sequence datasets using cubic splines
cub = ftcurvi(lev2,lev1,plev({lev2:lev1}),dat(:,:,{lev2:lev1}))
Integrate a sequence of equally spaced points using Simpson's Rule
simpeq
function simpseq ( dat: numeric , dx[1] : numeric )
[ DJF , JFM , FMA , MAM , AMJ , MJJ , JJA , JAS , ASO , SON , OND , NDJ ]
result = simpson ( f (lev|:,lat|:,lon|:,time|:) , dt )
; result(nz,ny,nx),dt = 1.0(constant interval between points)
usage
result = month_to_season12 (xMon:numeric)
Integrate a sequence of unequally spaced points using Simpson's three-point
formula.
計算季節的氣候平均值
month_to_season12
p
:pressure levels(氣壓值從低層(bottom)往上層(top)排)
X
:dat(the rightmost dimension of dat must be same length as p)
linlog:內差方式。「= 1」表使用線性內差;「= 2」表使用log內差。
Psfc :地面氣壓(必須與dat相同維度)
pbot, ptop:欲積分範圍。pbot表最底層,ptop表最上層。
simpne
example
for : xMon(time,lat,lon) , result : xJJA(12,lat,lon)
xJJA = month_to_season (xMon)
Tu@CCU
19/41
function simpne(x: numeric,y: numeric)
【Example】Let p(nz) and f(nt,nz,ny,nx) → result(nt,ny,nx)
result = simpne(p,f(time|:,lat|:,lon|:,lev|:))
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Statistic method:correlations
ͧᒅă஄Ъͧă࠹၆ᒅ‫ޘ‬
relhum ( Ta: numeric , w: numeric , prs:
prs: numeric )
(給定溫度、混合比、氣壓,計算相對濕度(單位為%))
mixhum_ptrh ( prs:
prs: numeric , Ta: numeric , rh:
rh: numeric , opt: integer )
(給定氣壓、溫度以及相對濕度,計算比濕或混合比)
mixhum_ptd(
mixhum_ptd( prs:
prs: numeric , Td: numeric ,opt : integer )
(給定氣壓和露點溫度,計算比濕或混合比)
prs
Ta
Td
rh
w
opt
:pressure (hPa/mb
(hPa/mb)) (any dimensionality)
:temperature (K) at each p (same dimensionality as p)
:dew point temperature (K) at each p
:relative humidity (%) (same dimensions as p)
: Mixing ratio (kg/kg)
:opt = 1, mixing ratio (kg/kg). 。
= -1( g/kg)
g/kg)
opt = 2, specific humidity (kg/kg)。
(kg/kg)。 = -2( g/kg)
g/kg)
prs=(/
; hPA
prs=(/ 1008.,1000.,950.,900.,850.,800.,750.,700.,650.,600/)
ta=(/
ta=(/ 29.3, 28.1, 23.5, 20.9, 18.4, 15.9, 13.1, 10.1, 6.7, 3.1 /)
/) ; ℃
rh=(/
rh=(/ 75.0,60.0, 61.1, 76.7, 90.5, 89.8, 78.3, 76.5, 46.0,55.0 /) ; %
w=(/20.38, 19.03,16.14,13.71,11.56,9.80,8.33,6.75,6.06,5.07/) ;g/Kg
ccr = esacr(dat1,maxlag)
ccr = esccr(dat1,dat2,maxlag)
; auto correlations
; cross correlations( data1 lead data2)
ccr = esacv(dat1,maxlag)
ccr = esccv(dat1,dat2,maxlag)
; auto covariances
; cross covariances
ccr = escorc(dat1,dat2)
ccr = escovc(dat1,dat2)
; between two variables at zero lag only
【註】假設 q(t) and s(t+k) ,"k" 從0 到 mxlag
auto correlations:c(k) = SUM [(q(t)-qAve)*(q(t+k)-qAve)}]/qVar
cros correlations:c(k) = SUM [(q(t)-qAve)*(s(t+k)-sAve)}]/(qStd*sStd)
auto covariancesc(k) = SUM [(q(t)-qAve)*(q(t+k)-qAve)}]/N
cross covariancesc(k) = SUM [(q(t)-qAve)*(s(t+k)-sAve)}]/N
cov = SUM [(X(t)-Xave)*(Y(t)-Yave)}]/(NT-1)
cor = SUM [(X(t)-Xave)*(Y(t)-Yave)}]/(Xstd*Ystd)
q = mixhum_ptrh (prs , ta+273.15 , rh*0.01
rh*0.01 , 1 ) ; mix ratio (kg/kg)
rh = relhum(ta+273.15 , w*0.001 , prs*100.)
prs*100.)
Statistic method:correlations
;************************************************
; calculate cross correlations
; note, the max lag should not be more than N/4
;************************************************
x_Lead_y = esccr(x,y,mxlag)
maxlag = 25
ccr = esccr(T1,T2,maxlag)
(T1,T2,maxlag)
xcd = ispan(0,maxlagispan(0,maxlag-1,1)
;************************************************
wks = gsn_open_wks("ps","corel")
gsn_open_wks("ps","corel")
res = True ; make plot mods
res@tiMainString = "37.7N 180E vs 23.72S 149W"
res@tiXAxisString = "LAG" ; xx-axis label
;************************************************
plot = gsn_xy(wks,xcd,ccr,res)
gsn_xy(wks,xcd,ccr,res) ; plot correlation
Auto & cross correlation
x(nt)
x(nt) , y(nt)
y(nt)
x(nt)
x(nt) , y(ny,nx,nt
y(ny,nx,nt))
x(nz,nt
x(nz,nt)) , y(ny,nx,nt
y(ny,nx,nt))
x(nb,na,nt
x(nb,na,nt)) , y(nz,ny,nx,nt
y(nz,ny,nx,nt))
x(ny,nx,nt
x(ny,nx,nt)) , y(ny,nx,nt
y(ny,nx,nt))
→ c(mxlag)
c(mxlag)
→ c(ny,nx,mxlag)
c(ny,nx,mxlag)
→ c(nz,ny,nx,mxlag)
c(nz,ny,nx,mxlag)
→ c(nb,na,nz,ny,nx,mxlag)
c(nb,na,nz,ny,nx,mxlag)
→ c(ny,nx,mxlag)
c(ny,nx,mxlag)
ccr2
between two variables
x(nt) , y(nt)
→ val (a scalar)
x(nt) , y(ny,nx,nt)
→ c(ny,nx)
x(nz,nt) , y(ny,nx,nt)
→ c(nz,ny,nx)
x(nb,na,nt) , y(nz,ny,nx,nt)
→ c(nb,na,nz,ny,nx)
x(ny,nx,nt) , y(ny,nx,nt)
→ c(ny,nx)
ccr1
;************************************************
maxlag = 25
totlag = maxlag * 2
;************************************************
ccr1 = esccr((T1,T2,maxlag)
,maxlag)
ccr2 = esccr((T2,T1,maxlag)
,maxlag)
;************************************************
ccrs = new( (/totlag
/),float)
(/totlag/),float)
ccrs(maxlag:)
= ccr1(1:maxlagccrs(maxlag:)
ccr1(1:maxlag-1)
ccrs(0:maxlagccrs(0:maxlag-1) = ccr2(0:maxlagccr2(0:maxlag-1:1:-1)
xcd
= ispan(ispan(-maxlag+1,maxlagmaxlag+1,maxlag-1,1)
;************************************************
plot = gsn_xy(wks,xcd,ccrs,res)
gsn_xy(wks,xcd,ccrs,res)
Statistic method:Regression (1/3)
rc = regline( x: numeric , y: numeric )
Calculates the linear regression
coefficient between two series
;************************************************
T1 = new(/ny,nx,nt/)
T2 = new(/ny,nx,nt/)
ccr = new(/ny,nx,maxlag/)
;************************************************
maxlag = 2
ccr = esccr(T1,T2,maxlag)
regline also returns the following attributes:
xave :average of x (scalar, float or double)
yave :average of y (scalar, float or double)
tva :t-statistic (assuming nullnull-hypothesis)
nptxy :number of points used
yintercept:y intercept
lag = 0
res@tiMainString = "Correlations at lag "+lag
plot = gsn_csm_contour_map_ce(wks,ccr(:,:,lag),res)
Tu@CCU
20/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Statistic method:Regression (2/3)
y = mx+b
Statistic method:Regression (3/3)
ycd = inin->TS(:,{60},{180}) ; extract time series at 60N,90
;************************************************
xcd = new((/nn
/),"float")
new((/nn/),"float")
ycd = new((/nn
/),"float")
new((/nn/),"float")
dat = new((/2,nn/),"float")
; ###############
xcd = ispan(0,dimsizes(ycd)ispan(0,dimsizes(ycd)-1,1)*1.
『regCoef』which
calculate the least
squared regression for a
mulit-dimensional array.
rc = regline(xcd,ycd)
regline(xcd,ycd)
;************************************************
; create xcd and calculate the regression coefficient
; note regline works on one dimensional arrays.
;************************************************
; y = mx+b
; m is the slope
: rc returned from regline
; b is the y intercept : rc@yave attribute of rc returned from regline
; ###############
dat(0,:) = ycd
ycd = T(lat|:,lon|:,time|:) ; reorder variable
;************************************************
; create x and calculate the regression coefficient
; note regline works on one dimensional arrays.
;************************************************
xcd = ispan(0,dimsizes(ycd&time)-1,1)*1.
rc = regCoef ( xcd , ycd )
;************************************************
plot = gsn_csm_contour_map_ce(wks,rc,res)
gsn_csm_contour_map_ce(wks,rc,res)
dat(1,:) = rc*(
xcd--rc@xave)
rc*(xcd
rc@xave) + rc@yave
or dat(1,:) = rc*(
xcd))
+ rc@yintercept
rc*(xcd
; ###############
plot = gsn_csm_xy (wks,xcd,dat(:,:),res)
wks,xcd,dat(:,:),res)
sst = new((/nt/),"float")
iopt = 0 ; 0=>remove mean ,
; 1=>remove mean + detrend
smth = 7 ; smooth: should be at least 3 and odd
pct = 0.10 ; percent tapered: (0.0 <= pct <= 1.0)
; #################################
; calculate spectrum
spct = specx_anal(dat(:,9),iopt,smth,pct)
;#######################################
; calculate confidence interval [here 5 and 95%]
; return 4 curves to be plotted
;#########################################
spsn = specx_ci (spct, 0.05, 0.95)
;#########################################
res@xyLineThicknesses = (/3.,2.,2.,2./)
res@xyDashPatterns
= (/0,0,1,1/)
res@xyLineColors = (/"black","green","blue","red"/)
; #################################
; plot = gsn_csm_xy(wks,spct@frq,spct@spcx,res)
plot = gsn_csm_xy(wks,spct@frq,spsn,res)
sst = new((/nt/),"float")
iopt = 0 ; 0=>remove mean ,
; 1=>remove mean + detrend
smth = 7 ; smooth: should be at least 3 and odd
pct = 0.10 ; percent tapered: (0.0 <= pct <= 1.0)
;*****************************************************
; calculate spectrum
spec = specx_anal( sst, iopt, smth, pct )
;*****************************************************
plot=gsn_csm_xy(wks,spec@frq,spec@spcx,res)
Statistic method:FFT
Reconstruct the signal of period 30~60 days : (nx=144,nt=365)
dd(nx,nt) → cf = ezfftf (dd)
dd) ==> cf (2,nx,nt/2)
; cf@xbar
= 0.0
cf ( : , : , 0:4)
= 0.0 ; set the wavenumber 0-4 to zero
cf ( : , : , 12:181) = 0.0 ; set the wavenumber 12-181 to zero
d36 = ezfftb (cf, cf@xbar)
Reconeconstruct
function ezfftf( x[*]...[*] : numeric) Æ get a0 、 an 、 bn
function ezfftb( cf[2][*]...[*] : numeric,xbar[*]...[*] : numeric )
function fourier_info(x:numeric, nhx:integer, Phase : numeric)
【Example 1】 Let x(N) where N=2000
cf = ezfftf (x) -- > a0 , an , bn
cf will be (2,1000) → fourier coefficients (2 , ….. , npts/2
)
npts/2)
cf@xbar will contain the series mean
cf@npts = 2000.
The frequency spacing is 1./N. The frequencies that the cf variable
corresponds to are:
Band Pass Filter
cf(0,0) and cf(1,0) is 1./N → wave number 1
cf(0,1) and cf(1,1) 2./N → wave number 2
cf(0,2) and cf(1,2) 3./N → wave number 3
Tu@CCU
21/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Statistic method:High/Low/Band Pass Filter
High Pass
(<30days)
<30days)
; nwt : The total number of weights (must be an odd number; nwt >= 3)
;
The more weights, the better the filter, but there is a greater loss of data.
; ihp : A scalar indicating the low-pass filter: ihp = 0; high-pass ihp = 1; band-pass ihp = 2.
; fca : The cut-off frequency of the ideal high or low-pass filter: (0.0 < fca < 0.5).
; fcb : The second cut-off frequency and used only when a band-pass filter is desired.(fca<fcb<0.5)
; nsigma : A scalar indicating the power of the sigma factor (nsigma >= 0). nsigma=1. is common.
; #######
; ####### ihp fca
fcb
sig
; bps = (/ 2 , (1./60) , (1./30), 1 /) ; 2 -> Band Pass (fca < fcb < 0.5)
; bps = (/ 1 , (1./30) , -999.0 , 1 /) ; 1 -> High Pass (0.0 < fca < 0.5)
bps = (/ 0 , (1./60) , -999.0 , 1 /) ; 0 -> Low Pass (0.0 < fca < 0.5)
; #######
nwt = (nt-1)/2-1
Band Pass
(30~
30~60days)
60days)
Low Pass
(> 60days)
60days)
ihp = floattointeger(bps(0))
sig = floattointeger(bps(3))
wgts = filwgts_lancos(nwt,ihp,bps(1),bps(2),sig)
hov = wgt_runave(hov(lat|:,lon|:,tim|:),wgts,1)
; #######
dtm = dim_avg(hov)
; #######
do l=0,nt-1
hov(:,l) = hov(:,l) + dtm(:)
end do
Statistic method:EOF
neof = 3 ; 表示取前三個模態
function eofunc(dd : numeric, neval : integer, optEOF : logical)
ne = 0 ; 表示畫出第一個模態
function eofunc_ts(dd : numeric, evec : numeric, optETS: logical)
dtmp = dd(::4,::8,:)
; dd(ny,nx,nt)
function eofunc_varimax(evec : numeric, optEVX: logical)
dtmp = rmMonAnnCycLLT(dtmp)
rmMonAnnCycLLT(dtmp) ; remove annual mean
dd( ny,nx,nt )
; compute eigenvector
evec = eofcov_Wrap(
eofcov_Wrap( dd , neof )
evec = eofcov_Wrap(dtmp,neof)
eofcov_Wrap(dtmp,neof)
pcs = eofcov_ts_Wrap(dtmp,evec)
eofcov_ts_Wrap(dtmp,evec)
→ evec(
evec( neof , ny , nx )
pcent = evec@pcvar(ne)
plot(ne)
plot(ne) = gsn_csm_contour_map_ce(wks,evec(ne,:,:),
gsn_csm_contour_map_ce(wks,evec(ne,:,:), res)
; principle component
pcs = eofcov_ts_Wrap(
eofcov_ts_Wrap( dd , evec ) → pcs ( neof , nt )
plot(ne)
plot(ne) = gsn_csm_xy(wks,xcd,pcs(ne,:),resxy)
gsn_csm_xy(wks,xcd,pcs(ne,:),resxy)
; ###################################################
; Normalize time series:
; The resulting principal component time series is normalized
; by the weights used to get the time series of the mean area amplitudes
; ###################################################
dint = 10
dtmp= ddc({slat:elat:dint},{slon:elon:dint},:)
evec = eofcov_Wrap(dtmp,neof)
; eigenvector
pcs = eofcov_ts_Wrap(dtmp,evec) ; time series coef
dims
nnx
sumWgt
pcs
Tu@CCU
22/41
= dimsizes(dtmp)
= dims(1)
= nnx * sum(sqrt(wgty({lat|slat:elat:dint})))
= pcs / sumWgt
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
原始資料
Tu@CCU
MJO Climate Variability
標準化
23/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
NCL program
各類資源代號
load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl
"$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl""
load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_csm.ncl
"$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_csm.ncl""
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl""
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl""
begin
nx = 144
ny = 73
hov = new((/ny,nx
/),"float")
new((/ny,nx/),"float")
wks = gsn_open_wks ("ps
", figname )
("ps",
res = True
res@txFont = 21
res@txFontHeightF = 0.012
…….
…….
plot = gsn_csm_hov(wks,
gsn_csm_hov(wks, hov(:,{slon:elon}),
hov(:,{slon:elon}), res)
am:annotation manager
cn:contour
ca:coordinate arrays
gs:graphical style
lb:label bar
lg:legend
mp:maps
pm:plot manager pr:primitive
sf:scalar field
st:streamlines
ti:title
tm:tickmark
tx:text
tr:transform
vf:vector field
vc:vector plot
vp:view port
wk:workstation
ws:workspace
xy:xy plot
end
graphic format
wks = gsn_open_wks ("檔案格式", "輸出檔名" )
.
檔案格式: "x11"、"ps"、"eps"、"epsi"、"ncgm"、"pdf "
也可以轉換成點陣圖,如: " gif
" 、 " jpg " 、 " png " ,方法如下:
system("convert -rotate -90 -density 108 -crop 0x0 "+fname+".ps "+fname+".png" )
設定前景與背景顏色
setvalues wks
Windiw Size
黑色
wkWidth : 800
"wkForegroundColor"
wkForegroundColor" : (/0.,0.,0./)
"wkBackgroundColor"
wkBackgroundColor" : (/1.,1.,1./)
end setvalues
setvalues wks
"wkForegroundColor"
wkForegroundColor" : (/0.,0.,0./)
wkHeight : 800
"wkBackgroundColor"
wkBackgroundColor" : (/1.,1.,1./)
白色
end setvalues
User Define Color map
Color map
Using RBG triplets
http://www.ncl.ucar.edu/Document/Graphics/color_table_gallery.shtml
gsn_define_colormap(wks,"BlAqGrYeOrRe")
colors = (/ (/255,255,255/), (/0,0,0/),\
; Defines a color map
Named colors
colors = (/"white","black",\
(/255,255,255/),\
"white",\
(/244,255,244/), \
"royal blue",\
(/217,255,217/), \
"light sky blue",\
(/163,255,163/),\
"powder blue",\
gsn_retrieve_colormap ( wks)
; return_val [*][3] : float
gsn_reverse_colormap(wks)
; reverse colormap
(/106,255,106/),\
"lightgreen",\
gsn_draw_colormap(wks)
; draw the color map
(/43,255,106/),\
"palegreen",\
(/0,224,0/), \
"wheat",\
(/0,134,0/)\
"brown",\
gsn_merge_colormaps (wks,colormap1,colormap2);merge
;merge two color maps
(/255,255,0/),\
"purple ",\
i = NhlNewColor(wks,0.8,0.8,0.8) will add the gray to colormap.
(/255,127,0/) /) / 255.0
gsn_draw_named_colors(wks,colors,(/rows,cols/)) ; draw the named colors.
gsn_define_colormap(wks,colors)
Tu@CCU
24/41
"pink"/)
gsn_define_colormap(wks,colors)
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Two types of coordinates
http://www.cgd.ucar.edu/csm/support/CSM_Graphics/Scripts/rgb.txt
List of Named Colors
1.0
90
【NDC:
NDC:Normalized Device Coordinates】
Coordinates】
To use the full colormap:
gsnSpreadColors = True
PLOT
Plot coordinates
You can select a start and stop
-90
0
point with:
360
NDC or Page coordinates
gsnSpreadColorStart = 15
0.0
0.0
gsnSpreadColorEnd = 220
1.0
gsn_draw_colormap(wks)
設定圖形大小
Text functions (can not be paneled)
call set (x1,x2,y1,y2,rlon1,rlon2,rlat1,rlat2,1)
NDC coordinates
title = “a title in ndc space”
space”
Plot coordinates
a title in ndc space
res = True
90
y = .95
res@vpOn = True or False:啟動
viewport設定。
設定。(( Default: True )
False:啟動viewport
res@vpXF = 0.2 :
txres = True
PLOT
(Default: 0.2)
0.2)
res@vpYF = 0.8 :
(Default: 0.6)
0.6)
res@vpHeightF = 0.6:
0.6:
(Default: 0.6)
0.6)
-90
0
gsn_text(wks,plot,text,100,3,txres)
res
Tick Mark(X / Y Labels)
= True
設定上、下、左、右座標軸之屬性
res@gsnDraw = False
res@gsnFrame = False
text
; change maj lon tm spacing
= “text in plot space”
res@gsnMajorLonSpacing =
; text resources
; change maj lat tm spacing
text in plot space
tres
-90
0
360
90
= True
res@gsnMajorLatSpacing =
tres@txFontHeightF = 0.012
; no lon minior tickmarks
plot(0) = gsn_csm_contour(wks,data,res)
x1=gsn_add_text(wks,plot(0),text,0,3,tres)
PLOT2
plot(1) = gsn_csm_contour(wks,data,res)
text in plot space
-90
0
360
360
txres@txFontHeightF = 0.012
gsn_add_text (can be paneled)
PLOT1
gsn_text_ndc(wks,title,x,y,txres)
gsn_text_ndc(wks,title,x,y,txres)
text = “text in plot space”
space”
※視窗大小從0
視窗大小從0 ~ 1
90
txres@txFontHeightF = 0.015
text in plot space
(Default: 0.8)
0.8)
res@vpWidthF = 0.6 :
x = 0.5
res@tmXBOn
=
res@tmXBMinorOn
=
x2=gsn_add_text(wks,plot(1),text,0,3,tres)
gsn_panel(wks,plot,(/2,1/),pres)
Tu@CCU
25/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
res@tmXB
BorderOn
res@tmXBBorderOn
res@tmXB
LabelsOn
res@tmXBLabelsOn
res@tmXB
LabelFont
res@tmXBLabelFont
res@
LabelFontHeightF
res@tmXB
tmXBLabelFontHeightF
res@
LabelFontColor
res@tmXB
tmXBLabelFontColor
res@
LabelFontAngleF
res@tmXB
tmXBLabelFontAngleF
res@
LabelFontDirection
res@tmXB
tmXBLabelFontDirection
res@
Style
res@tmXB
tmXBStyle
res@
Mode
res@tmXB
tmXBMode
res@
Values
res@tmXB
tmXBValues
res@
Labels
res@tmXB
tmXBLabels
res@tmXB
MinorValues
res@tmXBMinorValues
= False(
False(True)
True)
設定上邊線
res@tmXBOn
= False(
False(True)
True)
設定標記
= font number
設定字形
res@tmXBMajorLengthF
res@tmXBMajorOutwardLengthF
大TM向外延伸長度
= font size
設定字形大小
res@tmXBMajorLineColor
大TM之顏色
= indices
設定字形顏色
res@tmXBMajorThicknessF
= angles(
angles(ex: 90)
90)
設定字形角度
res@tmXBMinorOn
= "Across" or " Down"
字形直書或橫書
= Linear、
Linear、Log、
Log、Irregular
設定座標樣式
res@tmXBMinorLengthF
res@tmXBMinorOutwardLengthF
小TM向外延伸之長度
= Automatic、
Automatic、Manual、
Manual、Explicit
自訂座標模式
res@tmXBMinorLineColor
小TM之顏色
= (/1,121,241/)
標定文字位置
res@tmXBMinorThicknessF
= (/"1990","2000"/)
對應之標記文字
res@tmXMajorGrid
res@tmYMajorGrid
= False
開啟X軸網格線條
res@tmXMajorGridLineColor
res@tmYMajorGridLineColor
= 1
設定X軸網格線條顏色
res@tmXMajorGridThicknessF
res@tmYMajorGridThicknessF
= 1.0
設定X軸網格線條粗細
res@tmXMajorGridLineDashPattern
res@tmYMajorGridLineDashPattern
= 2
設定X軸網格線條樣式
小標文字位置
= False
設定 大TM
大TM之粗細
= False
設定小TM
小TM之粗細
call set (x1,x2,y1,y2,rlon1,rlon2,rlat1,rlat2,1)
; turn on built°」)
built-in tickmarks(經緯度標上「
tickmarks(經緯度標上「°
res@pmTickMarkDisplayMode = "
"
; label independently
mon = (/"DEC","JAN","FEB","MAR" ,"APR","MAY" /)
idy = (/ 0. , 30., 61., 89., 120., 150. /)
res@tmYLMode = "Explicit "
res@tmYLValues = idy
res@tmYLLabels = mon
若作上面的設定,則下面的設定將無作用
res@gsnMajorLonSpacing = 50
labx = (/1880,1900,1920,1960,1980/)
idxx = (labx-1880)*12+1
res@gsnMajorLatSpacing = 20
res@tmXBMode
= "Explicit "
res@tmXBValues = idxx
res@tmXBLabels = labx
res@tiMainString
= “This is the main title"
; 寫入標題文字
res@tiMainFont
= 21
; 設定字形
res@tiMainFontHeightF
= 0.05
; 設定字體大小
res@tiMainFontColor
= 1
; 設定字體顏色
res@tiMainFontAngleF
= 45.0
; 設定字體旋轉角度
res@tiMainFontDirection
= "Across" or "Down"
; 橫書or直書
res@tiMainFontQuality
= "High" or "Low"
; 設定字體品質
res@tiMainSide
= "Botton" or "Top"
; 決定座標軸文字位置 (上或下)
res@tiMainPosition
= "Center" or "Right" or "Left"
; 決定座標軸文字位置 (左中右)
res@gsnLeftString
= "LeftString"
; 附加小標題(左邊)
res@gsnCenterString
= "centerstring"
; 附加小標題(中間)
res@gsnRightString
= "RightString"
; 附加小標題(右邊)
res@gsnLeftString
=" "
; 表示不打字
res@gsnStringFont
= 21
; 設定小標題字型
res@gsnStringFontHeightF
= 0.012
; 設定小標題字體大小
res@gsnLeftStringFontHeightF
= 0.012
; 設定左側小標題字體大小
res@gsnCenterStringFontHeightF
= 0.012
; 設定中間小標題字體大小
res@gsnRightStringFontHeightF
= 0.012
; 設定右側小標題字體大小
Tu@CCU
One Dimension
Title
Lines or Bar Charts(Time Series)
不同SCALE
不同SCALE
26/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
定義X或Y座標軸的範圍
One Dimension
Lines or Bar Charts(Time Series)
res@trXMinF
= -90. res@trYMinF
plot = gsn_csm_xy( wks, xcd(nn), ycd(nn), res)
res@trXMaxF =
90.
plot = gsn_xy(wks, xcd(nn), ycd(nn), res)
res@trXReverse =True /False
= - 10.
res@trYMaxF =
50.
res@trYReverse = True/False
定義X&Y座標軸最小值
定義X&Y座標軸最大值
確定是否將座標軸反轉
plot = plot_xy2(wks, xcd(nn), ycdL(nn),ycdR(nn),resL, resR)
plot = gsn_csm_xy(wks,xcd,ycd,res)
plot = plot_xy3(wks, xcd(nn), ycdL(nn),ycdR(nn), ycdR2(nn), resL, resR,resR2)
plot = plot_x2y (wks, xcd1(nn), xcd2(nn), ycd(nn), resL, resR)
res@tiMainString = "Basic XY plot"
plot = plot_x2y2(wks, xcd1(nn), xcd2(nn), ycdL(nn),ycdR(nn),resL, resR)
plot = gsn_csm_xy (wks,u&lat,u(0,:,{82}),res)
plot = gsn_add_polyline(wks, plot: graphic, xcd(nn), ycd(nn), res)
gsn_polyline(wks,plot,(/xcd1,xcd2/),(/ycd1,ycd2/),False)(畫直線)
res@xyLineThicknessF
res@xyLineThicknesses
res@xyLineColor
res@xyLineColors
= 2.0
; 設定線條粗細
= (/1.0,2.0/)
= red
; 設定單條線顏色
= (/"blue","red"/)
; 設定多條線顏色
res@xyDashPattern
res@xyDashPatterns
res@xyExplicitLegendLabels
res@xyXStyle
res@xyYStyle
= 2
; 設定單條線型式
= (/0,2/)
; 設定多條線型式
res@xyLabelMode
= "Custom" "NoLabels"
"Lettered"
; label a line
res@xyExplicitLabels
res@xyLineLabelFont
res@xyLineLabelFontHeightF
res@xyLineLabelFontColor
res@xyLineLabelFontThicknessF
res@xyLineLabelConstantSpacingF
= "label"
= 21
= 0.02
= "red"
= 2.0
= 0.02
; text to use
= (/"EQ","20N","40N"/)
= Log, Linear, Irregular,
Time, and Geographic
; 設定座標軸樣式
res@xyMarkLineModes
res@xyMarker
res@xyMarkerColor
res@xyMarkerSizeF
=
=
=
=
res@tmLabelAutoStride
= True
; 選定mark的模式
; 設定mark的樣式
; 設定mark的顏色
; 設定mark的大小
; nice tick mark
labels
res@gsnXYBarChart
res@gsnXYBarChartColors
res@gsnXYBarChartColors2
res@gsnXYBarChartPatterns
res@gsnXYBarChartPatterns2
res@gsnXYBarChartBarWidth
res@gsnYRefLine
res@gsnYRefLineColor
res@gsnAboveYRefLineColor
res@gsnBelowYRefLineColor
= True
; create bar chart
res@gsnAboveYRefLineBarPatterns
res@gsnBelowYRefLineBarPatterns
"Markers"
16
"red"
0.01
;bar is up or down
= 0
= "black"
= "red"
= "blue"
= 1
or = (/1,3,4/)
= 1
or = (/1,3,4/)
res@gsnXYBarChartPatterns2
; between 0 and 1
res@xyMarkLineModes= "Markers"
res@xyMarker
= 2
res@xyDashPattern = 2
Scatter Plot
res@tiMainString
= "Scatter Plot"
; res@xyMarkLineModes = " Lines "
res@xyMarkLineModes = "
"
res@xyMarkers
= 16
res@xyMarkerColor
= " red "
res@xyMarkerSizeF
= 0.01
plot = gsn_csm_xy (wks,xcd,ycd,res)
Tu@CCU
27/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
data
= new((/2,dimsizes(u&lat)/),float)
data(0,:) = u(:,{82})
data(1,:) = u(:,{-69})
res@tiMainString = "Mulitple XY plot“
res@xyLineThicknesses = (/ 1.0 , 2.0 /)
res@xyLineColors
= (/"blue","red"/)
res@xyDashPatterns
= (/ 0 , 2 /)
plot = gsn_csm_xy (wks,u&lat,data,res)
相同SCALE
gsn_csm_xy3(wks,lon,t,u,v,res1,res2,res3)
wks = gsn_open_wks("ps","xy")
gsn_open_wks("ps","xy")
res1 = True
res2 = True
res3 = True
res1@gsnMaximize = True
res1@trXMaxF = 360.
resL@xyLineThicknesses = 2.
resL@tiYAxisString = " Temperature [solid]"
resL@trYMinF
= 0.
resL@trYMaxF
= 16.
resL@tiMainString
= "Curves Offset“
resL@xyLineColors = "blue"
resR@xyDashPatterns
= 1
resR@xyLineThicknesses = 2
resR@tiYAxisString
= " Year-Month"
resR@trYMinF
= 1008.
resR@trYMaxF
= 1024.
resR@xyLineColors
= "red"
不同SCALE
res1@xyLineColor = "red"
res2@xyLineColor = "green"
res3@xyLineColor = "blue"
res1@tiYAxisString = "t"
res2@tiYAxisString = "u"
res3@tiYAxisString = "v"
res3@trYMinF = -8.
res3@amOrthogonalPosF = 0.72
plot = gsn_csm_xy3(wks,lon,t,u,v,res1,res2,res3)
plot = plot_xy2(wks , xcd , t , p , resL , resR)
res@gsnFrame
res@trYMinF
res@trYMaxF
= False
= -3.0 ; min value on y-axis
= 3.0 ; max value on y-axis
res@gsnYRefLine
res@lgAutoManage
= False
res@pmLegendDisplayMode = "Always"
res@pmLegendSide
= "Top"
res@pmLegendWidthF
= 0.13
; Change width and
res@pmLegendHeightF
= 0.10
; height of legend.
res@pmLegendParallelPosF = 0.12
res@pmLegendOrthogonalPosF = -0.425
res@lgPerimOn
= True
; res@lgPerimFill
= 0
; res@lgPerimFillColor
= "green"
res@lgLabelFont
= 21
res@lgLabelFontHeightF = 0.016
Legends
= 0.0
res@gsnAboveYRefLineColor = “red”
res@gsnBelowYRefLineColor = “blue”
polyres@gsLineThicknessF
= 3.0
polyres@gsLineDashPattern = 1
plot = gsn_csm_xy (wks,xcd,soi,res)
gsn_polyline(wks,plot,xcd,soi2,polyres)
res@xyExplicitLegendLabels
res@xyLineColors
res@xyMarkLineModes
res@xyDashPatterns
res@xyLineThicknesses
frame (wks)
res@gsnXYBarChart = True ; create bar chart
plot = gsn_csm_xy (wks,xcd,soi,res)
res@lgLabelFont
= 21
; change font
res@lgLabelFontColor
= 10
; change font color
res@lgLabelFontHeightF
= 0.03 (在此設定下才能夠改變字體大小
res@lgAutoManage=False)
res@lgLabelAngleF
= 280.
; angle of legend label
res@lgLabelFontHeightF
= .03
; label font height
res@xyExplicitLegendLabels
= (/"U","V"/)
; explicit labels
res@xyMarkLineModes
= (/"MarkLines","Lines"/)
; line style
res@xyMarkers
= (/14,0/)
; marker style
res@xyMarkerColor
="red"
; marker color
res@xyLineThicknesses
= (/2.,2.,2.,2./)
; line thickness
res@xyLineColors
= (/"black","green","blue","red"/)
Tu@CCU
= (/" Global "," NH "," SH "/)
= (/"black","red","blue"/)
= (/"Lines","Lines","Lines"/)
= (/0,0,0/)
= (/4.,4.,4./)
Two Dimension-Contour
28/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Pressure vs. Longitude or Latitude or Time
Generic Interfaces
gsn_contour
plot= gsn_csm_pres_hgt (wks, dat(nz,nx), res)
gsn_streamline
plot= gsn_csm_pres_hgt_vector (wks, dat(nz,nx), v(nz,nx), w(nz,nx), res)
gsn_vector
gsn_vector_scalar
gsn_csm interfaces
gsn_csm_contour
gsn_csm_map
gsn_csm_contour_map_ce
gsn_csm_streamline_polar
gsn_csm_vector
hov!0
hov!1
hov&prs
hov&lon
"prs"
"lon" or "lat" or "time "
hov&plev
hov&rlon or hov&lat = hov&rlat
or hov&time= hov&date
plot = gsn_csm_pres_hgt(wks, hov, res )
vv = new((/nz,ny,nx/), "float") (vertically from top to bottom)
dps = new((/ny,nx/), "float") (unit=Pa)
psi = new((/nz,ny/), "float") (unit=Kg/s)
Hadley Cell
計算緯向平均之經向環流(zonal
計算緯向平均之經向環流(zonal mean meridional stream
function),也就是計算
Local Hadley Cell。
function),也就是計算Local
Cell。
需要給定經向風、緯度、垂直氣壓層以及地面氣壓等資料
rlat = latGlobeF(ny,"lat","latitude","degrees_north")
plev = (/1000,925,850,700,600,500,400,300,250,200,150,100/)
psi = nameDim(psi,(/"lev","lat"/)," ","Kg/s")
psi = zonal_mpsi ( v [*,*,*] , lat[*] , plev[*]
plev[*] , ps [*,*] )
v :經向風
=
=
=
=
psi&lat = rlat
psi&lev = plev
三(lev,lat,lon
)或四維(time,lev,lat,lon
time,lev,lat,lon)陣列。單位必須用「公尺
)陣列。單位必須用「公尺//秒(m/s
三(lev,lat,lon)或四維(
秒(m/s
)」。需特別注意的是,資料擺放必須從頂層(Top
)往底層(Bottom
Bottom)置
)置
)」。需特別注意的是,資料擺放必須從頂層(Top)往底層(
入(i.e.
入(i.e. p(0) < p(1) < p(2) ...)
...) 。
psi@_FillValue = -99.99
lat:緯度位置
lat:緯度位置
一維陣列。
; ######################################################################
plev:垂直氣壓層
plev:垂直氣壓層
一維陣列。單位必須是「帕(
)往底層(
一維陣列。單位必須是「帕(Pascals)
Pascals)」,排序從頂層(Top
」,排序從頂層(Top)往底層(
Bottom)置入。頂層必須大於
5 hPa(
1005hPa
Bottom)置入。頂層必須大於5
hPa(500Pa),最底層則必須小於
500Pa),最底層則必須小於1005hPa
(100500Pa) (也就是 500 < p(0) < p(1) < ... < 100500.)
100500.)
psi = zonal_mpsi(vv(::-1,:,{slon:elon}),rlat,plev(::-1)*100.,dps(:,{slon:elon})*100.)
ps:地面氣壓
ps:地面氣壓
二(lat,lon
)或三維(time,lat,lon
time,lat,lon)陣列。單位須是「帕
)陣列。單位須是「帕((Pascals)
二(lat,lon)或三維(
Pascals)
; ######################################################################
psi:經向流函數
psi:經向流函數
為輸出之二(lev,lat
)或三維(time,lev,lat
time,lev,lat)陣列。單位是「
)陣列。單位是「Kg/s
Kg/s」
」
為輸出之二(lev,lat)或三維(
plot = gsn_csm_pres_hgt( wks , psi({lev1:lev2},{slat:elat}) , res )
psi(:,:) = psi(::-1,:) * 1.e-10
Time vs. Latitude
Time vs. Longitude (Hovmueller)
plot = gsn_csm_lat_time(wks, hov(ny,nt), res)
plot = gsn_csm_time_lat(wks, hov(nt,ny), res)
plot = gsn_csm_hov(wks, hov(nt,nx), res)
res@tiMainString
hov!0
= "lat "
hov!1
= "time "
hov&lat
= hov&rlat
hov&time = hov&time
hov@long_name = "SST "
hov@units
= "C"
hov = dim_avg(sst(lat|:,tim|ism:iem,{lon|slon:elon}))
plot = gsn_csm_lat_time(wks, hov({slat:elat},:), res)
= "Pacific Region"
res@cnLevelSelectionMode = "ExplicitLevels"
res@cnLevelSpacingF
=
res@cnMinLevelValF
= -10.0
2.0
res@cnMaxLevelValF
= 10.0
res@cnLineLabelsOn
= True
res@cnFillOn
= True
res@gsnSpreadColors
= True
res@lbLabelAutoStride
= True
hov!0
hov!1
hov&time
hov&lat
= "time "
= "lat “
= hov&time
= hov&rlat
hov@units
= "C "
res@lbOrientation = "Vertical"
hov = dim_avg(sst(lat|:,tim|ism:iem,{lon|slon:elon}))
plot = gsn_csm_time_lat(wks, hov(:,{slat:elat}), res)
hov = dim_avg(dda(tim|ism:iem, lon|:,{lat|slat:elat}))
plot = gsn_csm_hov(wks, hov(:,{100:220}), res)
Tu@CCU
2π ⋅ Ra ⋅ cos(lat )
∫P V (lev, lat )dp
g
Ps
zonal _ mpsi (lev, lat ) =
29/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Creating Time Coordinates from Scratch
labx = sprinti("%4i",ispan(1996,2000,1))
idxx = fspan(0 , 4*12 , 5)
整數或實數與文字模式的轉換(常用於標示時間序列的年份或月份)
sprinti (format [1] : string, array: integer):將整數轉換成文字
sprintf (format [1] : string, array: float or double):將實數轉換成文字
【說明】格式以『%』開頭,欲轉換之數字格式結尾『i, f, e/E, g/G.』,例如:【"%+0.4i"】
print( sprinti ("%6.0i", 219) )
=
print( sprinti ("%6.4i",-219) )
= -0219
219
總位數六位,但有效位數為四位,不足補零
print( sprinti ("%0.4i", -219) )
= -0219
總位數四位,有效位數四位,不足補零
print( sprinti ("% 0.3i", 21) )
=
有效位數三位(不含負號),不足補零
print( sprinti ("%+0.4i", 21) )
= +0021
有效位數四位,正數強迫加正號,不足補零
print( sprinti ("%+0.4i", -21) )
= -0021
有效位數四位,負數強迫加負號,不足補零
print( sprintf ("%7.4f", 20.65) )
= 20.6500
總位數七位,小數點後有效位數四位
print( sprintf ("%7.2f", 20.65) )
= 20.65
總位數七位,小數點後有效位數兩位
print( sprintf ("%+0.3f", 20.65) )
= +20.650
總位數七位,小數點後有效位數三位
print( sprintf ("%12.4e", 20.65) )
= 2.0650e+01
總位數十二位,小數點後有效位數四位
print( sprintf ("%0.4e", 20.65) )
= 2.0650e+01
小數點後有效位數四位
print( sprintf ("%0.4g", 20.65) )
= 20.65
取四位數字(不包含小數點)
print( sprintf ("%0.3g", 20.65) )
= 20.6
取三位數字(不包含小數點)
print( sprintf ("%0.2g", 20.65) )
= 21
取二位數字(不包含小數點)
021
總位數六位(不含正負號),不補零
Map(1/6) - Projection
res@mpProjection = Orthographic
Map(2/6) - boundary
;投影方式
Stereographic
LambertEqualArea
Equal-Area projection.
Gnomonic
res@mpShapeMode
= "FreeAspect"
地圖不按X/Y比例繪製
res@mpLeftMapPosF
res@mpRightMapPosF
res@mpBottomMapPosF
res@mpTopMapPosF
= 0.2
= 0.8
= 0.4
= 0.8
地圖位置(x1)
地圖位置(x2)
地圖位置(y1)
地圖位置(y2)
res@mpCenterLonF
res@mpCenterLatF
res@mpCenterRotF
= 180.0
= 0.0
= 0.0
地圖投影中心(經度)
地圖投影中心(緯度)
地圖投影中心(旋轉角度)
res@mpMinLonF
res@mpMaxLonF
res@mpMinLatF
res@mpMaxLatF
=
=
=
=
地圖繪製範圍
AzimuthalEquidistant
Satellite
Mollweide
Mercator
CylindricalEquidistant
LambertConformal
Robinson
Map(3/6)- Outline
Changing the Aspect Ratio of a Map
res@mpShapeMode = “
res@vpWidth
= 0.8
res@vpHeight
= 0.4
100
300
-30
60
”
res@mpFillPattern
=0
res@mpOceanFillPattern
=0
res@mpLandFillPattern
=0
res@mpInlandFillPattern
=0
Fill pattern #17 is a special stippling pattern:(「0」 for solid fill)
Tu@CCU
30/41
res@mpOutline
= False or True
;
res@mpOutlineBoundarySets
= "National"
; 開啟國界線
res@mpGeophysicalLineColor
= "Navy"
;
res@mpGeophysicalLineThicknessF
= 1.5
; 海岸線粗細
res@mpOutlineBoundarySets
= "NoBoundaries"
res@mpOutlineSpecifiers
= (/"Continents"/)
; continents only
res@mpNationalLineColor
= “Black”
;
res@mpNationalLineDashPattern
= 2
res@mpNationalLineDashSegLenF
= 0.2
res@mpNationalLineThicknessF
=1.5
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
MapĞ4/6ğĈన‫ؠ‬ঔăౙăസ‫̝ڿ‬ᗞҒ
gsn_define_colormap(wks,"wh-bl-gr-ye-re")
res@mpFillOn
= True
res@mpLandFillColor
= 164
設定
底色
res@mpOceanFillColor
= 90
設定
底色
res@mpInlandWaterFillColor
= 54
設地
顏色
res@mpOutlineOn
res@cnFillDrawOrder
= True
= “Predraw”
Map(5/6)- Grid Line
啟動填色功能
是否畫出地圖的邊界線
先作此設定,背景地圖才會出現
res@mpGridAndLimbOn
= True
turn on lat/lon lines
res@mpGridSpacingF
= 30.
經緯度線格線間距
res@mpGridLonSpacingF
= 60.
經度線格線間距
res@mpGridLatSpacingF
= 30.
緯度線格線間距
res@mpGridLineDashPattern
= 2
樣式
res@mpGridLineDashSegLenF
= 0.15
(for a viewport width of 0.6)
res@mpGridLineThicknessF
= 2.0
粗細
res@mpGridLineColor
= 5
顏色
res@mpGridMaskMode
= "MaskLand"
= "MaskOcean"
陸地或海洋不標經緯線
Satellite Projection
Lambert Projection(Native)
Native)
res@gsnAddCyclic = False ; regional data
= False ; regional data
res@mpProjection
res@mpProjection
= "LambertConformal"
; color of cont. outlines
res@mpGeophysicalLineColor= "Black"
res@mpLimitMode
= "Corners"
; thickness of outlines
res@mpGeophysicalLineThicknessF = 2.5
res@mpLeftCornerLatF
= slat
res@mpLeftCornerLonF
= slon
res@gsnAddCyclic
= "Satellite"
res@mpOutlineBoundarySets
= "National"
res@mpNationalLineColor
= "Black"
res@mpNationalLineThicknessF = 2.5
res@mpNationalLineDashPattern = 0
res@mpRightCornerLatF = elat
res@mpRightCornerLonF = elon
res@mpLambertParallel1F= (slat+elat)*0.5
res@mpLambertParallel2F= (slat+elat)*0.5
res@mpLimitMode
res@mpMinLatF
res@mpMaxLatF
res@mpMinLonF
res@mpMaxLonF
= "LatLon"
= slat
= elat
= slon
= elon
res@mpCenterLonF
res@mpCenterLatF
= 110.
= 40.
res@mpLambertMeridianF= (slon+elon)*0.5
Default coast is better suited
for global domains.
http://www.iohttp://www.io-warnemuende.de/homepages/rfeistel/index.html
If not on NCAR system, must download
RANGS-GSHHS database.
rangs(0).zip
gshhs(0).zip
rangs(1).zip
gshhs(1).zip
Medium level coastline is
best for large subregions e.g.
Atlantic
rangs(2).zip
gshhs(2).zip
rangs(3).zip
gshhs(3).zip
mpDataBaseVersion ="Ncarg4_1"
rangs(4).zip
gshhs(4).zip
You must download all ten of these files, unzip
High resolution coastline is
best for very small regions
them, and either put them in the default directory
"$NCARG_ROOT/lib/ncarg/database/rangs"
mpDataBaseVersion =“highres”
Tu@CCU
31/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Contour:Cylindrical Equidistant Projections
plot = gsn_csm_map_ce (wks,res)
mpDataBaseVersion
="Ncarg4_1"
plot = gsn_csm_contour_map_ce(wks,dat(ny,nx),res)
mpDataBaseVersion
= "highres"
plot = gsn_csm_streamline_contour_map_ce(wks,uu,vv,dat,res)
plot = gsn_csm_vector_scalar_map_ce(wks,uu,vv,dat,res)
res@cnFillOn
res@cnLinesOn
res@cnFillDrawOrder
res@cnLineColor
res@cnLineDashPattern
res@cnLineThicknessF
Default
= True
= True
= "Predraw"
= 12
= 2
= 1.5
= 0.
res@gsnContourZeroLineThicknessF
res@gsnContourLineThicknessesScale = 2.
res@gsnContourNegLineDashPattern = 11
Contour Interval
開啟填色功能
繪製等值線條
先畫等值線再疊地圖
等值線顏色
等值線虛線格式
等值線寬度
設定零值線的粗細
等值線粗細
虛線樣式
設定等值線相關訊息("CONTOUR FROM $CMN$ TO $CMX$ BY $CIU$")
res@cnInfoLabelOn
= False
res@cnInfoLabelFont
= 21
res@cnInfoLabelFontHeightF
= 0.012
res@cnInfoLabelFontColor
= 10
等值線最大值
res@cnInfoLabelAngleF
= 90
等值線間距
res@cnInfoLabelTextDirection
= “down” or “Across”
直書或橫書
res@cnInfoLabelPerimOn
= False
關閉等值線訊息邊匡
res@cnInfoLabelSide
= “Top”、”Bottom”、”Right”、”Left”
res@cnLevelSelectionMode
= " ManualLevels "
自訂等值線
res@cnMinLevelValF
= -10.0
等值線最小值
res@cnMaxLevelValF
=
35.0
res@cnLevelSpacingF
=
1.0
關掉等值線相關訊息
res@cnLevelSelectionMode
= "ExplicitLevels"
自訂等值線
res@cnLevels
res@cnInfoLabelOrthogonalPosF
= - 0.07
= (/20,25,30,35/)
自訂等值線數值大小
res@cnInfoLabelParallelPosF
= 0.07
res@cnFillColors
= (/26,30,135,50,44,/)
自訂等值線顏色
res@cnInfoLabelString
="CONTOUR FROM $CMN$ TO $CMX$ BY $CIU$"
res@gsnSpreadColors
= True
將所定義之顏色全部用上
設定等值線訊息位置
automatically create nice min/max/cint values for blue/red colortable
symMinMaxPlt (u,20,False,res)
設定等值線Label的背景顏色
Contour Label information
res@cnLineLabelsOn
= True
turn on line labels
res@cnLineLabelBackgroundColor
= -1 or “white”
設定等值線標記數值背景顏色
res@cnLineLabelInterval
= 1(default = 2)
等值線數值標示間距
res@cnLineLabelDensityF
= 3.0
res@cnLineLabelFont
= 21
res@cnLineLabelFontColor
= 1
res@cnLineLabelFontHeightF
= 0.012
res@cnLineLabelFontThicknessF
= 1.5
res@cnLineLabelAngleF
= 0
Tu@CCU
左圖:res@cnLineLabelBackgroundColor
左圖:res@cnLineLabelBackgroundColor =
右圖:res@cnLineLabelBackgroundColor
右圖:res@cnLineLabelBackgroundColor =
標記密集度< 1.0 = less,
>1.0 = more
32/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
左圖:設定標註Label的間隔(default = 2)
res@cnLineLabelInterval = 1
右圖:設定Label密集度。<1.0 = less, >1.0 = more
res@cnLineLabelDensityF = 3.0
rlon
rlat
= lonGlobeFo(nx,"lon","longitude","degrees_east")
= latGlobeFo(ny,"lat","latitude","degrees_north")
hov
= nameDim(hov,(/"lat","lon"/),"SST","C")
hov&lat = rlat
hov&lon = rlon
res@mpCenterLonF =
plot = gsn_csm_contour_map_ce(wks,hov(::2,::2),res)
Contour Label Bars (1/2)
res@lbLabelBarOn
= "True" or "False"
res@lbLabelFont
= 21 or "Helvetica-Bold"
res@lbLabelFontHeightF
Contour Label Bars (2/2)
字型
字的大小
= 0.012
res@lbTitleOn
= True
; turn on title
res@lbTitleString
= "m/s"
; title string
res@lbTitlePosition
= "Right"
; title position
res@lbTitleFontHeightF
= .015
; make title smaller
res@lbTitleDirection
= "Across"
; title direction
res@lbFillPattern
= 1
res@lbLabelFontColor
(Default: Foreground )
字的顏色
res@lbLabelAngleF
= 0.0
字的角度
res@lbLabelStride
= 4
標示數字的間隔
res@pmLabelBarSide
= "Top"、"Bottom"、"Right"、"Left"
res@lbOrientation
= "Vertical" or "Horizontal"
垂直或水平擺放
res@pmLabelBarParallelPosF
= 0.5
res@lbLabelPosition
res@lbLabelAlignment
= "Center" or "Right" or "Left"
= "BoxCenters"
res@lbLabelDirection
= "Across" or "Down"
res@lbLabelStrings
= (/"1","2","3","4","5"/)
label orientation
直書或橫書
label文字
; Color bar水平位置(與軸之距離)
res@pmLabelBarOrthogonalPosF = 0.005
; Color bar垂直位置(與軸之距離)
res@pmLabelBarWidthF
= 0.15
; Color Bar的寬度
res@pmLabelBarHeightF
= 0.6
; Color Bar的高度
res@cnLabelBarEndLabelsOn
= True
; 將最小與最大值標在Color Bar的左右邊
gsn_reverse_colormap(wks)
; 將color bar 排序反轉
overlay
Overlays one plot object on another.
overlay ( base_id [1] : graphic, transform_id [1] : graphic )
res@gsnContourZeroLineThicknessF = 2.
res@gsnContourNegLineDashPattern = 1
res@cnLineColor = "Red"
plotu = gsn_csm_pres_hgt(wks, u, res )
res@cnLineColor = "Blue"
res@cnLineThicknessF = 2.
res@gsnRightString = " "
res@gsnLeftString = " "
res@gsnCenterString = " "
plotv = gsn_csm_contour(wks,
gsn_csm_contour(wks, v, res )
overlay(plotu,plotv)
overlay(plotu,plotv) ; now over lay plots
Tu@CCU
33/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
res
res@gsnDraw
res@gsnFrame
res@sfXArray
res@sfYArray
= True ; plot mods desired
= False ; don't draw yet
= False ; don't advance frame yet ; #############################################
; res@mpDataBaseVersion
= "MediumRes"
= rlon
; res@mpDataBaseVersion
= "Ncarg4_1"
= rlat
res@mpDataBaseVersion
= "highres"
; #############################################
; #############################################
polyres
= True
res@mpLimitMode
= "LatLon"
polyres@gsMarkerIndex = 16
; polymarker style
res@mpCenterLonF
= 180.
polyres@gsMarkerSizeF = 5.
; polymarker size
res@mpMinLonF
= bndmap(0)
polyres@gsMarkerColor = "red"
res@mpMaxLonF
= bndmap(1)
; #############################################
res@mpMinLatF
= bndmap(2)
plot = gsn_csm_contour_map(wks,rain,res)
res@mpMaxLatF
= bndmap(3)
; #############################################
; #############################################
pmark = gsn_add_polymarker(wks,plot,rlon,rlat,polyres)
res@mpFillOn
= False
; #############################################
; res@mpFillOn
= True
draw (plot)
res@mpLandFillColor
= "Gray"
frame (wks)
; res@mpOceanFillColor
= "light sky blue"
; #############################################
; res@mpInlandWaterFillColor = "pink"
opt
= True
opt@mopt = 0
opt@distmx = 10.0
res@sfXArray
= rlon
hov = triple2grid(rlon,rlat,rain,rlon1,rlat1,opt)
res@sfYArray
= rlat
plot = gsn_csm_contour_map(wks,rain,res)
gsn_csm_contour_map(wks,rain,res) hov = smth9(hov,0.5,0.25,False)
plot = gsn_csm_contour_map(wks,rain,res)
gsn_csm_contour_map(wks,rain,res)
; #############################################
; ##########
res@mpGeophysicalLineColor
= "Red" ; color of cont. outlines
res@mpGeophysicalLineThicknessF = 2.5
; ##########
; res@mpOutlineBoundarySets = "National"
; res@mpOutlineBoundarySets = "NoBoundaries"
; res@mpOutlineSpecifiers
= (/"Continents"/) ; continents only
; ##########
res@mpNationalLineColor
= "Red"
res@mpNationalLineDashPattern = 0
res@mpNationalLineThicknessF = 3.0
Streamline
gsn_csm_streamline (wks,uu,vv,res)
Two Dimension-Vector
gsn_csm_streamline_map_ce(wks,uu,vv,res)
gsn_csm_streamline_map_polar(wks,uu,vv,res)
gsn_csm_streamline_contour_map_ce(wks,uu,vv,dat,res)
gsn_csm_streamline_contour_map_polar(wks,uu,vv,dat,res)
gsn_csm_pres_hgt_streamline(wks,dat,xcd(nx),zcd(nz),res)
Wind Vector
gsn_vector(wks,uu,vv,res)
gsn_csm_vector_scalar(wks,uu,vv,dat,res)
gsn_vector_map(wks,uu,vv,res)
gsn_csm_vector_map_ce(wks,uu,vv,res)
gsn_csm_vector_map_polar(wks,uu,vv,res)
gsn_csm_vector_scalar_map_ce(wks,uu,vv,dat,res)
gsn_csm_vector_scalar_map_polar(wks,uu,vv,dat,res)
gsn_csm_streamline_contour_map_ce
(wks , uu , vv , sst , res)
res@stArrowLengthF
= 0.004
箭頭大小
res@stMinArrowSpacingF
= 0.004
箭頭之間的距離
res@stMinDistanceF
= 0.03
流線間距
res@stArrowStride
=3
箭頭間隔
res@stLineThicknessF
= 1.5
流線粗細
res@stLineColor
= "orange"
流線顏色
res@stStreamlineDrawOrder
= PreDraw or Draw or PostDraw
Wind Vector - Minimum Arrow
i = NhlNewColor(wks,0.7,0.7,0.7)
res@mpLandFillColor
= "gray"
res@lbOrientation
= "Vertical"
res@pmLabelBarOrthogonalPosF = -0.01
res@lbLabelStride
=4
res@cnLevelSelectionMode
= "ManualLevels"
res@cnMinLevelValF
= 24.0
res@cnMaxLevelValF
= 29
res@cnLevelSpacingF
= 0.10
res@stArrowLengthF
= 0.015
res@stArrowStride
= 1
plot= gsn_csm_streamline_contour_map_ce(wks,u,v,sst,res)
Tu@CCU
res@vcGlyphStyle
= "CurlyVector"
= "LineArrow"
= "FillArrow"
= "WindBarb"
; turn on curley vectors
res@vcLineArrowColor
= "white"
; vector color
res@vcLineArrowThicknessF
= 2.0
; vector thickness
res@vcVectorDrawOrder
= "PostDraw"
; draw vectors last
res@vcMinDistanceF
= 0.017
; thin out vectors
res@vcMonoLineArrowColor
= False
; create color vectors
res@gsnSpreadColors
= True
; use full colormap
res@lbLabelStride
= 2
; every other label
res@gsnSpreadColorEnd
= -3
; don't use added gray
res@vcMinAnnoArrowLineColor
34/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Reference Arrow
gsn_csm_vector_scalar_map_ce
(wks , uu , vv , sst , res)
res@vcRefAnnoOn (Reference Annotation) = Trun
res@vcRefAnnoFont
res@vcRefAnnoFontColor
gsnScalarContour = True
res@vcRefAnnoFontHeightF
res@vcRefAnnoFontAspectF
res@vcRefAnnoFontThicknessF
res@vcRefAnnoConstantSpacingF
res@vcRefAnnoAngleF
res@vcRefAnnoTextDirection
="Down"or"Across"
res@vcRefAnnoBackgroundColor
res@vcRefMagnitudeF
= 4.0
; define vector ref mag
res@vcRefLengthF
= 0.045
; define length of vec ref
res@vcRefAnnoParallelPosF
= 1.0
res@vcRefAnnoOrthogonalPosF
= -1.0
; move reference vector up
res@vcRefAnnoArrowLineColor
= "black"
; change ref vector color
res@vcRefAnnoArrowUseVecColor
= False
; don't use vec color for ref
res@vcRefAnnoSide
=Top、Bottom、Right、Left
res@vcRefAnnoString2On
= True
; turn on second string
res@vcRefAnnoString2
= "m/s"
; unit string
res@gsnScalarContour = True ; contours desired
res@gsnSpreadColorStart = 17
res@gsnSpreadColorEnd = 200
i = NhlNewColor(wks,0.7,0.7,0.7) ;add gray to colormap
res@mpLandFillColor = "gray" ; set land to be gray
res@vcRefAnnoSide
=Top
res@vcRefMagnitudeF
= 4.0
res@vcRefLengthF
= 0.045
res@vcRefAnnoOrthogonalPosF = -1.0
res@vcRefAnnoArrowLineColor = "black“
res@vcRefAnnoString2On = True
res@vcRefAnnoString2
= "m/s "
res@vcGlyphStyle
= "CurlyVector"
res@vcLineArrowColor
= "white"
res@vcLineArrowThicknessF = 2.0
res@vcVectorDrawOrder
= "PostDraw"
plot=gsn_csm_vector_scalar_map_ce(wks,u(:,:),v(:,:),
sst(:,:),res)
原始資料僅涵蓋部分區域時之設定方式
gsn_csm_vector_scalar_map_ce
;----------- Begin first plot ----------------------------------------resources = True
gsn_csm_vector_scalar_map_polar
nlon = dimsizes(lon)
nlat = dimsizes(lat)
res@vfXCStartV
= slon ; Define lat/lon corners
res@vfXCEndV
= elon ; for vector plot.
res@vfYCStartV
= slat
res@vfYCEndV
= elat
map = gsn_vector_map(wks,u,v,res)
; Zoom in on the plot area.
res@mpLimitMode
= "Corners"
res@mpLeftCornerLonF = slon
res@mpRightCornerLonF= elon
res@mpLeftCornerLatF = slat
res@mpRightCornerLatF = elat
res@vpXF = 0.1
res@vpYF = 0.92
res@vpWidthF = 0.75
res@vpHeightF = 0.75
map = gsn_vector_map(wks,u,v,res)
Set gsnScalarContour = True
to get vectors on top of contours.
Wind Bars
res@vcGlyphStyle
= " WindBarb"
res@vcWindBarbColor
= " Black "
res@vcWindBarbLineThicknessF
= 1.0
Wind Barb
res@vcRefMagnitudeF
res@vcWindBarbTickAngleF
= 10.
; make vectors largervc
res@vcRefLengthF
= 0.050
; ref vec lengthvc
res@vcGlyphStyle
= "WindBarb" ; choose wind barbsvc
res@vcWindBarbTickLengthF
= 0.3
res@vcMonoWindBarbColor = False ; color barbs by scalar vc
res@vcWindBarbTickSpacingF
= 0.125
res@vcMinDistanceF
= 0.025
res@vcWindBarbCalmCircleSizeF
= 0.25
res@tiMainString
= "WindBarbs colored by a scalar map"
res@vcWindBarbScaleFactorF
= 1.0
plot=gsn_csm_vector_scalar_map_ce(wks,u,v,t,vcres)
Tu@CCU
35/41
; thin out windbarbsvc
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Weather Map
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/wind_rose.ncl"
wrData = wr_GenBogusData (200)
Wind Rose
wspd = wrData(0,:)
wdir
= wrData(1,:)
wspd@long_name = "Wind Speed"
wspd@units
= "m/s"
wdir@long_name = "Wind Direction"
numPetals
WcircFr
spdBounds
= 8
; N, NE, E, SE, S, SW, W, N
= 10.
= (/ 10., 20., 30., 100. /)
RoseCol = (/ "blue", "green", "yellow", "red" /)
plot(0) = WindRoseBasic (wks,wspd,wdir,numPetals,circFr,res)
plot(1) = WindRoseThickLine (wks,wspd,wdir,numPetals, circFr,spdBounds,res)
plot(2) = WindRoseColor (wks,wspd,wdir,numPetals,circFr,spdBounds,colorBounds,res)
numPetals = 4 ; N, E, S, W
plot(3) = WindRoseColor (wks,wspd,wdir,numPetals,circFr,spdBounds,colorBounds,res)
Weather Map
wmbarb(wks, xcd, ycd, u, v)
wmbarbmap(wks, lat, lon, u, v)
http://ngwww.ucar.edu/supplements/wmap
Draws wind barbs
wmbarb( wks, x [*] : float, y [*] : float, dx [*] : float, dy [*] : float )
Draws wind barbs over maps (does not call frame)
wmbarbmap( wks, lat : float, lon : float, u : float, v : float )
Plots special symbols and icons
wmlabs( pname [1] : string, pval )
Plots station model data
wmstnm ( wks, x : float, y : float, imdat : string of 50 characters )
Draws weather front lines
wmdrft( wks, y [*] : float, x [*] : float )
Retrieves parameter values for selected Wmap routines.
wmgetp( pname[1] : string )
Draw vector
wmvect(wks,
wmvect(wks, 0.375, 0.4, u, v)
Windbar (wks, lat, lon,
lon, u, v)
Name
Type
EZF
integer
LWD
float
Description
A flag to be used only in NCL codes that, when set different from -1,
indicates wmap functions are to be used with the NCL mapping
functions.
Line width used when parameter WTY=1 (see below)
Windbar (wks, lat, lon,
lon, u, v)
Description
Default
Flag indicating orientation of the wind barb (=0 barbs
point away from wind direction; =1 barbs point toward
wind direction). A value of 1 is the meteorological
convention.
0
WDF
integer
0.00275
WBL
float
Size of the text labels in the station model display,
expressed as a fraction of the shaft length.
PAI
integer
UNT
integer
Flags whether to use imperial units (the default) or metric units in a
station model display.
WBA
float
Angle that the wind barb tics make with the wind barb shafts.
62.
WBC
float
Diameter of sky cover circle at base of wind barb, expressed as a
fraction of the shaft length.
0.3
WBD
float
Spacing between tick marks along a wind barb expressed as a
fraction of the wind barb shaft length.
0.1
WBF
integer
Tu@CCU
Type
-1
Current parameter array index used in specifying internal parameters
that are arrays.
Flag indicating whether the base of a wind barb should be drawn to
allow for the sky cover circle at its base
(WBF=1 means yes; WBF=0 means no).
Name
Default
0.17
1
WBR
float
Radius of the larger circle drawn for calm, as a fraction
of the wind barb shaft length.
0
WBS
float
The size, expressed as a fraction of the maximum screen
height, of a wind barb shaft.
WBT
float
Length of wind barb full tick as a fraction of its shaft
length.
0.33
WHT
float
Height of characters, expressed as a fraction of the
maximum screen width, of the characters used for
regional weather labels (plotted with WMLABW or
c_wmlabw).
0.014
WTY
integer
0
36/41
Flag indicating whether linewidths are to be
implemented via GKS (WTY=0), or simulated internally
(WTY=1).
07/23/2009
0.25
0.035
0
中國文化大學大氣科學系暑期電腦訓練課程:NCL
wmlabs (wks,lat,lon,symbol)
wks,lat,lon,symbol)
Symbol = HI、
HI、LOW、
LOW、ARROW、
ARROW、DOT
(Plots special symbols and icons for daily weather )
1
'SUN'
2
'WIND'
3
'ICE'
4
'CLOUD'
5
'RAIN'
6
'SNOWFLAKES'
7
'MC' (Mostly cloudy)
8
'MS' (Mostly sunny)
9
'RS' (Rain and snow)
?
?
?
10 'IT' (Sunny, T-storms)
?
11 'THUNDERSTORM'
12 'IS' (Intermittent showers)
wmsetp("pname",val)
High、Low
SHT
SHT, HIF, HIB, HIS, HIC - for high symbols
HIB
SHT, LOF, LOB, LOS - for low symbols
HIC
AOC, ARD, ARL, ARS , ASC, AWC - for arrows
HIF
SHT, COL, - for icons
HIS
DBC, DTC, DTS - for dots
LOB
CC1, CC2, CC3 - for clouds
LOC
Height of symbols, expressed as a fraction of the
maximum screen width, for all the special symbols.
float
integer
0
integer
Color index of the circumscribed circle for the "H"
drawn for the high pressure symbols.
1
integer
Color index for the "H" drawn for the high pressure
symbols.
1
integer
Color index for the shadow of the high pressure
symbols
1
integer
Color index for the background of the "L" drawn for
the low pressure symbols.
1
integer
Color index for the circumscribed circle for the "L"
drawn for the low pressure symbols.
1
0
0
LC1, LC2, LC3 - for lightning bolts
LOS
integer
Color index for the shadow of the low pressure
symbols.
SC1, SC2, SC3, SC4 - for suns
LOF
integer
Color index for the "L" drawn for the low pressure
symbols.
Arrows
ARS
ARD
ARL
float
float
float
Icons、Dot
0.035
Size of arrows
Direction of arrows, expressed in degrees.
COL
0.
length of an arrow's tail
1.
Color index for the outlines of arrows
(outlines drawn only if AOC is non-negative).
-1
Color index for the shadows of arrows
ASC
integer (drawn only if ASC is non-negative).
-1
AWC
integer Color index for the interior of arrows.
1
180
0
270
Tu@CCU
integer
Color index to use for all objects
1
integer
The color index to be used for backgrounds of city
and daily high/low labels.
1
CHT
float
Height of characters, expressed as a fraction of the
maximum screen width, of the city labels and
daily high/low temperatures.
0.0105
CMG
float
Size, expressed as a fraction of the maximum
screen height, of the margins used for the city
labels.
0.002
DBC
integer
The color index to be used for the background
shadow for the dots marking the city locations.
0
DTC
integer
The color index to use for the dots marking the
city locations.
1
DTS
float
CBC
90
AOC
integer
ARD Î
0.02
Background color index for the "H" drawn for the high
pressure symbols.
37/41
Size, expressed as a fraction of the maximum
screen height, of the dots used to mark cities.
07/23/2009
0.006
中國文化大學大氣科學系暑期電腦訓練課程:NCL
Cloud、Lightning、Sun
Plots station model data
CC1
CC2
CC3
integer
Color index for the interior of a cloud symbol.
2
wmsetp ("wbs",0.20)
(Specify the size of the wind barb)
integer
Color index for the outline of the cloud symbol.
1
wmstnm (wks,xcd,ycd,imdat
wks,xcd,ycd,imdat))
integer
Color index for the shadow of the cloud symbol.
1
(Station model )
LC1
integer
Color index for the interior of the lightning bolt
symbol
2
integer
Color index for the outline of the lightning bolt
symbol.
1
integer
Color index for the shadow of the lightning bolt
symbol
1
SC1
integer
Color index to be used for the center of the sun
symbol.
2
SC2
SC3
SC4
integer
Color index for the points of the sun symbol.
3
integer
Color index for the outline of the sun symbol.
1
integer
Color index for the shadow of the sun symbol.
1
LC2
LC3
A string of 50 characters encoded
as per the WMO/NOAA guidelines.
the characters are numbered from
left to right, starting at character
number 0
imdat="11212833201001120000300004014752028601117706086792"
imdat="RXhvvNddff1sTTT2sTd3PO4PPP5appp6RRRR7www1w28NhClCmCh"
character25
characters 26-29
character 30
character 31
characters 32-34
character 35
characters 36-38
character 39
character 40
characters 41-42
character 43
character 44
character 45
character 46
character 47
character 48
character 49
wmstnm(wks,xcd,ycd,imdat)
character0
characters 1
character 2
character 3-4
characters 5
character 6-7
characters 8-9
character 10
character 11
characters 12-14
character 15
character 16
character 17-19
character 20
character 21-24
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
iR
- the precipitation data indicator
iX
- weather data and station type indicator
h
W
N
dd
ff
“1"
- height above ground of base of lowest cloud
sn
- visibility in miles and fractions
- total amount of cloud cover
- direction from which wind is blowing
- wind speed in knots
- sign of temperature
- current air temperature
TTT - sign of temperature
“2" sn
- 2nd most sig. past weather
Td - dew point temperature
“3" Po - station pressure (not plotted)
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
“4"
PPPP
“5"
a
ppp
“6"
RRR
tR
“7"
ww
W1
W2
"8"
Nh
CL
CM
CH
- pressure reduced to sea level
- characteristic of barograph
- pressure change, last 3 hrs.
- precipitation
- time duration of precipitation
- present weather
- most significant past weather
- 2nd most sig. past weather
- Fraction of sky cover
- cloud type, low clouds
- cloud type, medium clouds
- cloud type, high clouds
ALO
integer
A weather front is at the surface or aloft (0 is surface; 1 is aloft).
0
Draw front
ARC
float
Length of current front line (retrieval only)
0.
BEG
float
space before first symbol on front line
0.015
wmdrft(wks, xlat, xlon)
BET
float
space between symbols on a front line
0.045
END
float
space after last symbol on front line
0.015
COL
integer
Color index to use for all objects
1
CFC
integer
Color index to use for cold front symbols.
1
WFC
integer
Color index to use for warm front symbols.
CS1
float
Slope of the left edge of a front line (used when SLF=0,2, or 3). (retrieval
only)
N/A
CS2
float
Slope of the right edge of a front line (used when SLF=0,1, or 3).
(retrieval only)
N/A
DWD
float
Line widths for front lines that do not have symbols along them (like
tropical fronts and convergence lines).
FRO
string
Tu@CCU
38/41
Front type (one of 'WARM', 'COLD', 'OCCLUDED', 'STATIONARY',
'SQUALL', 'TROPICAL', or 'CONVERGENCE').
1
2.0
WARM
8.
LIN
float
MXS
integer
Maximum number of symbols allowed along a weather front line.
NBZ
integer
The number of points to use in the Bezier curves for the symbols along
the warm fronts.
51
NMS
integer
number of symbols along a front line
-1
line widths for the more common fronts
07/23/2009
200
中國文化大學大氣科學系暑期電腦訓練課程:NCL
REV
reverses direction of front symbols
SLF
integer
flag for end slopes (0=use SL1 & SL2; 1=use SL1 only; 2=use SL2 only;
3=use neither SL1 or SL2). When either SL1 or SL2 is not used, it is
calculated internally.
SL1
float
slope at beginning of front line
0.0
SL2
float
slope at end of front line
0.0
3
integer
float
Width of a symbol along a weather front
SIG
float
Specifies the tension factor for tension spline calculations for drawing
front lines. Small values (~0.001) produce near cubic spline interpolation;
larger values (~20.) produce near linear interpolation.
T1C
integer
One colors for tropical fronts
T2C
integer
A second colors for tropical fronts
OER
integer
smoothing spline calculations for drawing front lines. The default is 0.005
times the absolute value of the maximum data value. Only applies when
SMF flags smooting spline usage.
SMF
integer
Specifies whether tension spline interpolation (=0) or smoothing spline
approximation (=1) is done to draw front lines.
0
float
Specifies a degree of smoothing for smoothing spline approximations
when drawing a front line. The default is 50 x the number of input data
points.
depen
ds
SMT
; Draw a stationary front.
wmsetp("ezf",1)
; using an existing map projection.
wmsetp("lin",1.0)
; Line width of front curve.
wmsetp("fro","stationary"); Specify stationary front.
wmsetp("cfc",3)
; Use blue for the triangles.
wmsetp("wfc",2)
; Use red for the bumps.
wmsetp("swi",0.04) ; Increase the size of the bumps and triangles.
wmdrft(wks, rlat, rlon) ; Draw front.
all 2s
STY
SWI
specify type of symbols along a front line. (1=cold; 2=warm).
; res@gsnDraw = False
res@gsnFrame = False
…………
plot = gsn_csm_contour_map(wks,hov,res)
N/A
integer
0.0325
0.001
1
1
; Draw a couple of High symbols.
wmsetp("hib",4)
; Cyan for background.
wmsetp("his",1)
; Black for shadow.
wmsetp("hic",5)
; Magenta for bounding circle.
wmsetp("sht",0.02) ; Increase size.
wmlabs(wks, rlat, rlon, "HI") ; Draw symbols.
depen
ds
frame (wks)
Others
SkewT - LogP
Opts = True
skewt_bkgd = skewT_BackGround (wks, Opts)
draw (skewt_bkgd)
Opts@DrawColAreaFill = True
Opts@DrawHeightScale = True
Opts@DrawHeightScaleFt= False
Opts@DrawFahrenheit = False
skewt_bkgd = skewT_BackGround (wks, Opts)
Opts = True
Opts@DrawColAreaFill = True
Opts@DrawHeightScale = True
skewt_bkgd=skewT_BackGround (wks, Opts)
draw (skewt_bkgd)
Tu@CCU
draw (skewt_bkgd)
39/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/skewt_func.ncl"
nlvl = 30
ncol = 16
TestData = asciiread (path+ifn , (/nlvl,ncol/), "float")
P = TestData (:,0) ; pressure [mb/hPa] (surface to top)
Ta = TestData (:,1) ; temperature [C]
Td = TestData (:,2) ; dew pt temp [C]
Z = TestData (:,4) ; geopotential [gpm]
wspd = TestData (:,5) ; wind speed [knots or m/s]
wdir = TestData (:,6) ; meteorological wind direct
wspd@_FillValue = -999.
wdir@_FillValue = -999.
; Create a few "pibal" reports
hght = (/ 1000., 3000., 7000., 25000. /)/3.208 ; hgt in M
hspd = (/ 50., 27., 123., 13. /) ;speed
hdir = (/ 95., 185., 275., 355. /) ;direction
Plcl: Lifting Condensation Level [hPa]
Tlcl: Temperature at the LCL
Shox: Showalter Index
Pwat: Total Precipitable Water [cm]
Cape:[Joules]
dataOpts = True
dataOpts@PlotWindH = True ; plot wind barbs at height lvls
dataOpts@HspdHdir = True ; wind speed and dir [else: u,v]
dataOpts@Height
= hght ; height of wind reports
dataOpts@Hspd
= hspd ; speed [or u component]
dataOpts@Hdir
= hdir ; dir [or v component]
dataOpts = True
dataOpts@Wthin = 3 ; plot every n-th wind barb
skewtOpts@DrawColAreaFill = True ; default is False
skewtOpts
= True
skewtOpts@DrawColAreaFill = True ; default is False
skewtOpts
= True
skewtOpts@DrawColAreaFill = True
skewtOpts@DrawHeightScale = True
skewtOpts@DrawHeightScaleFt= False
skewtOpts@DrawFahrenheit = False
skewt_bkgd = skewT_BackGround (wks, skewtOpts)
skewt_data = skewT_PlotData (wks,skewt_bkgd,p,ta,td,z,wspd,wdir,dataOpts)
draw (skewt_bkgd)
draw (skewt_data)
frame(wks)
skewt_bkgd = skewT_BackGround (wks, skewtOpts)
skewt_data = skewT_PlotData (wks , skewt_bkgd , P , Ta , Td , Z , wspd , wdir , dataOpts)
draw (skewt_bkgd)
draw (skewt_data)
frame(wks)
Special Topics: Equations
Superscript:
10~S~o~N~
gsn_text_ndc(wks ,"Created and placed by parts", xcd , ycd , res)
txres@txFontHeightF = 0.025
txres@txJust
= "CenterLeft"
; Default is "CenterCenter"
℃ or(℃)
2
W /m
Hk-1
H:B:k-1:N:
【法一】eqn = ":V1::F21:W:F21:/:F21:m:S:2:N:"
Greek Character:
【法二】eqn = ":V1::F21:W:H-35::V-5::F21:___:H-40::V-35::F21:m:S:2:N:"
(v ⋅ q ′) (v ′ ⋅ q )
r
( v ⋅ q )′
−
Subscript:
eqn = ":V1::S:o:N::F21:C:" or eqn = ":V1::F21:( :S:o:N::F21:C:N: )"
W
m2
10oN
σ
~F33~s
eqn1 = ":V1::F21: ( v:N::H-22::V20::F8:-:N::V-20::F21: q:S::F0:':N::F21: )"
eqn2 = ":V1::F21: ( v:S::F0:':N::F21: q:N::H-20::V20::F8:-:N::V-20::F21: )"
eqn3 = ":V1::F21: ( vq:N::F21: ):S::F0:':N::F21:"
eqn1 = ":V1::F8: - :V20::F21:1:H-25::V-7::F21:__:H-22::V-
「:H:」水平移動距離。『:V:』垂直移動距離
):S::F0:':N::F21: dp:N:"
「S」上標。「B」下標。「N」中斷先前的設定
1 500
30::F21:g:H20::V20::Y300::X200::F34:r:Y::X::H-10::V-50::F21: :B:1000:H(v ⋅ ∇q)′dp 30::V90::F21:500:N::V-45::F33: ( :N::F21:v:V8::F21: . :V-8::F18:t:F21:q:F33:
g ∫1000
【註】「:H:」水平移動距離。『:V:』垂直移動距離。「S」上標。「B」下標。「N」中斷先前的設定
Example
Tu@CCU
40/41
07/23/2009
中國文化大學大氣科學系暑期電腦訓練課程:NCL
• Create a graphical array
gsn_panel
plot = new(3, graphic)
• Create individual plots a members of the
graphical array
res
(/3,1/)
(/3,2/)
(/3,2/)
A panel plot
= True
res@gsnDraw = False
res@gsnFrame = False
plot(0) = gsn_xy (wks, x, y1, res)
•
plot(1) = gsn_xy (wks, x, y2, res)
pres
= True
plot(2) = gsn_xy (wks, x, y3, res)
pres@gsnPanelRowSpec = True
Pass the graphical array to gsn_panel
gsn_panel(wks,plot,(/1,3,2/),pres)
gsn_panel (wks, plot, (/3,1/),pres)
plot = new(2,graphic) ; create a plot array
plot(0) = gsn_csm_contour_map_ce(wks,u,res)
plot(1) = gsn_csm_contour_map_ce(wks,v,res)
res@gsnFrame
= False
don't advance panel plot
res@gsnPanelCenter
= False
layout is for the plots to be centered
res@gsnPanelRowSpec
= True
tell panel what order to plt
res@gsnPanelLabelBar
= True
add common colorbar
res@gsnPanelBottom
= 0.0
move bottom up
res@gsnPanelTop
= 0.5
draw up to the bndry of upper plot
res@gsnPanelYWhiteSpacePercent
=5
res@gsnPanelXWhiteSpacePercent
=5
Adds the white space to the panel plot
res@gsnPanelFigureStrings
= (/"a)","b)"/)
add strings to panel
gsn_panel(wks,plot,(/2,1/),res)
Shell Scripts
#!/bin/csh
foreach yr ( 1997 1991 1982 )
setenv YRENSO $yr
ncl cc.ncl
end
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
csy = stringtointeger(getenv("YRENSO"))
end
Tu@CCU
41/41
07/23/2009

Similar documents