爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: Soaring

[作图] NCL添加地区分界线-shp文件哪里可以下?

[复制链接]
 楼主| 发表于 2017-10-18 04:57:43 | 显示全部楼层
密码修改失败请联系微信:mofangbao
发表于 2017-10-18 12:28:15 | 显示全部楼层
Soaring 发表于 2017-10-18 04:57
https://coding.net/u/huangynj/p/NCL-Chinamap/git

谢谢你
密码修改失败请联系微信:mofangbao
发表于 2017-12-21 17:43:13 | 显示全部楼层
您好,我刚接触NCL,想请教您一个问题。
我在NCL网站找到了读wrfout的降水的代码,和关于加载shapefile的一些代码。我想在降水图上加上流域边界图,我现在有流域的shp文件,却不知道如何将两者结合,还请赐教~谢谢
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2017-12-22 10:05:11 | 显示全部楼层
yybubble 发表于 2017-12-21 17:43
您好,我刚接触NCL,想请教您一个问题。
我在NCL网站找到了读wrfout的降水的代码,和关于加载shapefile的 ...

  river                          = True
  river@gsLineThicknessF         = 2.0      
  river@gsLineColor              = "blue"
  plotrv = gsn_add_shapefile_polylines(wks,map,"./cnmap_NetCDF/river.nc",river)

这些都在我前面发的链接里
密码修改失败请联系微信:mofangbao
发表于 2017-12-23 22:42:43 | 显示全部楼层
Soaring 发表于 2017-12-22 10:05
river                          = True
  river@gsLineThicknessF         = 2.0      
  river@gs ...

哦哦~我试了下,我不是很明白map该怎么设置。
我把我在网上找的代码贴出来,您能帮我看看该怎么改吗?

;   Example script to produce plots for a WRF real-data run,
;   with the ARW coordinate dynamics option.
;   In this example we first get the entire field over time, which will
;   make it easier to calculate tendencies

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

begin
;
; The WRF ARW input file.  
; This needs to have a ".nc" appended, so just do it.
  a = addfile("/home/WRFV3/test/em_real/wrfout_d02_2005-06-20_00:00:00.nc","r")


; We generate plots, but what kind do we prefer?
  type = "png"
