From c23b71a3be9909e244219dbfe0aa93b9fe5d3767 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Mon, 18 Sep 2023 09:45:38 +0200 Subject: [PATCH] add check function --- src/nwbinspector/checks/nwb_containers.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/nwbinspector/checks/nwb_containers.py b/src/nwbinspector/checks/nwb_containers.py index d6e8af64b..ca9b0405b 100644 --- a/src/nwbinspector/checks/nwb_containers.py +++ b/src/nwbinspector/checks/nwb_containers.py @@ -3,8 +3,8 @@ import h5py from pynwb import NWBContainer - - +from hdmf.utils import get_data_shape +from numpy import ndarray from ..register_checks import register_check, Importance, InspectorMessage, Severity @@ -28,6 +28,25 @@ def check_large_dataset_compression(nwb_container: NWBContainer, gb_lower_bound: ) +@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=NWBContainer) +def check_dataset_is_empty(nwb_container: NWBContainer): + + def is_empty_data(data): + if isinstance(data, ndarray): + return data.size == 0 + elif isinstance(data, (list, tuple)): + return all(is_empty_data(item) for item in data) + else: + return not bool(data) + + if hasattr(nwb_container, "data"): + data = getattr(nwb_container, "data") + if is_empty_data(data): + return InspectorMessage( + message="Data object is empty. Please check the dataset before conversion" + ) + + @register_check(importance=Importance.BEST_PRACTICE_SUGGESTION, neurodata_type=NWBContainer) def check_small_dataset_compression( nwb_container: NWBContainer,