Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
77cb3d7
Redirected the 'home page' link to labgym.org instead of the labgym g…
alisaficiciyan Mar 3, 2026
1bcc859
Added the link to LabGym youtube tutorial describing preprocessing ba…
alisaficiciyan Mar 11, 2026
4f88a46
Added the link to the LabGym youtube tutorial describing how to draw …
alisaficiciyan Mar 24, 2026
a438bcb
Added the link to the LabGym youtube tutorial describing background s…
alisaficiciyan Mar 24, 2026
90f1b70
Added a tab that cannot be closed which includes the visuals of the L…
alisaficiciyan May 18, 2026
7b4bdb9
Made the font size larger for all text in the workflow map
alisaficiciyan May 19, 2026
67efa02
Changed the layout of the workflow map to better represent the workflow
alisaficiciyan May 19, 2026
db12725
Updated the workflow map to use fixed pixels instead of changing the …
alisaficiciyan May 28, 2026
a1d57b9
Changed the colors of the workflow map so that it is easy to distingu…
alisaficiciyan Jun 1, 2026
316866c
Changed the layout of the workflow so that each of the 3 sections is …
alisaficiciyan Jun 2, 2026
737a217
Made the workflow slightly larger on the screen so it is easier for u…
alisaficiciyan Jun 2, 2026
6b85681
Added a button to all pages in LabGym (except home and workflow map) …
alisaficiciyan Jun 7, 2026
11c5a8d
Standardized the margins in each of the boxes and changed the text so…
alisaficiciyan Jun 10, 2026
a1fe2a2
Added 4th category to the workflow map for post classification analys…
alisaficiciyan Jun 14, 2026
8e49f66
Added a pop-up feature so you can click on each box in the workflow m…
alisaficiciyan Jun 14, 2026
00dd075
Lightened the background of pop-ups; unbolded the titles of the box n…
alisaficiciyan Jun 17, 2026
51eb35e
Added an example count display that shows up after selecting a folder…
alisaficiciyan Jun 27, 2026
d1f1da4
Changed the example count so it is now triggered by adding a folder t…
alisaficiciyan Jul 3, 2026
c66c476
Added a line under each row which specifies how many example counts n…
alisaficiciyan Jul 3, 2026
a60c171
Instead of the whole text box popping up when attaching a folder for …
alisaficiciyan Jul 3, 2026
674ae9e
Added the behavior counts to the sorted behavior examples folder in a…
alisaficiciyan Jul 6, 2026
38b8abf
Added a title to both pop-ups to differentiate the two from each othe…
alisaficiciyan Jul 10, 2026
c9267e9
Added a box within each pop-up that allows users to change the minimi…
alisaficiciyan Jul 10, 2026
124429e
Updated the header of each pop-up to get rid of the header scrollbar …
alisaficiciyan Jul 10, 2026
b18799d
Capitalized the title in one of the workflow map pop-ups
alisaficiciyan Jul 29, 2026
c91faa8
Added youtube tutorial links for the following 2 videos: “Training a …
alisaficiciyan Jul 28, 2026
185d956
fix(gui): remove background subtraction tutorial link
btmlnsn Aug 4, 2026
e08229f
fix(categorizer): improve behavior count popup readability
btmlnsn Aug 4, 2026
686f79e
fix(categorizer): integrate behavior count actions into folder rows
btmlnsn Aug 4, 2026
3d7e196
fix(gui): fit workflow map to fixed window size
btmlnsn Aug 4, 2026
631f3b6
fix(gui): unify and resize runtime application icons
btmlnsn Aug 4, 2026
ce2f12e
feat(gui): detect native light and dark appearance
btmlnsn Aug 4, 2026
5bba162
fix(gui): adapt workflow map to native appearance
btmlnsn Aug 4, 2026
80b0c35
fix(gui): standardize hyperlink styling across LabGym
btmlnsn Aug 4, 2026
236b7c3
feat(gui): add resources link to home page
btmlnsn Aug 4, 2026
737c82b
fix(gui): align AF navigation and count diagnostics
btmlnsn Aug 11, 2026
6b2f69c
fix(tests): initialize mywx before wx imports
btmlnsn Aug 11, 2026
1bf12ea
Add probability matrix feature
MyraLyu Mar 9, 2026
c6c92eb
Update probability matrix code
MyraLyu Mar 18, 2026
8e67d3b
Update probability matrix code
MyraLyu Mar 18, 2026
127afef
Implement state transition map feature
MyraLyu Mar 20, 2026
6d668a2
Add a new botton for state-transition-map
MyraLyu Apr 7, 2026
055d4e9
Improve state transition map visualization
MyraLyu Jun 24, 2026
49918fc
Add frame-level probability matrix outputs
MyraLyu Jul 8, 2026
3ec5744
feat(stm): redesign state transition maps
btmlnsn Aug 6, 2026
422a472
fix(stm): polish state transition maps
btmlnsn Aug 10, 2026
ddba002
fix(analysis): distinguish missing heatmap data
btmlnsn Sep 22, 2026
9679e94
fix(analysis): use linear heatmap scale
btmlnsn Sep 22, 2026
61fb95e
fix(analysis): standardize STM edge widths
btmlnsn Sep 22, 2026
ea604d3
tests: calculate and return confusion matrix and report
AL3XPI Mar 10, 2026
4fc05a8
gui: render automated diagnostics dialog with MSV confusion matrix an…
AL3XPI Mar 10, 2026
15ff95d
gui: add safety checks to automated diagnostics table and matrix
AL3XPI Mar 11, 2026
63a9d05
gui: add normalized and raw data toggle to confusion matrix
AL3XPI Mar 11, 2026
161214c
gui: implement clickable confusion matrix cells and cross-platform ex…
AL3XPI Mar 11, 2026
bf3f617
gui: heatmap and threshold dropdown
AL3XPI Mar 25, 2026
7c76313
add NLP html base
AL3XPI Apr 28, 2026
8083fc8
NLP tabs and clickable entries
AL3XPI Apr 30, 2026
1c9ac17
training module GUI
AL3XPI May 11, 2026
4473caf
fix uncontrolled ranking logic creep
AL3XPI May 11, 2026
30b9c97
Implement Differential Diagnosis UI and immutable dataset cloning engine
AL3XPI May 12, 2026
2c40f3b
merge visualization
AL3XPI May 12, 2026
7d4c24e
feat: complete triage action plan pdf and h3 variance references
AL3XPI Jun 23, 2026
e77cf3b
feat: complete centroid calc
AL3XPI Jun 24, 2026
2603c44
cleaned up major conf
AL3XPI Jul 5, 2026
ffc0e4d
reportlab and toml
AL3XPI Aug 2, 2026
2576cb2
feat(categorizer): add interactive diagnostics
btmlnsn Aug 13, 2026
0123ee7
fix(categorizer): defer analyzer imports
btmlnsn Aug 13, 2026
e56c9a4
fix(windows): constrain PyTorch compatibility
btmlnsn Aug 13, 2026
10a87e5
fix(tests): read AC source files as UTF-8
btmlnsn Aug 13, 2026
3ecf256
fix(diagnostic): prevent matrix value clipping
btmlnsn Aug 13, 2026
11f9e4b
refactor(tests): use semantic diagnostics names
btmlnsn Aug 13, 2026
7d5e02b
fix(diagnostics): avoid native DC finalization
btmlnsn Aug 13, 2026
9c19544
style: remove trailing whitespace from diagnostics
btmlnsn Sep 23, 2026
f70cf53
fix(categorizer): remove duplicate diagnostics return block
btmlnsn Sep 23, 2026
540701e
fix(gui): restore accepted training module layout
btmlnsn Sep 23, 2026
69a9d9e
Merge pull request #3 from alisaficiciyan/pr/workflow-map-training-ux
btmlnsn Sep 23, 2026
3dc3081
fix(gui): avoid Windows-only curses import
btmlnsn Sep 24, 2026
d261ad5
Merge pull request #4 from MyraLyu/pr/probability-outputs-state-trans…
btmlnsn Sep 24, 2026
40c716b
fix(gui): avoid Windows-only curses import
btmlnsn Sep 24, 2026
1099daa
fix(ci): avoid macOS native teardown crash
btmlnsn Sep 24, 2026
9784ab1
fix(ci): pin macOS GUI test dependencies
btmlnsn Sep 24, 2026
6fbbb41
ci(nox): isolate macOS 3.9 wx.App tests
btmlnsn Aug 14, 2026
6102323
fix(ci): isolate macOS wx.App test lifecycles
btmlnsn Sep 24, 2026
cd0142e
ci(pytest): remove unused coverage filters
btmlnsn Aug 14, 2026
ec37729
docs: restore Windows installation guidance
btmlnsn Sep 24, 2026
b5f8227
Merge pull request #5 from AL3XPI/pr/categorizer-diagnostics-triage
btmlnsn Sep 24, 2026
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
4 changes: 4 additions & 0 deletions LabGym/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def main() -> None:
wx.App()
mywx.bring_wxapp_to_foreground()

