cf.FieldList

class cf.FieldList(sequence=())

Bases: cf.variablelist.VariableList

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

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

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

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

Initialization

Parameters :
sequence : iterable, optional

Define a new list with these elements.

coord(*args, **kwargs)

Apply the coord method to each element of the list.

Note that a coordinate list is returned (as opposed to a field list).

Parameters :
args, kwargs :

As for a field’s coord method.

Returns :

out : CoordinateList

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.

squeeze(*args, **kwargs)

Apply the squeeze method to each element of the list.

Parameters :
args, kwargs :

As for a field’s squeeze method.

Returns :

out : FieldList

unsqueeze(*args, **kwargs)

Apply the unsqueeze method to each element of the list.

Parameters :
args, kwargs :

As for a field’s unsqueeze method.

Returns :

out : FieldList

subset

Slice each field in the list, returning a new list of fields. Slicing by indices or by coordinate values are both allowed.

Examples

>>> fl
[<CF Variable: air_temperature(73, 96)>,
 <CF Variable: air_temperature(73, 96)>]
>>> fl.subset[0,0]
[<CF Variable: air_temperature(1,1)>,
 <CF Variable: air_temperature(1,1)>]
>>> fl.slice(longitude=0, latitude=0)
[<CF Variable: air_temperature(1,1)>,
 <CF Variable: air_temperature(1,1)>]

Previous topic

cf.CoordinateList

Next topic

cf.Partition

This Page