[ncl-talk] A simple climatology plot

Kwesi Quagraine starskykwesi at gmail.com
Wed Jan 4 09:07:15 MST 2017


Hello Mary, thanks for the script it helped a lot. it works now.

Regards,
Kwesi

On Wed, Jan 4, 2017 at 5:46 PM, Mary Haley <haley at ucar.edu> wrote:

> Kwesi,
>
> In your code you have these lines:
>
>   ;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)
>
> It looks like you attempted to make multiple plots with your "do
> nmo=0,180" do loop, but then commented this code out and only created one
> plot with:
>
> plot = gsn_csm_contour_map_ce(wks,prClm(0,:,:), res)  ; create plot
>
> You then tried to panel this one plot using gsn_panel, but told it that
> you had three plots. So, NCL drew the one plot on the left, and left the
> other two slots blank because there are no plots to draw.
>
> You need to create three plots, using a unique name for each one, and plot
> the three different "prClm" arrays you created.
>
> I've attached a modified version of your script, that renames your prClm
> variables to unique names, so then you can plot with something like this:
>
> ;---Create three plots with three different titles
>   plot    = new(3,graphic)
>
>   res at tiMainString = "CCCma"
>   plot(0) = gsn_csm_contour_map_ce(wks,prClm_CCCma(0,:,:), res)
>
>   res at tiMainString = "Cnrm"
>   plot(1) = gsn_csm_contour_map_ce(wks,prClm_Cnrm(0,:,:), res)
>
>   res at tiMainString = "Ichec"
>   plot(2) = gsn_csm_contour_map_ce(wks,prClm_Ichec(0,:,:), res)
>
>   resP                     = True               ; panel options
>   resP at gsnMaximize         = True               ; maximize image
>   resP at gsnPanelLabelBar    = True               ; Add common label bar
>   resP at txString            = "Precipitation: Climatology"
>
>   gsn_panel(wks,plot,(/3,1/),resP)
>
> Note that I changed the titles such that each individual plot has its own
> title, and then I added a main title to the paneled plots using txString.
> You will likely want to change this to match whatever titles you want.
>
> Instead of using gsn_define_colormap to set the colors, I recommend using
> the cnFillPalette resource. This allows you to associate the colors
> directly with the levels. For example:
>
>   res at cnLevelSelectionMode = "ExplicitLevels"   ; set explicit contour
> levels
>   res at cnLevels             = (/ 2.5, 3.0, 3.5, 4.5, 5.5, 6.5, 7.5, 10.0 /)
>   res at cnFillPalette        = (/"azure1","beige","lavender","PaleGreen",\
>                               "SeaGreen3","LightYellow","Yellow","HotPink","Red"/)
>
>
>
>  However, there's an error you need to correct.  You specified 13 contour
> levels with:
>
>   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 /)
>
> but only 9 colors (I'm not counting white and black)
>
>   colors = (/"white","black"             \      ; back/fore ground
>
>
>             ,"azure1","beige","lavender" \
>             ,"PaleGreen","SeaGreen3","LightYellow" \
>             ,"Yellow","HotPink","Red"/)
>
> You need to specify one more color than you have levels, because the level
> values will represent the values *between* colors. I fixed this by
> reducing the levels to just 8 levels.  You will likely need to change this
> as desired.
>
>
> This script is UNTESTED of course, because I can't run it without the
> data.  You may need to fix any typos I introduced.
>
> --Mary
>
>
>
> 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
>>
>>
>


-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170104/54bb1236/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/54bb1236/attachment.png 


More information about the ncl-talk mailing list