In [1]:
from IPython.display import Image
Image(url='https://vesg.ipsl.upmc.fr/thredds/fileServer/IPSLFS/jservon/CliMAF_Notebooks_html/CliMAF-logo-small.png') 
Out[1]:

CliMAF: Climate Model Assessment Framework

A science-oriented framework to ease the analysis of climate model simulations

WP5 ANR Convergence
Development team: Stéphane Sénési (CNRM-GAME), Gaëlle Rigoudy (CNRM-GAME), Jérôme Servonnat (LSCE-IPSL), Ludivine Vignon (CNRM-GAME), Laurent Franchisteguy (CNRM-GAME), Patrick Brockmann (LSCE-IPSL)
Beta-testing: Olivier Marti (LSCE-IPSL), Marie-Pierre Moine (CERFACS), Emilia Sanchez-Gomez (CERFACS)

contact: climaf@meteo.fr
users list: climaf-users@meteo.fr

Getting started with plot()

    1. basic 2D map
    1. edit the titles
    1. change font sizes
    1. change color palette, isolines
    1. ocean view: choose the longitude in the middle of the plot
    1. use any ncl resource with 'options'
      • 6.1. Raster plot (with 'options')
    1. Polar Stereographic projections
    1. add the contours of an auxilliary file
    1. Vectors of a wind field
    1. add a pattern (like statistical significance)
    1. Plot a region on an ORCA grid: need to regrid first on a regular grid
    1. Zonal mean atmospheric plot
    1. Various fancy projections available with 'proj'
      • 13.1 the cool Satellite projection

Import climaf

In [2]:
from climaf.api import *
clog('critical') # min verbosity = critical < warning < info < debug = max verbosity
CliMAF version = 1.2.13
CliMAF install => /ciclad-home/jservon/Evaluation/CliMAF/climaf_installs/climaf_V1.2.13_post
python => /modfs/modtools-phw/miniconda2/envs/analyse_2.7/bin/python
---
Required softwares to run CliMAF => you are using the following versions/installations:
ncl 6.6.2 => /modfs/modtools-phw/miniconda2/envs/analyse_2.7/bin/ncl
cdo 1.9.6 => /opt/nco/1.9/bin/cdo
nco (ncks) 4.5.2 => /opt/nco-4.5.2/bin/ncks
ncdump fichier => /modfs/modtools-phw/miniconda2/envs/analyse_2.7/bin/ncdump
Check stamping requirements
nco (ncatted) found -> /opt/nco-4.5.2/bin/ncatted
convert found -> /usr/bin/convert
pdftk found -> /usr/bin/pdftk
exiv2 found -> /ciclad-home/jservon/Evaluation/CliMAF/climaf_installs/climaf_V1.2.13_post/bin/exiv2
---
Cache directory set to : /data/jservon/climafcache (use $CLIMAF_CACHE if set) 
Cache directory for remote data set to : /data/jservon/climafcache/remote_data (use $CLIMAF_REMOTE_CACHE if set) 
warning  : When defining temp_penalty : duplicate declaration for input #0
warning  : When defining cquantile : duplicate declaration for input #0
warning  : When defining cquantile : duplicate declaration for input #0
Available macros read from ~/.climaf.macros are : []

0. Get a dataset

In [3]:
dat = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='v20130101',
         period='1980-2005', variable='tos', realm='ocean' )
summary(dat)
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tos/tos_Omon_CNRM-CM5_historical_r1i1p1_198001-198912.nc
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tos/tos_Omon_CNRM-CM5_historical_r1i1p1_199001-199912.nc
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tos/tos_Omon_CNRM-CM5_historical_r1i1p1_200001-200512.nc
Out[3]:
{'domain': 'global',
 'experiment': 'historical',
 'frequency': 'monthly',
 'model': 'CNRM-CM5',
 'period': 1980-2005,
 'project': 'CMIP5',
 'realization': 'r1i1p1',
 'realm': 'ocean',
 'root': '/bdd',
 'simulation': '',
 'table': '*',
 'variable': 'tos',
 'version': 'v20130101'}

1. Basic plot

In [4]:
myplot = plot(time_average(dat))
iplot(myplot)
Out[4]:

2. Edit the titles

In [5]:
myplot = plot(time_average(dat),
              title='My CliMAF plot',
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model)
iplot(myplot)
Out[5]:

3. Change the font size

In [6]:
myplot = plot(time_average(dat),
              # -- Title
              title='My CliMAF plot',
                  tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
                  gsnStringFontHeightF=0.02, #default=0.012
              )
iplot(myplot)
Out[6]:

Size of the Axis labels, colorbar labels, the fonts: see http://climaf.readthedocs.org/en/dev/scripts/plot.html?highlight=plot

4. Change the colorpalette and the isolines

In [7]:
myplot = plot(time_average(dat),
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
                  # -- Colorpalette
                  color='WhViBlGrYeOrRe',
                  # -- Add contours
                  contours=1,
                  # -- Isolines
                  min=-1,max=30,delta=1,
                  # -- And add an offset to switch from K to degC
                  offset = -273.15
              )
iplot(myplot)
Out[7]:

5. Ocean view: put longitude 200°E in the center (mpCenterLonF=200), and shade the land with grey (focus='ocean')

In [8]:
myplot = plot(regridn(time_average(dat),cdogrid='r360x180'),
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
                  # -- Longitude in the middle of the plot
                  mpCenterLonF=200,
                  # -- Grey on lands
                  focus='ocean'
              )
iplot(myplot)
Out[8]:

6. options = how to use any ncl resource : options

In [9]:
myplot = plot(regridn(time_average(dat),cdogrid='r360x180'),
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
                  # -- OPTIONS
                  options='pmLabelBarWidthF=0.065'
                  #options='pmLabelBarWidthF=0.065|'+\
                  #        'pmLabelBarOrthogonalPosF=0.01|'+\
                  #        'lbLabelFontHeightF=0.01|'+\
                  #        'tmXBLabelFontHeightF=0.01|'+\
                  #        'tmYLLabelFontHeightF=0.01'
              )
iplot(myplot)
Out[9]:

6.1 Create a raster plot with options

In [10]:
myplot = plot(regridn(time_average(dat),cdogrid='r90x45'), # --> Interpolate to coarser grid to see the raster
              # -- Title
              title='Raster plot with CliMAF',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
                  # -- deactivate the contours
                  # contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
                  # -- Use OPTIONS for the argument of the Raster plot
                  options='cnFillMode=RasterFill|cnRasterSmoothingOn=False'
              )
iplot(myplot)
Out[10]:

7. Polar stereographic views

In [11]:
# --> Set proj to 'NH' or 'SH'; the two additionnal characters set the last latitude visible 

projNH = 'NH20'
myplotNH = plot(regridn(clim_average(dat,'ANM'),cdogrid='r360x180'),
              # -- Title
              title=projNH+' plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
                  # -- Northern Hemisphere projection
                  proj=projNH
              )

projSH = 'SH60'
myplotSH = plot(regridn(clim_average(dat,'ANM'),cdogrid='r360x180'),
              # -- Title
              title=projSH+' plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # or: colors='-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30'
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
                  # -- Northern Hemisphere projection
                  proj=projSH,
              )

iplot(cpage(fig_lines=[[myplotNH,myplotSH]]))
Out[11]:

8. Add the contours of an auxillary file

In [12]:
# -- Get an auxillary file
aux = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='v20130101',
         period='1980-2005', variable='sic')#, realm='ocean' )
summary(aux)
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/seaIce/OImon/r1i1p1/v20130101/sic/sic_OImon_CNRM-CM5_historical_r1i1p1_185001-200512.nc
Out[12]:
{'domain': 'global',
 'experiment': 'historical',
 'frequency': 'monthly',
 'model': 'CNRM-CM5',
 'period': 1980-2005,
 'project': 'CMIP5',
 'realization': 'r1i1p1',
 'realm': '*',
 'root': '/bdd',
 'simulation': '',
 'table': '*',
 'variable': 'sic',
 'version': 'v20130101'}
In [13]:
# --> Provide the auxillary field as a second argument
myplotNH = plot(time_average(dat),
                    # -- Auxillary field provided as a second argument
                    time_average(aux),
                    # -- Add contours
                    contours='1 5 10 15',
                    # -- Handle options on the auxillary field
                    aux_options='cnLineThicknessF=8|cnLineColor=Red',
              # -- Title
              title='SST + Sea Ice contours',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
              # -- Northern Hemisphere projection
              proj='NH50'
              )
iplot(myplotNH)
Out[13]:

9. Add the vectors of a wind field

In [14]:
tauu = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='v20130101',
          period='1980-2005', variable='tauuo')
tauv = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='v20130101',
          period='1980-2005', variable='tauvo')
summary(tauv)
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tauvo/tauvo_Omon_CNRM-CM5_historical_r1i1p1_198001-198912.nc
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tauvo/tauvo_Omon_CNRM-CM5_historical_r1i1p1_199001-199912.nc
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tauvo/tauvo_Omon_CNRM-CM5_historical_r1i1p1_200001-200512.nc
Out[14]:
{'domain': 'global',
 'experiment': 'historical',
 'frequency': 'monthly',
 'model': 'CNRM-CM5',
 'period': 1980-2005,
 'project': 'CMIP5',
 'realization': 'r1i1p1',
 'realm': '*',
 'root': '/bdd',
 'simulation': '',
 'table': '*',
 'variable': 'tauvo',
 'version': 'v20130101'}
