cf.Field.derivative¶
-
Field.
derivative
(axis, wrap=None, one_sided_at_boundary=False, cyclic=None, ignore_coordinate_units=False, inplace=False, i=False)[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 byf.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.
- ignore_coordinate_units:
bool
, optional If True then the coordinates providing the cell spacings along the specified axis are assumed to be dimensionless, even if they do in fact have units. This does not change the magnitude of the returned numerical values, but the units of the returned field construct will be identical to the original units.
If False (the default) then the coordinate units will propagate through to the result. i.e. the units of the returned field construct will be the original units divided by the coordinate units.
For example, for a field construct with units of
m.s-1
and X coordinate units ofradians
, the units of the X derivative will bem.s-1.radians-1
by default, orm.s-1
if ignore_coordinate_units is True.New in version 3.16.3.
- 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
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.]]