[ncl-talk] A simple climatology plot

Dennis Shea shea at ucar.edu
Wed Jan 4 08:23:17 MST 2017


[a] You are constantly over writing the variable 'prClm'

[b] you constantly repeat code such as:
      months = (/"January", "February", "March", "April" \
            ,"May", "June", "July", "Auguat"         \
            ,"September", "October", "November"      \
            ,"December" /)
    Why are you doing this redundant code?

[c]

---
[1]
Rather than:

   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

Use
; NCL imports all the meta data.
   fili    = "CCCma91-05.nc3"
   f       = addfile (diri+fili , "r")
   pr      = f->pr       ; (time,lat,lon)
   printVarSummary(pr)
   printMinMax(pr,0)

   pr     = pr*86400    ; change units after importing the varible
   pr at unit= "mm/day"
   printVarSummary(pr)
   printMinMax(pr,0)

   prClm_0  = clmMonTLL( pr)
   printVarSummary(prClm_0)
   printMinMax(prClm_0,0)

Do the same for the other files except name them: pr_clm_1 and prClm_2


[2] Looking at your printVarSummary, it is clear that that the data are on
a rectilinear grid.
The 'lat' and 'lon' are coordinate variables.

Coordinates:
            month: [0..11]
            lat: [-46.25..42.75]   <==== rectilinear
            lon: [-25.25..60.75]   <====     "

Hence, you do *NOT* need. Delete these lines

  res at sfXArray          = lon   ; Only necessary if x doesn't
  res at sfYArray          = lat   ; contain 1D coordinate arrays

[3]
nmo = 0   ; January
plot(0) = gsn_csm_contour_map_ce(wks,prClm_0(nmo,:,:), res)  ; create plot
plot(1) = gsn_csm_contour_map_ce(wks,prClm_1(nmo,:,:), res)  ; create plot
plot(2) = gsn_csm_contour_map_ce(wks,prClm_2(nmo,:,:), res)  ; create plot

[4]
Change:
gsn_panel(wks,plot,(/3,1/),resP)
To:
gsn_panel(wks,(/prClm_0,prClm_1,prClm_2/),(/3,1/),resP)
or
gsn_panel(wks,(/prClm_0,prClm_1,prClm_2/),(/1,3/),resP)

[5]
In the future please do not send scripts which contain many code lines
which are commented out. Please send 'clean' scripts only.

Good Luck


On Tue, Jan 3, 2017 at 9:11 AM, Kwesi Quagraine <starskykwesi at gmail.com>
wrote:

> 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 <+233%2026%20617%203582>
> Skype: quagraine_cwasi
> Twitter: @Pkdilly
>
> [image: Inline image 1]
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170104/3be28c8f/attachment.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/20170104/3be28c8f/attachment.png 


More information about the ncl-talk mailing list