In [15]:
myplot = plot(regridn(time_average(dat),cdogrid='r360x180'),
                  # -- Specific to the plot of wind vectors:
                  None,
                  time_average(tauu),time_average(tauv),
                  vcRefLengthF=0.005, vcRefMagnitudeF=0.03,vcMinDistanceF=0.01,vcLineArrowColor='White',
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean'
              )
iplot(myplot)
Out[15]:

10. Add a pattern

In [16]:
myplot = plot(regridn(time_average(dat),cdogrid='r360x180'),
                  # -- Pattern
                  regridn(time_average(dat),cdogrid='r360x180'),
                  shade_above = 298,
                  #shade_below = 5,
                  #offset_aux = -273.15,
                  #shading_options='gsnShadeHigh=6',
                  # https://www.ncl.ucar.edu/Document/Graphics/Images/fillpatterns.png
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              #contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean'
              )
iplot(myplot)
Out[16]:

11. Plot a region on an ORCA grid: need to regrid first on a regular grid!

In [17]:
rgrd_dat = regridn(time_average(dat),cdogrid='r360x180')
myplot = plot(llbox(rgrd_dat,lonmin=-90,lonmax=20,latmin=0,latmax=90), title='North Atlantic')

iplot(myplot)
Out[17]:

12. Zonal mean atmospheric field

In [18]:
# -- A zonal field
## Add the contours of an auxillary file
ua_dat = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='latest',
            period='1980-2005', variable='ua')#, realm='ocean' )
summary(ua_dat)
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/atmos/Amon/r1i1p1/latest/ua/ua_Amon_CNRM-CM5_historical_r1i1p1_195001-200512.nc
Out[18]:
{'domain': 'global',
 'experiment': 'historical',
 'frequency': 'monthly',
 'model': 'CNRM-CM5',
 'period': 1980-2005,
 'project': 'CMIP5',
 'realization': 'r1i1p1',
 'realm': '*',
 'root': '/bdd',
 'simulation': '',
 'table': '*',
 'variable': 'ua',
 'version': 'latest'}
In [19]:
zonmean_plot = plot(zonmean(clim_average(ua_dat,'ANM')),title='Zonal Wind Speed',contours=1,y='lin')
iplot(zonmean_plot)
Out[19]:

13. Various fancy projections available with proj

see all projections here: https://www.ncl.ucar.edu/Document/Graphics/map_projections.shtml

In [20]:
pp = dict(gsnLeftString=dat.variable,
          gsnCenterString=dat.period,
          gsnRightString=dat.model)

proj = 'CylindricalEqualArea'
p1 = plot(time_average(dat), title=proj, proj=proj, **pp)
proj = 'Robinson'
p2 = plot(time_average(dat), title=proj, proj=proj, **pp)
proj = 'Mollweide'
p3 = plot(time_average(dat), title=proj, proj=proj, **pp)
proj = 'Orthographic'
p4 = plot(time_average(dat), title=proj, proj=proj, **pp)

iplot(cpage(fig_lines = [[p1,p2],[p3,p4]]))
Out[20]:

13.1 : Satellite projection

In [21]:
pp = dict(gsnLeftString=dat.variable,
          gsnCenterString=dat.period,
          gsnRightString=dat.model,
)

p1 = plot(time_average(dat), proj='Satellite',
              title='mpSatelliteDistF=3.0',
              options='mpCenterLonF=-40.|mpCenterLatF=45.|mpSatelliteDistF=3.0',
          **pp
          )
p2 = plot(time_average(dat), proj='Satellite',
              title='mpSatelliteDistF=2.0',
              options='mpCenterLonF=-40.|mpCenterLatF=45.|mpSatelliteDistF=2.0',
          **pp
          )
p3 = plot(time_average(dat), proj='Satellite',
              title='mpSatelliteDistF=5.0',
              options='mpCenterLonF=-40.|mpCenterLatF=45.|mpSatelliteDistF=5.0',
          **pp
          )
p4 = plot(time_average(dat), proj='Satellite',
              title='mpCenterLonF=130.|mpCenterLatF=-25.',
              options='mpCenterLonF=130.|mpCenterLatF=-25.|mpSatelliteDistF=3.0',
          **pp
          )
p5 = plot(time_average(dat), proj='Satellite',
              title='mpCenterLonF=295.|mpCenterLatF=-10.',
              options='mpCenterLonF=295.|mpCenterLatF=-10.|mpSatelliteDistF=3.0',
          **pp
          )


iplot(cpage(fig_lines=[[p1,p2,p3],[p4,p5,None]]))
Out[21]:
In [ ]: