- 积分
- 1372
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2017-11-13
- 最后登录
- 1970-1-1
|

楼主 |
发表于 2018-5-7 17:33:56
|
显示全部楼层
代码如下
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
arr = (/800,900,1000,1100,1200,1300,1400,1500,1600,1700/)
colors = (/10,20,30,38,48,56,66,74,84,94,98/) ; marker colors, dimsizes must
; be equal to dimsizes(arr)+1
labels = new(dimsizes(arr)+1,string) ; Labels for legend.
;---------------------------
loaddir = "./"
loadfilenm_obs = "obs_9yrmean_prc_2005-2013.txt"
loadfilenm_01 = "sta_1p5km_prc.txt"
loadfilenm_09 = "sta_9km_prc.txt"
;;;;;;;;;;;;;;;;;;;;;;;obs obs obs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f_obs = asciiread(loaddir+loadfilenm_obs,(/2301,13/),"float")
printVarSummary(f_obs)
obs = f_obs(:,3)
lat = f_obs(:,2)
lon = f_obs(:,1)
npts = 2301 ; Number of points.
;lat = random_uniform( 25., 50.,npts) ; Create some dummy latitude
;lon = random_uniform(235.,290.,npts) ; and longitude data that
; will contain the position of
; our markers.
R= f_obs(:,3) ; = random_uniform(-1.2,35.,npts) ; This is dummy data for determining
num_distinct_markers = dimsizes(arr)+1 ; number of distinct markers
lat_new = new((/num_distinct_markers,dimsizes(R)/),float,-999)
lon_new = new((/num_distinct_markers,dimsizes(R)/),float,-999)
;
; Group the points according to which range they fall in. At the
; same time, create the label that we will use later in the legend.
;
do i = 0, num_distinct_markers-1
if (i.eq.0) then
indexes = ind(R.lt.arr(0))
labels(i) = "x < " + arr(0)
end if
if (i.eq.num_distinct_markers-1) then
indexes = ind(R.ge.max(arr))
labels(i) = "x >= " + max(arr)
end if
if (i.gt.0.and.i.lt.num_distinct_markers-1) then
indexes = ind(R.ge.arr(i-1).and.R.lt.arr(i))
labels(i) = arr(i-1) + " <= x < " + arr(i)
end if
;
; Now that we have the set of indexes whose values fall within
; the given range, take the corresponding lat/lon values and store
; them, so later we can color this set of markers with the appropriate
; color.
;
if (.not.any(ismissing(indexes))) then
npts_range = dimsizes(indexes) ; # of points in this range.
lat_new(i,0:npts_range-1) = lat(indexes)
lon_new(i,0:npts_range-1) = lon(indexes)
end if
delete(indexes) ; Necessary b/c "indexes" may be a different
; size next time.
end do
f_01 = asciiread(loaddir+loadfilenm_01,(/2301,4/),"float")
;printVarSummary(f_obs)
obs01 = f_01(:,3)
lat01 = f_01(:,2)
lon01 = f_01(:,1)
npts = 2301 ; Number of points.
;lat = random_uniform( 25., 50.,npts) ; Create some dummy latitude
;lon = random_uniform(235.,290.,npts) ; and longitude data that
; will contain the position of
; our markers.
R01= f_01(:,3) ; = random_uniform(-1.2,35.,npts) ; This is dummy data for determining
; how to color the markers.
num_distinct_markers01 = dimsizes(arr)+1 ; number of distinct markers
lat_new01 = new((/num_distinct_markers01,dimsizes(R01)/),float,-999)
lon_new01 = new((/num_distinct_markers01,dimsizes(R01)/),float,-999)
;
; Group the points according to which range they fall in. At the
; same time, create the label that we will use later in the legend.
;
do i = 0, num_distinct_markers01-1
if (i.eq.0) then
indexes01 = ind(R01.lt.arr(0))
labels(i) = "x < " + arr(0)
end if
if (i.eq.num_distinct_markers01-1) then
indexes01 = ind(R01.ge.max(arr))
labels(i) = "x >= " + max(arr)
end if
if (i.gt.0.and.i.lt.num_distinct_markers01-1) then
indexes01 = ind(R01.ge.arr(i-1).and.R01.lt.arr(i))
labels(i) = arr(i-1) + " <= x < " + arr(i)
end if
if (.not.any(ismissing(indexes01))) then
npts_range = dimsizes(indexes01) ; # of points in this range.
lat_new01(i,0:npts_range-1) = lat01(indexes01)
lon_new01(i,0:npts_range-1) = lon01(indexes01)
end if
delete(indexes01) ; Necessary b/c "indexes" may be a different
; size next time.
end do
f_09 = asciiread(loaddir+loadfilenm_09,(/2301,4/),"float")
obs09 = f_09(:,3)
lat09 = f_09(:,2)
lon09 = f_09(:,1)
npts = 2301 ; Number of points.
;lat = random_uniform( 25., 50.,npts) ; Create some dummy latitude
;lon = random_uniform(235.,290.,npts) ; and longitude data that
; will contain the position of
; our markers.
R09= f_09(:,3) ; = random_uniform(-1.2,35.,npts) ; This is dummy data for determining
; how to color the markers.
num_distinct_markers09 = dimsizes(arr)+1 ; number of distinct markers
lat_new09 = new((/num_distinct_markers09,dimsizes(R09)/),float,-999)
lon_new09 = new((/num_distinct_markers09,dimsizes(R09)/),float,-999)
;
; Group the points according to which range they fall in. At the
; same time, create the label that we will use later in the legend.
;
do i = 0, num_distinct_markers09-1
if (i.eq.0) then
indexes09 = ind(R09.lt.arr(0))
labels(i) = "x < " + arr(0)
end if
if (i.eq.num_distinct_markers09-1) then
indexes09 = ind(R09.ge.max(arr))
labels(i) = "x >= " + max(arr)
end if
if (i.gt.0.and.i.lt.num_distinct_markers09-1) then
indexes09 = ind(R09.ge.arr(i-1).and.R09.lt.arr(i))
labels(i) = arr(i-1) + " <= x < " + arr(i)
end if
;
; Now that we have the set of indexes whose values fall within
; the given range, take the corresponding lat/lon values and store
; them, so later we can color this set of markers with the appropriate
; color.
;
if (.not.any(ismissing(indexes09))) then
npts_range = dimsizes(indexes09) ; # of points in this range.
lat_new09(i,0:npts_range-1) = lat09(indexes09)
lon_new09(i,0:npts_range-1) = lon09(indexes09)
end if
delete(indexes09) ; Necessary b/c "indexes" may be a different
; size next time.
end do
wks = gsn_open_wks("ps",get_script_prefix_name()) ; send graphics to PNG file
gsn_define_colormap(wks,"WhViBlGrYeOrRe") ; define a different color map
plot = new(3,graphic)
if(True)then
mpres = True
mpres@gsnMaximize = False ; Maximize plot in frame.
mpres@gsnFrame = False ; Don't advance the frame
mpres@gsnDraw = False
;
; Zoom in on United States.
;
mpres@mpMinLatF = 29.2
mpres@mpMaxLatF = 32.8
mpres@mpMinLonF = 119.2
mpres@mpMaxLonF = 123.
mpres@mpDataSetName = "Earth..4"
mpres@mpDataBaseVersion = "MediumRes"
mpres@mpOutlineOn = True
mpres@mpOutlineSpecifiers = (/"China:states","Taiwan"/)
mpres@mpGeophysicalLineThicknessF = 1.5
mpres@mpFillOn = True
mpres@mpFillDrawOrder = "PostDraw"
mpres@mpFillAreaSpecifiers = (/"Water","Land"/)
mpres@mpSpecifiedFillColors = (/"White","transparent"/)
mpres@gsnLeftStringFontHeightF = 0.023
mpres@tmXBLabelFontHeightF = 0.017
mpres@tmYLLabelFontHeightF = 0.017
mpres@mpOutlineBoundarySets = "NoBoundaries"
mpres@pmTickMarkDisplayMode = "Always"
mpres@gsnPanelLabelBar=True
;mpres@cnLevels= (/800,900,1000,1100,1200,1300,1400,1500,1600,1700/)
;mpres@cnFillColors=(/10,20,30,38,48,56,66,74,84,94,98/)
mpres@mpFillColors = (/"transparent","transparent", \
"lightgray","transparent"/) ;assign light gray to land masses
end if
mpres@tiMainString = "(a)obs"
plot(0) = gsn_csm_map(wks,mpres)
mpres01=mpres
mpres01@tiMainString ="(b)1p5km"
plot(1)= gsn_csm_map(wks,mpres01)
mpres09=mpres
mpres09@tiMainString ="(c)9km"
plot(2)= gsn_csm_map(wks,mpres09)
lbres = True
lbres@lbPerimOn = False ; no label bar box
lbres@lbOrientation = "Horizontal" ; orientation
lbres@vpWidthF = 0.7 ; size
lbres@vpHeightF = 0.1
lbres@lbLabelFontHeightF = 0.012 ; label font height
lbres@lbLabelAlignment = "InteriorEdges" ; where to label
lbres@lbMonoFillPattern = True ; fill sold
lbres@lbFillColors = colors;(/10,20,30,38,48,56,66,74,84,94,98/) ; must be RGB triplets
gsn_labelbar_ndc(wks, 11, arr, 0.15, 0.35, lbres)
gsres = True
gsres@gsMarkerIndex = 16 ; Use filled dots for markers.
do i = 0, num_distinct_markers-1
if (.not.ismissing(lat_new(i,0)))
gsres@gsMarkerColor = colors(i)
;gsn_polymarker(wks,plot(0),lon_new(i,:),lat_new(i,:),gsres)
p0=gsn_add_polymarker(wks,plot(0),lon_new(i,:),lat_new(i,:),gsres)
;print(lon_new(i,:))
;draw(p0)
end if
end do
do i = 0, num_distinct_markers01-1
if (.not.ismissing(lat_new01(i,0)))
gsres@gsMarkerColor = colors(i)
;gsn_polymarker(wks,plot(1),lon_new01(i,:),lat_new01(i,:),gsres)
p1=gsn_add_polymarker(wks,plot(1),lon_new01(i,:),lat_new01(i,:),gsres)
;draw(p1)
end if
end do
do i = 0, num_distinct_markers09-1
if (.not.ismissing(lat_new09(i,0)))
gsres@gsMarkerColor = colors(i)
;gsn_polymarker(wks,plot(2),lon_new09(i,:),lat_new09(i,:),gsres)
p2=gsn_add_polymarker(wks,plot(2),lon_new09(i,:),lat_new09(i,:),gsres)
;draw(p2)
end if
end do
panelres = True
panelres@gsnMaximize = True
gsn_panel(wks,plot,(/1,3/),panelres)
end
|
|