.. currentmodule:: cf .. default-role:: obj .. _fs_field_list: Introduction to the `cf.FieldList` object ========================================= A `cf.FieldList` object is an ordered sequence of `cf.Field` objects. It supports nearly all of the :ref:`python list-like operations `, the exceptions being the arithmetic and comparison operators for which it has :ref:`its own definitions `. For example: >>> fl [, ] >>> fl[0] >>> fl[::-1] [, ] >>> fl[slice(1, -1, 2)] [] Note that an indexing by an integer returns an individual field, but other types of index always return a field list. >>> len(fl) 2 >>> f = fl.pop() >>> f >>> len(fl) 1 >>> fl.append(f) >>> len(fl) 2 >>> f in fl True >>> from operator import attrgetter >>> fl [, ] >>> fl.sort(key=attrgetter('standard_name')) [, ] Selecting fields ^^^^^^^^^^^^^^^^ One or more fields from a field list may be selected with the `~cf.FieldList.select` method. This returns a single field or a new field list, depending on how many fields are selected. For example. >>> fl [, ] >>> fl.select('air_temperature') ] >>> fl.select('[air_temperature|x_wind]') [, ] Using field methods ^^^^^^^^^^^^^^^^^^^ A subset of a field's callable methods are also available to a field list object (see the list of :ref:`field list methods `). In general, these are methods which, on a field, return a field or `None`. These methods are applied to each constituent field independently, so >>> gl = fl.max() >>> fl.max(i=True) is exactly equivalent to >>> gl = cf.FieldList([f.max() for f in fl]) >>> for f in fl: ... f.max(i=True) .. _fs-fl-a-and-c: Arithmetic and comparison ^^^^^^^^^^^^^^^^^^^^^^^^^ All of the :ref:`operators defined for a field ` are also allowed for field list, the operation applying to each field independently. For example the commands: >>> gl = fl + 2 >>> gl = 2 // fl >>> gl = fl == 0 >>> fl += 2 are exactly equivalent to: >>> gl = cf.FieldList(f + 2 for f in fl) >>> gl = cf.FieldList(2 // f for f in fl) >>> gl = cf.FieldList(f == 0 for f in fl) >>> for f in fl: ... f += 2