Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move imports of extensions to the init of the interfaces #1144

Merged
merged 10 commits into from
Nov 22, 2024
Next Next commit
add failing test
  • Loading branch information
h-mayorquin committed Nov 15, 2024
commit 2d8e8cc77ca3d374c7e74176e81922089b1b48cc
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ def __init__(self, file_paths: list[FilePath], verbose: bool = False):

verbose : bool, default: False
"""

suffixes = [suffix for file_path in file_paths for suffix in Path(file_path).suffixes]
format_is_not_supported = [
suffix for suffix in suffixes if suffix not in [".wav"]
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
from pydantic import FilePath, validate_call
from pynwb.file import NWBFile

# import ndx_pose
from ....basetemporalalignmentinterface import BaseTemporalAlignmentInterface


@@ -48,6 +47,8 @@ def __init__(
verbose: bool, default: True
Controls verbosity.
"""
# from ndx_pose import PoseEstimation, PoseEstimationSeries

from ._dlc_utils import _read_config

file_path = Path(file_path)
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ def __init__(
verbose : bool, default: True
controls verbosity. ``True`` by default.
"""

from neuroconv.datainterfaces.behavior.video.video_utils import (
VideoCaptureContext,
)
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ def __init__(
verbose : bool, optional
Whether to print verbose output, by default True
"""

if aligned_timestamp_names is None:
aligned_timestamp_names = []
super().__init__(
36 changes: 35 additions & 1 deletion tests/test_on_data/behavior/test_behavior_interfaces.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import unittest
from datetime import datetime, timezone
from pathlib import Path
@@ -10,7 +11,6 @@
from natsort import natsorted
from ndx_miniscope import Miniscope
from ndx_miniscope.utils import get_timestamps
from ndx_pose import PoseEstimation, PoseEstimationSeries
from numpy.testing import assert_array_equal
from parameterized import param, parameterized
from pynwb import NWBHDF5IO
@@ -105,6 +105,8 @@ def check_extracted_metadata(self, metadata: dict):
assert metadata["Behavior"][self.pose_estimation_name] == self.expected_metadata[self.pose_estimation_name]

def check_read_nwb(self, nwbfile_path: str):
from ndx_pose import PoseEstimation, PoseEstimationSeries

with NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True) as io:
nwbfile = io.read()

@@ -381,6 +383,38 @@ def check_read_nwb(self, nwbfile_path: str):
assert all(expected_pose_estimation_series_are_in_nwb_file)


@pytest.fixture
def clean_pose_extension_import():
modules_to_remove = [m for m in sys.modules if m.startswith("ndx_pose")]
for module in modules_to_remove:
del sys.modules[module]


def test_ndx_proper_loading_deeplabcut(clean_pose_extension_import, tmp_path):

interface_kwargs = dict(
file_path=str(
BEHAVIOR_DATA_PATH
/ "DLC"
/ "open_field_without_video"
/ "m3v1mp4DLC_resnet50_openfieldAug20shuffle1_30000.h5"
),
config_file_path=str(BEHAVIOR_DATA_PATH / "DLC" / "open_field_without_video" / "config.yaml"),
)

interface = DeepLabCutInterface(**interface_kwargs)
metadata = interface.get_metadata()
metadata["NWBFile"]["session_start_time"] = "2021-01-01T12:00:00"
interface.run_conversion(nwbfile_path="test.nwb", metadata=metadata, overwrite=True)

nwbfile_path = tmp_path / "test.nwb"
with NWBHDF5IO(path=nwbfile_path, mode="r") as io:
read_nwbfile = io.read()
pose_estimation_container = read_nwbfile.processing["behavior"]["PoseEstimation"]

assert len(pose_estimation_container.fields) > 0


@pytest.mark.skipif(
platform == "darwin" and python_version < version.parse("3.10"),
reason="interface not supported on macOS with Python < 3.10",
3 changes: 2 additions & 1 deletion tests/test_on_data/behavior/test_lightningpose_converter.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
from warnings import warn

from hdmf.testing import TestCase
from ndx_pose import PoseEstimation
from pynwb import NWBHDF5IO
from pynwb.image import ImageSeries

@@ -134,6 +133,8 @@ def test_run_conversion_add_conversion_options(self):
self.assertNWBFileStructure(nwbfile_path=nwbfile_path, **self.conversion_options)

def assertNWBFileStructure(self, nwbfile_path: str, stub_test: bool = False):
from ndx_pose import PoseEstimation

with NWBHDF5IO(path=nwbfile_path) as io:
nwbfile = io.read()