def get_iblrig_version(): ph.get_iblrig_folder() # Find version number from `__init__.py` without executing it. file_path = Path(ph.get_iblrig_folder()) / "setup.py" with open(file_path, "r") as f: version = re.search(r"version=\"([^\"]+)\"", f.read()).group(1) return version
def make_stims_for_passiveCW_pcs(seed_num=None, save=False): if seed_num is not None: np.random.seed(seed_num) iblrig_path = Path(ph.get_iblrig_folder()) # Generate the position and contrast for the replayed stims contrasts = [1.0, 0.25, 0.125, 0.0625] zero_contrasts = [0.0] positions = [-35, 35] pc_repeats = 20 # zero % contrast is added with half the amount of pc_repeats zero_repeats = len(positions) * pc_repeats / 2 pos = sorted(positions * len(contrasts) * pc_repeats) cont = contrasts * pc_repeats * len(positions) pos.extend(positions * int(zero_repeats / len(positions))) cont.extend(zero_contrasts * int(zero_repeats)) sphase = [np.random.uniform(0, 2 * math.pi) for x in cont] gabors = np.array([[int(p), c, s] for p, c, s in zip(pos, cont, sphase)]) np.random.shuffle(gabors) # Make into strings for saving if save: fpath = iblrig_path / "visual_stim" / "passiveChoiceWorld" fpath = fpath / "Extensions" / "passiveCW_stims.csv" np.savetxt(fpath, gabors, delimiter=" ", fmt=["%d", "%f", "%f"]) return gabors
def start_passive_visual_stim(save2folder): here = os.getcwd() bns = ph.get_bonsai_path() stim_folder = str( Path(ph.get_iblrig_folder()) / "visual_stim" / "passiveChoiceWorld" ) wkfl = os.path.join(stim_folder, "passiveChoiceWorld_passive.bonsai") os.chdir(stim_folder) # Flags noedit = "--no-editor" # implies start and no-debug? noboot = "--no-boot" # Properties SA0_DueTime = "-p:Stim.SpontaneousActivity0.DueTime=00:10:00" RFM_FileName = "-p:Stim.ReceptiveFieldMappingStim.FileNameRFMapStim=" + str( Path(save2folder) / "_iblrig_RFMapStim.raw.bin" ) RFM_MappingTime = "-p:Stim.ReceptiveFieldMappingStim.MappingTime=00:05:00" cmd = [bns, wkfl, noboot, noedit, SA0_DueTime, RFM_FileName, RFM_MappingTime] log.info("Starting spontaneous activity and RF mapping stims") os.chdir(stim_folder) s = subprocess.run(cmd, stdout=subprocess.PIPE) # locking call os.chdir(here) log.info("Done") sys.stdout.flush() return s
def start_frame2ttl_test(data_file, lengths_file, harp=False): here = os.getcwd() bns = ph.get_bonsai_path() stim_folder = str( Path(ph.get_iblrig_folder()) / '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' 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, data_file_name, lengths_file_name]) os.chdir(here) return s
def test_get_iblrig_params_folder(self): f = ph.get_iblrig_params_folder() self.assertTrue(isinstance(f, str)) self.assertTrue("iblrig_params" in f) fp = Path(f) self.assertTrue( str(fp.parent) == str(Path(ph.get_iblrig_folder()).parent))
def test_get_commit_hash(self): import subprocess out = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip() # Run it ch = ph.get_commit_hash(ph.get_iblrig_folder()) self.assertTrue(out == ch)
def plot_pcqs(session_num, folder="./tasks/_iblrig_tasks_ephysChoiceWorld/sessions"): iblrig_path = Path(ph.get_iblrig_folder()) folder_path = Path(folder) folder = str(iblrig_path / folder_path) num = session_num pcqs = np.load(folder + f"/pcqs_session_{num}.npy") len_block = np.load(folder + f"/pcqs_session_{num}_len_blocks.npy") with plt.xkcd(scale=1, length=100, randomness=2): f = plt.figure(figsize=(16, 12), dpi=80) f.suptitle(f"Session number: {num}") ax_position = plt.subplot2grid([2, 2], [0, 0], rowspan=1, colspan=1, fig=f) ax_contrast = plt.subplot2grid([2, 2], [0, 1], rowspan=1, colspan=1, fig=f, sharex=ax_position) ax_qperiod = plt.subplot2grid([2, 2], [1, 0], rowspan=1, colspan=1, fig=f, sharex=ax_position) ax_sphase = plt.subplot2grid([2, 2], [1, 1], rowspan=1, colspan=1, fig=f, sharex=ax_position) ax_position.plot(pcqs[:, 0], ".", label="Position", color="b") ax_position.plot(smooth(pcqs[:, 0], window_len=20, window="blackman"), alpha=0.5, color="k") ax_contrast.plot(pcqs[:, 1] * 100, ".", label="Contrasts") ax_qperiod.plot(pcqs[:, 2], ".", label="Quiescent period") ax_sphase.plot(pcqs[:, 3], ".", label="Stimulus phase") [ ax.set_ylabel(l) for ax, l in zip( f.axes, [ "Position (º)", "Contrasts (%)", "Quiescent period (s)", "Stimulus phase (rad)", ], ) ] [ax.axvline(x, alpha=0.5) for x in np.cumsum(len_block) for ax in f.axes] f.show() return pcqs, len_block
def pre_generate_ephysCW_session_files( nsessions, path="./tasks/_iblrig_tasks_ephysChoiceWorld/sessions"): iblrig_path = Path(ph.get_iblrig_folder()) path = iblrig_path / Path(path) path.mkdir(parents=True, exist_ok=True) for i in range(nsessions): pc, len_block = make_ephysCW_pc() pcqs = make_ephysCW_pcqs(pc) np.save(path / f"session_{i}_ephys_pcqs.npy", pcqs) np.save(path / f"session_{i}_ephys_len_blocks.npy", len_block)
def alyx_ok() -> bool: out = False try: python = envs.get_env_python(env_name="ibllib") here = os.getcwd() os.chdir(os.path.join(ph.get_iblrig_folder(), "scripts")) os.system(f'{python} -c "from one.api import ONE; ONE()"') os.chdir(here) out = True except BaseException as e: log.warning(f"{e}\nCan't connect to Alyx.") return out
def plot_pcqs(session_num, folder='./tasks/_iblrig_tasks_ephysChoiceWorld/sessions'): iblrig_path = Path(ph.get_iblrig_folder()) folder_path = Path(folder) folder = str(iblrig_path / folder_path) num = session_num pcqs = np.load(folder + f'/pcqs_session_{num}.npy') len_block = np.load(folder + f'/pcqs_session_{num}_len_blocks.npy') with plt.xkcd(scale=1, length=100, randomness=2): f = plt.figure(figsize=(16, 12), dpi=80) f.suptitle(f'Session number: {num}') ax_position = plt.subplot2grid([2, 2], [0, 0], rowspan=1, colspan=1, fig=f) ax_contrast = plt.subplot2grid([2, 2], [0, 1], rowspan=1, colspan=1, fig=f, sharex=ax_position) ax_qperiod = plt.subplot2grid([2, 2], [1, 0], rowspan=1, colspan=1, fig=f, sharex=ax_position) ax_sphase = plt.subplot2grid([2, 2], [1, 1], rowspan=1, colspan=1, fig=f, sharex=ax_position) ax_position.plot(pcqs[:, 0], '.', label='Position', color='b') ax_position.plot(smooth(pcqs[:, 0], window_len=20, window='blackman'), alpha=0.5, color='k') ax_contrast.plot(pcqs[:, 1] * 100, '.', label='Contrasts') ax_qperiod.plot(pcqs[:, 2], '.', label='Quiescent period') ax_sphase.plot(pcqs[:, 3], '.', label='Stimulus phase') [ ax.set_ylabel(l) for ax, l in zip(f.axes, [ 'Position (º)', 'Contrasts (%)', 'Quiescent period (s)', 'Stimulus phase (rad)' ]) ] [ax.axvline(x, alpha=0.5) for x in np.cumsum(len_block) for ax in f.axes] f.show() return pcqs, len_block
def pre_generate_stim_phase( nsessions, path="./tasks/_iblrig_tasks_ephysChoiceWorld/sessions"): iblrig_path = Path(ph.get_iblrig_folder()) path = iblrig_path / Path(path) path.mkdir(parents=True, exist_ok=True) for i in range(nsessions): length = len(np.load(path.joinpath(f"session_{i}_ephys_pcqs.npy"))) sphase = np.array( [np.random.uniform(0, 2 * math.pi) for x in range(length)]) np.save(path / f"session_{i}_stim_phase.npy", sphase) else: length = len(np.load(path.joinpath("session_mock_ephys_pcqs.npy"))) sphase = np.array( [np.random.uniform(0, 2 * math.pi) for x in range(length)]) np.save(path / "session_mock_stim_phase.npy", sphase)
def start_screen_color(): here = os.getcwd() iblrig_folder_path = Path(ph.get_iblrig_folder()) os.chdir(str(iblrig_folder_path / "visual_stim" / "f2ttl_calibration")) bns = ph.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 subprocess.Popen([bns, wrkfl, editor, noboot]) time.sleep(3) os.chdir(here)
def pre_generate_passiveCW_session_files( nsessions, path="./tasks/_iblrig_tasks_ephysChoiceWorld/sessions"): iblrig_path = Path(ph.get_iblrig_folder()) path = iblrig_path / Path(path) path.mkdir(parents=True, exist_ok=True) for i in range(nsessions): delays, ids, = make_passiveCW_session_delays_ids() pcs = make_stims_for_passiveCW_pcs() np.save(path / f"session_{i}_passive_stimIDs.npy", ids) np.save(path / f"session_{i}_passive_stimDelays.npy", delays) np.save(path / f"session_{i}_passive_pcs.npy", pcs) else: delays, ids, = make_passiveCW_session_delays_ids() pcs = make_stims_for_passiveCW_pcs() np.save(path / "session_mock_passive_stimIDs.npy", ids) np.save(path / "session_mock_passive_stimDelays.npy", delays) np.save(path / "session_mock_passive_pcs.npy", pcs)
def make_stims_for_certification_pcs(seed_num=None, save=False): if seed_num is not None: np.random.seed(seed_num) iblrig_path = Path(ph.get_iblrig_folder()) # Generate the position and contrast for the replayed stims contrasts = [1.0, 0.5, 0.25, 0.125, 0.0625] positions = [-35, 35] pc_repeats = 20 pos = sorted(positions * len(contrasts) * pc_repeats) cont = contrasts * pc_repeats * len(positions) sphase = [np.random.uniform(0, 2 * math.pi) for x in cont] gabors = np.array([[int(p), c, s] for p, c, s in zip(pos, cont, sphase)]) np.random.shuffle(gabors) # Make into strings for saving if save: fpath = iblrig_path / "visual_stim" / "ephys_certification" fpath = fpath / "Extensions" / "certification_stims.csv" np.savetxt(fpath, gabors, delimiter=" ", fmt=["%d", "%f", "%f"]) return gabors
def test_get_iblrig_folder(self): f = ph.get_iblrig_folder() self.assertTrue(isinstance(f, str)) self.assertTrue("iblrig" in f)
create_ONE_alyx_user create_local_subjects_from_alyx Return: None or json dict """ import json from pathlib import Path from one.api import ONE from pybpodgui_api.models.project import Project import iblrig.path_helper as ph IBLRIG_PARAMS_FOLDER = Path(ph.get_iblrig_params_folder()) print(ph.get_iblrig_folder(), "\n", IBLRIG_PARAMS_FOLDER) local2alyx_names = {"IBL": "ibl_neuropixel_brainwide_01"} alyx2local_names = {"ibl_neuropixel_brainwide_01": "IBL"} # UTILS def _load_pybpod_obj_json(obj): objpath = Path(obj.path).joinpath(obj.name + ".json") with open(objpath, "r") as f: out = json.load(f) return out def _save_pybpod_obj_json(obj, data):