Skip to content

Commit 9b9cab1

Browse files
authored
Merge pull request #1500 from AllenNeuralDynamics/develop
[production merge] 2025-04-11
2 parents 9f39950 + 68de1a9 commit 9b9cab1

14 files changed

+4400
-242
lines changed

bonsai/Bonsai.config

Lines changed: 32 additions & 24 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies = [
3737
"aind-data-schema==1.1.0",
3838
"aind-data-schema-models==0.5.6",
3939
"pydantic >=2.9.2, <3",
40-
"stagewidget==1.0.4.dev5",
40+
"stagewidget==1.0.4.dev11",
4141
"python-logging-loki >=0.3.1, <2",
4242
"pykeepass >=4.0.7, <5",
4343
"pyyaml >=6, <7",

src/foraging_gui/Dialogs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ def _CalibrateLeftOne(self, repeat=False):
786786
"All measurements have been completed. Either press Repeat, or Finished"
787787
)
788788
return
789-
next_index = np.where(self.left_measurements is False)[0][0]
789+
next_index = np.where(self.left_measurements != True)[0][0]
790790
self.LeftOpenTime.setCurrentIndex(next_index)
791791
else:
792792
next_index = self.LeftOpenTime.currentIndex()
@@ -973,7 +973,7 @@ def _CalibrateRightOne(self, repeat=False):
973973
"All measurements have been completed. Either press Repeat, or Finished"
974974
)
975975
return
976-
next_index = np.where(self.right_measurements is False)[0][0]
976+
next_index = np.where(self.right_measurements != True)[0][0]
977977
self.RightOpenTime.setCurrentIndex(next_index)
978978
else:
979979
next_index = self.RightOpenTime.currentIndex()
@@ -1454,7 +1454,7 @@ def _SpotCheck(self, valve: Literal["Left", "Right"]):
14541454
if np.abs(error) > TOLERANCE:
14551455
reply = QMessageBox.critical(
14561456
self,
1457-
f"Spot check {valve}",
1457+
f"Spot check {valve}".format(np.round(result, 2)),
14581458
"Measurement is outside expected tolerance.<br><br>"
14591459
"If this is a typo, please press cancel."
14601460
'<br><br><span style="color:purple;font-weight:bold">IMPORTANT</span>: '
@@ -1671,7 +1671,7 @@ def _StartCamera(self):
16711671
or self.MainWindow.logging_type == -1
16721672
):
16731673
self.MainWindow.Ot_log_folder = (
1674-
self.MainWindow._restartlogging()
1674+
self.MainWindow._restartlogging(start_from_camera=True)
16751675
)
16761676
# set to check drop frame as true
16771677
self.MainWindow.to_check_drop_frames = 1
@@ -2589,7 +2589,7 @@ def _Open(self):
25892589
if self.SleepStart == 1: # only run once
25902590
self.SleepStart = 0
25912591
self.threadpool2.start(self.worker2)
2592-
if self.Open.isChecked() is False or self.SleepComplete2 == 1:
2592+
if self.Open.isChecked() == False or self.SleepComplete2 == 1:
25932593
break
25942594
self.Open.setStyleSheet("background-color : none")
25952595
self.Open.setChecked(False)
@@ -2619,7 +2619,7 @@ def _KeepOpen(self):
26192619
self.SleepComplete = 0
26202620
self._InitiateATrial()
26212621
self.threadpool1.start(self.worker1)
2622-
if self.KeepOpen.isChecked() is False:
2622+
if self.KeepOpen.isChecked() == False:
26232623
break
26242624
self.KeepOpen.setStyleSheet("background-color : none")
26252625
self.KeepOpen.setChecked(False)
@@ -2773,7 +2773,7 @@ def _update_metadata(
27732773
!= self.RigMetadataFile.text()
27742774
and self.RigMetadataFile.text() != ""
27752775
):
2776-
if dont_clear is False:
2776+
if dont_clear == False:
27772777
# clear probe angles if the rig metadata file is changed
27782778
self.meta_data["session_metadata"]["probes"] = {}
27792779
self.meta_data["session_metadata"]["microscopes"] = {}

