记录一次ncl从前端到后端出图过程:调用linux-shell执行ncl命令从nc文件出图

ncl出图大概长这样子:

 

数据文件:

ncl脚本:

 

;************************************************
;
; These files are loaded by default in NCL V6.2.0 and newer
; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"   
; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"    
;
; @Author Zhou
; @Date 2016-07-25
;
;************************************************
begin

;************************************************
;try to read file name from command line parameter
;************************************************
if (.not. isvar("fileName")) then      ; is fileName on command line?
      fileName = "hgt.2000.nc,hgt.2003.nc";
end if

fileArray = str_split(fileName, ",");
print(fileArray);

if (.not. isvar("filePath")) then      ; is filePath on command line?
      filePath = "./";
end if

;************************************************
; for time dimesion
;************************************************
if (.not. isvar("timeDimension")) then      ; is timeDim command line?
      timeDimension = 0;
end if
if (.not. isvar("timeDimensionStep")) then      ; is timeDim command line?
      timeDimensionStep = 5;
end if

;if (.not. isvar("level")) then      ; is levelSpace command line?
;     level = 5;
;end if


;************************************************
; for spacing
;************************************************
if (.not. isvar("levelSpace")) then      ; is levelSpace command line?
      levelSpace = 5;
end if


;************************************************
; for display rectangle
;************************************************
if (.not. isvar("rectMinLat")) then      ; is rectMinLat command line?
      rectMinLat = -90;
end if
if (.not. isvar("rectMaxLat")) then      ; is rectMaxLat command line?
      rectMaxLat = 90;
end if
if (.not. isvar("rectMinLon")) then      
  • 5
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
由于缺少数据文件,我无法直接为您提供完整的代码。但是,我可以给出一个实现的大体思路和一些相关的 NCL 函数,您可以根据自己的数据和需求进行修改和调整。 1. 绘制1980-2010年1月500 hPa 环流平均图 可以使用 NCL 中的 climo 函数计算出时间序列的月平均数据,然后再使用平均数据绘制环流图。具体步骤如下: ```ncl ; 读取数据 f = addfile("data.nc", "r") u = f->U(0,:,:,:) ; 第一个维度为时间,选择第一层和全球范围 ; 计算时间序列的月平均数据 u_climo = climo(u, "time", "jan") ; jan 表示计算一月份的平均值 ; 绘制环流图 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" res = True res@cnFillOn = True res@cnFillMode = "RasterFill" res@cnLineLabelsOn = False res@cnRasterSmoothingOn = True res@cnInfoLabelOn = False res@cnLevelSelectionMode = "ManualLevels" res@cnMinLevelValF = -15 res@cnMaxLevelValF = 15 res@cnLevelSpacingF = 1 res@lbTitleString = "500 hPa 环流平均图 (1980-2010年1月)" res@gsnDraw = False res@gsnFrame = False plot = gsn_csm_contour_map(wks, u_climo, res) ``` 2. 绘制1980年1月高度距平图 可以使用 NCL 中的 climo 函数计算出时间序列的月平均数据和对应的月平均高度场数据,然后再计算出 1980 年 1 月的高度距平,并绘制高度距平图。具体步骤如下: ```ncl ; 读取数据 f = addfile("data.nc", "r") u = f->U(0,:,:,:) ; 第一个维度为时间,选择第一层和全球范围 z = f->Z(0,:,:,:) ; 计算时间序列的月平均数据和月平均高度场数据 u_climo = climo(u, "time", "jan") z_climo = climo(z, "time", "jan") ; 计算1980年1月的高度距平 z_jan1980 = z_climo(1,:,:,:) z_jan1980_anom = z_jan1980 - z_climo(0,:,:,:) ; 绘制高度距平图 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" res = True res@cnFillOn = True res@cnFillMode = "RasterFill" res@cnLineLabelsOn = False res@cnRasterSmoothingOn = True res@cnInfoLabelOn = False res@cnLevelSelectionMode = "ManualLevels" res@cnMinLevelValF = -100 res@cnMaxLevelValF = 100 res@cnLevelSpacingF = 10 res@lbTitleString = "1980年1月高度距平图" res@gsnDraw = False res@gsnFrame = False plot = gsn_csm_contour_map(wks, z_jan1980_anom, res) ``` 3. 绘制1980年1月的环流纬偏图 可以使用 NCL 中的 addfile 函数读取数据文件,然后选择经度为全球范围,纬度为 20-90 度之间的数据。接着,可以使用 NCL 中的 gsn_csm_contour_map 函数绘制环流纬偏图。具体步骤如下: ```ncl ; 读取数据 f = addfile("data.nc", "r") v = f->V(0,:,:,20:88) ; 第一个维度为时间,选择第一层和纬度为 20-88 度之间的数据 ; 绘制环流纬偏图 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" res = True res@cnFillOn = True res@cnFillMode = "RasterFill" res@cnLineLabelsOn = False res@cnRasterSmoothingOn = True res@cnInfoLabelOn = False res@cnLevelSelectionMode = "ManualLevels" res@cnMinLevelValF = -15 res@cnMaxLevelValF = 15 res@cnLevelSpacingF = 1 res@lbTitleString = "1980年1月的环流纬偏图" res@gsnDraw = False res@gsnFrame = False plot = gsn_csm_contour_map(wks, v, res) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值