请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 5995|回复: 4

[作图] wrfout文件用ncl怎么控制画图区域呀

[复制链接]

新浪微博达人勋

发表于 2020-4-21 11:38:20 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 阿萨德撒 于 2020-4-21 11:40 编辑

;*************************************************
; WRF_pcp_1.ncl
;
; Concepts illustrated:
;   - Plotting WRF data
;   - Overlaying WRF precipitation on terrain map using wrf_xxx functions
;   - Changing the size of a PNG image
;   - Creating two contour plots with two sets of filled contours
;   - Creating a color map using RGB triplets
;   - Creating a color map using RGBA quadruplets
;   - Explicitly setting contour levels
;   - Adding a title to a labelbar
;   - Drawing fully transparent filled contours
;   - Creating horizontal and vertical labelbars
;   - Adding a vertical title to a labelbar
;
; 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"
; load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

;----------------------------------------------------------------------
; Main code
;----------------------------------------------------------------------
begin
;
; Open file and get variables.
;
  a = addfile("20190710.nc","r")

;
; Terrain
;
  ter = wrf_user_getvar(a,"HGT",0)
  ter@description = "Terrain Height"
  ter@units       = "m"
;
; Get non-convective, convective
; Calculate total precipitation
;
  scale = 6.       ; Artificial scale factor to see all colors
  rain_exp = wrf_user_getvar(a,"RAINNC",-1) /22.4
  rain_con = wrf_user_getvar(a,"RAINC", -1) /22.4
  rain_tot = (rain_exp + rain_con) * scale

  rain_tot@description = "Total Precipitation (inches)"
; Define contour levels here so we can determine up front
; what the merged color maps should be.

  precip_levels = (/ .01, 0.25, 0.50, 0.75, \
                    1.00, 1.25, 1.50, 1.75, \
                    2.00, 2.25, 2.50, 2.75, \
                    3.00, 3.25, 3.50, 3.75, \
                    4.00, 4.25, 4.50, 4.75, \
                    5.00,5.25,5.5,5.75,6.0 /)

  ter_levels = (/ .01, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, \
                   15, 16 ,17,18,19,20,21,22,23,24,25,26,27,28,29,30/) * 100.

  wtype          = "png"
  wtype@wkWidth  = 1500     ; Increase size for a slightly
  wtype@wkHeight = 1500     ; better looking PNG.
  wks = gsn_open_wks(wtype,"WRF_pcp")    ; Send graphics to PNG file

;
; Set up resource list that will be shared between the
; two wrf_contour calls.
;
  res                      = True
  res@gsnDraw              = False
  res@gsnFrame             = False
  res@cnLevelSelectionMode = "ExplicitLevels"
  res@cnFillOn             = True
  res@cnLinesOn            = False

  minlat =  30
  maxlat =  40
  minlon = 120
  maxlon = 130
  loc = wrf_user_ll_to_ij(a,(/minlon,maxlon/),(/minlat,maxlat/),res)
;
; Generate plot of terrain for background.
;
; First set up resource list specific to terrain plot.
;
  opts_ter                          = res

  opts_ter@cnLevels                 = ter_levels
;
; In order to use cnFillPalette with wrf_contour, you must
; gsnSpreadColors to False and cnSpanFillPalette to True.
;
  opts_ter@gsnSpreadColors          = False
  opts_ter@cnSpanFillPalette        = True
  opts_ter@cnFillPalette            = earth_pal()

; Resources to control labelbar title, size, and location.
  opts_ter@lbTitleString            = "Terrain"
  opts_ter@pmLabelBarWidthF         = 0.8
  opts_ter@pmLabelBarHeightF        = 0.35
  opts_ter@pmLabelBarOrthogonalPosF = -0.18

; Create terrain contours (no drawing done yet).
  contour_ter = wrf_contour(a,wks,ter,opts_ter)
print(contour_ter)
; Plotting options for precipitation
  opts_r                      = res

  opts_r@cnLevels             = precip_levels

  opts_r@gsnSpreadColors          = False
  opts_r@cnSpanFillPalette        = True
  opts_r@cnFillPalette            = precip_pal()
  opts_r@cnSmoothingDistanceF = .005

; Resources to control precipitation labelbar, which will be
; vertical.
  opts_r@lbTitleString            = "Total Precipitation"
  opts_r@lbTitleDirection         = "Down"
  opts_r@lbTitleJust              = "CenterRight"
  opts_r@lbTitlePosition          = "Right"
  opts_r@lbTitleOffsetF           = 0.07

  opts_r@lbOrientation            = "Vertical"
  opts_r@pmLabelBarSide           = "Right"
  opts_r@pmLabelBarHeightF        = 0.77
  opts_r@pmLabelBarWidthF         = 0.11
  opts_r@pmLabelBarOrthogonalPosF = 0.03
  opts_r@lbBoxMinorExtentF        = 0.4
cnConstFEnableFill = True

; Total Precipitation (color fill)
  contour_tot = wrf_contour(a, wks, rain_tot(0,:,:), opts_r)
;
; Use the special wrf_map_overlays function to figure out
; the correct map projection and do the overlay.
;
; Set up two resource lists for wrf_map_overlays.
;
  pltres                            = True

  mpres                             = True

        mpres@mpOutlineOn=True
        mpres@mpGeophysicalLineThicknessF=2.0
    mpres@mpNationalLineThicknessF=2.0
  mpres@mpGeophysicalLineColor      = "Black"
  mpres@mpNationalLineColor         = "Black"
  mpres@mpUSStateLineColor          = "Black"
  mpres@mpGridLineColor             = "Black"
  mpres@mpLimbLineColor             = "Black"
  mpres@mpPerimLineColor            = "Black"
;  mpres@mpGeophysicalLineThicknessF = .5
;  mpres@mpUSStateLineThicknessF     = .5
;  mpres@mpDataBaseVersion           = "HighRes"
;  mpres@mpDataResolution            = "FinestResolution"




  plot = wrf_map_overlays(a,wks,(/contour_ter,contour_tot/),pltres,mpres)
end

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

新浪微博达人勋

 楼主| 发表于 2020-4-21 13:53:27 | 显示全部楼层
本帖最后由 阿萨德撒 于 2020-4-21 13:54 编辑

也试过以前帖子上的人的方法,但是画图的图形是错的,压缩扭曲到一起了,请假一下大佬怎么改wrfout画图区域呀?
minlat =  27.
  maxlat =  31.5
  minlon = 118.0
  maxlon = 122.5
  loc = wrf_user_ll_to_ij(a,(/minlon,maxlon/),(/minlat,maxlat/),res)  ;查找目标经纬度对应的格点


;设置绘图区域
     mpres@mpLeftCornerLatF  = minlat
     mpres@mpRightCornerLatF = maxlat
     mpres@mpLeftCornerLonF  = minlon
     mpres@mpRightCornerLonF = maxlon


最后用wrf_map_overlays绘图
WRF_pcp.000001(1).png
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2020-4-21 14:23:07 | 显示全部楼层
阿萨德撒 发表于 2020-4-21 13:53
也试过以前帖子上的人的方法,但是画图的图形是错的,压缩扭曲到一起了,请假一下大佬怎么改wrfout画图区域 ...

能不能在wks那里添加设置范围的语句呀?
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-4-21 15:30:28 | 显示全部楼层

回帖奖励 +20 金钱

密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-4-21 20:56:30 | 显示全部楼层
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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