Visitar URL original
Fix SkeletonBuilder initialization from GUI by C-Achard · Pull Request #3380 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor SkeletonBuilder UI and add logging
Introduce logging and make SkeletonBuilder UI parameters configurable. Added import logging and module logger; initialize self._ax and self.df in constructor. Replace local ax and ampl with instance attributes (self._ax, self.ampl) and expose UI parameters (lasso_select_size, clear/export button axes and labels) to avoid hard-coded values. Update build_ui to use the new attributes and wire up LassoSelector and Buttons using configurable axes/text. These changes improve configurability and prepare for further config refactoring.
  • Loading branch information
C-Achard committed Jun 24, 2026
commit 718ab1a47e8121080b5101d308ea314d78e99463
45 changes: 28 additions & 17 deletions deeplabcut/utils/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Licensed under GNU Lesser General Public License v3.0
"""

import logging
import os
import warnings

Expand All @@ -33,6 +34,8 @@

from deeplabcut.generate_training_dataset.trainingsetmanipulation import drop_likelihood_columns

logger = logging.getLogger(__name__)


# NOTE @C-Achard 2026-03-26 duplicate config read/write functions
# should be addressed in config refactor
Expand All @@ -52,9 +55,18 @@ def write_config(configname, cfg):

class SkeletonBuilder:
def __init__(self, config_path):
### Usage parameters
self.lasso_select_size = 5
self.clear_button_axes = [0.85, 0.55, 0.1, 0.1]
self.clear_button_text = "Clear"
self.export_button_axes = [0.85, 0.45, 0.1, 0.1]
self.export_button_text = "Save"
self.ampl = 1.3 # Amplification factor for the zoomed-in view of the animal
###
self.config_path = config_path
self.cfg = read_config(config_path)
# Find uncropped labeled data
self._ax = None
self.df = None
found = False
root = os.path.join(self.cfg["project_path"], "labeled-data")
Expand Down Expand Up @@ -106,28 +118,27 @@ def __init__(self, config_path):

def build_ui(self):
self.fig = plt.figure()
ax = self.fig.add_subplot(111)
ax.axis("off")
self._ax = self.fig.add_subplot(111)
self._ax.axis("off")
lo = np.nanmin(self.xy, axis=0)
hi = np.nanmax(self.xy, axis=0)
center = (hi + lo) / 2
w, h = hi - lo
ampl = 1.3
w *= ampl
h *= ampl
ax.set_xlim(center[0] - w / 2, center[0] + w / 2)
ax.set_ylim(center[1] - h / 2, center[1] + h / 2)
ax.imshow(self.image)
ax.scatter(*self.xy.T, s=self.cfg["dotsize"] ** 2)
ax.add_collection(self.lines)
ax.invert_yaxis()

self.lasso = LassoSelector(ax, onselect=self.on_select)
ax_clear = self.fig.add_axes([0.85, 0.55, 0.1, 0.1])
ax_export = self.fig.add_axes([0.85, 0.45, 0.1, 0.1])
self.clear_button = Button(ax_clear, "Clear")
w *= self.ampl
h *= self.ampl
self._ax.set_xlim(center[0] - w / 2, center[0] + w / 2)
self._ax.set_ylim(center[1] - h / 2, center[1] + h / 2)
self._ax.imshow(self.image)
self._ax.scatter(*self.xy.T, s=self.cfg["dotsize"] ** 2)
self._ax.add_collection(self.lines)
self._ax.invert_yaxis()

self.lasso = LassoSelector(self._ax, onselect=self.on_select)
ax_clear = self.fig.add_axes(self.clear_button_axes)
ax_export = self.fig.add_axes(self.export_button_axes)
self.clear_button = Button(ax_clear, self.clear_button_text)
self.clear_button.on_clicked(self.clear)
self.export_button = Button(ax_export, "Export")
self.export_button = Button(ax_export, self.export_button_text)
self.export_button.on_clicked(self.export)
self.fig.canvas.mpl_connect("pick_event", self.on_pick)

Expand Down