NCL使用
1.批量
files = systemfunc ( "ls -1 /data3/users/ajuchao/fnl/200806/fnl*" ) ;是-1,不是-l
a = addfiles(files,"r")
numfiles=dimsizes(a)
ListSetType (a,"join")
addfiles返回的是一个list类型的变量,而这种变量的读取有两种方式,分别是“join”和“cat”,后者为默认,使用ListSetType进行切换。
cat方式将所有文件中变量在最左边的维上进行合并处理,join方式则在最左边额外产生一维,大小为文件数。
2.摄氏度表示方式: ~F35~J~F~C
3.逻辑操作符
.le. 小于等于(less-than-or-equal)
.lt. 小于(less-than)
.ge. 大于等于(greater-than-or-equal)
.gt. 大于(greater-than)
.ne. 不等于(not-equal)
.eq. 等于(equal)
.and. 且
.xor. 亦或(exclusive-or)
.or. 或
.not. 非
4.复制属性
copy_VarCoords(x,y)
将x的属性赋给y
5.排序颠倒
a=[1,2,3,4]
b=a(::-1)
b=[4,3,2,1]
6.调整维数顺序
ts1 = tmp1(lat|:,lon|:,time|:)
7. sprinti("%0.2i",month)
8. vmin = local_min(dist, False, 0.0)
dist为二维数组,得到最小值以及最小值所对应x,y点
xmin=vmin@xi
ymin=vmin@yi
min_value=vmin@minval
9.查找最大最小值所在点
Example:
;---Create a dummy 2 x 2 x 4 array.
a = (/(/(/1,2,3,4/), (/5,6,7,8/)/), (/(/9,1,9,8/),(/7,6,1,4/)/)/)
;---Convert to 1D
a1D = ndtooned(a)
dsizes_a = dimsizes(a)
;---Resolve the 1D indices back to their original 3D array.
indices = ind_resolve(maxind(a1D),dsizes_a)
print(indices)
返回值:(1,0,0)
9.读取文件
;-----------------------------------------------deal with WRF Output data
dir_wrf = "/home/jinjm1/gfs/TL/wrf/WRFV3_1/run/TL0017/"
fname_wrf = "wrfout_d01_2007-07-*|wrfout_d01_2007-08-01" ; 通过设置正则表达式控制添加什么文件
fname_wrf = integertochar(34)+fname_wrf+integertochar(34) ; 添加引号,ncl中没有转义符号
fils_wrf = systemfunc("ls "+dir_wrf+" | egrep "+fname_wrf) ; file paths + name
; print(fils_wrf)
f_wrf = addfiles(dir_wrf+fils_wrf+".nc", "r")
10. 短型转换为浮点型(具体选择看提供的算式)
Short2flt: x_float = x_short*scale + offset
Short2flt_hdf: x_float = scale*(x_short - offset)
offset: "add_offset", "OFFSET", "Offset", "_offset", "Intercept", "intercept"
scale: "SCALE", "Scale", "_scale", "scale_factor", "Scale_factor", "Slope" , "slope"
11. 选取某段的文件
例如:files1=systemfunc(“ls -1 wrfout_d01_2004-07-1[0-2]_* ")
则选取结果为
[ ] 内数字只能填写1-9
12. WRF 计算
nc_file = addfile("wrfout_d01_2000-01-24_12:00:00.nc","r")
T = nc_file->T
P = nc_file->P
PB = nc_file->PB
qv = nc_file->QVAPOR
T = T + 300. ; potential temperature in K.
P = P + PB ; full pressure in Pa.
tk = wrf_tk( P , T ) ; temperature in K.
eth = wrf_eth ( qv, tk, P )
13.刻度朝内
tmXBMajorOutwardLengthF
14.查看nc变量 ncl_filedump
15.去除边框
res@mpPerimOn = False
;res@pmTickMarkDisplayMode = "Always"
注意结合投影方式,如兰伯特(WRF) res@mpProjection = "LambertConformal" 和 圆柱等面积(CESM)res@mpProjection ="CylindricalEqualArea" 均可使用
16.调整label
res@pmLabelBarHeightF = 0.08 默认0.6
res@pmLabelBarWidthF = 0.4 默认0.15
res@pmLabelBarOrthogonalPosF = -0.1 默认0.02;向上移动
res@pmLabelBarParallelPosF = -0.1 默认0.5;向左移动
17.调整作图顺序cnFillDrawOrder
PreDraw 在所有图之前作图,会被之后任何elements覆盖
Draw
PostDraw 在所有图之后作图,覆盖之前的elements
files = systemfunc ( "ls -1 /data3/users/ajuchao/fnl/200806/fnl*" ) ;是-1,不是-l
a = addfiles(files,"r")
numfiles=dimsizes(a)
ListSetType (a,"join")
addfiles返回的是一个list类型的变量,而这种变量的读取有两种方式,分别是“join”和“cat”,后者为默认,使用ListSetType进行切换。
cat方式将所有文件中变量在最左边的维上进行合并处理,join方式则在最左边额外产生一维,大小为文件数。
2.摄氏度表示方式: ~F35~J~F~C
3.逻辑操作符
.le. 小于等于(less-than-or-equal)
.lt. 小于(less-than)
.ge. 大于等于(greater-than-or-equal)
.gt. 大于(greater-than)
.ne. 不等于(not-equal)
.eq. 等于(equal)
.and. 且
.xor. 亦或(exclusive-or)
.or. 或
.not. 非
4.复制属性
copy_VarCoords(x,y)
将x的属性赋给y
5.排序颠倒
a=[1,2,3,4]
b=a(::-1)
b=[4,3,2,1]
6.调整维数顺序
ts1 = tmp1(lat|:,lon|:,time|:)
7. sprinti("%0.2i",month)
8. vmin = local_min(dist, False, 0.0)
dist为二维数组,得到最小值以及最小值所对应x,y点
xmin=vmin@xi
ymin=vmin@yi
min_value=vmin@minval
9.查找最大最小值所在点
Example:
;---Create a dummy 2 x 2 x 4 array.
a = (/(/(/1,2,3,4/), (/5,6,7,8/)/), (/(/9,1,9,8/),(/7,6,1,4/)/)/)
;---Convert to 1D
a1D = ndtooned(a)
dsizes_a = dimsizes(a)
;---Resolve the 1D indices back to their original 3D array.
indices = ind_resolve(maxind(a1D),dsizes_a)
print(indices)
返回值:(1,0,0)
9.读取文件
;-----------------------------------------------deal with WRF Output data
dir_wrf = "/home/jinjm1/gfs/TL/wrf/WRFV3_1/run/TL0017/"
fname_wrf = "wrfout_d01_2007-07-*|wrfout_d01_2007-08-01" ; 通过设置正则表达式控制添加什么文件
fname_wrf = integertochar(34)+fname_wrf+integertochar(34) ; 添加引号,ncl中没有转义符号
fils_wrf = systemfunc("ls "+dir_wrf+" | egrep "+fname_wrf) ; file paths + name
; print(fils_wrf)
f_wrf = addfiles(dir_wrf+fils_wrf+".nc", "r")
10. 短型转换为浮点型(具体选择看提供的算式)
Short2flt: x_float = x_short*scale + offset
Short2flt_hdf: x_float = scale*(x_short - offset)
offset: "add_offset", "OFFSET", "Offset", "_offset", "Intercept", "intercept"
scale: "SCALE", "Scale", "_scale", "scale_factor", "Scale_factor", "Slope" , "slope"
11. 选取某段的文件
例如:files1=systemfunc(“ls -1 wrfout_d01_2004-07-1[0-2]_* ")
则选取结果为
[ ] 内数字只能填写1-9
12. WRF 计算
nc_file = addfile("wrfout_d01_2000-01-24_12:00:00.nc","r")
T = nc_file->T
P = nc_file->P
PB = nc_file->PB
qv = nc_file->QVAPOR
T = T + 300. ; potential temperature in K.
P = P + PB ; full pressure in Pa.
tk = wrf_tk( P , T ) ; temperature in K.
eth = wrf_eth ( qv, tk, P )
13.刻度朝内
tmXBMajorOutwardLengthF
14.查看nc变量 ncl_filedump
15.去除边框
res@mpPerimOn = False
;res@pmTickMarkDisplayMode = "Always"
注意结合投影方式,如兰伯特(WRF) res@mpProjection = "LambertConformal" 和 圆柱等面积(CESM)res@mpProjection ="CylindricalEqualArea" 均可使用
16.调整label
res@pmLabelBarHeightF = 0.08 默认0.6
res@pmLabelBarWidthF = 0.4 默认0.15
res@pmLabelBarOrthogonalPosF = -0.1 默认0.02;向上移动
res@pmLabelBarParallelPosF = -0.1 默认0.5;向左移动
17.调整作图顺序cnFillDrawOrder
PreDraw 在所有图之前作图,会被之后任何elements覆盖
Draw
PostDraw 在所有图之后作图,覆盖之前的elements
-
水波 赞了这篇日记 2021-12-20 16:53:01