verde.maxabs

Contents

verde.maxabs#

verde.maxabs(*args, nan=True)[source]#

Calculate the maximum absolute value of the given array(s).

Use this to set the limits of your colorbars and center them on zero.

Parameters:
args

One or more arrays. If more than one are given, a single maximum will be calculated across all arrays.

nanbool

If True, will use the NaN compatible version of the numpy functions, which ignore NaNs in the arrays. Otherwise, any NaNs will result in the return value being also a NaN.

Returns:
maxabsfloat

The maximum absolute value across all arrays.

Examples

>>> result = maxabs((1, -10, 25, 2, 3))
>>> float(result)
25.0
>>> result = maxabs(
...     (1, -10.5, 25, 2), (0.1, 100, -500), (-200, -300, -0.1, -499)
... )
>>> float(result)
500.0

If the array contains NaNs, we’ll use the nan version of of the numpy functions by default. You can turn this off through the nan argument.

>>> import numpy as np
>>> result = maxabs((1, -10, 25, 2, 3, np.nan))
>>> float(result)
25.0
>>> result = maxabs((1, -10, 25, 2, 3, np.nan), nan=False)
>>> float(result)
nan