# second_derivative¶

metpy.calc.second_derivative(f, axis=None, x=None, delta=None)

Calculate the second derivative of a grid of values.

Works for both regularly-spaced data and grids with varying spacing.

Either x or delta must be specified, or f must be given as an `xarray.DataArray` with attached coordinate and projection information. If f is an `xarray.DataArray`, and x or delta are given, f will be converted to a `pint.Quantity` and the derivative returned as a `pint.Quantity`, otherwise, if neither x nor delta are given, the attached coordinate information belonging to axis will be used and the derivative will be returned as an `xarray.DataArray`

This uses 3 points to calculate the derivative, using forward or backward at the edges of the grid as appropriate, and centered elsewhere. The irregular spacing is handled explicitly, using the formulation as specified by [Bowen2005].

Parameters
• f (array-like) – Array of values of which to calculate the derivative

• axis (int or str, optional) – The array axis along which to take the derivative. If f is ndarray-like, must be an integer. If f is a DataArray, can be a string (referring to either the coordinate dimension name or the axis type) or integer (referring to axis number), unless using implicit conversion to `pint.Quantity`, in which case it must be an integer. Defaults to 0. For reference, the current standard axis types are ‘time’, ‘vertical’, ‘y’, and ‘x’.

• x (array-like, optional) – The coordinate values corresponding to the grid points in f

• delta (array-like, optional) – Spacing between the grid points in f. There should be one item less than the size of f along axis.

Returns

array-like – The second derivative calculated along the selected axis

Changed in version 1.0: Changed signature from `(f, **kwargs)`