cf.Field.derivative

Field.derivative(axis, wrap=None, one_sided_at_boundary=False, inplace=False, i=False, cyclic=None)[source]

Calculate the derivative along the specified axis.

The derivative is calculated using centred finite differences apart from at the boundaries (see the one_sided_at_boundary parameter). If missing values are present then missing values will be returned at all points where a centred finite difference could not be calculated.

Parameters
axis:

The axis, defined by that which would be selected by passing the given axis description to a call of the field construct’s domain_axis method. For example, for a value of 'X', the domain axis construct returned by f.domain_axis('X') is selected.

wrap: bool, optional

Whether the axis is cyclic or not. By default wrap is set to the result of this call to the field construct’s iscyclic method: f.iscyclic(axis). If the axis is cyclic then centred differences at one boundary will always use values from the other boundary, regardless of the setting of one_sided_at_boundary.

one_sided_at_boundary: bool, optional

If True, and the field is not cyclic or wrap is True, then one-sided finite differences are calculated at the non-cyclic boundaries. By default missing values are set at non-cyclic boundaries.

inplace: bool, optional

If True then do the operation in-place and return None.

i: deprecated at version 3.0.0

Use the inplace parameter instead.

Returns
Field or None

The derivative of the field along the specified axis, or None if the operation was in-place.

Examples

>>> f = cf.example_field(0)
>>> print(f.dimension_coordinate('X').array)
[ 22.5  67.5 112.5 157.5 202.5 247.5 292.5 337.5]
>>> print(f.dimension_coordinate('X').cellsize.array)
[45. 45. 45. 45. 45. 45. 45. 45.]
>>> f[...] = [45, 90, 135, 180, 225, 270, 315, 360]
>>> f.iscyclic('X')
True
>>> print(f.array)
[[ 45.  90. 135. 180. 225. 270. 315. 360.]
 [ 45.  90. 135. 180. 225. 270. 315. 360.]
 [ 45.  90. 135. 180. 225. 270. 315. 360.]
 [ 45.  90. 135. 180. 225. 270. 315. 360.]
 [ 45.  90. 135. 180. 225. 270. 315. 360.]]
>>> print(f.derivative('X').array)
[[-3.  1.  1.  1.  1.  1.  1. -3.]
 [-3.  1.  1.  1.  1.  1.  1. -3.]
 [-3.  1.  1.  1.  1.  1.  1. -3.]
 [-3.  1.  1.  1.  1.  1.  1. -3.]
 [-3.  1.  1.  1.  1.  1.  1. -3.]]
>>> print(f.derivative('X', wrap=False).array)
[[-- 1.0 1.0 1.0 1.0 1.0 1.0 --]
 [-- 1.0 1.0 1.0 1.0 1.0 1.0 --]
 [-- 1.0 1.0 1.0 1.0 1.0 1.0 --]
 [-- 1.0 1.0 1.0 1.0 1.0 1.0 --]
 [-- 1.0 1.0 1.0 1.0 1.0 1.0 --]]
>>> print(
...   f.derivative('X', wrap=False, one_sided_at_boundary=True).array
... )
[[1. 1. 1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1. 1. 1.]]