ignore_warnings#

ignore_warnings(warning=<class 'RuntimeWarning'>)[source]#

Decorator for catching warnings. Useful in pore-scale models where nans are inevitable, and numpy gets annoying by throwing lots of RuntimeWarnings.

Parameters:

warning (Warning) – Python warning type that you want to temporarily ignore

Examples

>>> from openpnm.utils import ignore_warnings
>>> @ignore_warnings()
... def myfun(x):
...     return 1/x
>>> import numpy as np
>>> x = np.arange(5)
>>> myfun(x)
array([       inf, 1.        , 0.5       , 0.33333333, 0.25      ])