cf.VariableList

class cf.VariableList(sequence=())

Bases: cf.utils.CfList

An ordered sequence of variables stored in a list-like object.

In some contexts, whether an object is a variable or a variable list is not known and does not matter. So to avoid ungainly type testing, some aspects of the VariableList interface are shared by a variable and vice versa.

Any attribute or method belonging to a variable may be used on a variable list and will be applied independently to each element.

Just as it is straight forward to iterate over the variables in a variable list, a variable will behave like a single element variable list in iterative and indexing contexts.

Initialization

Parameters :
sequence : iterable, optional

Define a new list with these elements.

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
delattr(attr)

Delete a public attribute from each element of the list of variables.

dump(*arg, **kwargs)

Return a string containing the full descriptions of each variable in the list.

equals(other, rtol=None, atol=None, traceback=False)

True if two instances are logically equal, False otherwise.

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.

extract(*args, **kwargs)

Return the elements which match the given conditions.

The match conditions are passed to each element’s match method in turn.

Parameters :
args, kwargs :

As for the variable’s match method.

Returns :
out :

A new list containing the matching elements.

Examples

>>> f
[<>
 <>]
>>> f.extract(attr={'standard_name': 'air_temperature'})
[<>]
getattr(*args)

Return a built-in list of the public attributes of each element of the list of variables.

hasattr(*args)

Return a built-in list of the public attributes of each element of the list of variables.

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]
match(*args, **kwargs)

Return a list of booleans showing which elements match the given conditions.

The match conditions are passed to each element’s match method in turn.

Parameters :
args, kwargs :

As for the variable’s match method.

Returns :
out : list

A built-in list of booleans showing which elements match the conditions.

Examples

>>> f
[<>
 <>]
>>> f.match(attr={'standard_name': 'air_temperature'})
[True, False]
name(*arg, **kwargs)

Return a built-in list of the names of each element of the list of variables.

setattr(attr, value)

Set a public attribute from each element of the list of variables.

subset

Subset each variable in the list, returning a new list of variables.

Examples

>>> vl
[<CF Variable: air_temperature(73, 96)>,
 <CF Variable: air_temperature(73, 96)>]
>>> vl.subset[0,0]
[<CF Variable: air_temperature(1,1)>,
 <CF Variable: air_temperature(1,1)>]

Previous topic

cf.Variable

Next topic

Constants

This Page