Skip to content

Commit c145074

Browse files
authored
Merge branch 'main' into production_testing
2 parents 6f2a5a7 + 101b176 commit c145074

File tree

4 files changed

+67
-127
lines changed

4 files changed

+67
-127
lines changed

src/foraging_gui/Foraging.py

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ def __init__(self, parent=None, box_number=1, start_bonsai_ide=True):
243243
# initialize thread lock
244244
self.data_lock = threading.Lock()
245245

246-
# intialize behavior baseline time flag
247-
self.behavior_baseline_period = threading.Event()
248-
self.baseline_min_elapsed = 0
249-
250246
# create bias indicator
251247
self.bias_n_size = 200
252248
self.bias_indicator = BiasIndicator(
@@ -2765,7 +2761,6 @@ def keyPressEvent(self, event=None, allow_reset=False):
27652761
"laser_2_calibration_power",
27662762
"laser_1_calibration_voltage",
27672763
"laser_2_calibration_voltage",
2768-
"hab_time_box"
27692764
}:
27702765
continue
27712766
if child.objectName() == "UncoupledReward":
@@ -4011,11 +4006,11 @@ def _Save(self, ForceSave=0, SaveAs=0, SaveContinue=0, BackupSave=0):
40114006
):
40124007
self._AddWaterLogResult(session)
40134008
elif self.BaseWeight.text() == "" or self.WeightAfter.text() == "":
4014-
logging.warning(f"Waterlog for mouse {self.behavior_session_model.subject} cannot be added to slims"
4015-
f" due do unrecorded weight information.")
4009+
logging.error(f"Waterlog for mouse {self.behavior_session_model.subject} cannot be added to slims "
4010+
f"due do unrecorded weight information.")
40164011
elif session is None:
4017-
logging.warning(f"Waterlog for mouse {self.behavior_session_model.subject} cannot be added to slims"
4018-
f" due do metadata generation failure.")
4012+
logging.error(f"Waterlog for mouse {self.behavior_session_model.subject} cannot be added to slims "
4013+
f"due do metadata generation failure.")
40194014
except Exception as e:
40204015
logging.warning(
40214016
"Meta data is not saved!",
@@ -5462,7 +5457,6 @@ def _NewSession(self):
54625457

54635458
self.unsaved_data = False
54645459
self.ManualWaterVolume = [0, 0]
5465-
self.baseline_min_elapsed = 0 # variable to track baseline time elapsed before session for start/stop
54665460

54675461
# Clear Plots
54685462
if hasattr(self, "PlotM") and self.clear_figure_after_save:
@@ -5899,6 +5893,57 @@ def _Start(self):
58995893
elif self.behavior_session_model.allow_dirty_repo is None:
59005894
logging.error("Could not check for untracked local changes")
59015895

5896+
if self.PhotometryB.currentText() == "on" and (
5897+
not self.FIP_started
5898+
):
5899+
reply = QMessageBox.critical(
5900+
self,
5901+
"Box {}, Start".format(self.box_letter),
5902+
'Photometry is set to "on", but the FIP workflow has not been started',
5903+
QMessageBox.Ok,
5904+
)
5905+
self.Start.setChecked(False)
5906+
logging.info(
5907+
"Cannot start session without starting FIP workflow"
5908+
)
5909+
return
5910+
5911+
# Check if photometry excitation is running or not
5912+
if self.PhotometryB.currentText() == "on" and (
5913+
not self.StartExcitation.isChecked()
5914+
):
5915+
logging.warning(
5916+
'photometry is set to "on", but excitation is not running'
5917+
)
5918+
5919+
reply = QMessageBox.question(
5920+
self,
5921+
"Box {}, Start".format(self.box_letter),
5922+
'Photometry is set to "on", but excitation is not running. Start excitation now?',
5923+
QMessageBox.Yes | QMessageBox.No,
5924+
QMessageBox.Yes,
5925+
)
5926+
if reply == QMessageBox.Yes:
5927+
self.StartExcitation.setChecked(True)
5928+
logging.info("User selected to start excitation")
5929+
started = self._StartExcitation()
5930+
if started == 0:
5931+
reply = QMessageBox.critical(
5932+
self,
5933+
"Box {}, Start".format(self.box_letter),
5934+
"Could not start excitation, therefore cannot start the session",
5935+
QMessageBox.Ok,
5936+
)
5937+
logging.info(
5938+
"could not start session, due to failure to start excitation"
5939+
)
5940+
self.Start.setChecked(False)
5941+
return
5942+
else:
5943+
logging.info("User selected not to start excitation")
5944+
self.Start.setChecked(False)
5945+
return
5946+
59025947
# disable sound button
59035948
self.sound_button.setEnabled(False)
59045949

@@ -5915,9 +5960,6 @@ def _Start(self):
59155960
self.session_run = True # session has been started
59165961
self.keyPressEvent(allow_reset=True)
59175962

5918-
# set flag to perform habituation period
5919-
self.behavior_baseline_period.set()
5920-
59215963
else:
59225964
# Prompt user to confirm stopping trials
59235965
reply = QMessageBox.question(
@@ -5949,7 +5991,6 @@ def _Start(self):
59495991

59505992
self.session_end_tasks()
59515993
self.sound_button.setEnabled(True)
5952-
self.behavior_baseline_period.clear() # set flag to break out of habituation period
59535994

59545995
if (self.StartANewSession == 1) and (self.ANewTrial == 0):
59555996
# If we are starting a new session, we should wait for the last trial to finish
@@ -6096,21 +6137,12 @@ def _Start(self):
60966137
workerStartTrialLoop1 = self.workerStartTrialLoop1
60976138
worker_save = self.worker_save
60986139

6099-
# pause for specified habituation time
6100-
if self.baseline_min_elapsed <= self.hab_time_box.value():
6101-
self.wait_for_baseline()
6102-
61036140
# collecting the base signal for photometry. Only run once
61046141
if (
6105-
self.Start.isChecked()
6106-
and self.PhotometryB.currentText() == "on"
6107-
and self.PhotometryRun == 0
6142+
self.Start.isChecked()
6143+
and self.PhotometryB.currentText() == "on"
6144+
and self.PhotometryRun == 0
61086145
):
6109-
# check if workflow is running and start photometry timer
6110-
if not self.photometry_workflow_running():
6111-
self.Start.setChecked(False)
6112-
return
6113-
61146146
logging.info("Starting photometry baseline timer")
61156147
self.finish_Timer = 0
61166148
self.PhotometryRun = 1
@@ -6290,53 +6322,17 @@ def end_session_log(self) -> None:
62906322
else:
62916323
logging.info("No active session logger")
62926324

6293-
def wait_for_baseline(self) -> None:
6294-
"""
6295-
Function to wait for a baseline time before behavior
6296-
"""
6297-
6298-
# pause for specified habituation time
6299-
start_time = time.time()
6300-
6301-
# create habituation timer label and update every minute
6302-
hab_lab = QLabel()
6303-
hab_lab.setStyleSheet(f"color: {self.default_warning_color};")
6304-
self.warning_widget.layout().insertWidget(0, hab_lab)
6305-
update_hab_timer = QtCore.QTimer(
6306-
timeout=lambda: hab_lab.setText(f"Time elapsed: "
6307-
f"{round((self.baseline_min_elapsed * 60) // 60)} minutes"
6308-
f" {round((self.baseline_min_elapsed * 60) % 60)} seconds"),
6309-
interval=1000)
6310-
update_hab_timer.start()
6311-
6312-
logging.info(f"Waiting {round(self.hab_time_box.value() - self.baseline_min_elapsed)} min before starting "
6313-
f"session.")
6314-
6315-
elapsed = self.baseline_min_elapsed
6316-
while self.baseline_min_elapsed < self.hab_time_box.value() and self.behavior_baseline_period.is_set():
6317-
QApplication.processEvents()
6318-
# update baseline time elapsed before session for start/stop logic
6319-
self.baseline_min_elapsed = ((time.time() - start_time) / 60) + elapsed
6320-
6321-
update_hab_timer.stop()
6322-
self.behavior_baseline_period.clear()
6323-
6324-
63256325
def _StartTrialLoop(self, GeneratedTrials, worker1, worker_save):
6326-
6327-
if not self.Start.isChecked():
6326+
if self.Start.isChecked():
6327+
logging.info("starting trial loop")
6328+
else:
63286329
logging.info("ending trial loop")
6329-
return
6330-
6331-
logging.info("starting trial loop")
63326330

63336331
# Track elapsed time in case Bonsai Stalls
63346332
last_trial_start = time.time()
63356333
stall_iteration = 1
63366334
stall_duration = 5 * 60
63376335

6338-
logging.info(f"Starting session.")
6339-
63406336
while self.Start.isChecked():
63416337
QApplication.processEvents()
63426338
if (

src/foraging_gui/ForagingGUI.ui

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -262,28 +262,6 @@
262262
</property>
263263
</widget>
264264
</item>
265-
<item row="2" column="3">
266-
<widget class="QSpinBox" name="hab_time_box">
267-
<property name="sizePolicy">
268-
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
269-
<horstretch>0</horstretch>
270-
<verstretch>0</verstretch>
271-
</sizepolicy>
272-
</property>
273-
<property name="minimum">
274-
<number>0</number>
275-
</property>
276-
<property name="maximum">
277-
<number>90</number>
278-
</property>
279-
<property name="suffix">
280-
<string> min</string>
281-
</property>
282-
<property name="prefix">
283-
<string> Baseline: </string>
284-
</property>
285-
</widget>
286-
</item>
287265
<item row="2" column="1">
288266
<widget class="QPushButton" name="Save">
289267
<property name="sizePolicy">

src/foraging_gui/ForagingGUI_Ephys.ui

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<widget class="QComboBox" name="Task">
7070
<property name="geometry">
7171
<rect>
72-
<x>650</x>
72+
<x>620</x>
7373
<y>20</y>
7474
<width>152</width>
7575
<height>20</height>
@@ -2763,40 +2763,6 @@
27632763
<bool>false</bool>
27642764
</property>
27652765
</widget>
2766-
<widget class="QSpinBox" name="hab_time_box">
2767-
<property name="enabled">
2768-
<bool>true</bool>
2769-
</property>
2770-
<property name="geometry">
2771-
<rect>
2772-
<x>240</x>
2773-
<y>20</y>
2774-
<width>110</width>
2775-
<height>23</height>
2776-
</rect>
2777-
</property>
2778-
<property name="sizePolicy">
2779-
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
2780-
<horstretch>0</horstretch>
2781-
<verstretch>0</verstretch>
2782-
</sizepolicy>
2783-
</property>
2784-
<property name="styleSheet">
2785-
<string notr="true"/>
2786-
</property>
2787-
<property name="minimum">
2788-
<number>0</number>
2789-
</property>
2790-
<property name="maximum">
2791-
<number>90</number>
2792-
</property>
2793-
<property name="suffix">
2794-
<string> min</string>
2795-
</property>
2796-
<property name="prefix">
2797-
<string> Baseline: </string>
2798-
</property>
2799-
</widget>
28002766
<widget class="QPushButton" name="NewSession">
28012767
<property name="enabled">
28022768
<bool>true</bool>
@@ -3297,7 +3263,7 @@
32973263
<widget class="QLineEdit" name="ID">
32983264
<property name="geometry">
32993265
<rect>
3300-
<x>380</x>
3266+
<x>324</x>
33013267
<y>20</y>
33023268
<width>71</width>
33033269
<height>20</height>
@@ -3316,7 +3282,7 @@
33163282
<widget class="QLabel" name="label_72">
33173283
<property name="geometry">
33183284
<rect>
3319-
<x>350</x>
3285+
<x>300</x>
33203286
<y>20</y>
33213287
<width>21</width>
33223288
<height>20</height>
@@ -3692,7 +3658,7 @@
36923658
<widget class="QLabel" name="label_74">
36933659
<property name="geometry">
36943660
<rect>
3695-
<x>450</x>
3661+
<x>400</x>
36963662
<y>20</y>
36973663
<width>71</width>
36983664
<height>20</height>
@@ -3717,7 +3683,7 @@
37173683
<widget class="QLineEdit" name="Experimenter">
37183684
<property name="geometry">
37193685
<rect>
3720-
<x>524</x>
3686+
<x>474</x>
37213687
<y>20</y>
37223688
<width>121</width>
37233689
<height>20</height>

src/foraging_gui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.6.31"
1+
__version__ = "1.6.38"

0 commit comments

Comments
 (0)