From 0b1c67c04043642486421db7e9d65915e1c353fa Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Fri, 27 Sep 2024 13:00:42 -0400 Subject: [PATCH 1/2] reformatting checks --- pyproject.toml | 2 +- src/ibl_to_nwb/testing/_consistency_checks.py | 56 +++++++++---------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3123669..bc85ea8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,7 +75,7 @@ exclude = [ line-length = 120 [tool.ruff.lint] -select = ["F", "E", "I"] +select = ["F", "E", "I", "UP031", "UP032"] ignore = [ "PTH123", "D203", diff --git a/src/ibl_to_nwb/testing/_consistency_checks.py b/src/ibl_to_nwb/testing/_consistency_checks.py index a08e314..19d33b2 100644 --- a/src/ibl_to_nwb/testing/_consistency_checks.py +++ b/src/ibl_to_nwb/testing/_consistency_checks.py @@ -59,82 +59,76 @@ def _check_lick_data(*, eid: str, one: ONE, nwbfile: NWBFile): assert_array_equal(x=data_from_ONE, y=data_from_NWB) -def _check_RoiMotionEnergyInterface(*, eid: str, one: ONE, nwbfile: NWBFile, revision: str = None): +def _check_roi_motion_energy_data(*, eid: str, one: ONE, nwbfile: NWBFile): camera_views = ["body", "left", "right"] for view in camera_views: # data - data_from_NWB = ( - nwbfile.processing["behavior"].data_interfaces["%sCameraMotionEnergy" % view.capitalize()].data[:] - ) - data_from_ONE = one.load_dataset(eid, "%sCamera.ROIMotionEnergy" % view, collection="alf") + data_from_NWB = nwbfile.processing["behavior"].data_interfaces[f"{view.capitalize()}CameraMotionEnergy"].data[:] + data_from_ONE = one.load_dataset(eid, f"{view}Camera.ROIMotionEnergy", collection="alf") assert_array_equal(x=data_from_ONE, y=data_from_NWB) # timestamps data_from_NWB = ( - nwbfile.processing["behavior"].data_interfaces["%sCameraMotionEnergy" % view.capitalize()].timestamps[:] + nwbfile.processing["behavior"].data_interfaces[f"{view.capitalize()}CameraMotionEnergy"].timestamps[:] ) - data_from_ONE = one.load_dataset(eid, "_ibl_%sCamera.times" % view, collection="alf") + data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.times", collection="alf") assert_array_equal(x=data_from_ONE, y=data_from_NWB) -def _check_IblPoseEstimationInterface(*, eid: str, one: ONE, nwbfile: NWBFile, revision: str = None): +def _check_pose_estimation_data(*, eid: str, one: ONE, nwbfile: NWBFile, revision: str = None): camera_views = ["body", "left", "right"] for view in camera_views: - nodes = nwbfile.processing["behavior"].data_interfaces["PoseEstimation%sCamera" % view.capitalize()].nodes[:] + nodes = nwbfile.processing["behavior"].data_interfaces[f"PoseEstimation{view.capitalize()}Camera"].nodes[:] for node in nodes: # x data_from_NWB = ( nwbfile.processing["behavior"] - .data_interfaces["PoseEstimation%sCamera" % view.capitalize()] + .data_interfaces[f"PoseEstimation{view.capitalize()}Camera"] .pose_estimation_series[node] .data[:][:, 0] ) - data_from_ONE = one.load_dataset(eid, "_ibl_%sCamera.dlc.pqt" % view, collection="alf")[ - "%s_x" % node - ].values + data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.dlc.pqt", collection="alf")[f"{node}_x"].values assert_array_equal(x=data_from_ONE, y=data_from_NWB) # y data_from_NWB = ( nwbfile.processing["behavior"] - .data_interfaces["PoseEstimation%sCamera" % view.capitalize()] + .data_interfaces[f"PoseEstimation{view.capitalize()}Camera"] .pose_estimation_series[node] .data[:][:, 1] ) - data_from_ONE = one.load_dataset(eid, "_ibl_%sCamera.dlc.pqt" % view, collection="alf")[ - "%s_y" % node - ].values + data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.dlc.pqt", collection="alf")[f"{node}_y"].values assert_array_equal(x=data_from_ONE, y=data_from_NWB) # confidence data_from_NWB = ( nwbfile.processing["behavior"] - .data_interfaces["PoseEstimation%sCamera" % view.capitalize()] + .data_interfaces[f"PoseEstimation{view.capitalize()}Camera"] .pose_estimation_series[node] .confidence[:] ) - data_from_ONE = one.load_dataset(eid, "_ibl_%sCamera.dlc.pqt" % view, collection="alf")[ - "%s_likelihood" % node + data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.dlc.pqt", collection="alf")[ + f"{node}_likelihood" ].values assert_array_equal(x=data_from_ONE, y=data_from_NWB) # timestamps data_from_NWB = ( nwbfile.processing["behavior"] - .data_interfaces["PoseEstimation%sCamera" % view.capitalize()] + .data_interfaces[f"PoseEstimation{view.capitalize()}Camera"] .pose_estimation_series[node] .timestamps[:] ) - data_from_ONE = one.load_dataset(eid, "_ibl_%sCamera.times" % view, collection="alf") + data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.times", collection="alf") assert_array_equal(x=data_from_ONE, y=data_from_NWB) -def _check_BrainwideMapTrialsInterface(*, eid: str, one: ONE, nwbfile: NWBFile, revision: str = None): +def _check_trials_data(*, eid: str, one: ONE, nwbfile: NWBFile): data_from_NWB = nwbfile.trials[:] data_from_ONE = one.load_dataset(eid, "_ibl_trials.table", collection="alf") @@ -165,18 +159,18 @@ def _check_BrainwideMapTrialsInterface(*, eid: str, one: ONE, nwbfile: NWBFile, assert_frame_equal(left=data_from_NWB, right=data_from_ONE) -def _check_PupilTrackingInterface(*, eid: str, one: ONE, nwbfile: NWBFile, revision: str = None): +def _check_PupilTrackingInterface(*, eid: str, one: ONE, nwbfile: NWBFile): camera_views = ["left", "right"] for view in camera_views: # raw data_from_NWB = ( nwbfile.processing["behavior"] - .data_interfaces["%sPupilTracking" % view.capitalize()] - .time_series["%sRawPupilDiameter" % view.capitalize()] + .data_interfaces[f"{view.capitalize()}PupilTracking"] + .time_series[f"{view.capitalize()}RawPupilDiameter"] .data[:] ) - data_from_ONE = one.load_dataset(eid, "_ibl_%sCamera.features.pqt" % view, collection="alf")[ + data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.features.pqt", collection="alf")[ "pupilDiameter_raw" ].values @@ -185,18 +179,18 @@ def _check_PupilTrackingInterface(*, eid: str, one: ONE, nwbfile: NWBFile, revis # smooth data_from_NWB = ( nwbfile.processing["behavior"] - .data_interfaces["%sPupilTracking" % view.capitalize()] - .time_series["%sSmoothedPupilDiameter" % view.capitalize()] + .data_interfaces[f"{view.capitalize()}PupilTracking"] + .time_series[f"{view.capitalize()}SmoothedPupilDiameter"] .data[:] ) - data_from_ONE = one.load_dataset(eid, "_ibl_%sCamera.features.pqt" % view, collection="alf")[ + data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.features.pqt", collection="alf")[ "pupilDiameter_smooth" ].values assert_array_equal(x=data_from_ONE, y=data_from_NWB) -def _check_IblSortingInterface(*, eid: str, one: ONE, nwbfile: NWBFile, revision: str = None): +def _check_spike_sorting_data(*, eid: str, one: ONE, nwbfile: NWBFile, revision: str = None): units_table = nwbfile.units[:] probe_names = units_table["probe_name"].unique() From 8b568202edf73d759d2504a567a2ef6c4dacdf15 Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Fri, 27 Sep 2024 13:16:23 -0400 Subject: [PATCH 2/2] reformatting checks --- src/ibl_to_nwb/testing/_consistency_checks.py | 70 ++++++------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/src/ibl_to_nwb/testing/_consistency_checks.py b/src/ibl_to_nwb/testing/_consistency_checks.py index 19d33b2..dc26fc0 100644 --- a/src/ibl_to_nwb/testing/_consistency_checks.py +++ b/src/ibl_to_nwb/testing/_consistency_checks.py @@ -53,83 +53,65 @@ def _check_wheel_data(*, eid: str, one: ONE, nwbfile: NWBFile, revision: str = N def _check_lick_data(*, eid: str, one: ONE, nwbfile: NWBFile): - table = nwbfile.processing["behavior"].data_interfaces["LickTimes"][:] - data_from_NWB = table["lick_time"].values + processing_module = nwbfile.processing["behavior"] + lick_times_table = processing_module.data_interfaces["LickTimes"][:] + + data_from_NWB = lick_times_table["lick_time"].values data_from_ONE = one.load_dataset(eid, "licks.times") assert_array_equal(x=data_from_ONE, y=data_from_NWB) def _check_roi_motion_energy_data(*, eid: str, one: ONE, nwbfile: NWBFile): + processing_module = nwbfile.processing["behavior"] camera_views = ["body", "left", "right"] - for view in camera_views: + camera_motion_energy = processing_module.data_interfaces[f"{view.capitalize()}CameraMotionEnergy"] + # data - data_from_NWB = nwbfile.processing["behavior"].data_interfaces[f"{view.capitalize()}CameraMotionEnergy"].data[:] + data_from_NWB = camera_motion_energy.data[:] data_from_ONE = one.load_dataset(eid, f"{view}Camera.ROIMotionEnergy", collection="alf") assert_array_equal(x=data_from_ONE, y=data_from_NWB) # timestamps - data_from_NWB = ( - nwbfile.processing["behavior"].data_interfaces[f"{view.capitalize()}CameraMotionEnergy"].timestamps[:] - ) + data_from_NWB = camera_motion_energy.timestamps[:] data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.times", collection="alf") assert_array_equal(x=data_from_ONE, y=data_from_NWB) def _check_pose_estimation_data(*, eid: str, one: ONE, nwbfile: NWBFile, revision: str = None): + processing_module = nwbfile.processing["behavior"] camera_views = ["body", "left", "right"] - for view in camera_views: - nodes = nwbfile.processing["behavior"].data_interfaces[f"PoseEstimation{view.capitalize()}Camera"].nodes[:] + pose_estimation_container = processing_module.data_interfaces[f"PoseEstimation{view.capitalize()}Camera"] + nodes = pose_estimation_container.nodes[:] for node in nodes: # x - data_from_NWB = ( - nwbfile.processing["behavior"] - .data_interfaces[f"PoseEstimation{view.capitalize()}Camera"] - .pose_estimation_series[node] - .data[:][:, 0] - ) + data_from_NWB = pose_estimation_container.pose_estimation_series[node].data[:][:, 0] data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.dlc.pqt", collection="alf")[f"{node}_x"].values assert_array_equal(x=data_from_ONE, y=data_from_NWB) # y - data_from_NWB = ( - nwbfile.processing["behavior"] - .data_interfaces[f"PoseEstimation{view.capitalize()}Camera"] - .pose_estimation_series[node] - .data[:][:, 1] - ) + data_from_NWB = pose_estimation_container.pose_estimation_series[node].data[:][:, 1] data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.dlc.pqt", collection="alf")[f"{node}_y"].values assert_array_equal(x=data_from_ONE, y=data_from_NWB) # confidence - data_from_NWB = ( - nwbfile.processing["behavior"] - .data_interfaces[f"PoseEstimation{view.capitalize()}Camera"] - .pose_estimation_series[node] - .confidence[:] - ) + data_from_NWB = pose_estimation_container.pose_estimation_series[node].confidence[:] data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.dlc.pqt", collection="alf")[ f"{node}_likelihood" ].values assert_array_equal(x=data_from_ONE, y=data_from_NWB) # timestamps - data_from_NWB = ( - nwbfile.processing["behavior"] - .data_interfaces[f"PoseEstimation{view.capitalize()}Camera"] - .pose_estimation_series[node] - .timestamps[:] - ) + data_from_NWB = pose_estimation_container.pose_estimation_series[node].timestamps[:] data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.times", collection="alf") assert_array_equal(x=data_from_ONE, y=data_from_NWB) def _check_trials_data(*, eid: str, one: ONE, nwbfile: NWBFile): - data_from_NWB = nwbfile.trials[:] data_from_ONE = one.load_dataset(eid, "_ibl_trials.table", collection="alf") data_from_ONE["stimOff_times"] = one.load_dataset(eid, "_ibl_trials.stimOff_times", collection="alf") @@ -159,30 +141,22 @@ def _check_trials_data(*, eid: str, one: ONE, nwbfile: NWBFile): assert_frame_equal(left=data_from_NWB, right=data_from_ONE) -def _check_PupilTrackingInterface(*, eid: str, one: ONE, nwbfile: NWBFile): +def _check_pupil_tracking_data(*, eid: str, one: ONE, nwbfile: NWBFile): + processing_module = nwbfile.processing["behavior"] camera_views = ["left", "right"] for view in camera_views: + pupil_tracking_container = processing_module.data_interfaces[f"{view.capitalize()}PupilTracking"] + # raw - data_from_NWB = ( - nwbfile.processing["behavior"] - .data_interfaces[f"{view.capitalize()}PupilTracking"] - .time_series[f"{view.capitalize()}RawPupilDiameter"] - .data[:] - ) + data_from_NWB = pupil_tracking_container.time_series[f"{view.capitalize()}RawPupilDiameter"].data[:] data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.features.pqt", collection="alf")[ "pupilDiameter_raw" ].values - assert_array_equal(x=data_from_ONE, y=data_from_NWB) # smooth - data_from_NWB = ( - nwbfile.processing["behavior"] - .data_interfaces[f"{view.capitalize()}PupilTracking"] - .time_series[f"{view.capitalize()}SmoothedPupilDiameter"] - .data[:] - ) + data_from_NWB = pupil_tracking_container.time_series[f"{view.capitalize()}SmoothedPupilDiameter"].data[:] data_from_ONE = one.load_dataset(eid, f"_ibl_{view}Camera.features.pqt", collection="alf")[ "pupilDiameter_smooth" ].values