Пример #1
0
def _grep_param_dict(pattern: str = "") -> dict or str:
    """
    Returns subdict of all matches of pattern
    If subdict only has one entry will return just the value
    """
    pardict = params.load_params_file()
    out = {k: pardict[k] for k in pardict if pattern in k}
    if len(out) == 1:
        out = list(out.values())[0]
    return out
Пример #2
0
def init_calib_func() -> scipy.interpolate.pchip:
    PARAMS = params.load_params_file()
    if PARAMS['WATER_CALIBRATION_DATE'] == "":
        msg = f"""
    ##########################################
         Water calibration date is emtpy!
    ##########################################"""
        log.error(msg)
        raise ValueError("Rig not calibrated")

    time2vol = scipy.interpolate.pchip(
        PARAMS["WATER_CALIBRATION_OPEN_TIMES"],
        PARAMS["WATER_CALIBRATION_WEIGHT_PERDROP"])

    return time2vol
Пример #3
0
def init_calib_func_range() -> tuple:
    PARAMS = params.load_params_file()
    if PARAMS["WATER_CALIBRATION_RANGE"] == "":
        min_open_time = 0
        max_open_time = 1000
        msg = """
            ##########################################
                NO DATA: WATER CALIBRATION RANGE
            ##########################################
                        using full range
            ##########################################"""
        log.warning(msg)
    else:
        min_open_time = PARAMS["WATER_CALIBRATION_RANGE"][0]
        max_open_time = PARAMS["WATER_CALIBRATION_RANGE"][1]

    return min_open_time, max_open_time
Пример #4
0
    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()
Пример #5
0
import iblrig.bonsai as bonsai
import iblrig.frame2TTL as frame2TTL
import iblrig.iotasks as iotasks
import iblrig.misc as misc
import iblrig.params as params
import task_settings
import user_settings
from iblrig.bpod_helper import BpodMessageCreator, bpod_lights
from iblrig.rotary_encoder import MyRotaryEncoder
from session_params import SessionParamHandler

log = logging.getLogger("iblrig")
log.setLevel(logging.INFO)

PARAMS = params.load_params_file()
# start sph
sph = SessionParamHandler(task_settings, user_settings)
# frame2TTL seg thresholds
if frame2TTL.get_and_set_thresholds() == 0:
    sph.F2TTL_GET_AND_SET_THRESHOLDS = True
# Rotary encoder
re = MyRotaryEncoder(sph.ALL_THRESHOLDS, sph.STIM_GAIN,
                     sph.PARAMS["COM_ROTARY_ENCODER"])
sph.ROTARY_ENCODER = re

# get bpod
bpod = Bpod()
# Build messages
msg = BpodMessageCreator(bpod)
sc_play_tone = msg.sound_card_play_idx(sph.GO_TONE_IDX)
Пример #6
0
import iblrig.params as params
import iblrig.alyx as alyx
import datetime


pars = params.load_params_file()
print(f"\nPrevious value on [{pars['SCREEN_LUX_DATE']}] was [{pars['SCREEN_LUX_VALUE']}]")
value = input("\nPlease input the value of the luxometer (lux): ")
pars["SCREEN_LUX_VALUE"] = float(value)
pars["SCREEN_LUX_DATE"] = str(datetime.datetime.now().date())
print("  Updating local params file...")
lpars = params.update_params_file(pars)
print("  Updating lab location on Alyx...")
apars = alyx.update_alyx_params(pars, force=True)

print(
    "\nLux measurement updated on",
    f"[{lpars['SCREEN_LUX_DATE']}] with value [{lpars['SCREEN_LUX_VALUE']}]",
    "\n",
)
Пример #7
0
    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()