cf.SpaceList

class cf.SpaceList(sequence=())

Bases: cf.space.VariableList

A modified list for spaces supporting element-wise slicing, 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.

Slicing the space list returns a new space list with each element sliced with its slice() method.

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

Overloaded operators

Refer to VariableList.

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.
slice() Slice list element-wise.
sort() As for a built-in list.

Examples

>>> type(s)
<class 'cf.space.SpaceList'>
>>> s
[<CF Space: pmsl(30, 24)>,
 <CF Space: temperature(17, 30, 24)>]
>>> s[slice(0,2)]
[<CF Space: pmsl(30, 24)>,
 <CF Space: temperature(17, 30, 24)>]
>>> s[0]
<CF Space: pmsl(30, 24)>
>>> type(s[0])
<class 'cf.space.Space'>
>>> s[0].units
'Pa'
>>> s[-1].units
'K'
>>> s.units
['Pa', 'K']   
>>> s.not_an_attribute
[None, None]   
>>> s.extract(units = 'K')
[<CF Space: temperature(17, 30, 24)>]
>>> s.slice(lon = le(355))
[<CF Space: pmsl(30, 2)>,
 <CF Space: temperature(17, 30, 2)>]
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.
slice(exact=False, **kwargs)

Return a new list of spaces in which each space element has been sliced according to conditions on coordinate data values. Refer to the cf.Space.slice() method.

A coordinate and the conditions on its data are specified with **kwargs parameters.

If a coordinate is not specified, then its dimension is returned unchanged in each space. A call with no parameters (kwargs={}) returns a deep copy of the list of spaces.

The order in which coordinates are given in the parameter list is irrelevant.

Unless the exact keyword is True, the coordinates identified in different space elements may vary. For example, the keyword ‘lon’ could identify the ‘longitude’ coordinate in one variable and ‘longwave’ in another.

Parameters:
  • exact (bool) – Optional. If True then the remaining keyword arguments given by **kwargs are assumed to be unambiguous exact matches for coordinate names, as opposed to an unambiguous abbreviations.
  • **kwargs

    Other keyword arguments giving slice criteria are passed as **kwargs to each of the list’s variables’ slice() methods. Refer to the cf.Space.slice() method.

Returns:

A space list.

Examples

>>> print s
Data            : pressure(latitude_30, longitude)
Cell methods    : time: mean
Dimensions      : time(1) -> 1960-01-16 00:00:00
                : latitude_30(30) -> -5.28 to 7.48 degrees_north
                : longitude(24) -> 354.28 to 364.4 degrees_east
Auxiliary coords:  
Data            : u_compnt_of_wind(hybrid_sigma_pressure, latitude_29, longitude)
Cell methods    : time: mean
Dimensions      : time(1) -> 1960-01-16 00:00:00
                : hybrid_sigma_pressure(19) -> 0.9970123 to 0.00460588 1
                : latitude_29(29) -> -5.06 to 7.26 degrees_north
                : longitude(24) -> 354.28 to 364.4 degrees_east
Auxiliary coords:
>>> s
[<CF Space: pressure(30, 24)>,
 <CF Space: u_compnt_of_wind(19, 29, 24)>,
>>> s.slice(long = ge(360))
[<CF Space: pressure(30, 11)>,
 <CF Space: u_compnt_of_wind(19, 29, 11)>]

Refer to the cf.Space.slice() method for more examples.

Previous topic

cf.Space

Next topic

cf.Transform

This Page