[ncl-talk] getting less plots than what is required

Will Hobbs Will.Hobbs at utas.edu.au
Mon Aug 10 02:32:22 MDT 2015


There's en error in your final do loop, where you create the plots; you're using indices of 0 and 1 for the plots, regardless of the loop. Every loop will just overwrite the previous loop.

One possible fix:

   i = 0                                                          ;index to refer to the plot
   do ns=0,dimsizes(season_index)-1

    res at gsnCenterString   = season_label(ns)+":"+(ymStrt/100) +"-"+(ymLast/100)

    plot(i)    = gsn_csm_contour_map_ce(wks,precSeaClm(ns,:,:), res)  ; create plot, using i NOT 0
    plot(i+1)  = gsn_csm_contour_map_ce(wks,prec1SeaClm(ns,:,:), res)  ; create plot using i+1 NOT 1

    i = i+2 ; update i for the next loop

   end do

Normally in a loop you could use the loop integer (ns in this case) as the reference. But sometimes, is is the case here, it's necessary to use an index several times in the same loop, hence I created 'i'.

Will

From: george luke <lukejuliet2015 at gmail.com<mailto:lukejuliet2015 at gmail.com>>
Date: Monday, 10 August 2015 6:21 PM
To: "ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>" <ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>>
Subject: [ncl-talk] getting less plots than what is required

Dear All
I am trying to make 6plots BUT only two are being made. If i set

plot(0) = gsn_csm_contour_map_ce(wks,precSeaClm(ns,:,:), res)  ; create plot
    plot(1) = gsn_csm_contour_map_ce(wks,prec1SeaClm(ns,:,:), res)  ; create plot

I get only 3plots
BUT IF I SET
plot(ns) = gsn_csm_contour_map_ce(wks,precSeaClm(ns,:,:), res)  ; create plot
    plot(ns) = gsn_csm_contour_map_ce(wks,prec1SeaClm(ns,:,:), res)  ; create plot
I only get 2plots..

kindly help

Below is my script full script and also attached...

;***********************************************
; climo_3.ncl
;
; Concepts illustrated:
;   - Calculating monthly climatologies
;   - Calculating seasonal totals for 36yrs
;   - Creating a color map using named colors
;   - Paneling four plots on a page
;   - Adding a common labelbar to paneled plots
;   - Explicitly setting contour levels
;   - Changing the center longitude for a cylindrical equidistant projection
;   - Turning off the individual contour labelbar
;   - Adding a common title to paneled plots
;   - Turning off map fill
;   - Creating a center subtitle
;
;***********************************************
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"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
begin
;*******************************************************
; Read the file for GPCC
;*******************************************************
  ymStrt = 198101
  ymLast = 199012
  a    = addfile("GPCC.nc","r")

  TIME = a->time
  YYYYMM = cd_calendar(TIME, -1)
  iStrt  = ind(YYYYMM.eq.ymStrt)
  iLast  = ind(YYYYMM.eq.ymLast)
  prec = a->precip(iStrt:iLast,:,:)              ; (time,lat,lon)
  delete(prec at units)
  delete(prec at long_name)
  printMinMax(prec,True)

  printVarSummary(prec)
   time = a->time                                ; (time) ==> YYMM
  ntim = dimsizes(time)
  precClm = clmMonTLL(prec)
   printVarSummary(precClm)
;*******************************************************
; Read the file for GPCP
;*******************************************************
  ymStrt = 198101
  ymLast = 199012
  b    = addfile("GPCP.nc","r")
  ;TIME = b->time
  time1 =b->time
  delete(TIME)
  yyyymm = cd_calendar(time1, -1)
  iStrt  = ind(yyyymm.eq.ymStrt)
  iLast  = ind(yyyymm.eq.ymLast)
  prec1 = b->precip(iStrt:iLast,:,:)              ; (time,lat,lon)
  delete(prec1 at units)
  delete(prec1 at long_name)
  printMinMax(prec1,True)

  printVarSummary(prec1)
   time1 = b->time                             ; (time) ==> YYMM
  ntim1 = dimsizes(time1)
  prec1Clm = clmMonTLL(prec1)
   printVarSummary(prec1Clm)
