From bf935246f65de1778b9857ef1e8d3e3edd1f818e Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:32:40 -0400 Subject: [PATCH] Implement scope control over check submodule (#486) * implement scope control over check submodule * remove hallucinated names and fix test imports * adjust imports for deprecated submodules --------- Co-authored-by: CodyCBakerPhD --- src/nwbinspector/__init__.py | 2 +- src/nwbinspector/checks/__init__.py | 161 ++++++++++++++++-- .../checks/{behavior.py => _behavior.py} | 0 .../checks/{ecephys.py => _ecephys.py} | 0 .../checks/{general.py => _general.py} | 0 .../checks/{icephys.py => _icephys.py} | 0 .../{image_series.py => _image_series.py} | 0 .../checks/{images.py => _images.py} | 0 .../{nwb_containers.py => _nwb_containers.py} | 0 ...bfile_metadata.py => _nwbfile_metadata.py} | 0 src/nwbinspector/checks/{ogen.py => _ogen.py} | 0 .../checks/{ophys.py => _ophys.py} | 0 .../checks/{tables.py => _tables.py} | 0 .../{time_series.py => _time_series.py} | 0 src/nwbinspector/checks/behavior/__init__.py | 13 ++ src/nwbinspector/checks/ecephys/__init__.py | 13 ++ src/nwbinspector/checks/general/__init__.py | 13 ++ src/nwbinspector/checks/icephys/__init__.py | 13 ++ .../checks/image_series/__init__.py | 13 ++ src/nwbinspector/checks/images/__init__.py | 13 ++ .../checks/nwb_containers/__init__.py | 13 ++ .../checks/nwbfile_metadata/__init__.py | 13 ++ src/nwbinspector/checks/ogen/__init__.py | 13 ++ src/nwbinspector/checks/ophys/__init__.py | 13 ++ src/nwbinspector/checks/tables/__init__.py | 13 ++ .../checks/time_series/__init__.py | 13 ++ tests/test_check_configuration.py | 10 +- tests/unit_tests/test_nwbfile_metadata.py | 2 +- 28 files changed, 313 insertions(+), 18 deletions(-) rename src/nwbinspector/checks/{behavior.py => _behavior.py} (100%) rename src/nwbinspector/checks/{ecephys.py => _ecephys.py} (100%) rename src/nwbinspector/checks/{general.py => _general.py} (100%) rename src/nwbinspector/checks/{icephys.py => _icephys.py} (100%) rename src/nwbinspector/checks/{image_series.py => _image_series.py} (100%) rename src/nwbinspector/checks/{images.py => _images.py} (100%) rename src/nwbinspector/checks/{nwb_containers.py => _nwb_containers.py} (100%) rename src/nwbinspector/checks/{nwbfile_metadata.py => _nwbfile_metadata.py} (100%) rename src/nwbinspector/checks/{ogen.py => _ogen.py} (100%) rename src/nwbinspector/checks/{ophys.py => _ophys.py} (100%) rename src/nwbinspector/checks/{tables.py => _tables.py} (100%) rename src/nwbinspector/checks/{time_series.py => _time_series.py} (100%) create mode 100644 src/nwbinspector/checks/behavior/__init__.py create mode 100644 src/nwbinspector/checks/ecephys/__init__.py create mode 100644 src/nwbinspector/checks/general/__init__.py create mode 100644 src/nwbinspector/checks/icephys/__init__.py create mode 100644 src/nwbinspector/checks/image_series/__init__.py create mode 100644 src/nwbinspector/checks/images/__init__.py create mode 100644 src/nwbinspector/checks/nwb_containers/__init__.py create mode 100644 src/nwbinspector/checks/nwbfile_metadata/__init__.py create mode 100644 src/nwbinspector/checks/ogen/__init__.py create mode 100644 src/nwbinspector/checks/ophys/__init__.py create mode 100644 src/nwbinspector/checks/tables/__init__.py create mode 100644 src/nwbinspector/checks/time_series/__init__.py diff --git a/src/nwbinspector/__init__.py b/src/nwbinspector/__init__.py index 682725704..c8c2e181f 100644 --- a/src/nwbinspector/__init__.py +++ b/src/nwbinspector/__init__.py @@ -18,7 +18,7 @@ InspectorOutputJSONEncoder, ) from ._organization import organize_messages -from .checks import * +from .checks import * # These need to be imported to trigger registration with 'available_checks', but are not exposed default_check_registry = {check.__name__: check for check in available_checks} diff --git a/src/nwbinspector/checks/__init__.py b/src/nwbinspector/checks/__init__.py index 138c28eb9..5cf41a5bc 100644 --- a/src/nwbinspector/checks/__init__.py +++ b/src/nwbinspector/checks/__init__.py @@ -1,12 +1,149 @@ -from .ecephys import * -from .general import * -from .image_series import * -from .images import * -from .nwb_containers import * -from .nwbfile_metadata import * -from .ogen import * -from .ophys import * -from .tables import * -from .time_series import * -from .icephys import * -from .behavior import * +from ._ecephys import ( + check_negative_spike_times, + check_electrical_series_dims, + check_electrical_series_reference_electrodes_table, + check_spike_times_not_in_unobserved_interval, +) +from ._general import ( + check_description, + check_name_slashes, +) +from ._image_series import ( + check_image_series_data_size, + check_image_series_external_file_relative, + check_image_series_external_file_valid, +) +from ._images import ( + check_order_of_images_unique, + check_order_of_images_len, + check_index_series_points_to_image, +) +from ._nwb_containers import ( + check_empty_string_for_optional_attribute, + check_small_dataset_compression, + check_large_dataset_compression, +) +from ._nwbfile_metadata import ( + check_keywords, + check_institution, + check_subject_age, + check_subject_sex, + check_subject_exists, + check_doi_publications, + check_experimenter_form, + check_experimenter_exists, + check_experiment_description, + check_subject_id_exists, + check_subject_species_exists, + check_subject_species_form, + check_subject_proper_age_range, + check_session_start_time_future_date, + check_processing_module_name, + check_session_start_time_old_date, +) +from ._ogen import ( + check_optogenetic_stimulus_site_has_optogenetic_series, +) +from ._ophys import ( + check_excitation_lambda_in_nm, + check_plane_segmentation_image_mask_shape_against_ref_images, + check_roi_response_series_dims, + check_emission_lambda_in_nm, + check_roi_response_series_link_to_plane_segmentation, +) +from ._tables import ( + check_single_row, + check_ids_unique, + check_empty_table, + check_col_not_nan, + check_column_binary_capability, + check_dynamic_table_region_data_validity, + check_time_interval_time_columns, + check_time_intervals_stop_after_start, + check_table_values_for_dict, + check_table_time_columns_are_not_negative, +) +from ._time_series import ( + check_resolution, + check_missing_unit, + check_regular_timestamps, + check_timestamps_ascending, + check_data_orientation, + check_timestamps_without_nans, + check_timestamps_match_first_dimension, + check_timestamp_of_the_first_sample_is_not_negative, + check_rate_is_not_zero, +) +from ._icephys import ( + check_intracellular_electrode_cell_id_exists, +) +from ._behavior import ( + check_compass_direction_unit, + check_spatial_series_radians_magnitude, + check_spatial_series_dims, + check_spatial_series_degrees_magnitude, +) + +__all__ = [ + "check_negative_spike_times", + "check_electrical_series_dims", + "check_electrical_series_reference_electrodes_table", + "check_spike_times_not_in_unobserved_interval", + "check_description", + "check_name_slashes", + "check_image_series_data_size", + "check_image_series_external_file_relative", + "check_image_series_external_file_valid", + "check_order_of_images_unique", + "check_order_of_images_len", + "check_index_series_points_to_image", + "check_empty_string_for_optional_attribute", + "check_small_dataset_compression", + "check_large_dataset_compression", + "check_keywords", + "check_institution", + "check_subject_age", + "check_subject_sex", + "check_subject_exists", + "check_doi_publications", + "check_experimenter_form", + "check_experimenter_exists", + "check_experiment_description", + "check_subject_id_exists", + "check_subject_species_exists", + "check_subject_species_form", + "check_subject_proper_age_range", + "check_session_start_time_future_date", + "check_processing_module_name", + "check_session_start_time_old_date", + "check_optogenetic_stimulus_site_has_optogenetic_series", + "check_excitation_lambda_in_nm", + "check_plane_segmentation_image_mask_shape_against_ref_images", + "check_roi_response_series_dims", + "check_emission_lambda_in_nm", + "check_roi_response_series_link_to_plane_segmentation", + "check_single_row", + "check_ids_unique", + "check_empty_table", + "check_col_not_nan", + "check_column_binary_capability", + "check_dynamic_table_region_data_validity", + "check_time_interval_time_columns", + "check_time_intervals_stop_after_start", + "check_table_values_for_dict", + "check_table_time_columns_are_not_negative", + "check_resolution", + "check_missing_unit", + "check_regular_timestamps", + "check_timestamps_ascending", + "check_data_orientation", + "check_timestamps_without_nans", + "check_timestamps_match_first_dimension", + "check_timestamp_of_the_first_sample_is_not_negative", + "check_rate_is_not_zero", + "check_intracellular_electrode_cell_id_exists", + "check_compass_direction_unit", + "check_spatial_series_radians_magnitude", + "check_spatial_series_dims", + "check_spatial_series_degrees_magnitude", +] diff --git a/src/nwbinspector/checks/behavior.py b/src/nwbinspector/checks/_behavior.py similarity index 100% rename from src/nwbinspector/checks/behavior.py rename to src/nwbinspector/checks/_behavior.py diff --git a/src/nwbinspector/checks/ecephys.py b/src/nwbinspector/checks/_ecephys.py similarity index 100% rename from src/nwbinspector/checks/ecephys.py rename to src/nwbinspector/checks/_ecephys.py diff --git a/src/nwbinspector/checks/general.py b/src/nwbinspector/checks/_general.py similarity index 100% rename from src/nwbinspector/checks/general.py rename to src/nwbinspector/checks/_general.py diff --git a/src/nwbinspector/checks/icephys.py b/src/nwbinspector/checks/_icephys.py similarity index 100% rename from src/nwbinspector/checks/icephys.py rename to src/nwbinspector/checks/_icephys.py diff --git a/src/nwbinspector/checks/image_series.py b/src/nwbinspector/checks/_image_series.py similarity index 100% rename from src/nwbinspector/checks/image_series.py rename to src/nwbinspector/checks/_image_series.py diff --git a/src/nwbinspector/checks/images.py b/src/nwbinspector/checks/_images.py similarity index 100% rename from src/nwbinspector/checks/images.py rename to src/nwbinspector/checks/_images.py diff --git a/src/nwbinspector/checks/nwb_containers.py b/src/nwbinspector/checks/_nwb_containers.py similarity index 100% rename from src/nwbinspector/checks/nwb_containers.py rename to src/nwbinspector/checks/_nwb_containers.py diff --git a/src/nwbinspector/checks/nwbfile_metadata.py b/src/nwbinspector/checks/_nwbfile_metadata.py similarity index 100% rename from src/nwbinspector/checks/nwbfile_metadata.py rename to src/nwbinspector/checks/_nwbfile_metadata.py diff --git a/src/nwbinspector/checks/ogen.py b/src/nwbinspector/checks/_ogen.py similarity index 100% rename from src/nwbinspector/checks/ogen.py rename to src/nwbinspector/checks/_ogen.py diff --git a/src/nwbinspector/checks/ophys.py b/src/nwbinspector/checks/_ophys.py similarity index 100% rename from src/nwbinspector/checks/ophys.py rename to src/nwbinspector/checks/_ophys.py diff --git a/src/nwbinspector/checks/tables.py b/src/nwbinspector/checks/_tables.py similarity index 100% rename from src/nwbinspector/checks/tables.py rename to src/nwbinspector/checks/_tables.py diff --git a/src/nwbinspector/checks/time_series.py b/src/nwbinspector/checks/_time_series.py similarity index 100% rename from src/nwbinspector/checks/time_series.py rename to src/nwbinspector/checks/_time_series.py diff --git a/src/nwbinspector/checks/behavior/__init__.py b/src/nwbinspector/checks/behavior/__init__.py new file mode 100644 index 000000000..f9c304fe4 --- /dev/null +++ b/src/nwbinspector/checks/behavior/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._behavior import * diff --git a/src/nwbinspector/checks/ecephys/__init__.py b/src/nwbinspector/checks/ecephys/__init__.py new file mode 100644 index 000000000..9f60a96f3 --- /dev/null +++ b/src/nwbinspector/checks/ecephys/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._ecephys import * diff --git a/src/nwbinspector/checks/general/__init__.py b/src/nwbinspector/checks/general/__init__.py new file mode 100644 index 000000000..61ae39ecf --- /dev/null +++ b/src/nwbinspector/checks/general/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._general import * diff --git a/src/nwbinspector/checks/icephys/__init__.py b/src/nwbinspector/checks/icephys/__init__.py new file mode 100644 index 000000000..8106d53f1 --- /dev/null +++ b/src/nwbinspector/checks/icephys/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._icephys import * diff --git a/src/nwbinspector/checks/image_series/__init__.py b/src/nwbinspector/checks/image_series/__init__.py new file mode 100644 index 000000000..080c8bb2c --- /dev/null +++ b/src/nwbinspector/checks/image_series/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._image_series import * diff --git a/src/nwbinspector/checks/images/__init__.py b/src/nwbinspector/checks/images/__init__.py new file mode 100644 index 000000000..1bceb236e --- /dev/null +++ b/src/nwbinspector/checks/images/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._images import * diff --git a/src/nwbinspector/checks/nwb_containers/__init__.py b/src/nwbinspector/checks/nwb_containers/__init__.py new file mode 100644 index 000000000..38a595305 --- /dev/null +++ b/src/nwbinspector/checks/nwb_containers/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._nwb_containers import * diff --git a/src/nwbinspector/checks/nwbfile_metadata/__init__.py b/src/nwbinspector/checks/nwbfile_metadata/__init__.py new file mode 100644 index 000000000..2af1dc2b4 --- /dev/null +++ b/src/nwbinspector/checks/nwbfile_metadata/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._nwbfile_metadata import * diff --git a/src/nwbinspector/checks/ogen/__init__.py b/src/nwbinspector/checks/ogen/__init__.py new file mode 100644 index 000000000..dca19df19 --- /dev/null +++ b/src/nwbinspector/checks/ogen/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._ogen import * diff --git a/src/nwbinspector/checks/ophys/__init__.py b/src/nwbinspector/checks/ophys/__init__.py new file mode 100644 index 000000000..224835b85 --- /dev/null +++ b/src/nwbinspector/checks/ophys/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._ophys import * diff --git a/src/nwbinspector/checks/tables/__init__.py b/src/nwbinspector/checks/tables/__init__.py new file mode 100644 index 000000000..3257fb2e7 --- /dev/null +++ b/src/nwbinspector/checks/tables/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._tables import * diff --git a/src/nwbinspector/checks/time_series/__init__.py b/src/nwbinspector/checks/time_series/__init__.py new file mode 100644 index 000000000..84182bb49 --- /dev/null +++ b/src/nwbinspector/checks/time_series/__init__.py @@ -0,0 +1,13 @@ +import warnings + +message = ( + "All submodules below the level 'nwbinspector.checks' have been deprecated. " + "Please retrieve the specific check function(s) you wish to use from the `available_checks` registry " + "at the top-level or import directly from 'nwbinspector.checks'." +) + +warnings.warn(message=message, category=DeprecationWarning, stacklevel=2) + +# Still keep imports functional with warning for soft deprecation cycle +# TODO: remove after 9/15/2024 +from .._time_series import * diff --git a/tests/test_check_configuration.py b/tests/test_check_configuration.py index 92ff825bf..c8e67a386 100644 --- a/tests/test_check_configuration.py +++ b/tests/test_check_configuration.py @@ -3,16 +3,18 @@ from nwbinspector import ( Importance, - check_small_dataset_compression, - check_regular_timestamps, - check_data_orientation, - check_timestamps_match_first_dimension, available_checks, default_check_registry, validate_config, configure_checks, load_config, ) +from nwbinspector.checks import ( + check_small_dataset_compression, + check_regular_timestamps, + check_data_orientation, + check_timestamps_match_first_dimension, +) from nwbinspector._configuration import _copy_function diff --git a/tests/unit_tests/test_nwbfile_metadata.py b/tests/unit_tests/test_nwbfile_metadata.py index 33bbe5072..c3a09a6f2 100644 --- a/tests/unit_tests/test_nwbfile_metadata.py +++ b/tests/unit_tests/test_nwbfile_metadata.py @@ -22,9 +22,9 @@ check_processing_module_name, check_session_start_time_old_date, check_session_start_time_future_date, - PROCESSING_MODULE_CONFIG, ) from nwbinspector.testing import make_minimal_nwbfile +from nwbinspector.checks._nwbfile_metadata import PROCESSING_MODULE_CONFIG minimal_nwbfile = make_minimal_nwbfile()