From 0d3058eccd775e62e2db7178dc532c59126e8ee9 Mon Sep 17 00:00:00 2001 From: Florian Rau Date: Mon, 30 Oct 2023 18:26:10 +0000 Subject: [PATCH] remove some dead code --- iblrig/adaptive.py | 81 -------------------------------------------- iblrig/bonsai.py | 70 -------------------------------------- iblrig/user_input.py | 62 --------------------------------- 3 files changed, 213 deletions(-) delete mode 100644 iblrig/adaptive.py delete mode 100644 iblrig/bonsai.py delete mode 100644 iblrig/user_input.py diff --git a/iblrig/adaptive.py b/iblrig/adaptive.py deleted file mode 100644 index 01d6f0c7c..000000000 --- a/iblrig/adaptive.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python -# @Author: Niccolò Bonacchi -# @Creation_Date: Tuesday, February 5th 2019, 4:11:13 pm -# @Editor: Michele Fabbri -# @Edit_Date: 2022-01-24 -""" -Calibration tests and reward configurations -""" -import logging - -import numpy as np -import scipy as sp -from iblrig.raw_data_loaders import load_data - -log = logging.getLogger("iblrig") - - -def init_stim_gain(sph: object) -> float: - if not sph.ADAPTIVE_GAIN: - return sph.STIM_GAIN - - if sph.LAST_TRIAL_DATA and sph.LAST_TRIAL_DATA["trial_num"] >= 200: - stim_gain = sph.AG_MIN_VALUE - else: - stim_gain = sph.AG_INIT_VALUE - - return stim_gain - - -def impulsive_control(sph: object): - crit_1 = False # 50% perf on one side ~100% on other - crit_2 = False # Median RT on hard (<50%) contrasts < 300ms - crit_3 = False # Getting enough water - data = load_data(sph.PREVIOUS_SESSION_PATH) # Loads data of previous session - if data is None or not data: - return sph - - signed_contrast = np.array([x["signed_contrast"] for x in data]) - trial_correct = np.array([x["trial_correct"] for x in data]) - - # Check crit 1 - l_trial_correct = trial_correct[signed_contrast < 0] - r_trial_correct = trial_correct[signed_contrast > 0] - # If no trials on either side crit1 would be false and last check not pass, safe to return - if len(l_trial_correct) == 0 or len(r_trial_correct) == 0: - return sph - - p_left = sum(l_trial_correct) / len(l_trial_correct) - p_righ = sum(r_trial_correct) / len(r_trial_correct) - if np.abs(p_left - p_righ) >= 0.4: - crit_1 = True - - # Check crit 2 - rt = np.array( - [ - x["behavior_data"]["States timestamps"]["closed_loop"][0][1] - - x["behavior_data"]["States timestamps"]["stim_on"][0][0] - for x in data - ] - ) - if sp.median(rt[np.abs(signed_contrast) < 0.5]) < 0.3: - crit_2 = True - # Check crit 3 - previous_weight_factor = sph.LAST_SETTINGS_DATA["SUBJECT_WEIGHT"] / 25 - previous_water = sph.LAST_TRIAL_DATA["water_delivered"] / 1000 - - if previous_water >= previous_weight_factor: - crit_3 = True - - if crit_1 and crit_2 and crit_3: - # Reward decrease - sph.REWARD_AMOUNT -= sph.AR_STEP # 0.1 µl - if sph.REWARD_AMOUNT < sph.AR_MIN_VALUE: - sph.REWARD_AMOUNT = sph.AR_MIN_VALUE - # Increase timeout error - sph.ITI_ERROR = 3.0 - # Introduce interactive delay - sph.INTERACTIVE_DELAY = 0.250 # sec - sph.IMPULSIVE_CONTROL = "ON" - - return sph diff --git a/iblrig/bonsai.py b/iblrig/bonsai.py deleted file mode 100644 index ed0cd2d7b..000000000 --- a/iblrig/bonsai.py +++ /dev/null @@ -1,70 +0,0 @@ -import logging -import os -import subprocess -import sys -import time - -from iblrig import path_helper - -log = logging.getLogger("iblrig") - - -def start_frame2ttl_test(data_file, lengths_file, harp=False, display_idx=1): - here = os.getcwd() - bns = path_helper.get_bonsai_path() - stim_folder = str(path_helper.get_iblrig_path() / "visual_stim" / "f2ttl_calibration") - wkfl = os.path.join(stim_folder, "screen_60Hz.bonsai") - # Flags - noedit = "--no-editor" # implies start and no-debug? - noboot = "--no-boot" - display_idx = "-p:DisplayIndex=" + str(display_idx) - data_file_name = "-p:FileNameData=" + str(data_file) - lengths_file_name = "-p:FileNameDataLengths=" + str(lengths_file) - if harp: - harp_file_name = "-p:FileName=" + str(data_file.parent / "harp_ts_data.csv") - # Properties - log.info("Starting pulses @ 60Hz") - sys.stdout.flush() - os.chdir(stim_folder) - if harp: - s = subprocess.Popen( - [bns, wkfl, noboot, noedit, data_file_name, lengths_file_name, harp_file_name] - ) - else: - s = subprocess.Popen( - [bns, wkfl, noboot, noedit, display_idx, data_file_name, lengths_file_name] - ) - os.chdir(here) - return s - - -def start_screen_color(display_idx=1): - here = os.getcwd() - iblrig_folder_path = path_helper.get_iblrig_path() - os.chdir(str(iblrig_folder_path / "visual_stim" / "f2ttl_calibration")) - bns = path_helper.get_bonsai_path() - wrkfl = str(iblrig_folder_path / "visual_stim" / "f2ttl_calibration" / "screen_color.bonsai") - noedit = "--no-editor" # implies start - # nodebug = '--start-no-debug' - # start = '--start' - noboot = "--no-boot" - editor = noedit - display_idx = "-p:DisplayIndex=" + str(display_idx) - subprocess.Popen([bns, wrkfl, editor, noboot, display_idx]) - time.sleep(3) - os.chdir(here) - - -def start_camera_setup(): - here = os.getcwd() - iblrig_folder_path = path_helper.get_iblrig_path() - os.chdir(str(iblrig_folder_path / "devices" / "camera_setup")) - - bns = path_helper.get_bonsai_path() - wrkfl = path_helper.get_camera_setup_wrkfl() - - # noedit = "--no-editor" # implies start - noboot = "--no-boot" - editor = "--start-no-debug" - subprocess.call([bns, wrkfl, editor, noboot]) # locks until Bonsai closes - os.chdir(here) diff --git a/iblrig/user_input.py b/iblrig/user_input.py deleted file mode 100644 index 033451abb..000000000 --- a/iblrig/user_input.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python -# @Author: Niccolò Bonacchi -# @Creation_Date: Friday, May 17th 2019, 9:21:19 am -# @Editor: Michele Fabbri -# @Edit_Date: 2022-02-01 -""" -Various interaction with user and session forms -""" -import logging - -import iblrig.graphic as graph -from iblrig.misc import patch_settings_file - -log = logging.getLogger("iblrig") - - -def ask_session_delay() -> int: - out = graph.numinput( - "Session delay", - "Delay session initiation by (min):", - default=0, - minval=0, - maxval=60, - nullable=False, - askint=True, - ) - out = out * 60 - return out - - -def ask_is_mock(settings_file_path: str = None) -> bool: - out = None - resp = graph.strinput( - "Session type", "IS this a MOCK recording? (yes/NO)", default="NO", nullable=True, - ) - if resp is None: - return ask_is_mock(settings_file_path) - if resp.lower() in ["no", "n", ""]: - out = False - elif resp.lower() in ["yes", "y"]: - out = True - else: - return ask_is_mock(settings_file_path) - if settings_file_path is not None and out is not None: - patch = {"IS_MOCK": out} - patch_settings_file(settings_file_path, patch) - return out - - -def ask_confirm_session_idx(session_idx): - # Confirm this is the session to load with user. If not override SESSION_IDX - sess_num = int(session_idx + 1) - sess_num = graph.numinput( - "Confirm pregenerated session to load", - "Load trial sequence for recording day number:", - default=sess_num, - askint=True, - minval=1, - ) - if sess_num != session_idx + 1: - session_idx = sess_num - 1 - return session_idx