cf.CellMethods

class cf.CellMethods(string=None)

Bases: cf.utils.CfList

A CF cell methods object to describe the characteristic of a field that is represented by cell values.

Each cell method is stored in a dictionary and these dictionaries are stored in a list-like object. Similarly to a CF cell_methods string, the order of cell methods in the list is important.

The dictionary representing each cell method recognizes the following keys (where all keys are optional; the referenced sections are from the NetCDF Climate and Forecast (CF) Metadata Conventions and words in double quotes (”...”) refer to CF cell_methods components in the referenced sections):

Key Value
method A “method” component. Refer to section 7.3.
name

A list of all of the “name” components involved with the “method” component. Each element is either:

  • The standard_name of the cell method’s dimension
  • The string ‘area’
  • A netCDF variable name or netCDF dimension name

The last option only occurs if the cell method’s dimension either has no dimension coordinate or has a dimension coordinate with no standard_name.

This is a deviation from the “name” components as described in sections 7.3, 7.3.1 and 7.3.4, in that standard_names are stored whenever possible, rather than only in the special cases described in section 7.3.4. Inspection of the ‘no_coords’ list retains the information required to fully interpret the cell method.

dim A list of space dimension names corresponding to the ‘name’ list. A ‘name’ list value of ‘area’ always corresponds to a ‘dim’ list value of None.
no_coords A list of booleans, corresponding to the ‘name’ list, indicating whether or not a particular cell method is relevant to the data in a way which may not be precisely defined by the corresponding dimension or dimensions. Refer to section 7.3.4.
interval A list of Data objects giving “interval” component values, with their associated units, corresponding to the ‘name’ list. Refer to section 7.3.2.
comment A “comment” or non-standardised information, component. Refer to sections 7.3.2 and 7.4
within A “within” climatology component. Refer to section 7.4.
over An “over” cell portion or “over” climatology component. Refer to sections 7.3.3 and 7.4.
where A “where” component. Refer to section 7.3.3.

Note that the above table assumes that the cell methods have been constructed in the context of a field, the only way in which the ‘dim’ and ‘no_coords’ keys may take sensible values. If this is not the case, then elements of the ‘dim’ key default to False and elements of the ‘no_coords’ key default to None.

Examples

>>> c = cf.CellMethods('time: minimum within years time: mean over years (ENSO years)')
>>> print c
Cell methods    : time: minimum within years
                  time: mean over years (ENSO years)
>>> list(c)
[
 {'method'   : 'minimum',
  'name'     : ['time'],     
  'dim'      : [False],
  'no_coords': [None], 
  'within'   : 'years'
 },
 {'method'   : 'mean'
  'name'     : ['time'],
  'dim'      : [False], 
  'no_coords': [None],     
  'comment'  : 'ENSO years', 
  'over'     : 'years'
 }
]
>>> c = c.CellMethods('lat: lon: standard_deviation')
>>> list(c)
[
 {'dim'      : [False, False],
  'method'   : 'standard_deviation'
  'name'     : ['lat', 'lon'],
  'no_coords': [None, None],
 }
]

Initialization

Parameters :
string : str, optional

Initialize new instance from a CF-netCDF-like cell methods string. See the parse method for details. By default an empty cell methods is created.

Examples

>>> c = CellMethods()
>>> c = CellMethods('time: mean')
copy()

Return a deep copy.

Equivalent to copy.deepcopy(s).

Returns :
out :

The deep copy.

Examples

>>> s.copy()
count(value)

Return the number of occurrences of a given value.

Parameters :
value :

The value to count.

Returns :
out : int

The number of occurrences of value.

Examples

>>> s
[1, 2, 3, 2, 4, 2]
>>> s.count(1)
1
>>> s.count(2)
3
dump(id=None)

Return a string containing a full description of the instance.

If a cell methods ‘name’ is followed by a ‘*’ then that cell method is relevant to the data in a way which may not be precisely defined its corresponding dimension or dimensions.

Parameters :
id : str, optional

Set the common prefix of component names. By default the instance’s class name is used.

Returns :
out : str

A string containing the description.

Examples

>>> x = c.dump()
>>> print c.dump()
>>> print c.dump(id='cellmethods1')
equals(other, rtol=None, atol=None, traceback=False)

True if two cell methods are logically equal, False otherwise.

Keys ‘dim’ and ‘no_coords’ are ignored in the comparison.

Parameters :
other :

The object to compare for equality.

atol : float, optional

The absolute tolerance for all numerical comparisons, By default the value returned by the ATOL function is used.

rtol : float, optional

The relative tolerance for all numerical comparisons, By default the value returned by the RTOL function is used.

traceback : bool, optional

If True then print a traceback highlighting where the two instances differ.

Returns :
out : bool

Whether or not the two instances are equal.

Examples

has_cellmethods(other)

Return True if and only if this cell methods is a super set of another.

Parameters :
other : CellMethods

The other cell methods for comparison.

Returns :
out : bool

Whether or not this cell methods is a super set of the other.

Examples

>>> c = cf.CellMethods('time: mean height: mean area: mean')
>>> d = cf.CellMethods('area: mean time: mean')
>>> c.has_cellmethods(d)
True
index(value, start=0, stop=None)

Return the first index of a given value.

Parameters :

value :

start : int, optional

stop : int, optional

Returns :

out : int

Raises :
ValueError :

If the given value is not in the list.

Examples

>>> s
[1, 2, 3, 2, 4, 2]
>>> s.index(1)
1
>>> s.index(2, start=2)
3
>>> s.index(2, start=2, stop=4)
3
insert(index, object)

Insert an object before the given index in place.

Parameters :

index : int

object :

Returns :

None

Examples

>>> s
[1, 2, 3]
>>> s.insert(1, 'A')
>>> s
[1, 'A', 2, 3]
netCDF_translation(field)

Translate netCDF variable names.

Parameters :

field : Field

The field which provides the translation.

Returns :
out : CellMethods

A new cell methods instance with translated names.

Examples

>>> c = CellMethods('time: mean lon: mean')
>>> d = c.netCDF_translation(f)
parse(string=None)

Parse a CF cell_methods string into this CellMethods instance in place.

Parameters :
string : str, optional

The CF cell_methods string to be parsed into the CellMethods object. By default the cell methods will be empty.

Returns :

None

Examples

>>> c = cf.CellMethods()
>>> c = c.parse('time: minimum within years time: mean over years (ENSO years)')    
>>> print c
Cell methods    : time: minimum within years
                  time: mean over years (ENSO years)
strings()

Return a list of a CF-netCDF-like string of each cell method.

Note that if the intention is to concatenate the output list into a string for creating a netCDF(CF) cell_methods attribute, then the cell methods “name” components may need to be modified, where appropriate, to reflect netCDF variable names.

Returns :
out : list

A string for each cell method.

Examples

>>> c = cf.CellMethods('time: minimum within years time: mean over years (ENSO years)')
>>> c.strings()
['time: minimum within years',
 'time: mean over years (ENSO years)']

Previous topic

cf.CellMeasures

Next topic

cf.Coordinate

This Page