爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 17814|回复: 10

[其他] ncl 批处理grib数据时如何提取时间维度

[复制链接]

新浪微博达人勋

发表于 2014-11-21 09:01:32 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 hnqx 于 2014-11-21 09:07 编辑

正在学习ncl,在官网上看到一张图,想照葫芦画瓢 学着画一下     这是官网实例的网址http://www.ncl.ucar.edu/Applications/meteo.shtml
两个问题麻烦坛友们帮助我一下 谢谢,初次提问,表达不是很好 请见谅!
问题1:我用的资料是grib1,每6小时一间隔,需要用时间作为横坐标,批处理girb数据时不知如何获得时间维度的值(代码中的taus)
问题2:代码中levels是哪一个变量,是层数么?grib1资料用什么表示?


在实例代码的基础上修改了文件读取路径和变量名,代码如下:
diri = "/home/tanlei/share/201410/grib1/"
fils = systemfunc ("ls " + diri + "*.grib1")
    ;print(fils)
    f  = addfiles (fils,"r")
    ListSetType(f, "join")
    tempisobar = f[:]->TMP_3_ISBL
  ;levels    ???????  
  ;taus     ???????   
  rh         = f[:]->R_H_3_ISBL
  ugrid      = f[:]->U_GRD_3_ISBL
  vgrid      = f[:]->V_GRD_3_ISBL
  p            = f[:]->PRES_3_SFC
  tempht     = f[:]->TMP_3_HTGL







官网实例图片:
QQ图片20141121082712.jpg
QQ截图20141121083651.png


官网实例代;**************************************
;  meteo_1.ncl
;
; Concepts illustrated:
;   - Drawing a meteogram
;   - Creating a color map using RGB triplets
;   - Reversing the Y axis
;   - Explicitly setting tickmarks and labels on the bottom X axis
;   - Increasing the thickness of contour lines
;   - Drawing wind barbs
;   - Drawing a bar chart
;   - Changing the width and height of a plot
;   - Overlaying wind barbs and line contours on filled contours
;   - Changing the position of individual plots on a page
;
;***********************************************
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
;***********************************************
begin
  cdf = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/meteo_data.nc","r")
  tempisobar = cdf->tempisobar
  levels     = cdf->levels     
  taus       = cdf->taus      
  rh         = cdf->rh
  ugrid      = cdf->ugrid
  vgrid      = cdf->vgrid
  rain03     = cdf->rain03
  tempht     = cdf->tempht
;***********************************************
;  smooth temperature and humidity.
;***********************************************
  smothtemp = smth9(tempisobar, 0.50, -0.25, False)
  smothrh   = smth9(rh, 0.50, -0.25, False)
;***********************************************
;  open a workstation and define colormap using rgb triplets
;***********************************************
  wks = gsn_open_wks("ps","meteo")
  colors = (/                                                        \
             (/255,255,255/),   (/  0,  0,  0/),   (/255,255,255/),  \
             (/255,255,255/),   (/255,255,255/),   (/240,255,240/),  \
             (/220,255,220/),   (/190,255,190/),   (/120,255,120/),  \
             (/ 80,255, 80/),   (/ 50,200, 50/),   (/ 20,150, 20/),  \
             (/255,  0,  0/)                                         \
           /) / 255.0
  gsn_define_colormap(wks,colors) ; create colormap out of above colors
;***********************************************
; Create a different resource list for each of the 5 plots
;***********************************************
  rh_res      = True
  temp_res    = True
  uv_res      = True
  rain_res    = True
  tempsfc_res = True
;***********************************************
; Here are the resources that rh_res, temp_res, and uv_res share.
;***********************************************
  rh_res@trYReverse   = True     ; Reverse the Y values.
  rh_res@gsnDraw      = False    ; Don't draw individual plot.
  rh_res@gsnFrame     = False    ; Don't advance frame.
  rh_res@vpXF         = 0.15     ; x location
  rh_res@vpYF         = 0.90     ; y location
  rh_res@vpWidthF     = 0.7      ; width
  rh_res@vpHeightF    = 0.40     ; height

  temp_res            = rh_res   ; copy shared resources to other lists
  uv_res              = rh_res
