Beispiel #1
0
def extract_replay_debug(
    session_path: str,
    sync: dict = None,
    sync_map: dict = None,
    treplay: np.array = None,
    ax: plt.axes = None,
) -> Tuple[pd.DataFrame, pd.DataFrame]:
    # Load sessions sync channels, map
    if sync is None or sync_map is None:
        sync, sync_map = ephys_fpga.get_main_probe_sync(session_path, bin_exists=False)

    if treplay is None:
        passivePeriods_df = extract_passive_periods(session_path, sync=sync, sync_map=sync_map)
        treplay = passivePeriods_df.taskReplay.values

    if ax is None:
        f, ax = plt.subplots(1, 1)

    f = ax.figure
    f.suptitle("/".join(str(session_path).split("/")[-5:]))
    plot_sync_channels(sync=sync, sync_map=sync_map, ax=ax)

    passivePeriods_df = extract_passive_periods(session_path, sync=sync, sync_map=sync_map)
    treplay = passivePeriods_df.taskReplay.values

    plot_passive_periods(passivePeriods_df, ax=ax)

    fttl = ephys_fpga.get_sync_fronts(sync, sync_map["frame2ttl"], tmin=treplay[0])
    passiveGabor_df = _extract_passiveGabor_df(fttl, session_path)
    plot_gabor_times(passiveGabor_df, ax=ax)

    bpod = ephys_fpga.get_sync_fronts(sync, sync_map["bpod"], tmin=treplay[0])
    passiveValve_intervals = _extract_passiveValve_intervals(bpod)
    plot_valve_times(passiveValve_intervals, ax=ax)

    task_version = _load_task_protocol(session_path)
    audio = ephys_fpga.get_sync_fronts(sync, sync_map["audio"], tmin=treplay[0])
    passiveTone_intervals, passiveNoise_intervals = _extract_passiveAudio_intervals(audio,
                                                                                    task_version)
    plot_audio_times(passiveTone_intervals, passiveNoise_intervals, ax=ax)

    passiveStims_df = np.concatenate(
        [passiveValve_intervals, passiveTone_intervals, passiveNoise_intervals], axis=1
    )
    columns = ["valveOn", "valveOff", "toneOn", "toneOff", "noiseOn", "noiseOff"]
    passiveStims_df = pd.DataFrame(passiveStims_df, columns=columns)

    return (
        passiveGabor_df,
        passiveStims_df,
    )  # _ibl_passiveGabor.table.csv, _ibl_passiveStims.table.csv
Beispiel #2
0
    def _extract(
        self, sync: dict = None, sync_map: dict = None, plot: bool = False, **kwargs
    ) -> tuple:
        if sync is None or sync_map is None:
            sync, sync_map = ephys_fpga.get_main_probe_sync(self.session_path, bin_exists=False)

        # Passive periods
        passivePeriods_df = extract_passive_periods(
            self.session_path, sync=sync, sync_map=sync_map
        )
        trfm = passivePeriods_df.RFM.values
        treplay = passivePeriods_df.taskReplay.values

        try:
            # RFMapping
            passiveRFM_times = extract_rfmapping(
                self.session_path, sync=sync, sync_map=sync_map, trfm=trfm
            )
        except Exception as e:
            log.error(f"Failed to extract RFMapping datasets: {e}")
            passiveRFM_times = None

        try:
            (passiveGabor_df, passiveStims_df,) = extract_task_replay(
                self.session_path, sync=sync, sync_map=sync_map, treplay=treplay
            )
        except Exception as e:
            log.error(f"Failed to extract task replay stimuli: {e}")
            passiveGabor_df, passiveStims_df = (None, None)

        if plot:
            f, ax = plt.subplots(1, 1)
            f.suptitle("/".join(str(self.session_path).split("/")[-5:]))
            plot_sync_channels(sync=sync, sync_map=sync_map, ax=ax)
            plot_passive_periods(passivePeriods_df, ax=ax)
            plot_rfmapping(passiveRFM_times, ax=ax)
            plot_gabor_times(passiveGabor_df, ax=ax)
            plot_stims_times(passiveStims_df, ax=ax)
            plt.show()

        data = (
            passivePeriods_df,  # _ibl_passivePeriods.intervalsTable.csv
            passiveRFM_times,  # _ibl_passiveRFM.times.npy
            passiveGabor_df,  # _ibl_passiveGabor.table.csv,
            passiveStims_df  # _ibl_passiveStims.table.csv
        )

        # Set save names to None if data not extracted - these will not be saved or registered
        self.save_names = tuple(None if y is None else x for x, y in zip(self.save_names, data))
        return data
    def _extract(self,
                 sync: dict = None,
                 sync_map: dict = None,
                 plot: bool = False,
                 **kwargs) -> tuple:
        if sync is None or sync_map is None:
            sync, sync_map = ephys_fpga._get_main_probe_sync(self.session_path,
                                                             bin_exists=False)

        try:
            # Passive periods
            passivePeriods_df = extract_passive_periods(self.session_path,
                                                        sync=sync,
                                                        sync_map=sync_map)
            trfm = passivePeriods_df.RFM.values
            treplay = passivePeriods_df.taskReplay.values

        except BaseException as e:
            log.error("Failed to extract passive periods", e)
            passivePeriods_df = None
            trfm = None
            treplay = None

        try:
            # RFMapping
            passiveRFM_times = extract_rfmapping(self.session_path,
                                                 sync=sync,
                                                 sync_map=sync_map,
                                                 trfm=trfm)
        except BaseException as e:
            log.error("Failed to extract RFMapping datasets", e)
            passiveRFM_times = None
        try:
            (
                passiveGabor_df,
                passiveStims_df,
            ) = extract_task_replay(self.session_path,
                                    sync=sync,
                                    sync_map=sync_map,
                                    treplay=treplay)
        except BaseException as e:
            log.error("Failed to extract task replay stimuli", e)
            (
                passiveGabor_df,
                passiveStims_df,
            ) = (
                None,
                None,
            )
        if plot:
            f, ax = plt.subplots(1, 1)
            f.suptitle("/".join(str(self.session_path).split("/")[-5:]))
            plot_sync_channels(sync=sync, sync_map=sync_map, ax=ax)
            plot_passive_periods(passivePeriods_df, ax=ax)
            plot_rfmapping(passiveRFM_times, ax=ax)
            plot_gabor_times(passiveGabor_df, ax=ax)
            plot_stims_times(passiveStims_df, ax=ax)

        return (
            passivePeriods_df,  # _ibl_passivePeriods.intervalsTable.csv
            passiveRFM_times,  # _ibl_passiveRFM.times.npy
            passiveGabor_df,  # _ibl_passiveGabor.table.csv,
            passiveStims_df,  # _ibl_passiveStims.table.csv
        )