From 64206a26d40ae1d1aaf0787e565e005f5ad8c64c Mon Sep 17 00:00:00 2001 From: Andriy Date: Tue, 23 May 2023 15:59:08 -0400 Subject: [PATCH] fixed a bug in README, added argument type check in featurize() --- README.md | 34 ++++++++++++++++------------------ src/nyx/python/nyxus/nyxus.py | 15 +++++++++++---- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 3e7db3d0..f7538ad5 100644 --- a/README.md +++ b/README.md @@ -77,33 +77,31 @@ or a pair of 3D arrays containing 2D intensity and mask images. There is also tw from nyxus import Nyxus import numpy as np - nyx = Nyxus(["*ALL*"]) -intens = [ +intens = np.array([ [[1, 4, 4, 1, 1], - [1, 4, 6, 1, 1], - [4, 1, 6, 4, 1], - [4, 4, 6, 4, 1]], + [1, 4, 6, 1, 1], + [4, 1, 6, 4, 1], + [4, 4, 6, 4, 1]], [[1, 4, 4, 1, 1], - [1, 1, 6, 1, 1], - [1, 1, 3, 1, 1], - [4, 4, 6, 1, 1]] -] + [1, 1, 6, 1, 1], + [1, 1, 3, 1, 1], + [4, 4, 6, 1, 1]] +]) -seg = [ +seg = np.array([ [[1, 1, 1, 1, 1], - [1, 1, 1, 1, 1], - [1, 1, 1, 1, 1], - [1, 1, 1, 1, 1]], + [1, 1, 1, 1, 1], + [1, 1, 1, 1, 1], + [1, 1, 1, 1, 1]], [[1, 1, 1, 1, 1], - [1, 1, 1, 1, 1], - [0, 1, 1, 1, 1], - [1, 1, 1, 1, 1]] -] - + [1, 1, 1, 1, 1], + [0, 1, 1, 1, 1], + [1, 1, 1, 1, 1]] +]) features = nyx.featurize(intens, seg) ``` diff --git a/src/nyx/python/nyxus/nyxus.py b/src/nyx/python/nyxus/nyxus.py index 913a4487..8f6d1832 100644 --- a/src/nyx/python/nyxus/nyxus.py +++ b/src/nyx/python/nyxus/nyxus.py @@ -203,8 +203,8 @@ def featurize_directory( def featurize( self, - intensity_images: np.array, - label_images: np.array, + intensity_images: np.ndarray, + label_images: np.ndarray, intensity_names: list = [], label_names: list = [] ): @@ -218,9 +218,9 @@ def featurize( Parameters ---------- - intensity_dir : np.array + intensity_images : np.ndarray 2D image or 3D collection of intensity images. - label_images : np.array + label_images : np.ndarray 2D image or 3D collection of label images. intensity_names (optional): list names for the images in for the DataFrame output. @@ -234,6 +234,13 @@ def featurize( per image. """ + # verify argument types + if not isinstance(intensity_images, np.ndarray): + raise ValueError("intensity_images parameter must be numpy.ndarray") + + if not isinstance(label_images, np.ndarray): + raise ValueError("label_images parameter must be numpy.ndarray") + # verify dimensions of images are the same if(intensity_images.ndim == 2): if(label_images.ndim != 2):