Skip to content

Commit

Permalink
improved usability for "Show Training Level" tool
Browse files Browse the repository at this point in the history
  • Loading branch information
bimac committed Nov 20, 2023
1 parent 7e59a2b commit c8a0b1f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
8.12.8
------
* fix incorrect limits & unit for adaptive gain in trainingChoiceWorld
* usability improvements for "Show Training Level" tool

8.12.7
------
Expand Down
13 changes: 11 additions & 2 deletions iblrig/choiceworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,20 @@ def training_contrasts_probabilities(phase=1):
return frequencies / np.sum(frequencies)


def draw_training_contrast(phase):
def draw_training_contrast(phase: int) -> float:
probabilities = training_contrasts_probabilities(phase)
return np.random.choice(CONTRASTS, p=probabilities)


def contrasts_set(phase):
def contrasts_set(phase: int) -> np.array:
probabilities = training_contrasts_probabilities(phase)
return CONTRASTS[probabilities > 0]


def training_phase_from_contrast_set(contrast_set: list[float]) -> int | None:
contrast_set = sorted(contrast_set)
for phase in range(6):
expected_set = CONTRASTS[np.logical_and(training_contrasts_probabilities(phase) > 0, CONTRASTS >= 0)]
if np.array_equal(contrast_set, expected_set):
return phase
raise Exception(f'Could not determine training phase from contrast set {contrast_set}')
2 changes: 1 addition & 1 deletion iblrig/gui/ui_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,4 @@ def retranslateUi(self, wizard):
self.uiActionRecent.setText(_translate("wizard", "recent"))
self.uiActionTrainingTemplate.setText(_translate("wizard", "training rig"))
self.uiActionEphysTemplate.setText(_translate("wizard", "ephys rig"))
self.uiActionTrainingLevelV7.setText(_translate("wizard", "training level v7"))
self.uiActionTrainingLevelV7.setText(_translate("wizard", "Get Training Level"))
2 changes: 1 addition & 1 deletion iblrig/gui/ui_wizard.ui
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@
</action>
<action name="uiActionTrainingLevelV7">
<property name="text">
<string>training level v7</string>
<string>Get Training Level</string>
</property>
</action>
</widget>
Expand Down
27 changes: 15 additions & 12 deletions iblrig/gui/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
pass
import iblrig.path_helper
from iblrig.base_tasks import BaseSession
from iblrig.choiceworld import get_subject_training_info
from iblrig.choiceworld import get_subject_training_info, training_phase_from_contrast_set
from iblrig.constants import BASE_DIR
from iblrig.gui.ui_update import Ui_update
from iblrig.gui.ui_wizard import Ui_wizard
Expand Down Expand Up @@ -250,26 +250,29 @@ def _on_menu_training_level_v7(self):
This code will be removed and is here only for convenience while users transition from v7 to v8
:return:
"""
local_path = self.model.iblrig_settings['iblrig_local_data_path']
if not (local_path := Path(r'C:\iblrig_data\Subjects')).exists():
local_path = self.model.iblrig_settings['iblrig_local_data_path']
session_path = QtWidgets.QFileDialog.getExistingDirectory(
self, 'Select Session Path', str(local_path), QtWidgets.QFileDialog.ShowDirsOnly
)
if session_path is None:
if session_path is None or session_path == '':
return
file_jsonable = next(Path(session_path).glob('raw_behavior_data/_iblrig_taskData.raw.jsonable'), None)
if file_jsonable is None:
QtWidgets.QMessageBox().critical(self, 'Error', f'No jsonable found in {session_path}')
return
trials_table, bpod_data = iblrig.raw_data_loaders.load_task_jsonable(file_jsonable)
trials_table, _ = iblrig.raw_data_loaders.load_task_jsonable(file_jsonable)
if trials_table.empty:
QtWidgets.QMessageBox().critical(self, 'Error', f'No trials found in {session_path}')
return
last_trial = trials_table.iloc[-1]
QtWidgets.QMessageBox().information(
self,
f'{session_path}f',
f"{session_path}\n"
f" contrasts: {last_trial['contrast_set']}\n"
f"reward: {last_trial['reward_amount']} uL\n"
f"stim gain: {last_trial['stim_gain']}",
)
training_phase = training_phase_from_contrast_set(last_trial['contrast_set'])
info_text = f"{session_path}\n\n" \
f"training phase:\t{training_phase}\n" \
f"contrasts:\t{last_trial['contrast_set']}\n" \
f"reward:\t{last_trial['reward_amount']} uL\n" \
f"stimulus gain:\t{last_trial['stim_gain']}"
QtWidgets.QMessageBox().information(self, 'Training Level', info_text)

def _on_check_update_result(self, result: tuple[bool, str]) -> None:
"""
Expand Down

0 comments on commit c8a0b1f

Please sign in to comment.