- 积分
- 13374
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2019-10-6
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 不想去气象局 于 2019-12-8 22:58 编辑
用了兰溪大神的脚本,但在使用的时候因为我有三幅图的,不知道为啥出现了这样的情况然后我就把属性的复制稍微改了下,结果出现图一中海小图南岛的颜色和主图海南岛的颜色完全不一样,后面两幅图其实也有颜色深度上的区别,研究了好久捉摸不透, 请大神们赐教!!
我附上了全代码,但是我觉得的主要问题在代码里标了颜色,还是希望大家帮帮忙啦!!
当然也有可能问题不出在我以为的地方。。
; ==============================================================
; eof_1.ncl
;
; Concepts illustrated:
; - Calculating EOFs
; - Drawing a time series plot
; - Using coordinate subscripting to read a specified geographical region
; - Rearranging longitude data to span -180 to 180
; - Calculating symmetric contour intervals
; - Drawing filled bars above and below a given reference line
; - Drawing subtitles at the top of a plot
; - Reordering an array
; ==============================================================
; NCL V6.4.0 has new functions eofunc_n_Wrap and
; eofunc_ts_n_Wrap that allow you to calculate the EOFs without
; first having to first reorder the data. See eof_1_640.ncl.
; ==============================================================
; Calculate EOFs of the Sea Level Pressure over the North Atlantic.
; ==============================================================
; The slp.mon.mean file can be downloaded from:
; http://www.esrl.noaa.gov/psd/dat ... alysis.surface.html
; ==============================================================
; 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/csm/contributed.ncl"
begin
; ==============================================================
; User defined parameters that specify region of globe and
; ==============================================================
latS = 15.
latN = 55.
lonL = 100.
lonR = 140.
yStrt = 1961
yLast = 2018
; season = "DJF" ; choose Dec-Jan-Feb seasonal mean
neof = 3 ; number of EOFs
optEOF = True
optEOF@jopt = 0 ; This is the default; most commonly used; no need to specify.
;optEOF@jopt = 1 ; **only** if the correlation EOF is desired
optETS = False
; ==============================================================
; Open the file: Read only the user specified period
; ==============================================================
f = addfile ("3-mon.nc", "r")
TIME = f->time
; YYYY = cd_calendar(TIME,-1)/100 ; entire file
; iYYYY = ind(YYYY.ge.yrStrt .and. YYYY.le.yrLast)
spei = f->spei(2:686:12,:, :)
printVarSummary(spei) ; variable overview
; compute desired global seasonal mean: month_to_season (contributed.ncl)
; ==============================================================
; SLP = month_to_season (slp, season)
; nyrs = dimsizes(SLP&time)
; printVarSummary(SLP)
; =================================================================
; create weights: sqrt(cos(lat)) [or sqrt(gw) ]
; =================================================================
rad = 4.*atan(1.)/180.
clat = f->lat
clat = sqrt( cos(rad*clat) ) ; gw for gaussian grid
; =================================================================
; weight all observations
; =================================================================
wspei = spei ; copy meta data
wspei = spei*conform(spei, clat, 1)
; wspei@long_name = "Wgt: "+wspei@long_name
; =================================================================
; Reorder (lat,lon,time) the *weighted* input data
; Access the area of interest via coordinate subscripting
; =================================================================
xw = wspei({lat|latS:latN},{lon|lonL:lonR},time|:)
x = wspei(time|:,{lat|latS:latN},{lon|lonL:lonR})
eof = eofunc_Wrap(xw, neof, optEOF)
eof_ts = eofunc_ts_Wrap (xw, eof, optETS)
printVarSummary( eof ) ; examine EOF variables
printVarSummary( eof_ts )
; =================================================================
; Normalize time series: Sum spatial weights over the area of used
; =================================================================
dimxw = dimsizes( xw )
mln = dimxw(1)
sumWgt = mln*sum( clat({lat|latS:latN}) )
eof_ts = eof_ts/sumWgt
; =================================================================
; Extract the YYYYMM from the time coordinate
; associated with eof_ts [same as SLP&time]
; =================================================================
;yyyymm = cd_calendar(eof_ts&time,-2)/100
;;yrfrac = yyyymm_to_yyyyfrac(yyyymm, 0.0); not used here
;============================================================
; PLOTS
;============================================================
wks = gsn_open_wks("png","eof") ; send graphics to PNG file
plot = new(neof,graphic) ; create graphic array
; only needed if paneling
; EOF patterns
res = True
res@gsnDraw = False ; don't draw yet
res@gsnFrame = False ; don't advance frame yet
res@gsnAddCyclic = False ; plotted dataa are not cyclic
res@mpFillOn = False ; turn off map fill
res@mpMinLatF = latS ; zoom in on map
res@mpMaxLatF = latN
res@mpMinLonF = lonL
res@mpMaxLonF = lonR
res@cnFillOn = True ; turn on color fill
res@mpDataSetName = "./database/Earth..4"
res@mpDataBaseVersion = "MediumRes" ; or "Ncarg4_1"
res@mpAreaMaskingOn = True
res@mpMaskAreaSpecifiers = (/"China"/)
res@mpOutlineSpecifiers = (/"China","China:Provinces"/)
res@mpLandFillColor = "white"
res@mpInlandWaterFillColor = "white"
res@mpOceanFillColor = "white"
res@mpFillBoundarySets = "NoBoundaries"
res@mpOutlineBoundarySets = "NoBoundaries"
res@mpNationalLineColor = "black"
res@mpProvincialLineColor = "black"
res@mpGeophysicalLineColor = "black"
res@mpNationalLineThicknessF = 2
res@mpProvincialLineThicknessF = 1
res@cnInfoLabelOn =False
res@cnFillOn = True
res@cnFillDrawOrder = "PreDraw"
res@cnLinesOn = False ; True is default
res@cnLineLabelsOn = False ; True is default
res@cnFillPalette = "BlWhRe" ; set color map
res@lbLabelBarOn = False ; turn off individual lb's
; res@cnLevelSelectionMode = "ExplicitLevels"
; res@cnLevels = fspan(-0.04,0.04,9)
res@lbLabelAutoStride = True
res@pmTickMarkDisplayMode = "Always"
; set symmetric plot min/max
symMinMaxPlt(eof, 16, False, res) ; contributed.ncl
; panel plot only resources
resP = True ; modify the panel plot
resP@gsnMaximize = True ; large format
resP@gsnPanelLabelBar = True ; add common colorbar
; yStrt = yyyymm(0)/100
; yLast = yyyymm(nyrs-1)/100
resP@gsnPanelMainString = "SPEI "+": "+yStrt+"-"+yLast
;*******************************************
; first plot
;*******************************************
do n=0,neof-1
res@gsnLeftString = "EOF "+(n+1)
res@gsnRightString = sprintf("%5.1f", eof@pcvar(n)) +"%"
plot(n)=gsn_csm_contour_map(wks,eof(n,:,:),res)
;--- add South China Sea ---
nhres = True
nhres@gsnFrame = False
nhres@gsnDraw = False
nhres@vpHeightF = 0.18
nhres@vpWidthF = 0.18
nhres@cnInfoLabelOn =False
nhres@mpMinLatF = 2.0
nhres@mpMaxLatF = 23.0
nhres@mpMinLonF = 105.0
nhres@mpMaxLonF = 123.0
nhres@lbLabelBarOn = False
nhres@tmXBOn = False
nhres@tmYLOn = False
nhres@tmYROn = False
nhres@tmXTOn = False
nhres@gsnLeftString = ""
nhres@gsnRightString = ""
getvalues map1@contour
"cnFillOn" : nhres@cnFillOn
"cnLevelSelectionMode" : nhres@cnLevelSelectionMode
"cnLevels" : nhres@cnLevels
"cnFillColors" : nhres@cnFillColors
"cnFillDrawOrder" : nhres@cnFillDrawOrder
"cnLinesOn" : nhres@cnLinesOn
"cnLineLabelsOn" : nhres@cnLineLabelsOn
end getvalues
这是兰溪大神的脚本里的,但是我在使用的时候报错了,我就改成了下面红色的脚本
;nhres@cnLevelSelectionMode = res@cnLevelSelectionMode
;nhres@cnLevels = res@cnLevels
nhres@lbLabelAutoStride = res@lbLabelAutoStride
nhres@pmTickMarkDisplayMode = res@pmTickMarkDisplayMode
nhres@cnFillPalette = res@cnFillPalette ; set color map
nhres@lbLabelBarOn =res@lbLabelBarOn ; turn off individual lb's
nhres@cnFillOn =res@cnFillOn
nhres@cnLevelSelectionMode =res@cnLevelSelectionMode
nhres@cnLinesOn =res@cnLinesOn
nhres@cnLineLabelsOn =res@cnLineLabelsOn
nhres@gsnAddCyclic = False ; plotted dataa are not cyclic
map_nanhai = gsn_csm_contour_map(wks,eof(n,:,:),nhres)
adres = True
adres@amParallelPosF = 0.495 ; -0.5 is the left edge of the plot.
adres@amOrthogonalPosF = 0.49 ; -0.5 is the top edge of the plot.
adres@amJust = "BottomRight"
plotnh = gsn_add_annotation(plot(n),map_nanhai,adres)
end do
gsn_panel(wks,plot,(/1,neof/),resP) ; now draw as one plot
;*******************************************
; second plot
;*******************************************
; EOF time series [bar form]
rts = True
rts@gsnDraw = False ; don't draw yet
rts@gsnFrame = False ; don't advance frame yet
rts@gsnScale = True ; force text scaling
; these four resources allow the user to stretch the plot size, and
; decide exactly where on the page to draw it.
rts@vpHeightF = 0.40 ; Changes the aspect ratio
rts@vpWidthF = 0.85
rts@vpXF = 0.10 ; change start locations
rts@vpYF = 0.75 ; the plot
rts@tiYAxisString = "SPEI" ; y-axis label
rts@gsnYRefLine = 0. ; reference line
rts@gsnXYBarChart = True ; create bar chart
rts@gsnAboveYRefLineColor = "red" ; above ref line fill red
rts@gsnBelowYRefLineColor = "blue" ; below ref line fill blue
; panel plot only resources
rtsP = True ; modify the panel plot
rtsP@gsnMaximize = True ; large format
rtsP@gsnPanelMainString = "SPEI "+": "+yStrt+"-"+yLast
;year = yyyymm/100
; create individual plots
do n=0,neof-1
rts@gsnLeftString = "EOF "+(n+1)
rts@gsnRightString = sprintf("%5.1f", eof@pcvar(n)) +"%"
plot(n) = gsn_csm_xy (wks,ispan(1961,2018,1),dim_standardize(eof_ts(n,:),1),rts)
end do
gsn_panel(wks,plot,(/neof,1/),rtsP) ; now draw as one plot
end
|
|