;***********************************************
; Relative humidity only resources
;***********************************************
  rh_res@gsnSpreadColors   =  True              ; use full range of colors
  rh_res@gsnSpreadColorEnd = -2                 ; save last color (red)
  rh_res@cnFillOn          = True               ; turns on color fill
  rh_res@cnLineLabelsOn    = True               ; no contour labels
  rh_res@tiMainString      = "Meteogram for LGSA, 28/12Z" ; title

  rh_res@cnFillOn          = True               ; turns on the color
  rh_res@sfXArray          = taus               ; Define X/Y axes values that
  rh_res@sfYArray          = levels             ; all three data fields are on
  rh_res@tiYAxisString     = "Pressure (mb)"    ; Y axes label.

; y-left axis changes
  rh_res@tmYLMode       = "Explicit" ; Define own tick mark labels.
  rh_res@tmYLValues     = levels     ; location of explicit labels
  rh_res@tmYLLabels     = levels
  rh_res@tmYLMinorOn    = False            ; No Y-left minor tick marks.

; x-bottom axis changes
  rh_res@tmXBMode       = "Explicit" ; Define own tick mark labels.
  rh_res@tmXBValues     = taus       ; location of explicit labels
  rh_res@tmXBLabels     = (/"12z", "15z", "18z",  "21z", "Apr29", \
                            "03z", "06z", "09z",  "12z", "15z",   \
                            "18z", "21z", "Apr30","03z", "06z",   \
                            "09z", "12z", "15z",  "18z", "21z",   \
                            "May01", "03z", "06z",  "09z", "12z"/)

  rh_res@tmXBLabelAngleF      = 90.            ; change label angle
  rh_res@tmXBMinorOn          = False          ; No minor tick marks.
  rh_res@tmXBLabelJust        = "CenterCenter" ; label justification
  rh_res@tmXBLabelFontHeightF = .016           ; Font size
  rh_res@tiXAxisString        = ""             ; turn off x-axis string
;***********************************************
; Temperature only resources
;***********************************************
  temp_res@sfXArray        = taus    ; Define X/Y axes values that
  temp_res@sfYArray        = levels  ; all three data fields are on

  temp_res@cnLineLabelsOn  = True    ; no contour labels
  temp_res@cnLineThicknessF= 3.0     ; line thickness
  temp_res@cnLineColor     = "Red"   ; color of contour lines
;***********************************************
; wind barb only resources
;***********************************************
  uv_res@vfXArray            = taus       ; Define X/Y axes values that
  uv_res@vfYArray            = levels     ; all three data fields are on
  uv_res@vcRefAnnoOn         = False      ; turns off the ref vector
  uv_res@vcRefLengthF        = 0.040      ; set length of ref vector
  uv_res@vcGlyphStyle        = "WindBarb" ; turn on windbarbs
  uv_res@vcMonoWindBarbColor = True       ; to color the windbarbs with
                                          ; respect to speed use False
  uv_res@vcMapDirection = False                              ; needed to disassociate the coordinate plane from the wind barbs

;***********************************************
; rain histogram only resources
;***********************************************
  rain_res@vpXF            = 0.15   ; The left side of the box location
  rain_res@vpYF            = 0.34   ; The top side of the plot box location
  rain_res@vpWidthF        = 0.70   ; The Width of the plot box
  rain_res@vpHeightF       = 0.10   ; The height of the plot box
  rain_res@trYMinF         = 0.0    ; min value on y-axis
  rain_res@trYMaxF         = 0.5    ; max value on y-axis
  rain_res@trXMinF         = 0.0    ; min value on x-axis
  rain_res@trXMaxF         = 72.0   ; max value on x-axis

  rain_res@tiXAxisString  = ""                ; X axis label.
  rain_res@tiYAxisString  = "3hr rain total"  ; Y axis label.
  rain_res@tmXBMode       = "Explicit" ; Define own tick mark labels.
  rain_res@tmXBValues     = taus       ; location of explicit labels
  rain_res@tmXBLabels     = (/"12z", "", "18z",  "", "Apr29", \
                            "", "06z", "",  "12z", "",   \
                            "18z", "", "Apr30","", "06z",   \
                            "", "12z", "",  "18z", "",   \
                            "May01", "", "06z",  "", "12z"/)
  rain_res@tmXTOn         = False             ; turn off the top tickmarks
  rain_res@tmXBMinorOn    = False             ; No minor tick marks.

  rain_res@gsnDraw         = False            ; Don't draw individual plot.
  rain_res@gsnFrame        = False            ; Don't advance frame.
  rain_res@gsnYRefLine     = 0.0              ; create a reference line
  rain_res@gsnAboveYRefLineColor = "green"    ; above ref line fill green
  rain_res@gsnXYBarChart   = True             ; turn on bar chart


