Skip to content

Commit c8415cb

Browse files
Merge branch 'dev' into auto_publish_action
2 parents c335b1f + 609226a commit c8415cb

File tree

2 files changed

+47
-27
lines changed

2 files changed

+47
-27
lines changed

nwbinspector/checks/nwbfile_metadata.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import re
33

44
from pynwb import NWBFile
5-
from pynwb.file import Subject
5+
from pynwb.file import Subject, ProcessingModule
66

77
from ..register_checks import register_check, InspectorMessage, Importance
88

99
duration_regex = r"^P(?!$)(\d+(?:\.\d+)?Y)?(\d+(?:\.\d+)?M)?(\d+(?:\.\d+)?W)?(\d+(?:\.\d+)?D)?(T(?=\d)(\d+(?:\.\d+)?H)?(\d+(?:\.\d+)?M)?(\d+(?:\.\d+)?S)?)?$"
1010
species_regex = r"[A-Z][a-z]* [a-z]+"
1111

12+
PROCESSING_MODULE_CONFIG = ["ophys", "ecephys", "icephys", "behavior", "misc", "ogen", "retinotopy"]
13+
1214

1315
@register_check(importance=Importance.BEST_PRACTICE_SUGGESTION, neurodata_type=NWBFile)
1416
def check_experimenter(nwbfile: NWBFile):
@@ -42,23 +44,6 @@ def check_subject_age(subject: Subject):
4244
)
4345

4446

45-
# @nwbinspector_check(severity=1, neurodata_type=NWBFile)
46-
# def check_keywords(nwbfile: NWBFile):
47-
# """Check if keywords have been added for the session."""
48-
# if not nwbfile.keywords:
49-
# return "Metadata /general/keywords is missing!"
50-
51-
52-
# @nwbinspector_check(severity=1, neurodata_type=NWBFile)
53-
# def check_doi_publications(nwbfile: NWBFile):
54-
# """Check if related_publications have been added as doi links."""
55-
# valid_starts = ["doi:", "http://dx.doi.org/", "https://doi.org/"]
56-
# if nwbfile.related_publications:
57-
# for publication in nwbfile.related_publications:
58-
# if any([publication.startswith(valid_start) for valid_start in valid_starts]):
59-
# return f"Metadata /general/related_publications '{publication}' does not include 'doi'!"
60-
61-
6247
@register_check(importance=Importance.BEST_PRACTICE_SUGGESTION, neurodata_type=NWBFile)
6348
def check_subject_exists(nwbfile: NWBFile):
6449
"""Check if subject exists."""
@@ -95,8 +80,27 @@ def check_subject_species(subject: Subject):
9580
)
9681

9782

98-
# @nwbinspector_check(severity=2, neurodata_type=NWBFile)
99-
# def check_subject_species(nwbfile: NWBFile):
100-
# """Check if the subject species has been specified, if one exists."""
101-
# if nwbfile.subject and not nwbfile.subject.species:
102-
# return "Metadata /general/subject/species is missing!"
83+
@register_check(importance=Importance.BEST_PRACTICE_SUGGESTION, neurodata_type=ProcessingModule)
84+
def check_processing_module_name(processing_module: ProcessingModule):
85+
if processing_module.name not in PROCESSING_MODULE_CONFIG:
86+
return InspectorMessage(
87+
f"Processing module is named {processing_module.name}. It is recommended to use the "
88+
f"schema module names: {', '.join(PROCESSING_MODULE_CONFIG)}"
89+
)
90+
91+
92+
# @nwbinspector_check(severity=1, neurodata_type=NWBFile)
93+
# def check_keywords(nwbfile: NWBFile):
94+
# """Check if keywords have been added for the session."""
95+
# if not nwbfile.keywords:
96+
# return "Metadata /general/keywords is missing!"
97+
98+
99+
# @nwbinspector_check(severity=1, neurodata_type=NWBFile)
100+
# def check_doi_publications(nwbfile: NWBFile):
101+
# """Check if related_publications have been added as doi links."""
102+
# valid_starts = ["doi:", "http://dx.doi.org/", "https://doi.org/"]
103+
# if nwbfile.related_publications:
104+
# for publication in nwbfile.related_publications:
105+
# if any([publication.startswith(valid_start) for valid_start in valid_starts]):
106+
# return f"Metadata /general/related_publications '{publication}' does not include 'doi'!"

tests/unit_tests/test_nwbfile_metadata.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from datetime import datetime
33

44
from pynwb import NWBFile
5-
from pynwb.file import Subject
5+
from pynwb.file import Subject, ProcessingModule
66
import pytest
77

88
from nwbinspector import InspectorMessage, Importance
@@ -15,6 +15,8 @@
1515
check_subject_species,
1616
check_subject_exists,
1717
check_subject_id_exists,
18+
check_processing_module_name,
19+
PROCESSING_MODULE_CONFIG,
1820
)
1921
from nwbinspector.register_checks import Severity
2022
from nwbinspector.tools import make_minimal_nwbfile
@@ -199,9 +201,23 @@ def test_pass_check_subject_id_exist():
199201
assert check_subject_id_exists(subject) is None
200202

201203

202-
@pytest.mark.skip(reason="TODO")
203-
def test_check_subject_id():
204-
pass
204+
def test_check_processing_module_name():
205+
processing_module = ProcessingModule("test", "desc")
206+
assert check_processing_module_name(processing_module) == InspectorMessage(
207+
severity=Severity.NO_SEVERITY,
208+
message=f"Processing module is named test. It is recommended to use the schema "
209+
f"module names: {', '.join(PROCESSING_MODULE_CONFIG)}",
210+
importance=Importance.BEST_PRACTICE_SUGGESTION,
211+
check_function_name="check_processing_module_name",
212+
object_type="ProcessingModule",
213+
object_name="test",
214+
location="/",
215+
)
216+
217+
218+
def test_pass_check_processing_module_name():
219+
processing_module = ProcessingModule("ecephys", "desc")
220+
assert check_processing_module_name(processing_module) is None
205221

206222

207223
@pytest.mark.skip(reason="TODO")

0 commit comments

Comments
 (0)