# Establish Windows AppUserModelID / macOS Dock icon before any
# probe dialog or main window is shown (taskbar process identity only).
gui_main.setup_application_icons()

# Perform some pre-op sanity checks and probes of outside resources.
probes.probes()

Expand Down
197 changes: 196 additions & 1 deletion LabGym/analyzebehavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,44 @@
contour_frame,
generate_patternimage,
generate_patternimage_all,
plot_state_transition_map,
)
logger.debug('importing tools (done)')


PROBABILITY_HEATMAP_MISSING_COLOR = 'gray'
PROBABILITY_HEATMAP_MISSING_LEGEND = 'Gray: missing / non-finite'


def prepare_probability_heatmap_array(values):
'''Clip finite probabilities for linear 0–1 heat maps; mask non-finite values.

Does not modify the input array. Finite values are clipped to
[0, 1]. NaN, inf, and -inf are masked rather than converted to
0 or 1.
'''
data = np.array(values, dtype=np.float64, copy=True)
finite = np.isfinite(data)
clipped = np.empty_like(data)
clipped[finite] = np.clip(data[finite], 0.0, 1.0)
clipped[~finite] = np.nan
return np.ma.masked_where(~finite, clipped)


def probability_heatmap_colormap():
'''Return an inferno copy with gray for masked / non-finite cells.'''
import matplotlib.pyplot as plt
cmap = plt.get_cmap('inferno').copy()
cmap.set_bad(color=PROBABILITY_HEATMAP_MISSING_COLOR, alpha=1.0)
return cmap


