[ncl-talk] NCL Land Cover Mapping Problem

LSL lslrsgis at whu.edu.cn
Tue May 7 03:08:11 MDT 2019


Dear NCL Community,


I am trying to map Land Cover Types for wrfout domain 01 and 02. The 
resulted maps are containing much coaser blocks as expected, something 
strange. Besides, the figure using colorbar mapping method for Domain 01 
(MCD12Q1.D01.000002.png) is empty.


The result map and script is attached. Any indication is appreciated. Thank!

LSL

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190507/0835f12e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MCD12Q1.d02.000002.png
Type: image/png
Size: 48902 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190507/0835f12e/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MCD12Q1.d02.000001.png
Type: image/png
Size: 66821 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190507/0835f12e/attachment-0005.png>
-------------- next part --------------
;================================================
;  vegland_1.ncl
;================================================
; Concepts illustrated:
;   - Creating a vegetation classification plot using raster contours
;   - Plotting "byte" data
;   - Customizing a labelbar for a contour plot
;   - Centering labels with respect to labelbar boxes
;   - Changing the width and height of a labelbar
;   - Centering the labels inside each box in a labelbar
;   - Changing the labelbar labels
;   - Drawing text on the frame using NDC coordinates
;   - Using the "where" function to create a land-sea mask
;================================================
;
; 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
  domain = "d02"
  diri = "./"                          ; input directory
  fili = "MCD12Q1.MOSAIC.RESAMPLE.SUBSET."+domain+".nc"
  f    = addfile (diri+fili, "r")

  veg    = f->LC_Type1(0,:,:)                      ; note: type byte
 ;printVarSummary(x)

  info     = (/ " 1  Evergreen Needleleaf", \  ; n=0
                " 2  Evergreen Broadleaf ", \
                " 3  Deciduous Needleleaf", \
                " 4  Deciduous Broadleaf ", \
                " 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  Tundra              "  /) ; n=17
  ninfo    = dimsizes(info)

;************************************************
;lat/lon
;get a landmask and some other stuff from a wrfout file
; load a wrfout file to get land-mask info out
f = addfile("/home/lsl/Downloads/DATA/wrfout_2015/Processed/wrfout_" + domain + ".nc","r")
landmask = wrf_user_getvar(f,"LANDMASK",0)
;dsizes_array = dimsizes(land_mask)
; also get some map info for later on
truelat1 = f at TRUELAT1
truelat2 = f at TRUELAT2
cen_lon = f at CEN_LON
cen_lat = f at CEN_LAT
wrf_lat2d = f->XLAT(0,:,:)
wrf_lon2d = f->XLONG(0,:,:)
latr = wrf_lat2d
lonr = wrf_lon2d

;mask water and remove relaxation zone

dsizes_array = dimsizes(landmask)
print(dsizes_array)
landmask_nr = landmask(0:(dsizes_array(0)-1),0:(dsizes_array(1)-1))
lon = lonr(0:(dsizes_array(0)-1),0:(dsizes_array(1)-1))
lat = latr(0:(dsizes_array(0)-1),0:(dsizes_array(1)-1))
dsizes_landmask_nr = dimsizes(landmask_nr)
print(dsizes_landmask_nr)
nlat = dsizes_landmask_nr(0)
nlon = dsizes_landmask_nr(1)

; convert lon to be 0->360 not -180->180
lon = where(lon.lt.0,360.+lon,lon)

pole_lat1 = 60.31
pole_lon1 = 321.38



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

  wks = gsn_open_wks("png","MCD12Q1."+domain)        ; send graphics to PNG file

  res                 = True                ; Plot mods desired.

  res at gsnMaximize     = True                ; Maximize plot in frame.

  res at gsnStringFontHeightF         = 0.013
  res at gsnRightStringOrthogonalPosF = 0.02
  res at gsnLeftStringOrthogonalPosF  = 0.02

  res at cnFillOn        = True               ; Color plot desired.
  res at cnLinesOn       = False              ; Turn off contour lines      .
  res at cnLineLabelsOn  = False              ; Turn off contour labels.

  res at mpProjection           = "LambertConformal"
  res at mpLambertParallel1F    = 25.0                ; two parallels
  res at mpLambertParallel2F    = 47.0
  res at mpLambertMeridianF     = 105.0               ; central meridian

;  res at mpLimitMode            = "LatLon"
;  res at mpMinLatF              = 24.0                ; map area
;  res at mpMaxLatF              = 50.0                ; latitudes
;  res at mpMinLonF              = -125.0              ; and
;  res at mpMaxLonF              = -65.0               ; longitudes

res at mpLimitMode       = "Corners"
res at mpLeftCornerLatF  = lat(0,0)
res at mpLeftCornerLonF  = lon(0,0)
res at mpRightCornerLatF = lat(nlat-1,nlon-1)
res at mpRightCornerLonF = lon(nlat-1,nlon-1)

  
  res at gsnDraw          = False
  res at gsnFrame         = False
  res at gsnMaximize      = True 

  res at cnFillOn         = True               ; color Fill 
  res at cnFillMode       = "RasterFill"       ; Raster Mode
  res at cnLinesOn        = False              ; Turn off contour lines

  res at cnFillPalette     = "default"
; res at cnFillPalette     = "vegetation_modis"
  res at cnSpanFillPalette = False

  res at cnLineLabelsOn   = False              ; Turn off contour line labels

  res at cnLevelSelectionMode = "ExplicitLevels"              ; set explict contour levels
  res at cnLevels         = integertobyte( ispan(2,ninfo,1) ) ; one less than ninfo

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

  res at pmLabelBarHeightF        =  0.075
 ;res at pmLabelBarWidthF         =  0.60      ; default is 0.6
 ;res at pmLabelBarOrthogonalPosF = -0.0005    ; move up smidge

  res at mpCenterLonF     = 0                  ; set map center
  res at mpFillOn         = False

  res at gsnRightString   = fili
  print(veg)
  plot = gsn_csm_contour_map_ce(wks, veg, res) ; create plot
;  plot = gsn_csm_contour_map(wks, veg, res) ; create plot

  rtxt = True
  rtxt at txJust        = "CenterLeft"
  rtxt at txFontHeightF = 0.010 
                            ; 3 rows x 6 columns of text
  n  = -1
  xx = 0.05                 ; arbitrary
  do ncol=0,5
     yy = 0.22 
    do nrow=0,2
       n = n+1
       gsn_text_ndc (wks,info(n),xx,yy,rtxt)
       yy = yy - 3*rtxt at txFontHeightF
    end do
     xx = xx + 0.155 
  end do
  draw(plot)
  frame(wks)

;---------------------------------------------------------------------
; pure land/sea mask
;---------------------------------------------------------------------
  delete(res)
 res                 = True                ; Plot mods desired.

  res at gsnMaximize     = True                ; Maximize plot in frame.

  res at gsnStringFontHeightF         = 0.013
  res at gsnRightStringOrthogonalPosF = 0.02
  res at gsnLeftStringOrthogonalPosF  = 0.02

  res at cnFillOn        = True               ; Color plot desired.
  res at cnLinesOn       = False              ; Turn off contour lines      .
  res at cnLineLabelsOn  = False              ; Turn off contour labels.

  res at mpProjection           = "LambertConformal"
  res at mpLambertParallel1F    = 25.0                ; two parallels
  res at mpLambertParallel2F    = 47.0
  res at mpLambertMeridianF     = 105.0               ; central meridian

;  res at mpLimitMode            = "LatLon"
;  res at mpMinLatF              = 24.0                ; map area
;  res at mpMaxLatF              = 50.0                ; latitudes
;  res at mpMinLonF              = -125.0              ; and
;  res at mpMaxLonF              = -65.0               ; longitudes

res at mpLimitMode       = "Corners"
res at mpLeftCornerLatF  = lat(0,0)
res at mpLeftCornerLonF  = lon(0,0)
res at mpRightCornerLatF = lat(nlat-1,nlon-1)
res at mpRightCornerLonF = lon(nlat-1,nlon-1)


  res at cnInfoLabelOn       = False           ; Turn off info label.

  res at mpGeophysicalLineColor = "red"     ; color of continental outlines
  res at mpUSStateLineColor     = "red" 
  res at mpGridLineDashPattern  = 2         ; lat/lon lines as dashed
  res at mpOutlineBoundarySets  = "GeophysicalAndUSStates" 

  res at pmTickMarkDisplayMode = "Always"       ; Turn on map tickmarks.

  cmap = read_colormap_file("BlAqGrYeOrRe")   ; 100 colors
  res at cnFillPalette        = cmap(16:,:)
  res at cnFillMode           = "RasterFill"
  res at cnLevelSelectionMode = "ManualLevels"
  res at cnMinLevelValF       = 0.0              ; min contour level
  res at cnMaxLevelValF       = 14.0             ; max contour level
  res at cnLevelSpacingF      = 1.0              ; contour spacing

  res at pmLabelBarWidthF     = 0.6
  res at lbLabelFontHeightF   = 0.013
  res at lbLabelStride        = 2
  res at lbBoxLinesOn         = False

  map = gsn_csm_contour_map(wks,veg,res) 
end


-------------- next part --------------
A non-text attachment was scrubbed...
Name: MCD12Q1.D01.000002.png
Type: image/png
Size: 62823 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190507/0835f12e/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MCD12Q1.D01.000001.png
Type: image/png
Size: 71414 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190507/0835f12e/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MCD12Q1.MOSAIC.RESAMPLE.SUBSET.d02.nc
Type: application/x-netcdf
Size: 50872 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190507/0835f12e/attachment-0002.nc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MCD12Q1.MOSAIC.RESAMPLE.SUBSET.d01.nc
Type: application/x-netcdf
Size: 22752 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190507/0835f12e/attachment-0003.nc>


More information about the ncl-talk mailing list