src/foraging_gui/Foraging.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,17 +1414,22 @@ def _ReconnectBonsai(self):
14141414
QMessageBox.Ok,
14151415
)
14161416

1417-
def _restartlogging(self, log_folder=None):
1417+
def _restartlogging(self, log_folder=None,start_from_camera=False):
14181418
"""Restarting logging"""
14191419
logging.info("Restarting logging")
14201420
# stop the current session except it is a new session
14211421
if self.StartANewSession == 1 and self.ANewTrial == 1:
14221422
pass
14231423
else:
14241424
self._StopCurrentSession()
1425+
1426+
# We don't need to stop the recording when the start_from_camera is True as the logging is from the camera
1427+
if start_from_camera == False:
1428+
# Turn off the camera recording if it it on
1429+
if self.Camera_dialog.StartRecording.isChecked():
1430+
self.Camera_dialog.StartRecording.setChecked(False)
1431+
self.Camera_dialog.StartRecording()
14251432

1426-
# Turn off the camera recording in case it is on
1427-
self.Camera_dialog.StartRecording.setChecked(False)
14281433
# Turn off the preview if it is on and the autocontrol is on, which can make sure the trigger is off before starting the logging.
14291434
if (
14301435
self.Camera_dialog.AutoControl.currentText() == "Yes"
@@ -2660,7 +2665,7 @@ def keyPressEvent(self, event=None, allow_reset=False):
26602665
allow_reset (bool) allows the Baseweight etc. parameters to be reset to the empty string
26612666
"""
26622667
try:
2663-
if self.actionTime_distribution.isChecked() is True:
2668+
if self.actionTime_distribution.isChecked() == True:
26642669
self.PlotTime._Update(self)
26652670
except Exception:
26662671
logging.error(traceback.format_exc())
@@ -2889,7 +2894,7 @@ def _CheckTextChange(self):
28892894
):
28902895
if (
28912896
child.objectName() in ["qt_spinbox_lineedit", None, ""]
2892-
or child.isEnabled() is False
2897+
or child.isEnabled() == False
28932898
): # I don't understand where the qt_spinbox_lineedit comes from.
28942899
continue
28952900
if (
@@ -3447,7 +3452,7 @@ def _Optogenetics(self):
34473452
if self.OpenOptogenetics == 0:
34483453
self.Opto_dialog = OptogeneticsDialog(MainWindow=self)
34493454
self.OpenOptogenetics = 1
3450-
if self.action_Optogenetics.isChecked() is True:
3455+
if self.action_Optogenetics.isChecked() == True:
34513456
self.Opto_dialog.show()
34523457
else:
34533458
self.Opto_dialog.hide()
@@ -3457,7 +3462,7 @@ def _Camera(self):
34573462
if self.OpenCamera == 0:
34583463
self.Camera_dialog = CameraDialog(MainWindow=self)
34593464
self.OpenCamera = 1
3460-
if self.action_Camera.isChecked() is True:
3465+
if self.action_Camera.isChecked() == True:
34613466
self.Camera_dialog.show()
34623467
else:
34633468
self.Camera_dialog.hide()
@@ -3505,7 +3510,7 @@ def _Metadata(self):
35053510
if self.OpenMetadata == 0:
35063511
self.Metadata_dialog = MetadataDialog(MainWindow=self)
35073512
self.OpenMetadata = 1
3508-
if self.actionMeta_Data.isChecked() is True:
3513+
if self.actionMeta_Data.isChecked() == True:
35093514
self.Metadata_dialog.show()
35103515
else:
35113516
self.Metadata_dialog.hide()
@@ -3516,7 +3521,7 @@ def _WaterCalibration(self):
35163521
MainWindow=self
35173522
)
35183523
self.OpenWaterCalibration = 1
3519-
if self.action_Calibration.isChecked() is True:
3524+
if self.action_Calibration.isChecked() == True:
35203525
self.WaterCalibration_dialog.show()
35213526
else:
35223527
self.WaterCalibration_dialog.hide()
@@ -3527,7 +3532,7 @@ def _LaserCalibration(self):
35273532
MainWindow=self
35283533
)
35293534
self.OpenLaserCalibration = 1
3530-
if self.actionLaser_Calibration.isChecked() is True:
3535+
if self.actionLaser_Calibration.isChecked() == True:
35313536
self.LaserCalibration_dialog.show()
35323537
else:
35333538
self.LaserCalibration_dialog.hide()
@@ -3542,7 +3547,7 @@ def _TimeDistribution(self):
35423547
self.TimeDistribution_dialog.setWindowTitle(
35433548
"Simulated time distribution"
35443549
)
3545-
if self.actionTime_distribution.isChecked() is True:
3550+
if self.actionTime_distribution.isChecked() == True:
35463551
self.TimeDistribution_dialog.show()
35473552
else:
35483553
self.TimeDistribution_dialog.hide()
@@ -3575,7 +3580,7 @@ def _LickSta(self):
35753580
self.LickSta_dialog = LickStaDialog(MainWindow=self)
35763581
self.LickSta = 1
35773582
self.LickSta_dialog.setWindowTitle("Licks statistics")
3578-
if self.actionLicks_sta.isChecked() is True:
3583+
if self.actionLicks_sta.isChecked() == True:
35793584
self.LickSta_dialog.show()
35803585
else:
35813586
self.LickSta_dialog.hide()
@@ -4000,7 +4005,6 @@ def _Save(self, ForceSave=0, SaveAs=0, SaveContinue=0, BackupSave=0):
40004005
):
40014006
self._AddWaterLogResult(session)
40024007

4003-
40044008
except Exception as e:
40054009
logging.warning(
40064010
"Meta data is not saved!",
@@ -6166,7 +6170,7 @@ def _Start(self):
61666170

61676171
self._StartTrialLoop(GeneratedTrials, worker1, worker_save)
61686172

6169-
if self.actionDrawing_after_stopping.isChecked() is True:
6173+
if self.actionDrawing_after_stopping.isChecked() == True:
61706174
try:
61716175
self.PlotM._Update(
61726176
GeneratedTrials=GeneratedTrials, Channel=self.Channel2
@@ -6347,7 +6351,7 @@ def _StartTrialLoop(self, GeneratedTrials, worker1, worker_save):
63476351
self.Start.setStyleSheet("background-color : none")
63486352
break
63496353
# receive licks and update figures
6350-
if self.actionDrawing_after_stopping.isChecked() is False:
6354+
if self.actionDrawing_after_stopping.isChecked() == False:
63516355
self.PlotM._Update(
63526356
GeneratedTrials=GeneratedTrials, Channel=self.Channel2
63536357
)
@@ -6411,7 +6415,7 @@ def _StartTrialLoop(self, GeneratedTrials, worker1, worker_save):
64116415
)
64126416

64136417
# save the data everytrial
6414-
if GeneratedTrials.CurrentSimulation is True:
6418+
if GeneratedTrials.CurrentSimulation == True:
64156419
GeneratedTrials._GetAnimalResponse(
64166420
self.Channel, self.Channel3, self.data_lock
64176421
)
@@ -6429,7 +6433,7 @@ def _StartTrialLoop(self, GeneratedTrials, worker1, worker_save):
64296433
GeneratedTrials.B_CurrentTrialN > 0
64306434
and self.previous_backup_completed == 1
64316435
and self.save_each_trial
6432-
and GeneratedTrials.CurrentSimulation is False
6436+
and GeneratedTrials.CurrentSimulation == False
64336437
):
64346438
self.previous_backup_completed = 0
64356439
self.threadpool6.start(worker_save)

src/foraging_gui/GenerateMetadata.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
PowerUnit,
4343
SizeUnit,
4444
SoundIntensityUnit,
45+
TimeUnit
4546
)
4647

4748
import foraging_gui
@@ -905,7 +906,8 @@ def _get_photometry_detectors(self):
905906
DetectorConfig(
906907
name=current_detector["name"],
907908
exposure_time=exposure_time,
908-
trigger_type=TriggerType.INTERNAL,
909+
exposure_time_unit=TimeUnit.US,
910+
trigger_type=TriggerType.EXTERNAL,
909911
)
910912
)
911913

@@ -945,7 +947,7 @@ def _get_behavior_stimulus(self):
945947
Make the audio stimulus metadata
946948
"""
947949
self.behavior_stimulus = []
948-
if self.has_behavior_data is False:
950+
if self.has_behavior_data == False:
949951
logging.info("No behavior data stream detected!")
950952
return
951953

@@ -1376,7 +1378,7 @@ def _get_behavior_stream(self):
13761378
Make the behavior stream metadata
13771379
"""
13781380

1379-
if self.has_behavior_data is False:
1381+
if self.has_behavior_data == False:
13801382
self.behavior_streams = []
13811383
logging.info("No behavior data detected!")
13821384
return
@@ -1408,9 +1410,7 @@ def _get_behavior_software(self):
14081410
self.behavior_software = []
14091411
try:
14101412
# Get information about task repository
1411-
commit_ID = (
1412-
self.session_model.commit_hash
1413-
)
1413+
commit_ID = self.session_model.commit_hash
14141414
current_branch = (
14151415
subprocess.check_output(["git", "branch", "--show-current"])
14161416
.decode("ascii")

src/foraging_gui/MyFunctions.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def _CheckBaitPermitted(self):
407407
self.BaitPermitted = False
408408
else:
409409
self.BaitPermitted = True
410-
if self.BaitPermitted is False:
410+
if self.BaitPermitted == False:
411411
logging.warning(
412412
"The active side has no reward due to consecutive \nselections("
413413
+ str(MaxCLen)
@@ -807,10 +807,10 @@ def _get_current_block_reward(
807807
self.BS_CurrentBlockTrialN[i] = length[-1]
808808
index[i] = indexN[-1]
809809
self.BS_RewardedTrialN_CurrentLeftBlock = np.sum(
810-
B_RewardedHistory[0][index[0][0] : index[0][1] + 1] is True
810+
B_RewardedHistory[0][index[0][0] : index[0][1] + 1] == True
811811
)
812812
self.BS_RewardedTrialN_CurrentRightBlock = np.sum(
813-
B_RewardedHistory[1][index[1][0] : index[1][1] + 1] is True
813+
B_RewardedHistory[1][index[1][0] : index[1][1] + 1] == True
814814
)
815815
self.AllRewardThisBlock = (
816816
self.BS_RewardedTrialN_CurrentLeftBlock
@@ -845,16 +845,16 @@ def _GetBasic(self):
845845
self.BS_RespondedRate = np.nan
846846
else:
847847
self.BS_RespondedRate = self.BS_FinisheTrialN / self.BS_AllTrialN
848-
self.BS_RewardTrialN = np.sum(self.B_RewardedHistory is True)
848+
self.BS_RewardTrialN = np.sum(self.B_RewardedHistory == True)
849849
B_RewardedHistory = self.B_RewardedHistory.copy()
850850
# auto reward is considered as reward
851851
Ind = range(len(self.B_RewardedHistory[0]))
852852
for i in range(len(self.B_RewardedHistory)):
853853
B_RewardedHistory[i] = np.logical_or(
854854
self.B_RewardedHistory[i], self.B_AutoWaterTrial[i][Ind]
855855
)
856-
self.BS_RewardN = np.sum(B_RewardedHistory[0] is True) + np.sum(
857-
B_RewardedHistory[1] is True
856+
self.BS_RewardN = np.sum(B_RewardedHistory[0] == True) + np.sum(
857+
B_RewardedHistory[1] == True
858858
)
859859

860860
(
@@ -893,8 +893,8 @@ def _GetBasic(self):
893893
+ BS_auto_water_left
894894
+ BS_auto_water_right
895895
)
896-
self.BS_LeftRewardTrialN = np.sum(self.B_RewardedHistory[0] is True)
897-
self.BS_RightRewardTrialN = np.sum(self.B_RewardedHistory[1] is True)
896+
self.BS_LeftRewardTrialN = np.sum(self.B_RewardedHistory[0] == True)
897+
self.BS_RightRewardTrialN = np.sum(self.B_RewardedHistory[1] == True)
898898
self.BS_LeftChoiceN = np.sum(self.B_AnimalResponseHistory == 0)
899899
self.BS_RightChoiceN = np.sum(self.B_AnimalResponseHistory == 1)
900900
self.BS_OverallRewardRate = self.BS_RewardTrialN / (
@@ -2153,9 +2153,9 @@ def _CheckAutoWater(self):
21532153
extra={"tags": [self.win.warning_log_tag]},
21542154
)
21552155
elif (
2156-
np.all(B_RewardedHistory[0][-UnrewardedN:] is False)
2156+
np.all(B_RewardedHistory[0][-UnrewardedN:] == False)
21572157
and np.all(
2158-
B_RewardedHistory[1][-UnrewardedN:] is False
2158+
B_RewardedHistory[1][-UnrewardedN:] == False
21592159
)
21602160
and np.shape(B_RewardedHistory[0])[0] >= UnrewardedN
21612161
):
@@ -2497,7 +2497,7 @@ def _InitiateATrial(self, Channel1, Channel4):
24972497
if self.TP_Task in ["Coupled Baiting", "Uncoupled Baiting"]:
24982498
self.CurrentBait = self.CurrentBait | self.B_Baited
24992499
# For task rewardN, if this is the "initial N trials" of the active side, no bait will be be given.
2500-
if self.BaitPermitted is False:
2500+
if self.BaitPermitted == False:
25012501
# no reward in the active side
25022502
max_index = np.argmax(self.B_CurrentRewardProb)
25032503
self.CurrentBait[max_index] = False
@@ -2599,8 +2599,8 @@ def _InitiateATrial(self, Channel1, Channel4):
25992599
def _CheckSimulationSession(self):
26002600
"""To check if this is a simulation session"""
26012601
if (
2602-
self.win.actionWin_stay_lose_switch.isChecked() is True
2603-
or self.win.actionRandom_choice.isChecked() is True
2602+
self.win.actionWin_stay_lose_switch.isChecked() == True
2603+
or self.win.actionRandom_choice.isChecked() == True
26042604
):
26052605
self.CurrentSimulation = True
26062606
self.B_SimulationSession.append(True)
@@ -2652,7 +2652,7 @@ def _SimulateResponse(self):
26522652
self.B_CurrentRewarded[1] = False
26532653
self.B_CurrentRewarded[0] = True
26542654
elif (
2655-
self.B_AnimalCurrentResponse == 0 and self.CurrentBait[0] is False
2655+
self.B_AnimalCurrentResponse == 0 and self.CurrentBait[0] == False
26562656
):
26572657
self.B_Baited[0] = False
26582658
self.B_CurrentRewarded[0] = False
@@ -2662,7 +2662,7 @@ def _SimulateResponse(self):
26622662
self.B_CurrentRewarded[0] = False
26632663
self.B_CurrentRewarded[1] = True
26642664
elif (
2665-
self.B_AnimalCurrentResponse == 1 and self.CurrentBait[1] is False
2665+
self.B_AnimalCurrentResponse == 1 and self.CurrentBait[1] == False
26662666
):
26672667
self.B_Baited[1] = False
26682668
self.B_CurrentRewarded[0] = False

0 commit comments

Comments
 (0)