[ncl-talk] gsn_csm_contour_map_ce: Fatal: the input data array must be 1D or 2D

Saurabh Kelkar kelkarsaurabh527 at gmail.com
Mon Mar 2 22:05:37 MST 2020


Dear Sir,

My name is Saurabh Kelkar.

I am trying to plot a wrf 2 m Temp output for Delhi, India at a resolution
of 2km x 2km.

I have used an animation script available at NCL webpage and modified it
according to my needs. However, I am getting an error after executing it.

I am new to NCL, so I'm unable to comprehend the error message.

Could you please help me?

I am attaching the script file (Error is highlighted) and the error message
with this email.

Thank you!

Sincerely,
Saurabh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200303/ff792b17/attachment.html>
-------------- next part --------------
function labelbar(wks,plot)
local colors, levels, labels, nboxes, bb, bot
begin

;---Get bounding box that encloses plot, so we know where the bottom edge is.
  bb  = NhlGetBB(plot)
  bot = bb(1)             ; bottom edge of plot

;---Retrieve the contour levels and their associated colors.
  getvalues plot
    "cnLevels"     : levels
    "cnFillColors" : colors
  end getvalues

  nboxes = dimsizes(colors)

  labels                   = ""+levels    ; labels for the labelbar

;---Set some labelbar resources.
  lbres                    = True
  lbres at vpXF               = 0.15         ; Position labelbar at         
  lbres at vpYF               = 0.10
  lbres at vpWidthF           = 0.70
  lbres at vpHeightF          = 0.10

  lbres at lbPerimOn          = False            ; Turn off perimeter.
  lbres at lbOrientation      = "Horizontal"     ; Default is vertical.
  lbres at lbFillColors       = colors
  lbres at lbMonoFillPattern  = True             ; Fill them all solid.
  lbres at lbLabelFontHeightF = 0.013            ; Label font height
  lbres at lbLabelAlignment   = "InteriorEdges"

  lbid = gsn_create_labelbar(wks,nboxes,labels,lbres)

  draw(lbid)     ; Draw labelbar

  return(lbid)   ; Return it so we can maximize later if desired.
end

;----------------------------------------------------------------------
; Main code
;----------------------------------------------------------------------
begin

  start_cpu_time = get_cpu_time()     ; We will time this example

;---Open files
; dir   = "~/ncargtest/nclscripts/wrf_files/"
; dir   = "./"  ; new input directory
; files = systemfunc("ls " + dir + "wrfout_d01_2008-09*")
  a     = addfiles("wrfout_d01_2020-01-17_00:00:00.nc","r")

;---Read variables
;  t2   = a[:]->T2(0,:,:)                 ; terrain, 0 is the first time step
  hgt = a[:]->HGT(0,:,:)
  znu   = a[:]->ZNU                        ; (Time, bottom_top)
  t2   = wrf_user_getvar(a,"T2",-1)      
  times = wrf_user_list_times(a)           ; time as character strings

  printMinMax(t2,0)
  printVarSummary(t2)

;---Set all values < -28 to missing, so they don't get contoured.
  t2 at _FillValue = -999.
  t2            = where(t2.lt.239.42,t2 at _FillValue,t2)
  ntim           = dimsizes(t2(:,0,0))
  ilevels        = (/5,15,20,25/)           ; which level indexes to plot; levels 26
                                            ; and higher tend to have missing data
  nlev           = dimsizes(ilevels)
  ter_plot       = new(nlev,graphic)
  t2_plot       = new(nlev,graphic)

;---Open workstation
  wks = gsn_open_wks("png","animatest")

;---Set some common resources
  res                       = True
  res at gsnDraw               = False    ; turn off draw
  res at gsnFrame              = False    ; turn off frame
  res at cnFillOn              = True     ; turn on contour fill
  res at cnLinesOn             = False    ; turn off contour lines
  res at cnLineLabelsOn        = False    ; turn off contour line labels
  res at cnInfoLabelOn         = False    ; turn off info label

  res at gsnLeftString         = ""       ; turn off subtitles
  res at gsnRightString        = ""
  res at gsnCenterString       = ""

  res at lbLabelFontHeightF       = 0.015    ; size of labelbar labels
  res at pmLabelBarOrthogonalPosF = -0.02    ; move labelbar closer to plot
  res at tfDoNDCOverlay           = True     ; native map being used
  res at lbLabelBarOn             = False    ; will add to panel plot

;---Copy common resources for terrain plot
  tres = res 
  tres = wrf_map_resources(a[0],tres)    ; Use first file in list for map proj info

  tres at cnLevelSelectionMode  = "ExplicitLevels"
  tres at cnLevels              = ispan(1,2200,200)
  tres at cnFillPalette         = "OceanLakeLandSnow"
  tres at cnFillOpacityF        = 0.5                 ; make contours partially transparent

