From c192220a80e60ee7237ff20481f9231452dc63e8 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Mon, 17 Jun 2024 12:34:24 +0200 Subject: [PATCH 1/4] fix video len bug --- dlc2nwb/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dlc2nwb/utils.py b/dlc2nwb/utils.py index 6b7c796..225ccb2 100644 --- a/dlc2nwb/utils.py +++ b/dlc2nwb/utils.py @@ -74,7 +74,9 @@ def get_movie_timestamps(movie_file, VARIABILITYBOUND=1000, infer_timestamps=Tru reader = cv2.VideoCapture(movie_file) timestamps = [] - for _ in range(len(reader)): + n_frames = int(reader.get(cv2.CAP_PROP_FRAME_COUNT)) + + for _ in range(n_frames): _ = reader.read() timestamps.append(reader.get(cv2.CAP_PROP_POS_MSEC)) From c929dbbe37202d340ea9d5f44007c056fdde850f Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Mon, 17 Jun 2024 12:41:53 +0200 Subject: [PATCH 2/4] other fix --- dlc2nwb/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dlc2nwb/utils.py b/dlc2nwb/utils.py index 225ccb2..05080fe 100644 --- a/dlc2nwb/utils.py +++ b/dlc2nwb/utils.py @@ -75,6 +75,7 @@ def get_movie_timestamps(movie_file, VARIABILITYBOUND=1000, infer_timestamps=Tru reader = cv2.VideoCapture(movie_file) timestamps = [] n_frames = int(reader.get(cv2.CAP_PROP_FRAME_COUNT)) + fps = reader.get(cv2.CAP_PROP_FPS) for _ in range(n_frames): _ = reader.read() @@ -82,7 +83,7 @@ def get_movie_timestamps(movie_file, VARIABILITYBOUND=1000, infer_timestamps=Tru timestamps = np.array(timestamps) / 1000 # Convert to seconds - if np.nanvar(np.diff(timestamps)) < 1.0 / reader.fps * 1.0 / VARIABILITYBOUND: + if np.nanvar(np.diff(timestamps)) < 1.0 / fps * 1.0 / VARIABILITYBOUND: warnings.warn( "Variability of timestamps suspiciously small. See: https://github.com/DeepLabCut/DLC2NWB/issues/1" ) From 990e602ca156caae11b0994365d6d29b4cf751e2 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 19 Jun 2024 17:36:21 +0200 Subject: [PATCH 3/4] Optional args to export to overwrite nwb-pose defaults --- dlc2nwb/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dlc2nwb/utils.py b/dlc2nwb/utils.py index 05080fe..6bde30e 100644 --- a/dlc2nwb/utils.py +++ b/dlc2nwb/utils.py @@ -198,6 +198,7 @@ def _write_pes_to_nwbfile( paf_graph, timestamps, exclude_nans, + **optional_kwargs, ): pose_estimation_series = [] for kpt, xyp in df_animal.groupby(level="bodyparts", axis=1, sort=False): @@ -233,6 +234,7 @@ def _write_pes_to_nwbfile( source_software_version=deeplabcut_version, nodes=[pes.name for pes in pose_estimation_series], edges=paf_graph if paf_graph else None, + **optional_kwargs, ) if 'behavior' in nwbfile.processing: behavior_pm = nwbfile.processing["behavior"] From ade69b97429ccbddbbc530bdcc684f036fcfb117 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 19 Jun 2024 20:22:21 +0200 Subject: [PATCH 4/4] changed argument name to explicit --- dlc2nwb/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dlc2nwb/utils.py b/dlc2nwb/utils.py index 6bde30e..f2d70ac 100644 --- a/dlc2nwb/utils.py +++ b/dlc2nwb/utils.py @@ -198,7 +198,7 @@ def _write_pes_to_nwbfile( paf_graph, timestamps, exclude_nans, - **optional_kwargs, + **pose_estimation_container_kwargs, ): pose_estimation_series = [] for kpt, xyp in df_animal.groupby(level="bodyparts", axis=1, sort=False): @@ -234,7 +234,7 @@ def _write_pes_to_nwbfile( source_software_version=deeplabcut_version, nodes=[pes.name for pes in pose_estimation_series], edges=paf_graph if paf_graph else None, - **optional_kwargs, + **pose_estimation_container_kwargs, ) if 'behavior' in nwbfile.processing: behavior_pm = nwbfile.processing["behavior"]