- 积分
- 1210
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2016-7-2
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2017-3-10 10:03:15
|
显示全部楼层
本帖最后由 FrankieLJY 于 2017-3-10 10:04 编辑
上一段代码的图是我在一楼贴出来的图,但是京津冀以外的地区都有值,所以我想加一个mask,把兴趣区域以外的部分都给清除掉,所以我在NCL官网上找到一个案例http://www.ncl.ucar.edu/Applications/Scripts/shapefiles_5.ncl,进行修改,成如下脚本,但是一直有错误,希望版主有时间的时候帮我看看好吗,谢谢!
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/wrf/WRF_contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
undef("calcPolygonAreaAndCentroid")
function calcPolygonAreaAndCentroid(x, y, firstVert, lastVert)
local cY, cY, a, tmp
begin
cX = 0.d
cY = 0.d
area = 0.d
do i=firstVert,lastVert
if (i .eq. lastVert) then
j = firstVert
else
j = i + 1
end if
tmp = x(i)*y(j) - x(j)*y(i)
area = area + tmp
cX = cX + (x(i) + x(j))*tmp
cY = cY + (y(i) + y(j))*tmp
end do
area = area / 2.0
cX = cX / (6.0 * area)
cY = cY / (6.0 * area)
; recall that the area calculation may yield a negative result,
; depending upon CW vs. CCW ordering of the vertices.
return (/ abs(area), cX, cY /)
end
begin
dir1="/data1/Jingjinji2000-201001/" ;;;;;;;;;;;a1 前一个年份
;files1=systemfunc("ls wrfout_d02_2010-01-*")
files1= "wrfout2_2000_01"
a1=addfiles(dir1 + files1 + ".nc", "r")
dir2="/data1/Jingjinji2010-201001/" ;;;;;;;;;;;a2 后一个年份
;files2=systemfunc("ls wrfout_d02_2005-01-*")
files2= "wrfout2_2010_01"
a2=addfiles(dir2 + files2 + ".nc", "r")
b=addfile("./wrfout_d02_2010-01-15_00:00:00.nc", "r")
wks=gsn_open_wks("png", "a_test")
;======================================
;对各个参数进行计算
;======================================
xhr1 =wrf_user_getvar(a1, "T2", -1)
tc1=dim_avg_n(xhr1, 0)
tc1=tc1-273.16
tc1@description="Surface Temperature"
tc1@units="C"
xhr2 =wrf_user_getvar(a2, "T2", -1)
tc2=dim_avg_n(xhr2, 0)
tc2=tc2-273.16
tc2@description="Surface Temperature"
tc2@units="C"
tc=tc2-tc1
;tc=tc*2
tc@description="Surface Temperature"
tc@units="C"
tc@lat2d = b->XLAT(0,:,:) ; direct assignment
tc@lon2d = b->XLONG(0,:,:)
sCritical = 6.0
tc@_FillValue = 255
; ----------------------------------------------
; Get the national boundary from a shapefile.
; We'll use this as a mask for the data.
; ----------------------------------------------
natBdry = addfile("./JJJ.shp", "r")
maskedS = new(dimsizes(b),typeof(b),b@_FillValue)
maskedS@lat2d = b@lat2d
maskedS@lon2d = b@lon2d
; Get the size of the lat/lon grid of variable "s"
sDims = dimsizes(b)
iNumLat = sDims(1)
iNumLon = sDims(2)
; Put data in the areas that we don't want masked.
do j=0,iNumLat-1
print("masking row " + j)
do i=0,iNumLon-1
if(gc_inout(b->XLAT(0,j,i), b->XLONG(0,j,i), natBdry->y, natBdry->x)) then
maskedS(:,j,i) = tc(:,j,i)
end if
end do
end do
; We want a very specific colormap...
cmap = (/ (/1., 1., 1./), (/ 0., 0., 0./), \ ; background/foreground
(/ 231./255., 250./255., 254./255. /), \ ; color for ocean
(/ 230./255., 236./255., 236./255. /), \ ; color for land outside AOI
(/ .3, .3, .3 /), \ ; color for city labels
(/ 1., 1., 1. /), \ ; colors for data mapping...
(/ 221./255., 184./255., 129./255. /), \
(/ 254./255., 157./255., 014./255. /), \
(/ 253./255., 075./255., 251./255. /), \
(/ 116./255., 042./255., 253./255. /), \
(/ 255./255., 001./255., 001./255. /), \
(/ 034./255., 062./255., 255./255. /) \
/)
gsn_define_colormap(wks, cmap)
res = True ; plot mods desired
res@gsnFrame = False
res@gsnDraw = False
res@gsnMaximize = True
res@cnFillColors = cmap(5:,:)
res@cnLevelSelectionMode = "ExplicitLevels"
res@cnLevels = (/ 5.4, 6.2, 6.9, 7.4, 7.8, 8.6 /)
res@cnMinLevelValF = 5.0
res@cnMaxLevelValF = 10.0
res@cnFillOn = True ; color plot desired
res@cnLinesOn = False ; turn off contour lines
res@cnLineLabelsOn = False ; turn off contour labels
; -----------------------------------------------
; Set map extent to zoom in on Pakistan
; -----------------------------------------------
res@mpMinLonF = 113.
res@mpMaxLonF = 120.
res@mpMinLatF = 35.
res@mpMaxLatF = 43.
res@mpGeophysicalLineColor = 1
res@mpOceanFillColor = 2 ; color for sea
res@mpLandFillColor = 3 ; color for land outside of borders
res@mpOutlineBoundarySets = "Geophysical" ; draw coastlines for entire region
res@mpGridAndLimbOn = True
res@mpGridLineColor = (/ .25, .25, .25 /)
res@mpGridLatSpacingF = 4.0
res@mpGridLonSpacingF = 4.0
; ----------------------------------------------
; Turn on lat / lon labeling
; ----------------------------------------------
res@pmTickMarkDisplayMode = "Always" ; turn on tickmarks
res@tmXTOn = False ; turn off top labels
res@tmYROn = False ; turn off right labels
; -----------------------------------------------
; Loop over all times and levels ( uncomment )
; Demo: one arbitrarily closen time and level
; -----------------------------------------------
dims = dimsizes(tc) ; dimensions of x
ntim = dims(0) ; number of time steps
klev = dims(1) ; number of "bottom_top" levels
nt = 0
;;do nt=0,ntim-1 ; uncomment for loop
;; do ll=0,klev-1
res@tiMainString = Times(nt)
res@lbLabelBarOn = False
plot = gsn_csm_contour_map(wks,maskedS(nt,:,:),res)
draw(plot)
frame(wks)
end |
|