In this example we work through the following steps:

  1. Import the cf package.
  2. Read a field from disk and find a summary of its contents.
  3. Take a latitute-longitude slice of the field.
  4. Import the cfplot package.
  5. Create a blockfill plot of the latitude-longitude slice.
  6. Read in a second field and find a summary of its contents.
  7. Check the cyclicity of the fields are set correctly.
  8. Regrid the first field to the grid of the second conservatively and find a summary of the resulting field's contents.
  9. Plot a latitute-longitude slice of the field.

1. Import the cf package.

In [1]:
import cf

2. Read a field from disk and find a summary of its contents.

In [2]:
f = cf.read('cru_ts3.22.2001.2010.pre.dat.nc')
f
Out[2]:
<CF Field: long_name:precipitation(long_name:time(120), long_name:latitude(360), long_name:longitude(720)) mm>
In [3]:
print f
long_name:precipitation field summary
-------------------------------------
Data           : long_name:precipitation(long_name:time(120), long_name:latitude(360), long_name:longitude(720)) mm
Axes           : long_name:time(120) = [2001-01-16 00:00:00, ..., 2010-12-16 00:00:00] gregorian
               : long_name:latitude(360) = [-89.75, ..., 89.75] degrees_north
               : long_name:longitude(720) = [-179.75, ..., 179.75] degrees_east

3. Take a latitute-longitude slice of the field.

In [4]:
g = f.subspace[0]
g
Out[4]:
<CF Field: long_name:precipitation(long_name:time(1), long_name:latitude(360), long_name:longitude(720)) mm>

4. Import the cfplot package.

In [5]:
%matplotlib inline

import cfplot as cfp

5. Create a blockfill plot of the latitude-longitude slice.

In [6]:
cfp.con(g, blockfill=True)
/home/charles/anaconda/lib/python2.7/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):

6. Read in a second field and find a summary of its contents.

In [7]:
g = cf.read('N96_DJF_precip_means.nc')
g
Out[7]:
<CF Field: long_name:TOTAL PRECIPITATION RATE     KG/M2/S(long_name:t(1), long_name:Surface(1), latitude(145), longitude(192)) mm/day>
In [8]:
print g
long_name:TOTAL PRECIPITATION RATE     KG/M2/S field summary
------------------------------------------------------------
Data           : long_name:TOTAL PRECIPITATION RATE     KG/M2/S(long_name:t(1), long_name:Surface(1), latitude(145), longitude(192)) mm/day
Cell methods   : long_name:t: mean
Axes           : long_name:t(1) = [1996-07-16 00:00:00] 360_day
               : long_name:Surface(1) = [0.0]
               : latitude(145) = [-90.0, ..., 90.0] degrees_north
               : longitude(192) = [0.0, ..., 358.125] degrees_east

7. Check the cyclicity of the fields are set correctly.

In [9]:
f.iscyclic('X')
Out[9]:
False
In [10]:
f.cyclic('X', period=cf.Data(360, 'degrees'))
f.iscyclic('X')
Out[10]:
True
In [11]:
g.iscyclic('X')
Out[11]:
False
In [12]:
g.cyclic('X', period=cf.Data(360, 'degrees'))
g.iscyclic('X')
Out[12]:
True

8. Regrid the first field to the grid of the second conservatively and find a summary of the resulting field's contents.

In [13]:
h = f.regrids(g)
h
Out[13]:
<CF Field: long_name:precipitation(long_name:time(120), latitude(145), longitude(192)) mm>
In [14]:
print h
long_name:precipitation field summary
-------------------------------------
Data           : long_name:precipitation(long_name:time(120), latitude(145), longitude(192)) mm
Axes           : long_name:time(120) = [2001-01-16 00:00:00, ..., 2010-12-16 00:00:00] gregorian
               : latitude(145) = [-90.0, ..., 90.0] degrees_north
               : longitude(192) = [0.0, ..., 358.125] degrees_east

9. Plot a latitute-longitude slice of the field.

In [15]:
cfp.con(h.subspace[0], blockfill=True)