;---Copy common resources for t2 plot
  dres                       = res      

  dres at cnFillMode            = "RasterFill"
  dres at cnLevelSelectionMode  = "ExplicitLevels"
  dres at cnLevels              = ispan(-28,50,8)

;---Read in colormap so we can subset it.
  cmap_r                     = read_colormap_file("WhViBlGrYeOrRe")
  dres at cnFillPalette         = cmap_r(6:,:)  ; skip the first few colors

;---Panel resources
  pres                  = True
  pres at gsnFrame         = False   ; so we can add a labelbar 
  pres at gsnPanelBottom   = 0.1
;
; Loop through each time step and draw a set of paneled plots
; Time 0 has constant fields, so skip it.
;
  do nt=1,ntim-1

;---For each set of levels, check for all missing or constant fields
    skip_this_one = False
    first         = True
    do nl=0,nlev-1
      ilev  = ilevels(nl)
      if(all(ismissing(t2(nt,ilev,:))).or.(min(t2(nt,ilev,:)).eq.max(t2(nt,ilev,:)))) then
        print("Field is constant at time='" + times(nt) + "' and level=" + znu(nt,ilev) +". Skipping...")
        skip_this_one = True
        continue
      else
        print("time  ='" + times(nt) + "'")
        print("level =" + znu(nt,ilev))
      end if
    end do

;---Skip this time step if one or more plots would be invalid.
    if(skip_this_one) then
      continue
    end if

;---For each set of levels, generate a 2 x 2 panel plot
    do nl=0,nlev-1
      ilev  = ilevels(nl)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ter_plot(nl) = gsn_csm_contour_map(wks,t2,False)                                    ;This the where 
      t2_plot(nl) = gsn_csm_contour(wks,t2(nt,ilev,:,:),False)                            ;the error is occuring.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;---Create a labelbar just once
      if(first) then
        lbid = labelbar(wks,t2_plot(nl))
        first = False
      end if
      overlay(ter_plot(nl),t2_plot(nl))
    end do

;---Draw the labelbar at the bottom and then the four paneled plots
    draw(lbid)
    pres at gsnPanelFigureStrings = ""+znu(nt,ilevels)
    pres at gsnPanelMainString    = times(nt)
    gsn_panel(wks,ter_plot,(/2,2/),pres)
    frame(wks)                           ; Advance the frame
  end do

;---Calculate total time for this example.
  end_cpu_time = get_cpu_time()
  print(get_script_prefix_name() + ": elapsed time = " + (end_cpu_time-start_cpu_time) + " seconds.")
end
-------------- next part --------------
Copyright (C) 1995-2018 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.5.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.


Variable: times
Type: string
Total Size: 136 bytes
            17 values
Number of Dimensions: 1
Dimensions and sizes:   [17]
Coordinates:
Number Of Attributes: 2
  description : times in file
  _FillValue :  missing
(0)     2020-01-17_00:00:00
(1)     2020-01-17_03:00:00
(2)     2020-01-17_06:00:00
(3)     2020-01-17_09:00:00
(4)     2020-01-17_12:00:00
(5)     2020-01-17_15:00:00
(6)     2020-01-17_18:00:00
(7)     2020-01-17_21:00:00
(8)     2020-01-18_00:00:00
(9)     2020-01-18_03:00:00
(10)    2020-01-18_06:00:00
(11)    2020-01-18_09:00:00
(12)    2020-01-18_12:00:00
(13)    2020-01-18_15:00:00
(14)    2020-01-18_18:00:00
(15)    2020-01-18_21:00:00
(16)    2020-01-19_00:00:00
(0)     TEMP at 2 M (K) : min=239.432   max=296.118

Variable: t2
Type: float
Total Size: 5940548 bytes
            1485137 values
Number of Dimensions: 3
Dimensions and sizes:   [Time | 17] x [south_north | 199] x [west_east | 439]
Coordinates:
Number Of Attributes: 6
  FieldType :   104
  MemoryOrder : XY
  description : TEMP at 2 M
  units :       K
  stagger :
  coordinates : XLONG XLAT XTIME
(0)     time  ='2020-01-17_03:00:00'
(0)     level =0.9545
(0)     time  ='2020-01-17_03:00:00'
(0)     level =0.752
(0)     time  ='2020-01-17_03:00:00'
(0)     level =0.57255
(0)     time  ='2020-01-17_03:00:00'
(0)     level =0.38675
(0)     gsn_csm_contour_map_ce: Fatal: the input data array must be 1D or 2D
fatal:Illegal right-hand side type for assignment
fatal:["Execute.c":8637]:Execute: Error occurred at or near line 147 in file 4paneAnim.ncl


More information about the ncl-talk mailing list