From 085b25ccd9b07fb3d47032da408dcadcc6cbdcc0 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Tue, 26 Nov 2024 07:40:36 -0800 Subject: [PATCH 01/30] added labels and inputs --- src/foraging_gui/Foraging.py | 2 +- src/foraging_gui/ForagingGUI.ui | 46 ++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 9a798d718..a5966920a 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -31,7 +31,7 @@ import webbrowser from pydantic import ValidationError -from StageWidget.main import get_stage_widget +#from StageWidget.main import get_stage_widget import foraging_gui import foraging_gui.rigcontrol as rigcontrol diff --git a/src/foraging_gui/ForagingGUI.ui b/src/foraging_gui/ForagingGUI.ui index d3012194d..e87dbe19f 100644 --- a/src/foraging_gui/ForagingGUI.ui +++ b/src/foraging_gui/ForagingGUI.ui @@ -3414,7 +3414,7 @@ Double dipping: - + 0 @@ -3428,7 +3428,7 @@ Double dipping: - 20 + 30 @@ -3904,7 +3904,7 @@ Double dipping: - + 0 @@ -3912,7 +3912,7 @@ Double dipping: - stop ignores> + auto stop ignore window: Qt::AutoText @@ -4196,6 +4196,44 @@ Double dipping: + + + + + 0 + 0 + + + + auto stop ignore ratio threshold: + + + Qt::AutoText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 70 + 16777215 + + + + .8 + + + From 91b55c97a83fcb314f43ceda2fb569e8e64a9c1a Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Tue, 26 Nov 2024 08:29:00 -0800 Subject: [PATCH 02/30] stop session if ignored threshold is exceeded --- src/foraging_gui/MyFunctions.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/foraging_gui/MyFunctions.py b/src/foraging_gui/MyFunctions.py index a35ad33ee..dd66b2941 100644 --- a/src/foraging_gui/MyFunctions.py +++ b/src/foraging_gui/MyFunctions.py @@ -1154,7 +1154,7 @@ def _ShowInformation(self): def _CheckStop(self): '''Stop if there are many ingoral trials or if the maximam trial is exceeded MaxTrial''' - StopIgnore=int(self.TP_StopIgnores)-1 + StopIgnore=round(self.TP_auto_stop_ignore_ratio_threshold*self.TP_auto_stop_ignore_win) MaxTrial=int(self.TP_MaxTrial)-2 # trial number starts from 0 MaxTime=float(self.TP_MaxTime)*60 # convert minutes to seconds if hasattr(self, 'BS_CurrentRunningTime'): @@ -1166,26 +1166,25 @@ def _CheckStop(self): stop = False msg ='' warning_label_text = '' - warning_label_color = 'color: gray;' # Check for reasons to stop early - if (np.shape(self.B_AnimalResponseHistory)[0]>=StopIgnore) and (np.all(self.B_AnimalResponseHistory[-StopIgnore:]==2)): + non_auto_reward = self.B_AnimalResponseHistory[np.where(~self.TP_AutoReward)] # isolate non-auto-reward trials + win_sz = self.TP_auto_stop_ignore_win + if non_auto_reward.shape[0] > win_sz and non_auto_reward[-win_sz:][np.where(2)].shape[0] >= StopIgnore: stop=True - msg = 'Stopping the session because the mouse has ignored at least {} consecutive trials'.format(self.TP_StopIgnores) - warning_label_text = 'Stop because ignore trials exceed or equal: '+self.TP_StopIgnores - warning_label_color = self.win.default_warning_color + msg = f'Stopping the session because the mouse has ignored at least ' \ + f'{self.TP_auto_stop_ignore_ratio_threshold*100}% of {self.TP_auto_stop_ignore_win} ' \ + f'consecutive trials' + warning_label_text = 'Stop because ignore trials exceed or equal: '+\ + f'{self.TP_auto_stop_ignore_ratio_threshold*100}% of {self.TP_auto_stop_ignore_win}' elif self.B_CurrentTrialN>MaxTrial: stop=True msg = 'Stopping the session because the mouse has reached the maximum trial count: {}'.format(self.TP_MaxTrial) warning_label_text = 'Stop because maximum trials exceed or equal: '+self.TP_MaxTrial - warning_label_color = self.win.default_warning_color elif self.BS_CurrentRunningTime>MaxTime: stop=True msg = 'Stopping the session because the session running time has reached {} minutes'.format(self.TP_MaxTime) warning_label_text = 'Stop because running time exceeds or equals: '+self.TP_MaxTime+'m' - warning_label_color = self.win.default_warning_color - else: - stop=False # Update the warning label text/color logging.warning(warning_label_text, extra={'tags': [self.win.warning_log_tag]}) From 5d08028b2d1970f581a3819fbe6edace8dcd860a Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Tue, 26 Nov 2024 08:38:43 -0800 Subject: [PATCH 03/30] adding in 30 minute check --- src/foraging_gui/Foraging.py | 2 +- src/foraging_gui/MyFunctions.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index a5966920a..9a798d718 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -31,7 +31,7 @@ import webbrowser from pydantic import ValidationError -#from StageWidget.main import get_stage_widget +from StageWidget.main import get_stage_widget import foraging_gui import foraging_gui.rigcontrol as rigcontrol diff --git a/src/foraging_gui/MyFunctions.py b/src/foraging_gui/MyFunctions.py index dd66b2941..71019bc74 100644 --- a/src/foraging_gui/MyFunctions.py +++ b/src/foraging_gui/MyFunctions.py @@ -1170,7 +1170,8 @@ def _CheckStop(self): # Check for reasons to stop early non_auto_reward = self.B_AnimalResponseHistory[np.where(~self.TP_AutoReward)] # isolate non-auto-reward trials win_sz = self.TP_auto_stop_ignore_win - if non_auto_reward.shape[0] > win_sz and non_auto_reward[-win_sz:][np.where(2)].shape[0] >= StopIgnore: + if self.BS_CurrentRunningTime >= 30 and \ + non_auto_reward.shape[0] > win_sz and non_auto_reward[-win_sz:][np.where(2)].shape[0] >= StopIgnore: stop=True msg = f'Stopping the session because the mouse has ignored at least ' \ f'{self.TP_auto_stop_ignore_ratio_threshold*100}% of {self.TP_auto_stop_ignore_win} ' \ From 636019a1cc0362ac0fe037d54281b674962751a5 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Tue, 26 Nov 2024 09:09:57 -0800 Subject: [PATCH 04/30] update ephys ui file --- src/foraging_gui/Dialogs.py | 2 +- src/foraging_gui/ForagingGUI_Ephys.ui | 52 ++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/foraging_gui/Dialogs.py b/src/foraging_gui/Dialogs.py index 8cb419766..baaad96af 100644 --- a/src/foraging_gui/Dialogs.py +++ b/src/foraging_gui/Dialogs.py @@ -2815,7 +2815,7 @@ def update_auto_train_lock(self, engaged): for widget in self.widgets_locked_by_auto_train: # Exclude some fields so that RAs can change them without going off-curriculum # See https://github.com/AllenNeuralDynamics/aind-behavior-blog/issues/620 - if widget.objectName() in ["StopIgnores", "MaxTrial", "MaxTime"]: + if widget.objectName() in ["auto_stop_ignore_win", "MaxTrial", "MaxTime"]: continue widget.setEnabled(False) # set the border color to green diff --git a/src/foraging_gui/ForagingGUI_Ephys.ui b/src/foraging_gui/ForagingGUI_Ephys.ui index 789f2631e..da9f01f02 100644 --- a/src/foraging_gui/ForagingGUI_Ephys.ui +++ b/src/foraging_gui/ForagingGUI_Ephys.ui @@ -1170,7 +1170,7 @@ 1 - + 542 @@ -1186,7 +1186,7 @@ - stop ignores> + auto stop ignore window: Qt::AutoText @@ -1195,7 +1195,7 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + 614 @@ -1211,7 +1211,51 @@ - 20 + 30 + + + + + + 1080 + 232 + 67 + 16 + + + + + 0 + 0 + + + + auto stop ignore ratio threshold: + + + Qt::AutoText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 1150 + 232 + 80 + 20 + + + + + 0 + 0 + + + + .8 From 6de004a7977473bce9cc0ab75b107a191a520879 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Wed, 27 Nov 2024 06:40:53 -0800 Subject: [PATCH 05/30] using B_AutoWaterTrial --- src/foraging_gui/MyFunctions.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/foraging_gui/MyFunctions.py b/src/foraging_gui/MyFunctions.py index 71019bc74..2cc2973ac 100644 --- a/src/foraging_gui/MyFunctions.py +++ b/src/foraging_gui/MyFunctions.py @@ -1167,8 +1167,9 @@ def _CheckStop(self): msg ='' warning_label_text = '' - # Check for reasons to stop early - non_auto_reward = self.B_AnimalResponseHistory[np.where(~self.TP_AutoReward)] # isolate non-auto-reward trials + # Check for reasons to stop early + auto_rewards = np.array([any(x) for x in np.column_stack(self.B_AutoWaterTrial.astype(bool))]) + non_auto_reward = self.B_AnimalResponseHistory[np.where(~auto_rewards)] # isolate non-auto-reward trials win_sz = self.TP_auto_stop_ignore_win if self.BS_CurrentRunningTime >= 30 and \ non_auto_reward.shape[0] > win_sz and non_auto_reward[-win_sz:][np.where(2)].shape[0] >= StopIgnore: From 3e125bc0ca424b47a4d63a21fcb4adf3c19318fb Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 9 Dec 2024 15:05:46 -0800 Subject: [PATCH 06/30] fixing bugs --- src/foraging_gui/MyFunctions.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/foraging_gui/MyFunctions.py b/src/foraging_gui/MyFunctions.py index 2cc2973ac..1f01af364 100644 --- a/src/foraging_gui/MyFunctions.py +++ b/src/foraging_gui/MyFunctions.py @@ -1154,10 +1154,10 @@ def _ShowInformation(self): def _CheckStop(self): '''Stop if there are many ingoral trials or if the maximam trial is exceeded MaxTrial''' - StopIgnore=round(self.TP_auto_stop_ignore_ratio_threshold*self.TP_auto_stop_ignore_win) + StopIgnore=round(float(self.TP_auto_stop_ignore_ratio_threshold)*int(self.TP_auto_stop_ignore_win)) MaxTrial=int(self.TP_MaxTrial)-2 # trial number starts from 0 MaxTime=float(self.TP_MaxTime)*60 # convert minutes to seconds - if hasattr(self, 'BS_CurrentRunningTime'): + if hasattr(self, 'BS_CurrentRunningTime'): pass else: self.BS_CurrentRunningTime=0 @@ -1169,16 +1169,17 @@ def _CheckStop(self): # Check for reasons to stop early auto_rewards = np.array([any(x) for x in np.column_stack(self.B_AutoWaterTrial.astype(bool))]) - non_auto_reward = self.B_AnimalResponseHistory[np.where(~auto_rewards)] # isolate non-auto-reward trials - win_sz = self.TP_auto_stop_ignore_win - if self.BS_CurrentRunningTime >= 30 and \ - non_auto_reward.shape[0] > win_sz and non_auto_reward[-win_sz:][np.where(2)].shape[0] >= StopIgnore: + non_auto_reward = self.B_AnimalResponseHistory[np.where(~auto_rewards.astype(bool))] # isolate non-auto-reward + win_sz = int(self.TP_auto_stop_ignore_win) + + if self.BS_CurrentRunningTime >= 30 and len(np.where(non_auto_reward[-win_sz:] == 2)[0]) >= StopIgnore: stop=True + threshold = float(self.TP_auto_stop_ignore_ratio_threshold)*100 msg = f'Stopping the session because the mouse has ignored at least ' \ - f'{self.TP_auto_stop_ignore_ratio_threshold*100}% of {self.TP_auto_stop_ignore_win} ' \ + f'{threshold}% of {self.TP_auto_stop_ignore_win} ' \ f'consecutive trials' warning_label_text = 'Stop because ignore trials exceed or equal: '+\ - f'{self.TP_auto_stop_ignore_ratio_threshold*100}% of {self.TP_auto_stop_ignore_win}' + f'{threshold}% of {self.TP_auto_stop_ignore_win}' elif self.B_CurrentTrialN>MaxTrial: stop=True msg = 'Stopping the session because the mouse has reached the maximum trial count: {}'.format(self.TP_MaxTrial) From a30875ae6cb32d1868fa0349784f94db80d12d32 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 9 Dec 2024 15:59:43 -0800 Subject: [PATCH 07/30] adding min time and reoragnizing ephys --- src/foraging_gui/ForagingGUI.ui | 40 ++- src/foraging_gui/ForagingGUI_Ephys.ui | 374 +++++++++++++++++--------- src/foraging_gui/MyFunctions.py | 4 +- 3 files changed, 283 insertions(+), 135 deletions(-) diff --git a/src/foraging_gui/ForagingGUI.ui b/src/foraging_gui/ForagingGUI.ui index e87dbe19f..7a9f449f3 100644 --- a/src/foraging_gui/ForagingGUI.ui +++ b/src/foraging_gui/ForagingGUI.ui @@ -4197,6 +4197,44 @@ Double dipping: + + + + 0 + 0 + + + + min time (min): + + + Qt::AutoText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 70 + 16777215 + + + + 30 + + + + @@ -4215,7 +4253,7 @@ Double dipping: - + diff --git a/src/foraging_gui/ForagingGUI_Ephys.ui b/src/foraging_gui/ForagingGUI_Ephys.ui index da9f01f02..370451f03 100644 --- a/src/foraging_gui/ForagingGUI_Ephys.ui +++ b/src/foraging_gui/ForagingGUI_Ephys.ui @@ -1170,50 +1170,6 @@ 1 - - - - 542 - 232 - 67 - 16 - - - - - 0 - 0 - - - - auto stop ignore window: - - - Qt::AutoText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 614 - 232 - 80 - 20 - - - - - 0 - 0 - - - - 30 - - @@ -1671,94 +1627,6 @@ 0.1,0.3,0.7 - - - - 790 - 232 - 67 - 16 - - - - - 0 - 0 - - - - max trial= - - - Qt::AutoText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 863 - 232 - 80 - 20 - - - - - 0 - 0 - - - - 1000 - - - - - - 1080 - 232 - 80 - 20 - - - - - 0 - 0 - - - - 120 - - - - - - 983 - 232 - 91 - 20 - - - - - 0 - 0 - - - - max time (min)= - - - Qt::AutoText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - @@ -2242,6 +2110,248 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + 10 + 315 + 79 + 16 + + + + + 0 + 0 + + + + Auto stop: + + + Qt::AutoText + + + + + + 320 + 315 + 67 + 16 + + + + + 0 + 0 + + + + max trial= + + + Qt::AutoText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 400 + 312 + 80 + 20 + + + + + 0 + 0 + + + + 1000 + + + + + + 581 + 312 + 80 + 20 + + + + + 0 + 0 + + + + 120 + + + + + + 490 + 315 + 91 + 20 + + + + + 0 + 0 + + + + max time (min)= + + + Qt::AutoText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 772 + 312 + 80 + 20 + + + + + 0 + 0 + + + + 30 + + + + + + 681 + 315 + 91 + 20 + + + + + 0 + 0 + + + + min time (min)= + + + Qt::AutoText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 150 + 315 + 75 + 16 + + + + + 0 + 0 + + + + ignore window: + + + Qt::AutoText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 230 + 312 + 80 + 20 + + + + + 0 + 0 + + + + 30 + + + + + + 882 + 315 + 180 + 16 + + + + + 0 + 0 + + + + auto stop ignore ratio threshold: + + + Qt::AutoText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 1072 + 312 + 80 + 20 + + + + + 0 + 0 + + + + .8 + + diff --git a/src/foraging_gui/MyFunctions.py b/src/foraging_gui/MyFunctions.py index 1f01af364..9aee2c347 100644 --- a/src/foraging_gui/MyFunctions.py +++ b/src/foraging_gui/MyFunctions.py @@ -1171,8 +1171,8 @@ def _CheckStop(self): auto_rewards = np.array([any(x) for x in np.column_stack(self.B_AutoWaterTrial.astype(bool))]) non_auto_reward = self.B_AnimalResponseHistory[np.where(~auto_rewards.astype(bool))] # isolate non-auto-reward win_sz = int(self.TP_auto_stop_ignore_win) - - if self.BS_CurrentRunningTime >= 30 and len(np.where(non_auto_reward[-win_sz:] == 2)[0]) >= StopIgnore: + min_time = int(self.TP_min_time) + if self.BS_CurrentRunningTime/60 >= 30 and len(np.where(non_auto_reward[-win_sz:] == 2)[0]) >= StopIgnore: stop=True threshold = float(self.TP_auto_stop_ignore_ratio_threshold)*100 msg = f'Stopping the session because the mouse has ignored at least ' \ From 368757e818b8f416e26cbf4d7d88cf6218094c32 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 9 Dec 2024 16:00:22 -0800 Subject: [PATCH 08/30] referencing min time --- src/foraging_gui/MyFunctions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foraging_gui/MyFunctions.py b/src/foraging_gui/MyFunctions.py index 9aee2c347..a94f7ec21 100644 --- a/src/foraging_gui/MyFunctions.py +++ b/src/foraging_gui/MyFunctions.py @@ -1172,7 +1172,7 @@ def _CheckStop(self): non_auto_reward = self.B_AnimalResponseHistory[np.where(~auto_rewards.astype(bool))] # isolate non-auto-reward win_sz = int(self.TP_auto_stop_ignore_win) min_time = int(self.TP_min_time) - if self.BS_CurrentRunningTime/60 >= 30 and len(np.where(non_auto_reward[-win_sz:] == 2)[0]) >= StopIgnore: + if self.BS_CurrentRunningTime/60 >= min_time and len(np.where(non_auto_reward[-win_sz:] == 2)[0]) >= StopIgnore: stop=True threshold = float(self.TP_auto_stop_ignore_ratio_threshold)*100 msg = f'Stopping the session because the mouse has ignored at least ' \ From 9d4d313c24e93d59e8460d1ab972d9f82aaca6ed Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Tue, 10 Dec 2024 11:41:44 -0800 Subject: [PATCH 09/30] changing formating of ephys gui --- src/foraging_gui/ForagingGUI_Ephys.ui | 64 +++++---------------------- 1 file changed, 10 insertions(+), 54 deletions(-) diff --git a/src/foraging_gui/ForagingGUI_Ephys.ui b/src/foraging_gui/ForagingGUI_Ephys.ui index 370451f03..a952e9194 100644 --- a/src/foraging_gui/ForagingGUI_Ephys.ui +++ b/src/foraging_gui/ForagingGUI_Ephys.ui @@ -1170,50 +1170,6 @@ 1 - - - - 1080 - 232 - 67 - 16 - - - - - 0 - 0 - - - - auto stop ignore ratio threshold: - - - Qt::AutoText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 1150 - 232 - 80 - 20 - - - - - 0 - 0 - - - - .8 - - @@ -2135,7 +2091,7 @@ - 320 + 339 315 67 16 @@ -2160,7 +2116,7 @@ - 400 + 402 312 80 20 @@ -2179,7 +2135,7 @@ - 581 + 613 312 80 20 @@ -2198,7 +2154,7 @@ - 490 + 512 315 91 20 @@ -2223,7 +2179,7 @@ - 772 + 863 312 80 20 @@ -2242,7 +2198,7 @@ - 681 + 762 315 91 20 @@ -2267,7 +2223,7 @@ - 150 + 105 315 75 16 @@ -2292,7 +2248,7 @@ - 230 + 190 312 80 20 @@ -2324,7 +2280,7 @@ - auto stop ignore ratio threshold: + ignore ratio threshold: Qt::AutoText @@ -2336,7 +2292,7 @@ - 1072 + 1081 312 80 20 From b6ab2b7663f3514e644befaea7699ba8021cfb63 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Wed, 11 Dec 2024 09:30:33 -0800 Subject: [PATCH 10/30] changing layout --- src/foraging_gui/ForagingGUI.ui | 8 ++++---- src/foraging_gui/ForagingGUI_Ephys.ui | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/foraging_gui/ForagingGUI.ui b/src/foraging_gui/ForagingGUI.ui index 7a9f449f3..ccf1dc1bb 100644 --- a/src/foraging_gui/ForagingGUI.ui +++ b/src/foraging_gui/ForagingGUI.ui @@ -3567,7 +3567,7 @@ Double dipping: - + @@ -3982,7 +3982,7 @@ Double dipping: - + @@ -4234,7 +4234,7 @@ Double dipping: - + @@ -4253,7 +4253,7 @@ Double dipping: - + diff --git a/src/foraging_gui/ForagingGUI_Ephys.ui b/src/foraging_gui/ForagingGUI_Ephys.ui index a952e9194..ce38a260a 100644 --- a/src/foraging_gui/ForagingGUI_Ephys.ui +++ b/src/foraging_gui/ForagingGUI_Ephys.ui @@ -2091,7 +2091,7 @@ - 339 + 1004 315 67 16 @@ -2116,7 +2116,7 @@ - 402 + 1081 312 80 20 @@ -2267,7 +2267,7 @@ - 882 + 212 315 180 16 @@ -2292,7 +2292,7 @@ - 1081 + 402 312 80 20 From b787679acaf335239054de4f64cd13b0ea78548b Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Wed, 11 Dec 2024 10:12:56 -0800 Subject: [PATCH 11/30] changing setstylesheet to correct syntax --- src/foraging_gui/Dialogs.py | 26 +++++++++++++------------- src/foraging_gui/Foraging.py | 30 +++++++++++++++--------------- src/foraging_gui/MyFunctions.py | 7 ++----- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/foraging_gui/Dialogs.py b/src/foraging_gui/Dialogs.py index bc0b6f43b..43d03fd0e 100644 --- a/src/foraging_gui/Dialogs.py +++ b/src/foraging_gui/Dialogs.py @@ -322,7 +322,7 @@ def __init__(self, MainWindow,parent=None): self._UpdateFigure() self.setWindowTitle('Water Calibration: {}'.format(self.MainWindow.current_box)) self.Warning.setText('') - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') # find all buttons and set them to not be the default button for container in [self]: for child in container.findChildren((QtWidgets.QPushButton)): @@ -412,7 +412,7 @@ def _Finished(self): self.StartCalibratingLeft.setEnabled(True) self.StartCalibratingRight.setEnabled(True) self.Warning.setText('Calibration Finished') - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') def _Continue(self): @@ -515,7 +515,7 @@ def _StartCalibratingLeft(self): self.StartCalibratingLeft.setChecked(False) self.StartCalibratingLeft.setStyleSheet("background-color : none") self.Warning.setText('Calibration was terminated!') - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') self.StartCalibratingRight.setEnabled(True) return @@ -666,7 +666,7 @@ def _StartCalibratingRight(self): self.StartCalibratingRight.setChecked(False) self.StartCalibratingRight.setStyleSheet("background-color : none") self.Warning.setText('Calibration was terminated!') - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') self.StartCalibratingRight.setEnabled(True) return @@ -816,7 +816,7 @@ def _CalibrationStatus(self,opentime, weight_before, i, cycle, interval): '\nTime remaining: {}'.format(self._TimeRemaining( i,cycle,opentime,interval)) ) - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') def _Save(self,valve,valve_open_time,valve_open_interval,cycle,total_water,tube_weight,append=False): '''save the calibrated result and update the figure''' @@ -1040,7 +1040,7 @@ def _SpotCheck(self, valve: Literal['Left', 'Right']): '\nTime remaining: {}'.format(self._TimeRemaining( i, self.SpotCycle, open_time, self.SpotInterval)) ) - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') # set the valve open time getattr(self.MainWindow.Channel, f'{valve}Value')(float(open_time) * 1000) @@ -1558,12 +1558,12 @@ def _Capture(self): self.Warning.setText('') if self.Location_1.currentText()=='Both': self.Warning.setText('Data not captured! Please choose left or right, not both!') - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') self.Warning.setAlignment(Qt.AlignCenter) return if self.LaserPowerMeasured.text()=='': self.Warning.setText('Data not captured! Please enter power measured!') - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') self.Warning.setAlignment(Qt.AlignCenter) return for attr_name in dir(self): @@ -1600,7 +1600,7 @@ def _Save(self): except Exception as e: logging.error(str(e)) self.Warning.setText('Data not saved! Please Capture the power first!') - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') self.Warning.setAlignment(Qt.AlignCenter) return # delete invalid indices @@ -1684,7 +1684,7 @@ def _Save(self): self.Warning.setText('') if LaserCalibrationResults=={}: self.Warning.setText('Data not saved! Please enter power measured!') - self.Warning.setStyleSheet(self.MainWindow.default_warning_color) + self.Warning.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') self.Warning.setAlignment(Qt.AlignCenter) return self.MainWindow.LaserCalibrationResults=LaserCalibrationResults @@ -2296,7 +2296,7 @@ def update_auto_train_fields(self, self.label_curriculum_name.setText('subject not found') self.label_last_actual_stage.setText('subject not found') self.label_next_stage_suggested.setText('subject not found') - self.label_subject_id.setStyleSheet(self.MainWindow.default_warning_color) + self.label_subject_id.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') # disable some stuff self.checkBox_override_stage.setChecked(False) @@ -2380,7 +2380,7 @@ def update_auto_train_fields(self, else: self.label_last_actual_stage.setText('irrelevant (curriculum overridden)') self.label_next_stage_suggested.setText('irrelevant') - self.label_next_stage_suggested.setStyleSheet(self.MainWindow.default_warning_color) + self.label_next_stage_suggested.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') # Set override stage automatically self.checkBox_override_stage.setChecked(True) @@ -2857,7 +2857,7 @@ def update_auto_train_lock(self, engaged): widget.setStyleSheet("") self.MainWindow.TrainingParameters.setStyleSheet("") self.MainWindow.label_auto_train_stage.setText("off curriculum") - self.MainWindow.label_auto_train_stage.setStyleSheet(self.MainWindow.default_warning_color) + self.MainWindow.label_auto_train_stage.setStyleSheet(f'color: {self.MainWindow.default_warning_color};') # enable override diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 4d7b33bc2..122706fe1 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -255,7 +255,7 @@ def _show_disk_space(self): self.diskspace.setText(f"Used space: {used/1024**3:.2f}GB Free space: {free/1024**3:.2f}GB") self.DiskSpaceProgreeBar.setValue(int(used/total*100)) if free/1024**3 < 100 or used/total > 0.9: - self.DiskSpaceProgreeBar.setStyleSheet("QProgressBar::chunk {background-"+self.default_warning_color+"}") + self.DiskSpaceProgreeBar.setStyleSheet(f"QProgressBar::chunk {{background-color: {self.default_warning_color};}}") logging.warning(f"Low disk space Used space: {used/1024**3:.2f}GB Free space: {free/1024**3:.2f}GB") else: self.DiskSpaceProgreeBar.setStyleSheet("QProgressBar::chunk {background-color: green;}") @@ -299,19 +299,19 @@ def _LoadUI(self): logging.info('Using ForagingGUI.ui interface') self.label_date.setText(str(date.today())) self.default_warning_color="purple" - self.default_text_color="color: purple;" - self.default_text_background_color='background-color: purple;' + self.default_text_color="purple" + self.default_text_background_color='purple' elif self.default_ui=='ForagingGUI_Ephys.ui': logging.info('Using ForagingGUI_Ephys.ui interface') self.Visualization.setTitle(str(date.today())) self.default_warning_color="red" - self.default_text_color="color: red;" - self.default_text_background_color='background-color: red;' + self.default_text_color="red" + self.default_text_background_color='red' else: logging.info('Using ForagingGUI.ui interface') - self.default_warning_color="color: red;" - self.default_text_color='color: red;' - self.default_text_background_color='background-color: red;' + self.default_warning_color="red" + self.default_text_color='red' + self.default_text_background_color='red' def connectSignalsSlots(self): '''Define callbacks''' @@ -556,7 +556,7 @@ def _manage_warning_labels(self,warning_labels,warning_text=''): warning_labels = [warning_labels] for warning_label in warning_labels: warning_label.setText(warning_text) - warning_label.setStyleSheet(self.default_warning_color) + warning_label.setStyleSheet(f'color: {self.default_warning_color};') def _session_list(self): '''show all sessions of the current animal and load the selected session by drop down list''' @@ -962,7 +962,7 @@ def _no_stage(self): self.Warning_Newscale.setText('Lost newscale stage connection') else: self.Warning_Newscale.setText('Newscale stage not connected') - self.Warning_Newscale.setStyleSheet(self.default_warning_color) + self.Warning_Newscale.setStyleSheet(f'color: {self.default_warning_color};') def _connect_stage(self,instance): '''connect to a stage''' @@ -1986,11 +1986,11 @@ def _CheckTextChange(self): self.Continue=0 if child.objectName() in {'LickSpoutReferenceArea','Fundee','ProjectCode','GrantNumber','FundingSource','Investigators','ProbeTarget','RigMetadataFile','Experimenter', 'UncoupledReward', 'ExtraWater','laser_1_target','laser_2_target','laser_1_calibration_power','laser_2_calibration_power','laser_1_calibration_voltage','laser_2_calibration_voltage'}: - child.setStyleSheet(self.default_text_color) + child.setStyleSheet(f'color: {self.default_text_color};') self.Continue=1 if child.text()=='': # If empty, change background color and wait for confirmation self.UpdateParameters=0 - child.setStyleSheet(self.default_text_background_color) + child.setStyleSheet(f'background-color: {self.default_text_background_color};') self.Continue=1 if child.objectName() in {'RunLength','WindowSize','StepSize'}: if child.text()=='': @@ -1999,7 +1999,7 @@ def _CheckTextChange(self): child.setStyleSheet('background-color: white;') if self.Continue==1: continue - child.setStyleSheet(self.default_text_color) + child.setStyleSheet(f'color: {self.default_text_color};') try: # it's valid float float(child.text()) @@ -3855,7 +3855,7 @@ def _Start(self): # check experimenter name reply = QMessageBox.critical(self, 'Box {}, Start'.format(self.box_letter), - f'The experimenter is ' + f'The experimenter is ' f'{self.behavior_session_model.experimenter[0]}. Is this correct?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.No: @@ -4588,7 +4588,7 @@ def _UpdateSuggestedWater(self,ManualWater=0): self.TotalWaterWarning.setText('Supplemental water is >3.5! Health issue and LAS should be alerted!') elif self.default_ui=='ForagingGUI_Ephys.ui': self.TotalWaterWarning.setText('Supplemental water is >3.5! Health issue and \n LAS should be alerted!') - self.TotalWaterWarning.setStyleSheet(self.default_warning_color) + self.TotalWaterWarning.setStyleSheet(f'color: {self.default_warning_color};') else: self.TotalWaterWarning.setText('') self.SuggestedWater.setText(str(np.round(suggested_water,3))) diff --git a/src/foraging_gui/MyFunctions.py b/src/foraging_gui/MyFunctions.py index a6ffbac54..86bd65085 100644 --- a/src/foraging_gui/MyFunctions.py +++ b/src/foraging_gui/MyFunctions.py @@ -262,7 +262,7 @@ def _CheckSessionControl(self): else: state='on' self.win.Opto_dialog.SessionControlWarning.setText('Session control state: '+state) - self.win.Opto_dialog.SessionControlWarning.setStyleSheet(self.win.default_warning_color) + self.win.Opto_dialog.SessionControlWarning.setStyleSheet(f'color: {self.win.default_warning_color};') def _get_uncoupled_reward_prob_pool(self): # Get reward prob pool from the input string (e.g., ["0.1", "0.5", "0.9"]) @@ -1166,24 +1166,21 @@ def _CheckStop(self): stop = False msg ='' warning_label_text = '' - warning_label_color = 'color: gray;' + # Check for reasons to stop early if (np.shape(self.B_AnimalResponseHistory)[0]>=StopIgnore) and (np.all(self.B_AnimalResponseHistory[-StopIgnore:]==2)): stop=True msg = 'Stopping the session because the mouse has ignored at least {} consecutive trials'.format(self.TP_StopIgnores) warning_label_text = 'Stop because ignore trials exceed or equal: '+self.TP_StopIgnores - warning_label_color = self.win.default_warning_color elif self.B_CurrentTrialN>MaxTrial: stop=True msg = 'Stopping the session because the mouse has reached the maximum trial count: {}'.format(self.TP_MaxTrial) warning_label_text = 'Stop because maximum trials exceed or equal: '+self.TP_MaxTrial - warning_label_color = self.win.default_warning_color elif self.BS_CurrentRunningTime>MaxTime: stop=True msg = 'Stopping the session because the session running time has reached {} minutes'.format(self.TP_MaxTime) warning_label_text = 'Stop because running time exceeds or equals: '+self.TP_MaxTime+'m' - warning_label_color = self.win.default_warning_color else: stop=False From bb93799d98735797aaae192024d3d0f513419e39 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 09:21:04 -0800 Subject: [PATCH 12/30] fixxing merge errors for autostop logic --- src/foraging_gui/MyFunctions.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/foraging_gui/MyFunctions.py b/src/foraging_gui/MyFunctions.py index 394cfba81..0a9a0f275 100644 --- a/src/foraging_gui/MyFunctions.py +++ b/src/foraging_gui/MyFunctions.py @@ -1166,7 +1166,6 @@ def _CheckStop(self): stop = False msg ='' warning_label_text = '' - # Check for reasons to stop early auto_rewards = np.array([any(x) for x in np.column_stack(self.B_AutoWaterTrial.astype(bool))]) non_auto_reward = self.B_AnimalResponseHistory[np.where(~auto_rewards.astype(bool))] # isolate non-auto-reward @@ -1180,8 +1179,6 @@ def _CheckStop(self): f'consecutive trials' warning_label_text = 'Stop because ignore trials exceed or equal: '+\ f'{threshold}% of {self.TP_auto_stop_ignore_win}' - msg = 'Stopping the session because the mouse has ignored at least {} consecutive trials'.format(self.TP_StopIgnores) - warning_label_text = 'Stop because ignore trials exceed or equal: '+self.TP_StopIgnores elif self.B_CurrentTrialN>MaxTrial: stop=True msg = 'Stopping the session because the mouse has reached the maximum trial count: {}'.format(self.TP_MaxTrial) From 79bd31e41790eb5ab34e11f2d1a8971c52024a95 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 10:38:16 -0800 Subject: [PATCH 13/30] revert file name changes --- src/foraging_gui/Foraging.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index e02e3fc08..dca5ca97f 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -9,7 +9,7 @@ import logging from hashlib import md5 -import logging_loki +#import logging_loki import socket import harp import threading @@ -25,7 +25,7 @@ import serial import numpy as np import pandas as pd -from pykeepass import PyKeePass +#from pykeepass import PyKeePass from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar from scipy.io import savemat, loadmat from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QSizePolicy @@ -2810,6 +2810,7 @@ def _get_folder_structure_old(self): # includes subject and date of session session_name = self.behavior_session_model.session_name = f'behavior_{self.behavior_session_model.subject}_' \ f'{self.behavior_session_model.date.strftime("%Y-%m-%d_%H-%M-%S")}' + id_name = session_name.split("behavior_")[-1] self.SessionFolder=os.path.join(self.default_saveFolder, self.current_box,self.behavior_session_model.subject, session_name) self.MetadataFolder=os.path.join(self.SessionFolder, 'metadata-dir') @@ -2817,9 +2818,9 @@ def _get_folder_structure_old(self): self.HarpFolder=os.path.join(self.SessionFolder, 'HarpFolder') self.VideoFolder=os.path.join(self.SessionFolder, 'VideoFolder') self.PhotometryFolder=os.path.join(self.SessionFolder, 'PhotometryFolder') - self.SaveFileMat=os.path.join(self.behavior_session_model.root_path,f'{session_name}.mat') - self.SaveFileJson=os.path.join(self.behavior_session_model.root_path,f'{session_name}.json') - self.SaveFileParJson=os.path.join(self.behavior_session_model.root_path,f'{session_name}.json') + self.SaveFileMat=os.path.join(self.behavior_session_model.root_path,f'{id_name}.mat') + self.SaveFileJson=os.path.join(self.behavior_session_model.root_path,f'{id_name}.json') + self.SaveFileParJson=os.path.join(self.behavior_session_model.root_path,f'{id_name}.json') def _get_folder_structure_new(self): '''get the folder structure for the new data format''' @@ -2827,13 +2828,14 @@ def _get_folder_structure_new(self): # session_name includes subject and date of session session_name = self.behavior_session_model.session_name=f'behavior_{self.behavior_session_model.subject}_' \ f'{self.behavior_session_model.date.strftime("%Y-%m-%d_%H-%M-%S")}' + id_name = session_name.split("behavior_")[-1] self.SessionFolder=os.path.join(self.default_saveFolder, self.current_box,self.behavior_session_model.subject, session_name) self.behavior_session_model.root_path=os.path.join(self.SessionFolder,'behavior') - self.SaveFileMat=os.path.join(self.behavior_session_model.root_path,f'{session_name}.mat') - self.SaveFileJson=os.path.join(self.behavior_session_model.root_path,f'{session_name}.json') - self.SaveFileParJson=os.path.join(self.behavior_session_model.root_path,f'{session_name}_par.json') - self.behavior_session_modelJson = os.path.join(self.behavior_session_model.root_path,f'behavior_session_model_{session_name}.json') + self.SaveFileMat=os.path.join(self.behavior_session_model.root_path,f'{id_name}.mat') + self.SaveFileJson=os.path.join(self.behavior_session_model.root_path,f'{id_name}.json') + self.SaveFileParJson=os.path.join(self.behavior_session_model.root_path,f'{id_name}_par.json') + self.behavior_session_modelJson = os.path.join(self.behavior_session_model.root_path,f'behavior_session_model_{id_name}.json') self.HarpFolder=os.path.join(self.behavior_session_model.root_path,'raw.harp') self.VideoFolder=os.path.join(self.SessionFolder,'behavior-videos') self.PhotometryFolder=os.path.join(self.SessionFolder,'fib') @@ -2950,17 +2952,22 @@ def _Open_getListOfMice(self): Returns a list of mice with data saved on this computer ''' filepath = os.path.join(self.default_saveFolder,self.current_box) - mouse_dirs = os.listdir(filepath) + now = datetime.now() + all_mouse_dirs = os.listdir(filepath) + dates = [datetime.fromtimestamp(os.path.getmtime(os.path.join(self.default_saveFolder, self.current_box,path))) + for path in all_mouse_dirs] + mouse_dirs = [mouse_dir for mouse_dir, mod_date in zip(all_mouse_dirs, dates) if (now-mod_date).days <= 14] + print(mouse_dirs) mice = [] for m in mouse_dirs: session_dir = os.path.join(self.default_saveFolder, self.current_box, str(m)) sessions = os.listdir(session_dir) - if len(sessions) == 0 : - continue for s in sessions: + print(s) if 'behavior_' in s: json_file = os.path.join(self.default_saveFolder, self.current_box, str(m), s,'behavior',s.split('behavior_')[1]+'.json') + print(json_file) if os.path.isfile(json_file): mice.append(m) break From bb51c13c13b6e065689c443646d7e58e452334a6 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 11:19:24 -0800 Subject: [PATCH 14/30] adding back in logging --- src/foraging_gui/Foraging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index dca5ca97f..a10612f3e 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -9,7 +9,7 @@ import logging from hashlib import md5 -#import logging_loki +import logging_loki import socket import harp import threading @@ -25,7 +25,7 @@ import serial import numpy as np import pandas as pd -#from pykeepass import PyKeePass +from pykeepass import PyKeePass from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar from scipy.io import savemat, loadmat from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QSizePolicy From 05a8f7724f44595e2456a245207446a6c4c721d8 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 11:24:19 -0800 Subject: [PATCH 15/30] removing print staements --- src/foraging_gui/Foraging.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index a10612f3e..1646f52a9 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2957,17 +2957,14 @@ def _Open_getListOfMice(self): dates = [datetime.fromtimestamp(os.path.getmtime(os.path.join(self.default_saveFolder, self.current_box,path))) for path in all_mouse_dirs] mouse_dirs = [mouse_dir for mouse_dir, mod_date in zip(all_mouse_dirs, dates) if (now-mod_date).days <= 14] - print(mouse_dirs) mice = [] for m in mouse_dirs: session_dir = os.path.join(self.default_saveFolder, self.current_box, str(m)) sessions = os.listdir(session_dir) for s in sessions: - print(s) if 'behavior_' in s: json_file = os.path.join(self.default_saveFolder, self.current_box, str(m), s,'behavior',s.split('behavior_')[1]+'.json') - print(json_file) if os.path.isfile(json_file): mice.append(m) break From 5330f6d7fb497437c3fa9004325e1997d8a179d1 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 14:26:52 -0800 Subject: [PATCH 16/30] added experimenter name to load combobox and verify box --- src/foraging_gui/Foraging.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 1646f52a9..c8ce79104 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -9,7 +9,7 @@ import logging from hashlib import md5 -import logging_loki +#import logging_loki import socket import harp import threading @@ -25,7 +25,7 @@ import serial import numpy as np import pandas as pd -from pykeepass import PyKeePass +#from pykeepass import PyKeePass from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar from scipy.io import savemat, loadmat from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QSizePolicy @@ -2874,7 +2874,7 @@ def _Concat(self,widget_dict,Obj,keyname): def _OpenLast(self): self._Open(open_last=True) - def _OpenLast_find_session(self,mouse_id): + def _OpenLast_find_session(self,mouse_id, experimenter): ''' Returns the filepath of the last available session of this mouse Returns a tuple (Bool, str) @@ -2913,7 +2913,11 @@ def _OpenLast_find_session(self,mouse_id): session_date = date.split('-')[1]+'/'+date.split('-')[2]+'/'+date.split('-')[0] reply = QMessageBox.information(self, 'Box {}, Please verify'.format(self.box_letter), - 'Mouse ID: {}
Last session: {}
Filename: {}'.format(mouse_id, session_date, s), + '' + 'Mouse ID: {}
' + 'Last session: {}
' + 'Filename: {}
' + 'Experimenter: {}'.format(mouse_id, session_date, s, experimenter), QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Ok) if reply == QMessageBox.Cancel: logging.info('User hit cancel') @@ -2958,6 +2962,7 @@ def _Open_getListOfMice(self): for path in all_mouse_dirs] mouse_dirs = [mouse_dir for mouse_dir, mod_date in zip(all_mouse_dirs, dates) if (now-mod_date).days <= 14] mice = [] + experimenters = [] for m in mouse_dirs: session_dir = os.path.join(self.default_saveFolder, self.current_box, str(m)) sessions = os.listdir(session_dir) @@ -2966,9 +2971,13 @@ def _Open_getListOfMice(self): json_file = os.path.join(self.default_saveFolder, self.current_box, str(m), s,'behavior',s.split('behavior_')[1]+'.json') if os.path.isfile(json_file): + with open(json_file, 'r') as file: + name = json.load(file)["Experimenter"] mice.append(m) + print(name) + experimenters.append(name) break - return mice + return mice, experimenters def _Open(self,open_last = False,input_file = ''): if input_file == '': @@ -2976,14 +2985,15 @@ def _Open(self,open_last = False,input_file = ''): self._StopCurrentSession() if open_last: - mice = self._Open_getListOfMice() - W = MouseSelectorDialog(self, mice) + mice, experimenters = self._Open_getListOfMice() + W = MouseSelectorDialog(self, [m + ' ' + n for m, n in zip(mice, experimenters)]) - ok, mouse_id = ( + ok, info = ( W.exec_() == QtWidgets.QDialog.Accepted, W.combo.currentText(), ) - + mouse_id = info.split(' ', 1)[0] + experimenter = None if mouse_id not in mice else experimenters[mice.index(mouse_id)] if not ok: logging.info('Quick load failed, user hit cancel or X') return @@ -2999,7 +3009,7 @@ def _Open(self,open_last = False,input_file = ''): return # attempt to load last session from mouse - good_load, fname = self._OpenLast_find_session(mouse_id) + good_load, fname = self._OpenLast_find_session(mouse_id, experimenter) if not good_load: logging.info('Quick load failed') return From 85bfb8aa2a1b8081996b430c0bce676d97beae76 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 14:35:05 -0800 Subject: [PATCH 17/30] adding imports --- src/foraging_gui/Foraging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index c8ce79104..3950e5e6a 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -9,7 +9,7 @@ import logging from hashlib import md5 -#import logging_loki +import logging_loki import socket import harp import threading @@ -25,7 +25,7 @@ import serial import numpy as np import pandas as pd -#from pykeepass import PyKeePass +from pykeepass import PyKeePass from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar from scipy.io import savemat, loadmat from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QSizePolicy From bef741004ab86b67a6537ed5768893ea71b4d163 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 14:39:03 -0800 Subject: [PATCH 18/30] ability to look up older mouse --- src/foraging_gui/Foraging.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 3950e5e6a..486595b86 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2957,10 +2957,10 @@ def _Open_getListOfMice(self): ''' filepath = os.path.join(self.default_saveFolder,self.current_box) now = datetime.now() - all_mouse_dirs = os.listdir(filepath) + mouse_dirs = os.listdir(filepath) dates = [datetime.fromtimestamp(os.path.getmtime(os.path.join(self.default_saveFolder, self.current_box,path))) - for path in all_mouse_dirs] - mouse_dirs = [mouse_dir for mouse_dir, mod_date in zip(all_mouse_dirs, dates) if (now-mod_date).days <= 14] + for path in mouse_dirs] + two_week = [mouse_dir for mouse_dir, mod_date in zip(mouse_dirs, dates) if (now-mod_date).days <= 14] mice = [] experimenters = [] for m in mouse_dirs: @@ -2977,7 +2977,7 @@ def _Open_getListOfMice(self): print(name) experimenters.append(name) break - return mice, experimenters + return mice, experimenters, two_week def _Open(self,open_last = False,input_file = ''): if input_file == '': @@ -2985,8 +2985,9 @@ def _Open(self,open_last = False,input_file = ''): self._StopCurrentSession() if open_last: - mice, experimenters = self._Open_getListOfMice() - W = MouseSelectorDialog(self, [m + ' ' + n for m, n in zip(mice, experimenters)]) + mice, experimenters, two_week = self._Open_getListOfMice() + # only add mice from two weeks in drop down + W = MouseSelectorDialog(self, [m + ' ' + n for m, n in zip(two_week, experimenters)]) ok, info = ( W.exec_() == QtWidgets.QDialog.Accepted, From 5119e1e466de24936849ae8c4b49eac71e6d1ef0 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 14:41:26 -0800 Subject: [PATCH 19/30] remove print statements --- src/foraging_gui/Foraging.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 486595b86..25bf5406e 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2974,7 +2974,6 @@ def _Open_getListOfMice(self): with open(json_file, 'r') as file: name = json.load(file)["Experimenter"] mice.append(m) - print(name) experimenters.append(name) break return mice, experimenters, two_week From 30fb1c1b2d72b7d1894a7a292f2734ea46a91709 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 15:00:33 -0800 Subject: [PATCH 20/30] fixing bugs in matching name and id --- src/foraging_gui/Foraging.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 25bf5406e..3ef4ea91a 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2958,8 +2958,8 @@ def _Open_getListOfMice(self): filepath = os.path.join(self.default_saveFolder,self.current_box) now = datetime.now() mouse_dirs = os.listdir(filepath) - dates = [datetime.fromtimestamp(os.path.getmtime(os.path.join(self.default_saveFolder, self.current_box,path))) - for path in mouse_dirs] + mouse_dirs.sort(reverse=True, key=lambda x: os.path.getmtime(os.path.join(filepath, x))) # in order of date modified + dates = [datetime.fromtimestamp(os.path.getmtime(os.path.join(filepath, path))) for path in mouse_dirs] two_week = [mouse_dir for mouse_dir, mod_date in zip(mouse_dirs, dates) if (now-mod_date).days <= 14] mice = [] experimenters = [] @@ -2985,6 +2985,7 @@ def _Open(self,open_last = False,input_file = ''): if open_last: mice, experimenters, two_week = self._Open_getListOfMice() + print(mice, experimenters, two_week) # only add mice from two weeks in drop down W = MouseSelectorDialog(self, [m + ' ' + n for m, n in zip(two_week, experimenters)]) From c9c5a0d5c52b617c89677765863ae0df0f31505d Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Thu, 12 Dec 2024 15:01:59 -0800 Subject: [PATCH 21/30] remove print statement --- src/foraging_gui/Foraging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 3ef4ea91a..ae1e628e7 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2984,9 +2984,9 @@ def _Open(self,open_last = False,input_file = ''): self._StopCurrentSession() if open_last: + # list of mice, experimenters, and two week in chronological order form date modified mice, experimenters, two_week = self._Open_getListOfMice() - print(mice, experimenters, two_week) - # only add mice from two weeks in drop down + # only add mice from two weeks in drop down. W = MouseSelectorDialog(self, [m + ' ' + n for m, n in zip(two_week, experimenters)]) ok, info = ( From c4ed6f5e50ff4af237b3956feae1cc481e94ee37 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Fri, 13 Dec 2024 09:01:02 -0800 Subject: [PATCH 22/30] mimicing return press to update step size --- src/foraging_gui/Foraging.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index ae1e628e7..544a23a99 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -3203,6 +3203,7 @@ def _Open(self,open_last = False,input_file = ''): self.stage_widget.movement_page_view.lineEdit_y2.setText(str(last_positions['y2'])) self.stage_widget.movement_page_view.lineEdit_z.setText(str(last_positions['z'])) self.move_aind_stage() + step_size = self.stage_widget.movement_page_view.lineEdit_step_size.returnPressed.emit() elif 'B_NewscalePositions' in Obj.keys() and len(Obj['B_NewscalePositions']) != 0: # cross compatibility for mice run on older version of code. last_positions = Obj['B_NewscalePositions'][-1] self.current_stage.move_absolute_3d(float(last_positions[0]), From fc78d46da88574865aeb87bbe717584f134e754f Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 16 Dec 2024 13:18:59 -0800 Subject: [PATCH 23/30] resetting shadding --- src/foraging_gui/bias_indicator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/foraging_gui/bias_indicator.py b/src/foraging_gui/bias_indicator.py index 7f2015d3b..a11484abc 100644 --- a/src/foraging_gui/bias_indicator.py +++ b/src/foraging_gui/bias_indicator.py @@ -231,6 +231,8 @@ def clear(self): # reset bias list self._biases = [] # reset upper and lower ci + self._upper_scatter_item = PlotDataItem([0], [0], pen='lightgray') + self._lower_scatter_item = PlotDataItem([0], [0], pen='lightgray') self.bias_plot.addItem(self._upper_scatter_item) self.bias_plot.addItem(self._lower_scatter_item) self.bias_plot.addItem(FillBetweenItem(curve1=self._upper_scatter_item, From 06b26e4398dffe76d7c82535067f8f924b5adb56 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 16 Dec 2024 14:28:15 -0800 Subject: [PATCH 24/30] index eperimenter list --- src/foraging_gui/Foraging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 544a23a99..5ed0175f4 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2987,7 +2987,7 @@ def _Open(self,open_last = False,input_file = ''): # list of mice, experimenters, and two week in chronological order form date modified mice, experimenters, two_week = self._Open_getListOfMice() # only add mice from two weeks in drop down. - W = MouseSelectorDialog(self, [m + ' ' + n for m, n in zip(two_week, experimenters)]) + W = MouseSelectorDialog(self, [m + ' ' + experimenters[mice.index(m)] for m in two_week]) ok, info = ( W.exec_() == QtWidgets.QDialog.Accepted, From 97b329e7bfa6188f570ccb8c6e2d91f6385295bf Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 16 Dec 2024 15:16:42 -0800 Subject: [PATCH 25/30] add print to debug --- src/foraging_gui/Foraging.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 5ed0175f4..a72a739ee 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2987,6 +2987,8 @@ def _Open(self,open_last = False,input_file = ''): # list of mice, experimenters, and two week in chronological order form date modified mice, experimenters, two_week = self._Open_getListOfMice() # only add mice from two weeks in drop down. + print(mice) + print(m) W = MouseSelectorDialog(self, [m + ' ' + experimenters[mice.index(m)] for m in two_week]) ok, info = ( From 257ed804985e72c3fc4a088be4e69089903c7b4c Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 16 Dec 2024 15:17:20 -0800 Subject: [PATCH 26/30] print list --- src/foraging_gui/Foraging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index a72a739ee..c0b58872b 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2988,7 +2988,7 @@ def _Open(self,open_last = False,input_file = ''): mice, experimenters, two_week = self._Open_getListOfMice() # only add mice from two weeks in drop down. print(mice) - print(m) + print(two_week) W = MouseSelectorDialog(self, [m + ' ' + experimenters[mice.index(m)] for m in two_week]) ok, info = ( From 9cb0173bd142c69364512ee56ff4e543d161e160 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 16 Dec 2024 15:21:03 -0800 Subject: [PATCH 27/30] add print --- src/foraging_gui/Foraging.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index c0b58872b..c5740536e 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2961,6 +2961,8 @@ def _Open_getListOfMice(self): mouse_dirs.sort(reverse=True, key=lambda x: os.path.getmtime(os.path.join(filepath, x))) # in order of date modified dates = [datetime.fromtimestamp(os.path.getmtime(os.path.join(filepath, path))) for path in mouse_dirs] two_week = [mouse_dir for mouse_dir, mod_date in zip(mouse_dirs, dates) if (now-mod_date).days <= 14] + print(mouse_dirs) + print(two_week) mice = [] experimenters = [] for m in mouse_dirs: @@ -2976,6 +2978,7 @@ def _Open_getListOfMice(self): mice.append(m) experimenters.append(name) break + print(mice) return mice, experimenters, two_week def _Open(self,open_last = False,input_file = ''): From f010103ccd16dedd42de5221a0b8f9c7dd4b5d8b Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 16 Dec 2024 15:22:43 -0800 Subject: [PATCH 28/30] change where two week is created --- src/foraging_gui/Foraging.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index c5740536e..74f5fd430 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2959,10 +2959,6 @@ def _Open_getListOfMice(self): now = datetime.now() mouse_dirs = os.listdir(filepath) mouse_dirs.sort(reverse=True, key=lambda x: os.path.getmtime(os.path.join(filepath, x))) # in order of date modified - dates = [datetime.fromtimestamp(os.path.getmtime(os.path.join(filepath, path))) for path in mouse_dirs] - two_week = [mouse_dir for mouse_dir, mod_date in zip(mouse_dirs, dates) if (now-mod_date).days <= 14] - print(mouse_dirs) - print(two_week) mice = [] experimenters = [] for m in mouse_dirs: @@ -2978,7 +2974,8 @@ def _Open_getListOfMice(self): mice.append(m) experimenters.append(name) break - print(mice) + dates = [datetime.fromtimestamp(os.path.getmtime(os.path.join(filepath, path))) for path in mouse_dirs] + two_week = [mouse_dir for mouse_dir, mod_date in zip(mouse_dirs, dates) if (now - mod_date).days <= 14] return mice, experimenters, two_week def _Open(self,open_last = False,input_file = ''): From b048ec906dfc486f0060e1c2c8824b2539495401 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 16 Dec 2024 15:25:24 -0800 Subject: [PATCH 29/30] iterating through mice list --- src/foraging_gui/Foraging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 74f5fd430..58796802f 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2975,7 +2975,7 @@ def _Open_getListOfMice(self): experimenters.append(name) break dates = [datetime.fromtimestamp(os.path.getmtime(os.path.join(filepath, path))) for path in mouse_dirs] - two_week = [mouse_dir for mouse_dir, mod_date in zip(mouse_dirs, dates) if (now - mod_date).days <= 14] + two_week = [mouse_dir for mouse_dir, mod_date in zip(mice, dates) if (now - mod_date).days <= 14] return mice, experimenters, two_week def _Open(self,open_last = False,input_file = ''): From 398cc81f1aa7c7d174b9f78e8070e86eaeb7bbb6 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Mon, 16 Dec 2024 16:02:11 -0800 Subject: [PATCH 30/30] removing print --- src/foraging_gui/Foraging.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 58796802f..52d6df42a 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -2987,8 +2987,6 @@ def _Open(self,open_last = False,input_file = ''): # list of mice, experimenters, and two week in chronological order form date modified mice, experimenters, two_week = self._Open_getListOfMice() # only add mice from two weeks in drop down. - print(mice) - print(two_week) W = MouseSelectorDialog(self, [m + ' ' + experimenters[mice.index(m)] for m in two_week]) ok, info = (