Skip to content

Commit 5a2bda5

Browse files
Merge branch 'dev' into document_formatter
2 parents e5bf5a6 + eb50c44 commit 5a2bda5

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

nwbinspector/checks/images.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from hdmf.utils import get_data_shape
2+
3+
from pynwb.base import Images
4+
5+
from ..register_checks import register_check, Importance, InspectorMessage
6+
7+
8+
@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=Images)
9+
def check_order_of_images_unique(images: Images):
10+
if images.order_of_images is None:
11+
return
12+
if not len(set(images.order_of_images)) == len(images.order_of_images):
13+
return InspectorMessage(message="order_of_images should have unique values.")
14+
15+
16+
@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=Images)
17+
def check_order_of_images_len(images: Images):
18+
if images.order_of_images is None:
19+
return
20+
if not len(images.order_of_images) == len(images.images):
21+
return InspectorMessage(
22+
message=f"Length of order_of_images ({len(images.order_of_images)}) does not match the number of images ("
23+
f"{len(images.images)})."
24+
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
long_description = f.read()
66
setup(
77
name="nwbinspector",
8-
version="0.4.7",
8+
version="0.4.8",
99
description="Tool to inspect NWB files for best practices compliance.",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

tests/unit_tests/test_images.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import numpy as np
2+
3+
from pynwb.base import Images, ImageReferences
4+
from pynwb.image import GrayscaleImage
5+
6+
from nwbinspector import InspectorMessage, Importance
7+
from nwbinspector.checks.images import check_order_of_images_unique, check_order_of_images_len
8+
9+
10+
def test_check_order_of_images_unique():
11+
12+
imgs = [GrayscaleImage(name=f"image{i}", data=np.random.randn(10, 10)) for i in range(5)]
13+
img_refs = ImageReferences(name="order_of_images", data=imgs + [imgs[0]])
14+
images = Images(name="my_images", images=imgs, order_of_images=img_refs)
15+
16+
assert check_order_of_images_unique(images) == InspectorMessage(
17+
message="order_of_images should have unique values.",
18+
importance=Importance.BEST_PRACTICE_VIOLATION,
19+
check_function_name="check_order_of_images_unique",
20+
object_type="Images",
21+
object_name="my_images",
22+
location="/",
23+
)
24+
25+
26+
def test_pass_check_order_of_images_unique():
27+
28+
imgs = [GrayscaleImage(name=f"image{i}", data=np.random.randn(10, 10)) for i in range(5)]
29+
img_refs = ImageReferences(name="order_of_images", data=imgs)
30+
images = Images(name="my_images", images=imgs, order_of_images=img_refs)
31+
32+
assert check_order_of_images_unique(images) is None
33+
34+
35+
def test_check_order_of_images_len():
36+
37+
imgs = [GrayscaleImage(name=f"image{i}", data=np.random.randn(10, 10)) for i in range(5)]
38+
img_refs = ImageReferences(name="order_of_images", data=imgs + [imgs[0]])
39+
images = Images(name="my_images", images=imgs, order_of_images=img_refs)
40+
41+
assert check_order_of_images_len(images) == InspectorMessage(
42+
message=f"Length of order_of_images (6) does not match the number of images (5).",
43+
importance=Importance.BEST_PRACTICE_VIOLATION,
44+
check_function_name="check_order_of_images_len",
45+
object_type="Images",
46+
object_name="my_images",
47+
location="/",
48+
)
49+
50+
51+
def test_pass_check_order_of_images_len():
52+
53+
imgs = [GrayscaleImage(name=f"image{i}", data=np.random.randn(10, 10)) for i in range(5)]
54+
img_refs = ImageReferences(name="order_of_images", data=imgs)
55+
images = Images(name="my_images", images=imgs, order_of_images=img_refs)
56+
57+
assert check_order_of_images_len(images) is None

0 commit comments

Comments
 (0)