Skip to content

Instantly share code, notes, and snippets.

@emmanuelle
Last active April 16, 2019 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save emmanuelle/1964c4a81fabebd41173d75ff1e26018 to your computer and use it in GitHub Desktop.
Save emmanuelle/1964c4a81fabebd41173d75ff1e26018 to your computer and use it in GitHub Desktop.
Inspect which functions of scikit-image are compatible with 3-D arrays.
import numpy as np
import inspect
from skimage import exposure, feature, filters, measure, morphology, \
restoration, segmentation, transform, util
def only_one_nondefault(args):
"""
Returns True if the function has only one non-keyword parameter,
False otherwise.
"""
defaults = 0 if args.defaults is None else len(args.defaults)
if len(args.args) >= 1 and (len(args.args) - defaults <= 1):
return True
else:
return False
test_3d_float = np.ones((20, 20, 10))
test_3d_float[:5, :5, :5] = 0.
test_3d_int = np.ones((20, 20, 10), dtype=np.uint8)
test_3d_int[:5, :5, :5] = 0
compatible_3d = []
not_3d = []
several_arguments = []
functions = []
for submodule in [exposure, feature, filters, measure, morphology,
restoration, segmentation, transform, util]:
functions += inspect.getmembers(submodule, inspect.isfunction)
for function in functions:
args = inspect.getargspec(function[1])
only_one_argument = only_one_nondefault(args)
if only_one_argument:
try:
function[1](test_3d_float)
compatible_3d.append(function[0])
except ValueError:
not_3d.append(function[0])
except TypeError:
try:
function[1](test_3d_int)
compatible_3d.append(function[0])
except ValueError:
not_3d.append(function[0])
except:
compatible_3d.append(function[0])
except:
compatible_3d.append(function[0])
else:
several_arguments.append(function[0])
print("total number of functions: ", len(functions))
print("number of functions with several arguments: ", len(several_arguments))
print("number of functions compatible with 3-D arrays: ", len(compatible_3d))
print("number of functions not compatible with 3-D arrays: ", len(not_3d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment