爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 6090|回复: 2

[作图] NCL画图求助

[复制链接]

新浪微博达人勋

发表于 2014-10-16 21:22:40 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
NCL画图出现问题,向各位大神求助,跪谢!
以下是我的NCL脚本,资料是OLR以及气温的月均值数据,想把OLR以及气温随时间的距平变化图画到一张XY图上,想画1989-2013年每年1月的资料,运行总是报错。之前用这个程序画2013年1-12月OLR及气温随时间的距平变化图是可以画成功,但是想把每年9月份的数据挑出来然后画图就不行了,我在想是不是cd_inv_calendar这个函数是不是不能画间断时间的呀?请各位大神指教
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/skewt_func.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/wind_rose.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/time_axis_labels.ncl"
begin
minlat = 32
maxlat = 42
minlon = 110
maxlon = 120
minyr = 1980
maxyr = 2013
timerange = cd_inv_calendar((/minyr, maxyr/), (/1, 1/),(/1, 31/),(/0, 0/),(/0, 0/),(/0, 0/),"hours since 1-1-1 00:00:0.0", 0)
print(timerange)
yr = ispan(minyr,maxyr,1)
nyrs = dimsizes(yr)
print(nyrs)
one = new(nyrs, "integer")  ;; create arrays
  • of required size
    one = 1       ; array syntax
    zero = one   ; create arrays
  • of required size
    zero = 0     ; array syntax
    tt = cd_inv_calendar(yr,one,one,zero,zero,zero,"hours since 1-1-1 00:00:0.0", 0)
    ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    f=addfile("/cygdrive/e/wangcd/air.mon.mean.nc","r")
    print(f)
    lat   = f->lat                                 
    lon   = f->lon                        
    time  = f->time({timerange(0) : timerange(1)})
    air = dim_avg_n(short2flt(f->air({timerange(0) : timerange(1)}, {minlat : maxlat}, {minlon : maxlon})), (/1, 2/))
    air_juping = dim_rmvmean(air)
    printVarSummary(air_juping)
    ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
    f1=addfile("/cygdrive/e/wangcd/olr.mon.mean.nc","r")
    print(f1)
    timerange1 = cd_inv_calendar((/minyr, maxyr/), (/1, 1/),(/1, 31/),(/0, 0/),(/0, 0/),(/0, 0/),"hours since 1800-1-1 00:00:0.0", 0)
    olr = dim_avg_n(short2flt(f1->olr({timerange1(0) : timerange1(1)}, {minlat : maxlat}, {minlon : maxlon})), (/1, 2/))
    olr_juping = dim_rmvmean(olr)
    printVarSummary(olr_juping)
    ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    juping =new((/2,34/),float)
    juping(0,:) =air_juping
    juping(1,:) =olr_juping
    ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    siglvl = 0.05
    mxlag=0
    ccr =esccr(air_juping,olr_juping,mxlag)
    Nr = 34
    prob =rtest(ccr,Nr,0)
      yes_no = where(prob.lt.siglvl, True, False)
      print(ccr+"   "+prob+"   "+yes_no)
    ;print(ccr)
    ;print(prob)
    wtype = "png"
    wks = gsn_open_wks(wtype,"huabeiTO1")
    gsn_define_colormap(wks,"rainbow")
    res = True
    res@gsnFrame = False
    restick           = True
    restick@ttmFormat = "%Y/%c"
    time_axis_labels(time,res,restick)
    res@trXMinF= timerange(0)
    res@trXMaxF= timerange(1)
    res@vpWidthF= 1.0
    res@vpHeightF= 0.7
    res@tmXBMode="Explicit"
    res@xyLineColors           = (/"blue","red"/)
    res@gsnMaximize = True
    res@tiMainString= "Variation of the air temperature and OLR in Huabei area "
    ;res@tiYAxisString= "T(degC)"

    plot = gsn_csm_xy(wks,time,juping,res)
    rc = regline(time, air_juping)
    x = (/time(0), time(dimsizes(time) - 1)/)
    yreg = rc * x + rc@yintercept
    rc1 = regline(time, olr_juping)
    x1 = (/time(0), time(dimsizes(time) - 1)/)
    yreg1 = rc1 * x1 + rc1@yintercept
    air_zero =new((/34/),"float")
    do n =0,33
       air_zero(n)=0
    end do
    lnres = True
    lnres@gsLineThicknessF = 2.0
    lnres@gsLineColor = "yellow"
    gsn_polyline(wks,plot,x,yreg,lnres)
    lnres1 = True
    lnres1@gsLineThicknessF = 3.0
    lnres1@gsLineColor = "green"
    gsn_polyline(wks,plot,x,yreg1,lnres1)
    gsn_polyline(wks,plot,time,air_zero,True)
      legend = create "Legend" legendClass wks
        "vpXF"                     : 0.26                    ; orientation on page
        "vpYF"                     : 0.17
        "vpWidthF"                 : 0.5                     ; width
        "vpHeightF"                : 0.1                     ; height
        "lgPerimOn"                : False                   ; no perimeter
        "lgItemCount"              : 4                       ; how many
        "lgLineLabelStrings"       : (/"Temperature","OLR","Tem trend","OLR trend"/) ; labels
        "lgLabelsOn"               : False                   ; no default lables
        "lgLineLabelFontHeightF"   : 0.015                   ; font height
        "lgDashIndexes"            : (/0,1,0,1/)             ; line paters
        "lgLineColors"             : (/"blue","red","yellow","green"/)
        "lgMonoLineLabelFontColor" : True                    ; one label color
      end create
      draw(legend)
      frame(wks)

    end
  • 密码修改失败请联系微信:mofangbao

    新浪微博达人勋

    发表于 2014-10-17 10:15:20 | 显示全部楼层
    你这个程序好复杂啊,你这还是画了从选择的起止时间的每一个月吧。你可以这样写air((year-1948)*12+0,:,:)  表示某一年(year)的1月。
    密码修改失败请联系微信:mofangbao

    新浪微博达人勋

     楼主| 发表于 2014-10-17 19:09:00 | 显示全部楼层
    0708011 发表于 2014-10-17 10:15
    你这个程序好复杂啊,你这还是画了从选择的起止时间的每一个月吧。你可以这样写air((year-1948)*12+0,:,:) ...

    好的,我去试试,谢谢你!
    密码修改失败请联系微信:mofangbao
    您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

    本版积分规则

    Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

    本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

    快速回复 返回顶部 返回列表