; type = "pdf"
; type = "ps"
; type = "ncgm"
  wks = gsn_open_wks(type,"plt_Precip2")



  ; Set some basic resources
  res = True
  res@MainTitle = "REAL-TIME WRF"

  pltres = True
  mpres = True
  mpres@mpGeophysicalLineColor = "Black"
  mpres@mpNationalLineColor    = "Black"
  mpres@mpUSStateLineColor     = "Black"
  mpres@mpGridLineColor        = "Black"
  mpres@mpLimbLineColor        = "Black"
  mpres@mpPerimLineColor       = "Black"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; First get the variables we will need        

    slp = wrf_user_getvar(a,"slp",-1)    ; slp
      wrf_smooth_2d( slp, 3 )            ; smooth slp

  ; Get non-convective, convective
  ; Calculate total precipitation
    rain_exp = wrf_user_getvar(a,"RAINNC",-1)
    rain_con = wrf_user_getvar(a,"RAINC",-1)
    rain_tot = rain_exp + rain_con
      rain_tot@description = "Total Precipitation"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; What times and how many time steps are in the data set?
  times = wrf_user_getvar(a,"times",-1)  ; get all times in the file
  ntimes = dimsizes(times)         ; number of times in the file

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  do it = 2,ntimes-1,2             ; TIME LOOP - start at hour 6 as we are only interested in 6hourly tendencies

    print("Working on time: " + times(it) )
    res@TimeLabel = times(it)   ; Set Valid time to use on plots


    rain_exp_tend = rain_exp(it,:,:) - rain_exp(it-2,:,:)
    rain_con_tend = rain_con(it,:,:) - rain_con(it-2,:,:)
    rain_tot_tend = rain_tot(it,:,:) - rain_tot(it-2,:,:)
      rain_exp_tend@description = "Explicit Precipitation Tendency"
      rain_con_tend@description = "Param  Precipitation Tendency"
      rain_tot_tend@description = "Precipitation Tendency"


   ; Plotting options for Sea Level Pressure
     opts_psl = res         
     opts_psl@ContourParameters = (/ 900., 1100., 2. /)
     opts_psl@cnLineColor       = "Blue"
     opts_psl@cnInfoLabelOn     = False
     opts_psl@cnLineLabelFontHeightF = 0.01
     opts_psl@cnLineLabelPerimOn = False
     opts_psl@gsnContourLineThicknessesScale = 1.5
     contour_psl = wrf_contour(a,wks,slp(it,:,:),opts_psl)
     delete(opts_psl)
   

   ; Plotting options for Precipitation
     opts_r = res                        
     opts_r@UnitLabel            = "mm"
     opts_r@cnLevelSelectionMode = "ExplicitLevels"
     opts_r@cnLevels             = (/ 0, 50, 100, 150, 200, 250, 300, \
                                     350, 400, 450, 500, 550, 600, 650, 700/)
     opts_r@cnFillColors         = (/"White","DarkOliveGreen1", \
                                     "DarkOliveGreen3","Chartreuse", \
                                     "Chartreuse3","DarkGreen", \
                                     "Yellow","Orange","Orangered","Red", \
                                     "Red4","SlateBlue1","SlateBlue3", \
                                     "RoyalBlue3","RoyalBlue4", \
                                     "Blue2","Blue4" /)

     opts_r@cnInfoLabelOn        = False
     opts_r@cnConstFLabelOn      = False
     opts_r@cnFillOn             = True


   ; Total Precipitation (color fill)
     contour_tot = wrf_contour(a,wks, rain_tot(it,:,:), opts_r)

   ; Precipitation Tendencies
     opts_r@SubFieldTitle = "from " + times(it-2) + " to " + times(it)

     contour_tend = wrf_contour(a,wks, rain_tot_tend,opts_r) ; total (color)
     contour_res = wrf_contour(a,wks,rain_exp_tend,opts_r)   ; exp (color)
     opts_r@cnFillOn = False
     opts_r@cnLineColor = "Red4"
     contour_prm = wrf_contour(a,wks,rain_con_tend,opts_r)   ; con (red lines)
     delete(opts_r)

   ;--- add shp file boundaries to test whether the border overlap---
     ShpDir = "/home/shapefile/changjiang/" ;"$NCARG_ROOT/lib/ncarg/nclscripts/cnmap/"
     cnres                       = True
     cnres@gsLineThicknessF      = 2
     cnres@gsLineColor           = "black"

   ; MAKE PLOTS                                       

     ; Total Precipitation
       plot = wrf_map_overlays(a,wks,contour_tot,pltres,mpres)

     ; Total Precipitation Tendency + SLP
       plot = wrf_map_overlays(a,wks,(/contour_tend,contour_psl/),pltres,mpres)

     ; Non-Convective and Convective Precipiation Tendencies
       plot = wrf_map_overlays(a,wks,(/contour_res,contour_prm/),pltres,mpres)

       plotshp = gsn_add_shapefile_polylines(wks,map,ShpDir+"basinchangjiang.shp",cnres)
  
  end do        ; END OF TIME LOOP

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

end
密码修改失败请联系微信:mofangbao
发表于 2017-12-24 21:43:57 | 显示全部楼层
我搞定了~谢谢~
密码修改失败请联系微信:mofangbao
发表于 2018-1-31 15:56:00 | 显示全部楼层
yybubble 发表于 2017-12-23 22:42
哦哦~我试了下,我不是很明白map该怎么设置。
我把我在网上找的代码贴出来,您能帮我看看该怎么改吗?
...

你好,我也是想把研究区域边界加载到降水上面,我用的wrf_Precip.ncl 。自己找到的加载shp是filename="/home/syrus/data/Tibet/tibetan/tibetan.shp"
  pres             = True
  pres@gsLineColor = "blue"
  pres@gsLineThicknessF =2
poly=gsn_add_shapefile_polylines(wks,plot,filename,pres)

draw(plot)
frame(wks)

但是做出来的是降水图和shp是独立的,不是叠加在一起的。因为也是初学者,各种乱试。我看您是解决了这个问题,请问可以贴出您的完整代码,让我学习学习,谢谢。
密码修改失败请联系微信:mofangbao
发表于 2018-1-31 16:19:17 | 显示全部楼层

你好,请问 怎么搞定的那?谢谢
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2018-2-1 10:02:16 | 显示全部楼层
小莹子 发表于 2018-1-31 15:56
你好,我也是想把研究区域边界加载到降水上面,我用的wrf_Precip.ncl 。自己找到的加载shp是filename="/h ...

https://coding.net/u/huangynj/p/NCL-Chinamap/git
这里面有完整的代码和使用说明
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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