;************************************************
; Compute the monthly climatology using a function in contributed.ncl
;************************************************
  precMonClm = clmMonTLL(prec)   ; (12,:,:)
  precSeaClm = runave_n_Wrap(precMonClm, 3, -1, 0)  ; unweighted seasonal average
  printVarSummary(precSeaClm)

   prec1MonClm = clmMonTLL(prec1)   ; (12,:,:)
  prec1SeaClm = runave_n_Wrap(prec1MonClm, 3, -1, 0)  ; unweighted seasonal average
  printVarSummary(prec1SeaClm)

   season_index = (/3,6,10/)  ; MAM, JJA, OND
  season_label = (/ "MAM", "JJA","OND"/)

;************************************************
; create colors
;*************************************************
  wks = gsn_open_wks("x11", "clim_gpcp")          ; open  a work station


 colors = (/ (/255,255,255/),(/255,255,255/), (/244,255,244/), \
  (/217,255,217/), (/163,255,163/), (/106,255,106/), \
  (/43,255,106/), (/0,224,0/), (/0,134,0/),(/255,255,0/),\
  (/255,127,0/) /) * 1.0 ; we multiply by 1 to make colors float

    colors = colors/255.               ; normalize (required by NCL)
 ;************************************************
; create panel plots
;*************************************************
 plot   = new ( 6, graphic)                    ; create graphical array

    res                      = True               ; plot options desired

  ;res at cnFillDrawOrder      = "Predraw"
  res at cnFillOn             = True               ; turn on color fill
  res at cnInfoLabelOn        = False              ; turn off contour info label
  res at cnLinesOn            = False              ; turn off contour lines
  res at cnLineLabelsOn       = False              ; turn off line labels
  res at cnFillPalette        =colors
  res at cnLevelSelectionMode = "ExplicitLevels"   ; set explicit contour levels
 res at cnLevels        =(/0.1,0.2,0.4,0.8,1.6,3.2,6.4,12.8,25,30,40,45,60,75,83,100/)

  res at mpFillOn             = False              ; turn off gray continents
  res at mpCenterLonF         = 180                ; Centers the plot at 180

  res at lbLabelBarOn         = False              ; No single label bar
  res at gsnDraw              = False
  res at gsnFrame             = False
  resP                     = True               ; panel options
  resP at txString            = "Seasons"   ; common title
  resP at gsnMaximize         = True               ; maximize image
  resP at gsnPanelLabelBar    = True               ; Add common label bar

  ;****************ZOOM INTO YOUR LOCATION*********************

  res at mpLimitMode           = "LatLon"
 ;res at mpOutlineOn    =True
 ;res at mpOutlineSpecifiers     =True
  res at mpMinLonF            = 21.               ; select a subregion
  res at mpMaxLonF            = 54.
  res at mpMinLatF            = -12.
  res at mpMaxLatF            = 22.5


  ;res at mpLandFillColor      = "background"       ; color of land

  ;*********************Masking*********************************

      res at mpFillDrawOrder = "Postdraw"


      resMap= True
      resMap at mpPerimOn = False
     resMap at mpGridAndLimbOn = False
    resMap at gsnTickMarksOn = False
    resMap at mpDataSetName = "Earth..3"
     resMap at mpOutlineOn = True


  res at mpFillOn                    = False        ; turn off gray fill
  res at mpOutlineBoundarySets       = "National"   ; turn on country boundaries

  resMap at mpFillOn = True
  resMap at mpOceanFillColor = "transparent"
  resMap at mpLandFillColor = "transparent"
  resMap at mpInlandWaterFillColor = "transparent"

   res at mpDataBaseVersion = "MediumRes"            ; choose higher resolution

   do ns=0,dimsizes(season_index)-1

    res at gsnCenterString   = season_label(ns)+":"+(ymStrt/100) +"-"+(ymLast/100)

    ;res at gsnCenterString   = ""
    plot(0) = gsn_csm_contour_map_ce(wks,precSeaClm(ns,:,:), res)  ; create plot
    plot(1) = gsn_csm_contour_map_ce(wks,prec1SeaClm(ns,:,:), res)  ; create plot


   end do
  gsn_panel(wks,plot,(/3,3/),resP)

 end



University of Tasmania Electronic Communications Policy (December, 2014).
This email is confidential, and is for the intended recipient only. Access, disclosure, copying, distribution, or reliance on any of it by anyone outside the intended recipient organisation is prohibited and may be a criminal offence. Please delete if obtained in error and email confirmation to the sender. The views expressed in this email are not necessarily the views of the University of Tasmania, unless clearly intended otherwise.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150810/deaf128a/attachment.html 


More information about the ncl-talk mailing list