eumap.misc.nan_percentile

nan_percentile(arr, q=[25, 50, 75], keep_original_vals=False)[source]

Optimized function to calculate percentiles ignoring np.nan in a 3D Numpy array [1].

Parameters
  • arr (array) – 3D Numpy array where the first dimension is used to derive the percentiles.

  • q (List) – Percentiles values between 0 and 100.

  • keep_original_vals – If True it does a copy of arr to preserve the structure and values.

References

[1] Kersten’s blog

Examples

>>> import numpy as np
>>> from eumap.misc import nan_percentile
>>>
>>> data = np.random.rand(10, 10, 10)
>>> data[2:5,0:10,0] = np.nan
>>> data_perc = nan_percentile(data, q=[25, 50, 75])
>>> print(f'Shape: data={data.shape} data_perc={data_perc.shape}')