[ncl-talk] A simple climatology plot

Kwesi Quagraine starskykwesi at gmail.com
Tue Jan 3 09:11:57 MST 2017


Hello NCl Users, I am new to ncl and I have a problem. I am trying to make
a  plot similar to the one attached with a common color bar and the file
contains precipitation data from 1991-2005. Here's what I have done so far.

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"

wksType = "pdf"
   wksName = "climo123"                          ; ": "+yrStrt+"_"+yrLast

   diri    = "/media/kwesi/Maxtor/paper/"         ; input directory


;***********************************************************
; Read first file; Create climatology for desired period
;***********************************************************

   fili    = "CCCma91-05.nc3"
   f       = addfile (diri+fili , "r")

   pr     = f->pr*86400     ; (time,lat,lon)
   time    = f->time
   lat     = f->lat
   lon     = f->lon

   ntim = dimsizes(time)
   pr!0 = "time"
   pr!1 = "lat"
   pr!2 = "lon"
   pr&time = time
   pr&lat = lat
   pr&lon = lon

   months = (/"January", "February", "March", "April" \
            ,"May", "June", "July", "Auguat"         \
            ,"September", "October", "November"      \
            ,"December" /)
   prClm  = clmMonTLL( pr)                  ; Climatology

   delete(time)
   delete(pr)

   printVarSummary( prClm )
   printMinMax( prClm, True )

;***********************************************************
; Read second file ; Create climatology for desired period
;
;***********************************************************

   fili    = "Cnrm91-05.nc3"
   f       = addfile (diri+fili , "r")
   pr      = f->pr*86400     ; (time,lat,lon)
   time    = f->time
   lat     = f->lat
   lon     = f->lon

   ntim = dimsizes(time)
   pr!0 = "time"
   pr!1 = "lat"
   pr!2 = "lon"
   pr&time = time
   pr&lat = lat
   pr&lon = lon
   months = (/"January", "February", "March", "April" \
            ,"May", "June", "July", "Auguat"         \
            ,"September", "October", "November"      \
            ,"December" /)

   prClm  = clmMonTLL( pr)                  ; Climatology

   delete(time)
   delete(pr)

   printVarSummary( prClm )
   printMinMax( prClm, True )

;***********************************************************
; Read third file; Create climatology for desired period
;***********************************************************

   fili    = "Ichec91-05.nc3"
   f       = addfile (diri+fili , "r")

   pr      = f->pr*86400     ; (time,lat,lon)
   time    = f->time
   lat     = f->lat
   lon     = f->lon

   ntim = dimsizes(time)
   pr!0 = "time"
   pr!1 = "lat"
   pr!2 = "lon"
   pr&time = time
   pr&lat = lat
   pr&lon = lon

   months = (/"January", "February", "March", "April" \
            ,"May", "June", "July", "Auguat"         \
            ,"September", "October", "November"      \
            ,"December" /)
   prClm  = clmMonTLL( pr)                  ; Climatology

   ;delete(time)
   delete(pr)

   printVarSummary( prClm )
   printMinMax( prClm, True )

;*************************************************
; create colors
;*************************************************


  colors = (/"white","black"             \      ; back/fore ground
            ,"azure1","beige","lavender" \
            ,"PaleGreen","SeaGreen3","LightYellow" \
            ,"Yellow","HotPink","Red"/)         ; choose colors for color
map
            wks = gsn_open_wks(wksType, wksName)
  gsn_define_colormap(wks, colors)              ; generate new color map

;************************************************
; create panel plots
;*************************************************
  plot   = new (3 , graphic)                    ; create graphical array

  res                      = True               ; plot options desired

  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 cnLevelSelectionMode = "ExplicitLevels"   ; set explicit contour
levels
  res at cnLevels             = (/ 2.0, 2.5 \ ; set unequal contour levels
                              , 3.0, 3.5, 4.0, 4.5, 5.0 \
                              ,5.5, 6.0, 6.5, 7.0, 7.5,10.0 /)



  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            = "GPCC Precipitation: Climatology"   ; common
