cf.VariableList

class cf.VariableList(sequence=())

Bases: cf.space.CfList

A modified list for variables (any object which is subclass of Variable, such as a space, coordinate, etc.) supporting element-wise attribute retrieval and subsetting by phenomena criteria.

When requesting a non-private attribute that the cf list does not have, and the _elements_atts attribute is True, instead of raising an AttributeError a cf list is returned containing the values of the attribute from each of the elements, with a value of None if an element does not have the attribute. The setting of an attribute is as usual, i.e. it is set on the object itself rather that the object’s elements.

Parameters:sequence (iterable) – Optional. Initialize new list from sequence’s items.

Overloaded operators

Refer to CfList.

Attributes

Refer to CfList.

Method Description
append() As for a built-in list.
copy() Create a deep copy.
count() As for a built-in list but using numerically tolerant equality.
dump() Return a string containing a full description of the each of the list’s elements.
equals() Determine whether two lists are congruent element-wise.
extend() As for a built-in list.
extract() Select list elements which match phenomena criteria.
index() As for a built-in list but using numerically tolerant equality.
insert() As for a built-in list.
pop() As for a built-in list.
properties() Return a set of writable, public attributes.
remove() As for a built-in list.
reverse() As for a built-in list.
sort() As for a built-in list.
copy()

Create a deep copy of the list. Equivalent to calling copy.deepcopy on the list.

Returns:A deep copy of the list.
count(value)
Returns:The number of occurrences of value using numerically tolerant equality.
dump(id=None, nc=False, omit=())

Return a string containing a full description of each variable in the list, utilizing each variable’s dump() method.

Parameters:
  • idOptional. Set the common prefix of variable component names. If None then defaults to the class name.
  • id – str
  • nc (bool) – Optional. If True then include attributes whose names begin “nc”.
  • omit (sequence) – Optional. Omit the given attributes from each variable’s the description.
Returns:

A string containing the descriptions of each variable in the list.

See also

cf.dump()

equals(other, rtol=None, atol=None, override=True)

Return True if two instances are congruent in that each pair of their elements are equal.

Equality of numbers is to within a tolerance. Refer to cf for details.

Parameters:
  • other (object) – The variable to compare against for equality.
  • atol (None or float) – Optional. If None then use the default method for setting the absolute tolerance for equality of real numbers (refer to cf for details). If a float then set the absolute tolerance to this value for all comparisons (refer to the override parameter).
  • override (bool) – Optional. If False then only use a float value of the rtol or atol parameters if it can not be set from attributes of the objects being compared.
  • rtol (None or float) – Optional. If None then use the default method for setting the relative tolerance for equality of real numbers (refer to cf for details). If a float then set the relative tolerance to this value for all comparisons (refer to the override parameter).
Returns:

True if the two objects are congruent, False otherwise.

extract(deep=False, exact=False, **kwargs)

Return a subset of a list of variables by selecting only the variables which match conditions on their phenomena.

A variable’s phenomena are its attributes and, if it has any, its size 1 coordinates.

A phenomenon and its conditions are specified with **kwargs parameters.

A variable in the list matches the conditions if and only if it contains all of the specified phenomena and they pass all of their given criteria. A variable always matches no criteria (kwargs={})

A match for a variable is determined by passing the criteria to the variable’s extract() method.

Unless the exact keyword is True, the phenomena identified in different variable elements may vary. For example, the keyword ‘unit’ could identify the ‘units’ phenomenon in one variable and ‘unitary’ in another.

By default, the returned list of variables is a shallow copy of part of the original list (in the same way that a standard slice is). To return a list whose elements are deep copies, set the deep parameter to True.

Parameters:
  • deep (bool) – Optional. If True then return deep copies of variables in the list.
  • exact (bool) – Optional. If True then the remaining keyword arguments given by **kwargs are assumed to be unambiguous exact matches for a phenomenon names, as opposed to an unambiguous abbreviations.
  • **kwargs

    Other keyword arguments giving any phenomena criteria are passed as **kwargs to the extract() method of each of the list’s variables. Refer to cf.Variable.extract().

Returns:

A list of variables

Examples

>>> s
[<CF Space: pressure(30, 24)>,
 <CF Space: u_compnt_of_wind(19, 29, 24)>
>>> s.units
['hPa', 'm s-1']
>>> s.extract(units = 'm s-1')
[<CF Space: u_compnt_of_wind(19, 29, 24)>]
>>> t = s.extract(uni = 'm\s*s-1')
>>> t
[<CF Space: u_compnt_of_wind(19, 29, 24)>]
>>> t[0] is s[1]
True
>>> t = s.extract(uni = 'm\s*s-1', deep=True)
>>> t[0] is s[1]
False

Refer to cf.Variable.extract() for more examples.

index(value, start=0, stop=None)
Returns:The first index of value using numerically tolerant equality. Restrict the search to the slice start:stop. If stop is None then the slice is :obj:`start:`cf.
insert(index, object)

L.insert(index, object) – insert object before index

properties(nc=False)

Return a set of writable, public attribute names, excluding methods.

An attribute created by assigning directly to the __dict__ dictionary (as opposed to using setattr()) will not appear in this set.

Parameters:nc (bool) – If False then exclude attributes whose names begin “nc”.
Returns:A set of attribute names.

Previous topic

cf.Variable

This Page