def update_alyx_params(data: dict, force: bool = False) -> dict: old = load_alyx_params(data["NAME"]) if old is None: log.info("board params not found, creating...") new = rig_params.create_new_params_dict() write_alyx_params(new) old = load_alyx_params(new["NAME"]) board = rig_params.get_board_name() if "NAME" in data and data["NAME"] != board: log.error(f"Board {board} not equal to data['NAME'] {data['NAME']}") raise (AttributeError) for k in data: if k in old.keys(): old[k] = data[k] else: if not force: log.info(f"Unknown key {k}: skipping key...") continue elif force: log.info( f"Adding new key {k} with value {data[k]} to {board} json field" ) old[k] = data[k] write_alyx_params(data=old, force=True) log.info(f"Changed board params: {data}") return old
def load_board_params() -> dict: board = rig_params.get_board_name() one = get_one() try: out = one.alyx.rest('locations', 'read', id=board)['json'] out = json.loads(out) except Exception as e: log.error(e) out = None return out
def write_board_params(data: dict = None, force: bool = False) -> None: if data is None: data = rig_params.EMPTY_BOARD_PARAMS data['NAME'] = rig_params.get_board_name() data['COM_BPOD'] = rig_params.get_board_comport() board = data['NAME'] one = get_one() p = load_board_params() if p and not force: log.info('Board params already present, exiting...') return p patch_dict = {"json": json.dumps(data)} one.alyx.rest('locations', 'partial_update', id=board, data=patch_dict) return data
def __init__(self, subject_name, protocol=False, make=False): self.IBLRIG_FOLDER = get_iblrig_folder() self.IBLRIG_EPHYS_SESSION_FOLDER = get_pregen_session_folder() self._BOARD = params.get_board_name() self._PROTOCOL = protocol self.IBLRIG_COMMIT_HASH = get_commit_hash(self.IBLRIG_FOLDER) self.IBLRIG_VERSION_TAG = get_version_tag(self.IBLRIG_FOLDER) self.IBLRIG_PARAMS_FOLDER = get_iblrig_params_folder() self.IBLRIG_DATA_FOLDER = get_iblrig_data_folder(subjects=False) self.IBLRIG_DATA_SUBJECTS_FOLDER = get_iblrig_data_folder(subjects=True) self.PARAMS = params.load_params_file() # TODO: check if can remove old bpod_comports file self.IBLRIG_PARAMS_FILE = str(Path(self.IBLRIG_PARAMS_FOLDER) / ".bpod_comports.json") self.SUBJECT_NAME = subject_name self.SUBJECT_FOLDER = os.path.join(self.IBLRIG_DATA_SUBJECTS_FOLDER, self.SUBJECT_NAME) self.BONSAI = get_bonsai_path(use_iblrig_bonsai=True) self.VISUAL_STIM_FOLDER = str(Path(self.IBLRIG_FOLDER) / "visual_stim") self.VISUAL_STIMULUS_TYPE = get_visual_stim_type(self._PROTOCOL) self.VISUAL_STIMULUS_FILE_NAME = get_visual_stim_file_name(self.VISUAL_STIMULUS_TYPE) self.VISUAL_STIMULUS_FILE = str( Path(self.VISUAL_STIM_FOLDER) / self.VISUAL_STIMULUS_TYPE / self.VISUAL_STIMULUS_FILE_NAME ) self.VIDEO_RECORDING_FOLDER = os.path.join( self.IBLRIG_FOLDER, "devices", "camera_recordings" ) self.VIDEO_RECORDING_FILE = os.path.join( self.VIDEO_RECORDING_FOLDER, "TrainingRig_SaveVideo_TrainingTasks.bonsai" ) self.MIC_RECORDING_FOLDER = os.path.join(self.IBLRIG_FOLDER, "devices", "microphone") self.MIC_RECORDING_FILE = os.path.join(self.MIC_RECORDING_FOLDER, "record_mic.bonsai") self.SESSION_DATETIME = datetime.datetime.now().isoformat() self.SESSION_DATE = datetime.datetime.now().date().isoformat() self.SESSION_DATE_FOLDER = os.path.join(self.SUBJECT_FOLDER, self.SESSION_DATE) self.SESSION_NUMBER = get_session_number(self.SESSION_DATE_FOLDER) self.SESSION_FOLDER = str(Path(self.SESSION_DATE_FOLDER) / self.SESSION_NUMBER) self.SESSION_RAW_DATA_FOLDER = os.path.join(self.SESSION_FOLDER, "raw_behavior_data") self.SESSION_RAW_VIDEO_DATA_FOLDER = os.path.join(self.SESSION_FOLDER, "raw_video_data") self.SESSION_RAW_EPHYS_DATA_FOLDER = os.path.join(self.SESSION_FOLDER, "raw_ephys_data") self.SESSION_RAW_IMAGING_DATA_FOLDER = os.path.join( self.SESSION_FOLDER, "raw_imaging_data" ) self.SESSION_RAW_PASSIVE_DATA_FOLDER = os.path.join( self.SESSION_FOLDER, "raw_passive_data" ) self.SESSION_NAME = "{}".format(os.path.sep).join( [self.SUBJECT_NAME, self.SESSION_DATE, self.SESSION_NUMBER] ) self.BASE_FILENAME = "_iblrig_task" self.SETTINGS_FILE_PATH = os.path.join( self.SESSION_RAW_DATA_FOLDER, self.BASE_FILENAME + "Settings.raw.json" ) self.DATA_FILE_PATH = os.path.join( self.SESSION_RAW_DATA_FOLDER, self.BASE_FILENAME + "Data.raw.jsonable" ) # Water calinbration files self.LATEST_WATER_CALIBRATION_FILE = get_water_calibration_func_file(latest=True) self.LATEST_WATER_CALIB_RANGE_FILE = get_water_calibration_range_file(latest=True) if self.LATEST_WATER_CALIBRATION_FILE.parent != self.LATEST_WATER_CALIB_RANGE_FILE.parent: self.LATEST_WATER_CALIBRATION_FILE = str(self.LATEST_WATER_CALIBRATION_FILE) self.LATEST_WATER_CALIB_RANGE_FILE = None else: self.LATEST_WATER_CALIBRATION_FILE = str(self.LATEST_WATER_CALIBRATION_FILE) self.LATEST_WATER_CALIB_RANGE_FILE = str(self.LATEST_WATER_CALIB_RANGE_FILE) if str(self.LATEST_WATER_CALIBRATION_FILE) == ".": self.LATEST_WATER_CALIBRATION_FILE = None self.LATEST_WATER_CALIB_RANGE_FILE = None # Previous session files self.PREVIOUS_DATA_FILE = get_previous_data_file( self._PROTOCOL, self.SUBJECT_NAME, self.SESSION_FOLDER ) self.PREVIOUS_SETTINGS_FILE = get_previous_settings_file( self._PROTOCOL, self.SUBJECT_NAME, self.SESSION_FOLDER ) self.PREVIOUS_SESSION_PATH = get_previous_session_path( self._PROTOCOL, self.SUBJECT_NAME, self.SESSION_FOLDER ) if make: self.make_missing_folders(make) self.display_logs()
# Load PARAMS file ports # If file exists open file if not initialize log.debug("Loading params file...") PARAMS = params.load_params() # Check PARAMS values checks = [] for k in PARAMS: if PARAMS[k] is None or PARAMS[k] == "": checks.append(1) log.warning(f"{k}: Value not found") if sum(checks) != 0: log.error("Missing values in params file") raise (ValueError) # Check board name assert PARAMS["NAME"] == params.get_board_name() # COM ports check PARAMS["COM_BPOD"] PARAMS["COM_ROTARY_ENCODER"] PARAMS["COM_F2TTL"] # F2TTL CALIBRATION: check f2ttl values from params, warn if old calibration PARAMS["F2TTL_DARK_THRESH"] PARAMS["F2TTL_LIGHT_THRESH"] PARAMS["F2TTL_CALIBRATION_DATE"] # WATER CALIBRATION: check water calibration values from params, warn if old calibration log.debug("Checking water calibration...") PARAMS["WATER_CALIBRATION_RANGE"] PARAMS["WATER_CALIBRATION_OPEN_TIMES"] PARAMS["WATER_CALIBRATION_WEIGHT_PERDROP"] PARAMS["WATER_CALIBRATION_DATE"] # F2TTL CALIBRATION: check f2ttl values from params, warn if old calibration
# Load PARAMS file ports # If file exists open file if not initialize log.debug("Loading params file...") PARAMS = params.load_params() # Check PARAMS values checks = [] for k in PARAMS: if PARAMS[k] is None or PARAMS[k] == '': checks.append(1) log.warning(f'{k}: Value not found') if sum(checks) != 0: log.error('Missing values in params file') raise (ValueError) # Check board name assert (PARAMS['NAME'] == params.get_board_name()) # COM ports check PARAMS['COM_BPOD'] PARAMS['COM_ROTARY_ENCODER'] PARAMS['COM_F2TTL'] # F2TTL CALIBRATION: check f2ttl values from params, warn if old calibration PARAMS['F2TTL_DARK_THRESH'] PARAMS['F2TTL_LIGHT_THRESH'] PARAMS['F2TTL_CALIBRATION_DATE'] # WATER CALIBRATION: check water calibration values from params, warn if old calibration log.debug("Checking water calibration...") PARAMS['WATER_CALIBRATION_RANGE'] PARAMS['WATER_CALIBRATION_OPEN_TIMES'] PARAMS['WATER_CALIBRATION_WEIGHT_PERDROP'] PARAMS['WATER_CALIBRATION_DATE'] # F2TTL CALIBRATION: check f2ttl values from params, warn if old calibration
def __init__(self, subject_name, protocol=False, make=False): self.IBLRIG_FOLDER = get_iblrig_folder() self.IBLRIG_EPHYS_SESSION_FOLDER = str( Path(self.IBLRIG_FOLDER) / 'tasks' / '_iblrig_tasks_ephysChoiceWorld' / 'sessions') self._BOARD = params.get_board_name() self._PROTOCOL = protocol self.IBLRIG_COMMIT_HASH = get_commit_hash(self.IBLRIG_FOLDER) self.IBLRIG_VERSION_TAG = get_version_tag(self.IBLRIG_FOLDER) self.IBLRIG_PARAMS_FOLDER = get_iblrig_params_folder() self.IBLRIG_DATA_FOLDER = get_iblrig_data_folder(subjects=False) self.IBLRIG_DATA_SUBJECTS_FOLDER = get_iblrig_data_folder(subjects=True) self.PARAMS = params.load_params_file() self.IBLRIG_PARAMS_FILE = str( Path(self.IBLRIG_PARAMS_FOLDER) / '.bpod_comports.json') self.SUBJECT_NAME = subject_name self.SUBJECT_FOLDER = os.path.join( self.IBLRIG_DATA_SUBJECTS_FOLDER, self.SUBJECT_NAME) self.BONSAI = get_bonsai_path(use_iblrig_bonsai=True) self.VISUAL_STIM_FOLDER = str(Path(self.IBLRIG_FOLDER) / 'visual_stim') self.VISUAL_STIMULUS_TYPE = get_visual_stim_type(self._PROTOCOL) self.VISUAL_STIMULUS_FILE = str( Path(self.VISUAL_STIM_FOLDER) / self.VISUAL_STIMULUS_TYPE / 'Gabor2D.bonsai') self.VIDEO_RECORDING_FOLDER = os.path.join( self.IBLRIG_FOLDER, 'devices', 'camera_recordings') self.VIDEO_RECORDING_FILE = os.path.join( self.VIDEO_RECORDING_FOLDER, 'one_camera.bonsai') self.SESSION_DATETIME = datetime.datetime.now() self.SESSION_DATE = self.SESSION_DATETIME.date().isoformat() self.SESSION_DATETIME = self.SESSION_DATETIME.isoformat() self.SESSION_DATE_FOLDER = os.path.join( self.SUBJECT_FOLDER, self.SESSION_DATE) self.SESSION_NUMBER = get_session_number(self.SESSION_DATE_FOLDER) self.SESSION_FOLDER = str( Path(self.SESSION_DATE_FOLDER) / self.SESSION_NUMBER) self.SESSION_RAW_DATA_FOLDER = os.path.join( self.SESSION_FOLDER, 'raw_behavior_data') self.SESSION_RAW_VIDEO_DATA_FOLDER = os.path.join( self.SESSION_FOLDER, 'raw_video_data') self.SESSION_RAW_EPHYS_DATA_FOLDER = os.path.join( self.SESSION_FOLDER, 'raw_ephys_data') self.SESSION_RAW_IMAGING_DATA_FOLDER = os.path.join( self.SESSION_FOLDER, 'raw_imaging_data') self.SESSION_NAME = '{}'.format(os.path.sep).join( [self.SUBJECT_NAME, self.SESSION_DATE, self.SESSION_NUMBER]) self.BASE_FILENAME = '_iblrig_task' self.SETTINGS_FILE_PATH = os.path.join(self.SESSION_RAW_DATA_FOLDER, self.BASE_FILENAME + 'Settings.raw.json') self.DATA_FILE_PATH = os.path.join(self.SESSION_RAW_DATA_FOLDER, self.BASE_FILENAME + 'Data.raw.jsonable') # Water calinbration files self.LATEST_WATER_CALIBRATION_FILE = get_water_calibration_func_file(latest=True) self.LATEST_WATER_CALIB_RANGE_FILE = get_water_calibration_range_file(latest=True) if self.LATEST_WATER_CALIBRATION_FILE.parent != self.LATEST_WATER_CALIB_RANGE_FILE.parent: self.LATEST_WATER_CALIBRATION_FILE = str(self.LATEST_WATER_CALIBRATION_FILE) self.LATEST_WATER_CALIB_RANGE_FILE = None else: self.LATEST_WATER_CALIBRATION_FILE = str(self.LATEST_WATER_CALIBRATION_FILE) self.LATEST_WATER_CALIB_RANGE_FILE = str(self.LATEST_WATER_CALIB_RANGE_FILE) if str(self.LATEST_WATER_CALIBRATION_FILE) == '.': self.LATEST_WATER_CALIBRATION_FILE = None self.LATEST_WATER_CALIB_RANGE_FILE = None # Previous session files self.PREVIOUS_DATA_FILE = get_previous_data_file(self._PROTOCOL, self.SUBJECT_NAME, self.SESSION_FOLDER) self.PREVIOUS_SETTINGS_FILE = get_previous_settings_file(self._PROTOCOL, self.SUBJECT_NAME, self.SESSION_FOLDER) self.PREVIOUS_SESSION_PATH = get_previous_session_path(self._PROTOCOL, self.SUBJECT_NAME, self.SESSION_FOLDER) if make: self.make_missing_folders(make) self.display_logs()