def probability_heatmap_norm():
'''Return a fixed linear 0–1 scale, independent of the plotted data.'''
from matplotlib.colors import Normalize
return Normalize(vmin=0.0, vmax=1.0)


class AnalyzeAnimal():

def __init__(self):
Expand Down Expand Up @@ -646,10 +680,171 @@ def categorize_behaviors(self,path_to_categorizer,uncertain=0,min_length=None):
self.event_probability[n][i-continued_length:i]=[['NA',-1]]*continued_length
continued_length=1
i+=1

self.export_probability_matrices(make_heatmap=True)

print('Behavioral categorization completed!')
self.log.append('Behavioral categorization completed!')

def export_probability_matrices(self, make_heatmap=True, max_frames_for_heatmap=6000):

import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.patches import Patch

os.makedirs(self.results_path, exist_ok=True)

behavior_names = list(self.all_behavior_parameters.keys())
T = len(self.all_time)

for ID in self.event_probability:
P = np.zeros((T, len(behavior_names)), dtype=np.float32)

for k, behavior_name in enumerate(behavior_names):
probs = self.all_behavior_parameters[behavior_name]['probability'][ID]
P[:, k] = np.array(probs, dtype=np.float32)

np.save(
os.path.join(self.results_path, f'probability_matrix_ID{ID}.npy'),
P
)

df = pd.DataFrame(P, columns=behavior_names)
df.insert(0, 'time_s', np.array(self.all_time))
df.insert(0, 'frame', np.arange(T))
df.to_csv(
os.path.join(self.results_path, f'probability_matrix_ID{ID}.csv'),
index=False,
float_format='%.4f'
)

if make_heatmap:
P_plot = P
stride = 1

if P_plot.shape[0] > max_frames_for_heatmap:
stride = int(np.ceil(P_plot.shape[0] / max_frames_for_heatmap))
P_plot = P_plot[::stride, :]

time_plot = np.array(self.all_time)[::stride]

P_plot = prepare_probability_heatmap_array(P_plot)
P_plot = P_plot.T

num_behaviors, num_frames = P_plot.shape

fig_width = max(18, num_frames / 140)
fig_height = max(8, num_behaviors * 0.55)

fig, ax = plt.subplots(figsize=(fig_width, fig_height), dpi=200)

im = ax.imshow(
P_plot,
aspect='auto',
interpolation='nearest',
cmap=probability_heatmap_colormap(),
norm=probability_heatmap_norm()
)

ax.set_yticks(np.arange(-0.5, num_behaviors, 1), minor=True)
ax.grid(
which='minor',
axis='y',
color='white',
linestyle='-',
linewidth=2.2
)

ax.set_xticks(np.arange(-0.5, num_frames, 1), minor=True)
ax.grid(
which='minor',
axis='x',
color='white',
linestyle='-',
linewidth=0.12,
alpha=0.25
)

ax.tick_params(which='minor', bottom=False, left=False)

if num_frames <= 50:
xticks = np.arange(num_frames)
else:
step = max(1, num_frames // 20)
xticks = np.arange(0, num_frames, step)

ax.set_xticks(xticks)

frame_labels = xticks * stride
time_labels = time_plot[xticks]

ax.set_xticklabels(
[
f'{frame}\n{time:.2f}s'
for frame, time in zip(frame_labels, time_labels)
],
fontsize=9,
rotation=45,
ha='right'
)

ax.set_yticks(np.arange(num_behaviors))
ax.set_yticklabels(
behavior_names,
fontsize=13,
fontweight='bold'
)

ax.set_xlabel(
'Frame / Time (s)' if stride == 1 else f'Frame / Time (s), stride={stride}',
fontsize=14,
fontweight='bold'
)

ax.set_ylabel(
'Behavior',
fontsize=14,
fontweight='bold'
)

ax.set_title(
f'Frame-Level Probability Matrix (ID {ID})',
fontsize=16,
fontweight='bold'
)

cbar = fig.colorbar(im, ax=ax, pad=0.02)
cbar.set_label(
'Probability\n'+PROBABILITY_HEATMAP_MISSING_LEGEND,
fontsize=12,
fontweight='bold'
)
cbar.ax.tick_params(labelsize=10)
ax.legend(
handles=[
Patch(
facecolor=PROBABILITY_HEATMAP_MISSING_COLOR,
edgecolor='black',
label=PROBABILITY_HEATMAP_MISSING_LEGEND,
)
],
loc='upper right',
fontsize=8,
framealpha=0.85,
)

plt.tight_layout()

plt.savefig(
os.path.join(self.results_path, f'probability_heatmap_ID{ID}.png'),
dpi=300,
bbox_inches='tight'
)

plt.close(fig)


def annotate_video(self,ID_colors,behavior_to_include,show_legend=True,interact_all=False):

Expand Down Expand Up @@ -1125,7 +1320,7 @@ def export_results(self,normalize_distance=True,parameter_to_analyze=[]):
if self.categorize_behavior:
events_df=pd.DataFrame(self.event_probability,index=self.all_time)
events_df.to_excel(os.path.join(self.results_path,'all_event_probability.xlsx'),float_format='%.2f',index_label='time/ID')

all_parameters=[]

if self.categorize_behavior:
Expand Down
Loading
Loading