Skip to content

Commit

Permalink
Expose similar options to downstream run_checks (#443)
Browse files Browse the repository at this point in the history
* outer level tqdm over all files

* expose similar options to downstream run_checks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix upper level

* expose JSON encoder

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
CodyCBakerPhD and pre-commit-ci[bot] authored Apr 22, 2024
1 parent e6b4c2d commit 8499ef0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upcoming

### Improvements

* Exposed progress bar control to `inspect_all` and `run_checks` to allow compatibility with more generic visualizations of inspection progress related to the NWB GUIDED. [#443](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/443)

# v0.4.34

### Fixes
Expand Down
9 changes: 8 additions & 1 deletion src/nwbinspector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from .version import __version__
from .register_checks import available_checks, Importance
from .nwbinspector import inspect_all, inspect_nwbfile, inspect_nwbfile_object, run_checks, load_config
from .nwbinspector import (
InspectorOutputJSONEncoder,
inspect_all,
inspect_nwbfile,
inspect_nwbfile_object,
run_checks,
load_config,
)
from .nwbinspector import inspect_nwb # TODO: remove after 7/1/2023
from .checks.ecephys import *
from .checks.general import *
Expand Down
36 changes: 30 additions & 6 deletions src/nwbinspector/nwbinspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,10 @@ def inspect_nwbfile(
)

try:
nwbfile_object = robust_s3_read(command=io.read, max_retries=max_retries)
in_memory_nwbfile = robust_s3_read(command=io.read, max_retries=max_retries)

for inspector_message in inspect_nwbfile_object(
nwbfile_object=nwbfile_object,
nwbfile_object=in_memory_nwbfile,
checks=checks,
config=config,
ignore=ignore,
Expand Down Expand Up @@ -686,16 +687,39 @@ def inspect_nwbfile_object(
yield inspector_message


def run_checks(nwbfile: pynwb.NWBFile, checks: list):
def run_checks(
nwbfile: pynwb.NWBFile,
checks: list,
progress_bar_class: Optional[tqdm] = None,
progress_bar_options: Optional[dict] = None,
) -> Iterable[InspectorMessage]:
"""
Run checks on an open NWBFile object.
Parameters
----------
nwbfile : NWBFile
checks : list
nwbfile : pynwb.NWBFile
The in-memory pynwb.NWBFile object to run the checks on.
checks : list of check functions
The list of check functions that will be run on the in-memory pynwb.NWBFile object.
progress_bar_class : type of tqdm.tqdm, optional
The specific child class of tqdm.tqdm to use to make progress bars.
Defaults to not displaying progress per set of checks over an invidiual file.
progress_bar_options : dict, optional
Dictionary of keyword arguments to pass directly to the `progress_bar_class`.
Yields
------
results : a generator of InspectorMessage objects
A generator that returns a message on each iteration, if any are triggered by downstream conditions.
Otherwise, has length zero (if cast as `list`), or raises `StopIteration` (if explicitly calling `next`).
"""
for check_function in checks:
if progress_bar_class is not None:
check_progress = progress_bar_class(iterable=checks, total=len(checks), **progress_bar_options)
else:
check_progress = checks

for check_function in check_progress:
for nwbfile_object in nwbfile.objects.values():
if check_function.neurodata_type is None or issubclass(type(nwbfile_object), check_function.neurodata_type):
try:
Expand Down

0 comments on commit 8499ef0

Please sign in to comment.