title
  resP at gsnMaximize         = True               ; maximize image
  resP at gsnPanelLabelBar    = True               ; Add common label bar

;---Set to False if plotting regional data or setting sfXArray/sfYArray
  res at gsnAddCyclic      =False

  res at sfXArray          = lon   ; Only necessary if x doesn't
  res at sfYArray          = lat   ; contain 1D coordinate arrays
;
; Zoom in on map if desired. There are other ways to zoom in on
; map if you have a different projection, like lambert conformal.
;
  res at mpMinLatF         = -60
  res at mpMaxLatF         = 0
  res at mpMinLonF         = -20
  res at mpMaxLonF         = 60
  ;res at mpCenterLonF      = (res at mpMinLonF + res at mpMaxLonF) / 2.

  ;i = -1                                        ; Climatologies
  ;do nmo=0,180                                 ; loop over the months
     ;i = i+1
     ;res at gsnCenterString   = months(nmo)+":"+time(0)/100 +"-"+
time(ntim-1)/100
     ;plot(i) = gsn_csm_contour_map_ce(wks,prClm(nmo,:,:), res)  ; create
plot
  ;end do
plot = gsn_csm_contour_map_ce(wks,prClm(0,:,:), res)  ; create plot
  gsn_panel(wks,plot,(/3,1/),resP)

-------After running the script I get
Variable: prClm
Type: float
Total Size: 1486416 bytes
            371604 values
Number of Dimensions: 3
Dimensions and sizes:    [month | 12] x [lat | 179] x [lon | 173]
Coordinates:
            month: [0..11]
            lat: [-46.25..42.75]
            lon: [-25.25..60.75]
Number Of Attributes: 3
  _FillValue :    1e+20
  time_op_ncl :    Climatology: 15 years
  info :    function clmMonLLT: contributed.ncl
(0)
(0)    min=0   max=63.1759

Variable: prClm
Type: float
Total Size: 1486416 bytes
            371604 values
Number of Dimensions: 3
Dimensions and sizes:    [month | 12] x [lat | 179] x [lon | 173]
Coordinates:
            month: [0..11]
            lat: [-46.25..42.75]
            lon: [-25.25..60.75]
Number Of Attributes: 3
  info :    function clmMonLLT: contributed.ncl
  time_op_ncl :    Climatology: 15 years
  _FillValue :    1e+20
(0)
(0)    min=0   max=69.7658

Variable: prClm
Type: float
Total Size: 1486416 bytes
            371604 values
Number of Dimensions: 3
Dimensions and sizes:    [month | 12] x [lat | 179] x [lon | 173]
Coordinates:
            month: [0..11]
            lat: [-46.25..42.75]
            lon: [-25.25..60.75]
Number Of Attributes: 3
  info :    function clmMonLLT: contributed.ncl
  time_op_ncl :    Climatology: 15 years
  _FillValue :    1e+20
(0)
(0)    min=0   max=53.8587
​ and the file named climo123 as attached.​ Any help will be much
appreciated.

-- 
Try not to become a man of success but rather a man of value-Albert Einstein

University of Cape Coast|College of Agriculture and Natural Sciences|Department
of Physics|
Team Leader|Recycle Up! Ghana|Technology Without Borders|
Other emails: kwesi.quagraine at ucc.edu.gh|kwesi.quagraine at teog.de|
Mobile: +233266173582
Skype: quagraine_cwasi
Twitter: @Pkdilly

[image: Inline image 1]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170103/5026e5a4/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kwesi.png
Type: image/png
Size: 56429 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170103/5026e5a4/attachment-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: climo123.pdf
Type: application/pdf
Size: 420185 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170103/5026e5a4/attachment-0001.pdf 


More information about the ncl-talk mailing list