In [1]:
from IPython.display import Image

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)

users list:

The goals of CliMAF are to provide the scientists with simplified and science-oriented means for :

  • accessing both model and references data
  • pre-tretament (period and geographical selections, regridding, averaging like seasonal mean computations...)
  • plotting maps, cross-sections and time series
  • building atlases
  • plugging personal scripts in an atlas or in an analysis workflow
  • sharing such scripts
  • handlling ensembles (multi-model, multi-realization) CliMAF provides full managment of the outputs by handling the naming of the output files; it also stores the information on "how I obtained this file" under the form of an expression called CRS (CliMAF Reference Syntax) that allows checking for the existing files and avoid recomputing the same files twice (or more).

Main operators and how to plug your script

How we:

  • compute a climatology
  • regrid a dataset
  • select a geographical region
  • use the CliMAF cdo swiss knife: ccdo()
  • plug your own operator: simple command line or script

You will find the complete list of CliMAF operators documented on this page:

This notebook is only a way to illustrate the ones we use most of the time

Use the "Quick search" function to see if an operator already exists for what you want to do! (example: try 'regrid' or 'climatology' in quick search tool)

First, import climaf

In [2]:
from climaf.api import *
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 : []

And set verbosity ('critical' -> minimum ; 'debug' -> maximum)

In [3]:
clog('critical') # min verbosity = critical < warning < info < debug = max verbosity

... and dont' forget to open the documentation in case you have questions.

-> Use the "Quick search" space to search for what you are interested in, it is really powerfull!

We use a CMIP5 simulation as toy dataset

ds() = searching for the data in a science-oriented logic

In [4]:
# -- We use ds() to get the dataset
dat_cmip5 = ds(project='CMIP5',
# -- summary() gives the list of files found by ds() and the pairs 'facets':'values' associated with the request
# -> The user can then refine the request to select only one file
{'domain': 'global',
 'experiment': 'historical',
 'frequency': 'monthly',
 'model': 'CNRM-CM5',
 'period': 1980-2000,
 'project': 'CMIP5',
 'realization': 'r1i1p1',
 'realm': '*',
 'root': '/bdd',
 'simulation': 'r1i1p1',
 'table': '*',
 'variable': 'tos',
 'version': 'latest'}
In [5]:
Help on function clim_average in module climaf.functions:

clim_average(dat, season)
    Computes climatological averages on the annual cycle of a dataset, on the months
    specified with 'season', either:
    - the annual mean climatology (season => 'ann','annual','climato','clim','climatology','annual_average','anm')
    - seasonal climatologies (e.g. season = 'DJF' or 'djf' to compute the seasonal climatology
      over December-January-February; available seasons: DJF, MAM, JJA, SON, JFM, JAS, JJAS
    - individual monthly climatologies (e.g. season = 'january', 'jan', '1' or 1 to get
      the climatological January)
    - annual maximum or minimum (typically makes sense with the mixed layer depth)
    Note that you can use upper case or lower case characters to specify the months or seasons.
    clim_average computes the annual cycle for you.
      >>> dat= ....   # some dataset, with whatever variable
      >>> climds_JFM = clim_average(dat,'JFM')         # The climatology of dat over January-February-March
      >>> climds_ANM = clim_average(dat,'annual_mean') # The annual mean climatology
      >>> climds_September = clim_average(dat,'September') # The annual mean climatology of September
      >>> climds_September = clim_average(dat,9) # Same as previous example, with a float

In [6]:
# -- Annual mean
annual_mean_dat_cmip5 = clim_average(dat_cmip5, 'ANM')

# -- DJF and JJA climatologies
djf_dat_cmip5 = clim_average(dat_cmip5, 'DJF')
jja_dat_cmip5 = clim_average(dat_cmip5, 'JJA')

# -- Climatology of March
march_dat_cmip5 = clim_average(dat_cmip5, 'March')

2. Regridding

In [8]:
ref = ds(project='ref_climatos',
{'clim_period': '195501-201212',
 'domain': 'global',
 'frequency': 'annual_cycle',
 'obs_type': 'observations',
 'period': fx,
 'product': 'WOA13-v2',
 'project': 'ref_climatos',
 'simulation': 'refproduct',
 'table': 'Omon',
 'variable': 'tos'}
In [9]:
rgrd_annual_mean_dat_cmip5 = regrid(annual_mean_dat_cmip5, ref)

Second method: regrid on standard regular cdogrid: regridn()

regridn() is based on cdo; you can specify the destination grid (cdogrid) and the regridding method (option='remapcon', 'remapbil'...)

In [10]:
Help on function regridn in module climaf.operators:

regridn(*args, **dic)
    regridn : regrid an object to a named grid
    Interpolate the object to another grid, using CDO
    **References** :
    **Provider / contact** : climaf at meteo dot fr
    **Inputs** (in the order of CliMAF call):
      - any dataset (but only one)
    **Mandatory arguments**:
      - ``cdogrid`` : target grid name, according to CDO standard 
    **Optional arguments**:
      - ``option`` : interpolation option (cf. CDO doc); default : 
        'remapbil' for bilinear interpolation
    **Output** : the interpolated object
    **Climaf call example** ::
      >>> ds= .... #some dataset, with whatever variable
      >>> remapbil_ds=regridn(ds,cdogrid="r180x90")  # Target Grid is 2°x2° - interpolation is bilinear
      >>> remapcon2_ds=regridn(ds,cdogrid="n127", option="remapcon2") # Target Grid is Gaussian - interpolation is 2nd order conservative
    **Side effects** : None
    **Implementation** : standard CDO calls (remapgrid)

In [11]:
# -- Standard = remapbil
rgrd_anm_dat_cmip5 = regridn(annual_mean_dat_cmip5, cdogrid='r360x180')
print cfile(rgrd_anm_dat_cmip5)

# -- First order conservative (cdo remapcon)
remapcon_rgrd_anm_dat_cmip5 = regridn(annual_mean_dat_cmip5, cdogrid='r360x180', option='remapcon')
print cfile(remapcon_rgrd_anm_dat_cmip5)

# -- Nearest neighbour
remapnn_rgrd_anm_dat_cmip5 = regridn(annual_mean_dat_cmip5, cdogrid='r360x180', option='remapnn')
print cfile(remapnn_rgrd_anm_dat_cmip5)
In [12]:
NAtl_anm_dat_cmip5 = llbox(rgrd_anm_dat_cmip5, lonmin=-80, lonmax=40, latmin=20, latmax=80)

4. Using the CliMAF CDO swiss knife: ccdo()

ccdo() is a very simple way to use any cdo operator, even piped operators, from CliMAF.

You can do A LOT of things with ccdo.

In [13]:
# -- Compute a climatological annual cycle using ymonavg
annual_cycle_dat_cmip5 = ccdo(dat_cmip5, operator='ymonavg')
# --> FYI: the annual_cycle operator already exists -> try in the quick search
In [14]:
# -- Pipe CDO operators: select a region on a regridded annual cycle
test = ccdo(dat_cmip5, operator='sellonlatbox,-80,40,20,80 -remapbil,r360x180 -ymonavg')

Check the CDO users guide to search for the operators that can be interesting for you:

You can plug any script, binary, command line to make it a CliMAF operator if:

  • you can write it in one command line
  • that takes an input netcdf file and an output netcdf file or figure as arguments
  • and optional arguments

Simple example with cdo timavg

In [15]:
cscript('ctimavg','cdo timavg ${in} ${out}')
CliMAF operator : ctimavg
In [16]:
my_clim = ctimavg(dat_cmip5)



Use ${ins} to stand for multiple input files:

Example with ncrcat: takes multiple files as argument and the last one as output/result file

In [17]:
cscript('cncrcat','ncrcat ${ins} ${out}')
CliMAF operator : cncrcat

And look at the documentation to see how to:

  • deal with ensembles => mmin
  • output figures

Check in ${CLIMAF}/climaf/ to see many examples on how to plug:

  • nco and cdo operators
  • ncl and python scripts

TBD: simple examples with simple scripts to focus on how to write your command line

This was Main_operators_and_how_to_plug_your_script!

-> go back to the other examples to see more on data access, how to work with ensembles, build an html page...

In [ ]: