爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

终于作出了替换下垫面的图了

[复制链接]
发表于 2022-3-9 22:47:04 | 显示全部楼层
您好,求一个您这个帖子里面的代码吧。您贴出来的之前的代码,运行报错呢。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-3-10 08:05:50 | 显示全部楼层
sun92 发表于 2022-3-9 22:47
您好,求一个您这个帖子里面的代码吧。您贴出来的之前的代码,运行报错呢。

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"   



  f0=addfile("geo_em.d04.nc","r")
  lon=f0->XLONG_M(0,:,:)
  lat=f0->XLAT_M(0,:,:)
  lu=f0->LU_INDEX(0,:,:)
  lu@description = ""
  lu@units = ""
  printVarSummary(lon)
  printVarSummary(lat)
  printVarSummary(lu)

  info     = (/ " 1  Evergreen Needleleaf Forest", \  ; n=0
                " 2  Evergreen Broadleaf Forest", \
                " 3  Deciduous Needleleaf Forest", \
                " 4  Deciduous Broadleaf Forest", \
                " 5  Mixed Forest        ", \
                " 6  Closed Shrublands   ", \
                " 7  Open Shrublands     ", \
                " 8  Woody Savannas      ", \
                " 9  Savannas            ", \
                "10  Grasslands          ", \
                "11  Permanent Wetlands  ", \
                "12  Croplands           ", \
                "13  Urban and Built-up  ", \
                "14  Cropland Mosaics    ", \
                "15  Snow and Ice        ", \
                "16  Bare Soil and Rocks ", \
                "17  Water Bodies        ", \
                "18  Wooded Tundra", \
                "19  Mixed Tundra", \
                "20  Barren Tundra"  /) ; n=19

ninfo = dimsizes(info)

colors     = (/ "white","black","darkgreen", \  ; 1
"darkolivegreen", \      ;2
"darkkhaki", \     ;3
"green2", \ ;4
"limegreen", \    ;5
"darkolivegreen1", \         ;6
"greenyellow", \                            ;7
"darkolivegreen3", \    ;8
"darkolivegreen4", \                ;9
"darkolivegreen2", \         ; 10
"orange1", \            ;11
"yellow", \        ;12
"red", \  ;13
"chocolate1", \ ;  14
"white", \  ;15
"gold1", \ ; 16
"blue", \ ; 17
"grey", \   ;18
"pink", \   ;19
"purple" /) ; 20

;************************************************
; create plot
;************************************************

  wks = gsn_open_wks("png","anduse")  


gsn_define_colormap(wks,colors)     

  res                  = True               ; plot mods desired
  res@gsnDraw          = False
  res@gsnFrame         = False
  res@gsnMaximize      = True
  res@gsnAddCyclic     = False              ; Don't add a cyclic point, important-zhiyong
  res@cnFillOn         = True               ; color Fill
  res@cnFillMode       = "RasterFill"       ; Raster Mode
  res@cnLinesOn        = False              ; Turn off contour lines

  res@cnLevelSelectionMode = "ExplicitLevels" ; set explict contour levels
  res@cnLevels         = integertobyte( ispan(2,ninfo,1) )

  res@lbLabelPosition  = "center"           ; label position
  res@lbLabelAlignment = "BoxCenters"       ; label orientation
  res@lbLabelStrings   = ispan(1,ninfo,1)  

  res@pmLabelBarOrthogonalPosF = 0.2  ; move up smidge
  res@pmTickMarkDisplayMode = "Always"

  res@tmXBMode = "Automatic"
  res@tmYLMode = "Automatic"
  res@tmXTLabelsOn = False
  res@tmYRLabelsOn = False
  res@tmXTMajorLineColor  = 0
  res@tmYRMajorLineColor  = 0


  res@mpCenterLonF     = 0                  ; set map center
  res@mpFillOn         = False
  res@mpOutlineOn      = False              ; set default boundaries
  res@tfDoNDCOverlay   = True
  res@mpProjection      = "LambertConformal"
  res@mpLambertParallel1F = 30.0
  res@mpLambertParallel2F = 60.0
  res@mpLambertMeridianF  = 113.0        ; central meridian
  res@mpLimitMode         = "LatLon"

  res@sfXArray =lon
  res@sfYArray =lat

  res@mpMinLatF =  min(lat)
  res@mpMaxLatF =  max(lat)
  res@mpMinLonF =  min(lon)
  res@mpMaxLonF =  max(lon)

  res@tmXBMode = "Automatic"
  res@tmYLMode = "Automatic"
  res@tmXBLabelFontHeightF  = 0.01     ;the height of lat and lon

;  plot = gsn_csm_contour_map_ce(wks, lu, res) ; create plot
   plot = gsn_csm_contour_map(wks, lu, res)

;
;add text

  rtxt = True
  rtxt@txJust        = "Centerleft"
  rtxt@txFontHeightF = 0.01
                            ; 5 rows x 4 columns of text
  n  = -1
  xx = 0.12                ; arbitrary
  do ncol=0,3
     yy = 0.3
    do nrow=0,4
       n = n+1
       gsn_text_ndc (wks,info(n),xx,yy,rtxt)
       yy = yy - 3*rtxt@txFontHeightF
    end do
     xx = xx + 0.20
  end do

  draw(plot)
  frame(wks)
quit

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

使用道具 举报

发表于 2023-10-10 20:17:21 | 显示全部楼层
感谢楼主的脚本,楼主画出的图水体呈现紫色的原因很有可能是楼主用了modis21类的数据,modis21类中多了第21类(湖)用于区分第17类(海之类的水体),而代码中只分了20类,因此在图上,湖也显示为紫色;如果不修改代码,换成modis20类,则图上的水体全部划分为17类,水体颜色应该为蓝色(第17类)。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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