Skip to content

Commit 9e200b8

Browse files
Safer DLC version retrieval (#18)
* better upstream version grab; adding some descriptions * Update dlc2nwb/utils.py Co-authored-by: Jessy Lauer <[email protected]> * Update utils.py Co-authored-by: Jessy Lauer <[email protected]>
1 parent a2c0a29 commit 9e200b8

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

dlc2nwb/utils.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1-
import cv2
21
import datetime
32
import os
3+
import pickle
4+
import warnings
45
from pathlib import Path
6+
from platform import python_version
7+
8+
import cv2
9+
import yaml
510
import numpy as np
611
import pandas as pd
7-
import pickle
8-
import warnings
912
from hdmf.build.warnings import DtypeConversionWarning
13+
from packaging.version import Version # Installed with setuptools
1014
from pynwb import NWBFile, NWBHDF5IO
1115
from ndx_pose import PoseEstimationSeries, PoseEstimation
12-
import yaml
1316
from ruamel.yaml import YAML
1417

1518
# If available determine version
1619
try:
17-
from deeplabcut import __version__
18-
deeplabcut_version = __version__
20+
if Version(python_version()) >= Version("3.8"):
21+
from importlib.metadata import version as get_package_version # Only available in Python>=3.8
22+
23+
deeplabcut_version = get_package_version("deeplabcut")
24+
else:
25+
from pkg_resources import get_distribution # Installed with setuptools
26+
27+
deeplabcut_version = get_distribution("deeplabcut").version
1928
except ModuleNotFoundError:
2029
deeplabcut_version = None
2130

31+
2232
def read_config(configname):
2333
"""
2434
Reads structured config file defining a project.
@@ -176,8 +186,16 @@ def _get_pes_args(config_file, h5file, individual_name, infer_timestamps=True):
176186
return scorer, df, video, paf_graph, timestamps, cfg
177187

178188

179-
def _write_pes_to_nwbfile(nwbfile, animal, df_animal, scorer, video, paf_graph, timestamps,
180-
exclude_nans):
189+
def _write_pes_to_nwbfile(
190+
nwbfile,
191+
animal,
192+
df_animal,
193+
scorer,
194+
video, # Expects this to be a tuple; first index is string path, second is the image shape as "0, width, 0, height"
195+
paf_graph,
196+
timestamps,
197+
exclude_nans,
198+
):
181199
pose_estimation_series = []
182200
for kpt, xyp in df_animal.groupby(level="bodyparts", axis=1, sort=False):
183201
data = xyp.to_numpy()
@@ -200,7 +218,7 @@ def _write_pes_to_nwbfile(nwbfile, animal, df_animal, scorer, video, paf_graph,
200218
confidence_definition="Softmax output of the deep neural network.",
201219
)
202220
pose_estimation_series.append(pes)
203-
221+
204222
pe = PoseEstimation(
205223
pose_estimation_series=pose_estimation_series,
206224
description="2D keypoint coordinates estimated using DeepLabCut.",

0 commit comments

Comments
 (0)