;***********************************************
; temperature at surface only resources
;***********************************************
  tempsfc_res@vpXF            = 0.15   ; The left side of the box location
  tempsfc_res@vpYF            = 0.18   ; The top side of the plot box loc
  tempsfc_res@vpWidthF        = 0.70   ; The Width of the plot box
  tempsfc_res@vpHeightF       = 0.10   ; The height of the plot box
  tempsfc_res@trXMaxF         = 72.0   ; max value on x-axis
  tempsfc_res@trYMaxF         = max(tempht)+.5   ; max value on y-axis
  tempsfc_res@trYMinF         = min(tempht)-.5   ; min value on y-axis

  tempsfc_res@tiXAxisString  = ""            ; turn off x-axis string
  tempsfc_res@tiYAxisString  = "Temp at 2m"  ; set y-axis string
  tempsfc_res@tmXBMode       = "Explicit" ; Define own tick mark labels.
  tempsfc_res@tmXBValues     = taus       ; location of explicit labels
  tempsfc_res@tmXBLabels     = (/"12z", "", "18z",  "", "Apr29", \
                            "", "06z", "",  "12z", "",   \
                            "18z", "", "Apr30","", "06z",   \
                            "", "12z", "",  "18z", "",   \
                            "May01", "", "06z",  "", "12z"/)
  tempsfc_res@tmXTOn         = False         ; turn off the top tickmarks
  tempsfc_res@xyLineThicknesses = 2          ; increase line thickness
  tempsfc_res@xyLineColor    =  "red"        ; set line color

  tempsfc_res@gsnDraw         = False        ; Don't draw individual plot.
  tempsfc_res@gsnFrame        = False        ; Don't advance frame.

;********************************************************
; Create the five plots (they won't get drawn here, because gsnDraw
; was set to False for all of them.
;********************************************************
  rhfill    = gsn_contour(wks,smothrh,rh_res)
  templine  = gsn_contour(wks,smothtemp,temp_res)
  windlayer = gsn_vector(wks,ugrid,vgrid,uv_res)
  rainhist  = gsn_csm_xy(wks,taus,rain03,rain_res)
  temptmsz  = gsn_csm_xy(wks,taus,tempht,tempsfc_res)
;********************************************************
; three of the above plots become one overlay plot
;********************************************************
  overlay(rhfill,templine)   ; result is templine over rhfill
  overlay(rhfill,windlayer)  ; result is windlayer over the other two
  draw(rhfill)               ; draw this overlay result
  draw(rainhist)             ; draw the rain histogram
  draw(temptmsz)             ; draw the temperature time series
  frame(wks)                 ; finally advance the frame once all on page
end









meteo_1.ncl

10.18 KB, 下载次数: 12, 下载积分: 金钱 -5

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

新浪微博达人勋

 楼主| 发表于 2014-11-21 09:08:28 | 显示全部楼层
首先给自己支持一下
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-11-21 09:08:49 | 显示全部楼层
没人回复再顶一下 别掉下去了
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-11-21 09:35:10 | 显示全部楼层
感觉好复杂呀
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-11-22 16:53:49 | 显示全部楼层
原来用过这个,感觉不是特别智能,很多东西需要调。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-11-22 23:37:13 | 显示全部楼层
怎么没人回答,是不是我的问题表述不清楚
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-5-13 22:12:07 | 显示全部楼层
.....................
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2018-9-29 23:32:27 | 显示全部楼层
楼主,你的问题解决了么?我也要面对你面对的问题了!想请教一下!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2020-2-29 17:11:29 | 显示全部楼层
同样有这个问题
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-3-17 20:01:22 | 显示全部楼层
grb和nc是不是不一样的处理啊
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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