Esempio n. 1
0
def raster_from_epoch(signals, epoch, occurrences=0, channels=0,
                          xlabel='Time', ylabel='Value',
                          linestyle='-', linewidth=1,
                          ax=None, title=None):
    """TODO: doc"""
    raise NotImplementedError
    if occurrences is None:
        return
    occurrences = pad_to_signals(signals, occurrences)
    channels = pad_to_signals(signals, channels)

    legend = [s.name for s in signals]
    times = []
    values = []
    for s, o, c in zip(signals, occurrences, channels):
        # Get occurrences x chans x time
        extracted = s.extract_epoch(epoch)
        # Get values from specified occurrence and channel
        value_vector = extracted[o][c]
        # Convert bins to time (relative to start of epoch)
        # TODO: want this to be absolute time relative to start of data?
        time_vector = np.arange(0, len(value_vector)) / s.fs
        times.append(time_vector)
        values.append(value_vector)
    plot_timeseries(times, values, xlabel, ylabel, legend=legend,
                    linestyle=linestyle, linewidth=linewidth,
                    ax=ax, title=title)
Esempio n. 2
0
def timeseries_from_epoch(signals,
                          epoch,
                          occurrences=0,
                          channels=0,
                          xlabel='Time',
                          ylabel='Value',
                          linestyle='-',
                          linewidth=1,
                          ax=None,
                          title=None,
                          pre_dur=None,
                          dur=None,
                          PreStimSilence=None):
    """TODO: doc"""
    if occurrences is None:
        return
    occurrences = pad_to_signals(signals, occurrences)
    channels = pad_to_signals(signals, channels)
    if PreStimSilence is None:
        d = signals[0].get_epoch_bounds('PreStimSilence')
        if len(d):
            PreStimSilence = np.mean(np.diff(d))
        else:
            PreStimSilence = 0
    if pre_dur is None:
        pre_dur = PreStimSilence

    legend = [s.name for s in signals]
    times = []
    values = []
    for s, o, c in zip(signals, occurrences, channels):
        # Get occurrences x chans x time
        extracted = s.extract_epoch(epoch)
        # Get values from specified occurrence and channel
        value_vector = extracted[o][c]
        # Convert bins to time (relative to start of epoch)
        # TODO: want this to be absolute time relative to start of data?
        time_vector = np.arange(0, len(value_vector)) / s.fs - PreStimSilence

        # limit time range if specified
        good_bins = (time_vector >= -PreStimSilence)
        if dur is not None:
            good_bins[time_vector > dur] = False

        times.append(time_vector[good_bins])
        values.append(value_vector[good_bins])

    plot_timeseries(times,
                    values,
                    xlabel,
                    ylabel,
                    legend=legend,
                    linestyle=linestyle,
                    linewidth=linewidth,
                    ax=ax,
                    title=title)
Esempio n. 3
0
def timeseries_from_signals(signals,
                            channels=0,
                            xlabel='Time',
                            ylabel='Value',
                            linestyle='-',
                            linewidth=1,
                            ax=None,
                            title=None):
    """TODO: doc"""
    channels = pad_to_signals(signals, channels)

    times = []
    values = []
    legend = []
    for s, c in zip(signals, channels):
        # Get values from specified channel
        value_vector = s.as_continuous()[c]
        # Convert indices to absolute time based on sampling frequency
        time_vector = np.arange(0, len(value_vector)) / s.fs
        times.append(time_vector)
        values.append(value_vector)
        if s.chans is not None:
            legend.append(s.name + ' ' + s.chans[c])

    plot_timeseries(times,
                    values,
                    xlabel,
                    ylabel,
                    legend=legend,
                    linestyle=linestyle,
                    linewidth=linewidth,
                    ax=ax,
                    title=title)
Esempio n. 4
0
def timeseries_from_signals(signals=None,
                            channels=0,
                            no_legend=False,
                            time_range=None,
                            rec=None,
                            sig_name=None,
                            **options):
    """
    Plot one or more timeseries extracted from a list of signals

        :param signals: List of signals to plot
        :param channels: List of channels, one per signal(??)
        :param no_legend: True/False guess what this means?
        :param time_range: if not None, plot time_range[0]:time_range[1] (seconds) of the signal
        :return: Matplotlib axes containing the plot
    """
    if channels is None:
        channels = 0
    if signals is None:
        signals = [rec[sig_name]]

    channels = pad_to_signals(signals, channels)
    times = []
    values = []
    legend = []
    for i, s in enumerate(signals):
        if len(signals) > 1:
            chanset = [channels[i]]
        else:
            chanset = channels
        for c in chanset:
            if type(c) is str:
                c = 0
            # Get values from specified channel
            value_vector = s.as_continuous()[c]
            # Convert indices to absolute time based on sampling frequency
            time_vector = np.arange(0, len(value_vector)) / s.fs
            times.append(time_vector)
            values.append(value_vector)
            if s.chans is not None:
                legend.append(s.name + ' ' + s.chans[c])

    if no_legend:
        legend = None

    if time_range is not None:
        time_range = np.round(np.array(time_range) * s.fs).astype(int)
        times = [t[np.arange(time_range[0], time_range[1])] for t in times]
        values = [v[np.arange(time_range[0], time_range[1])] for v in values]

    ax = plot_timeseries(times, values, legend=legend, **options)

    return ax
Esempio n. 5
0
def timeseries_from_signals(signals,
                            channels=0,
                            xlabel='Time',
                            ylabel='Value',
                            ax=None,
                            title=None):
    """TODO: doc"""
    channels = pad_to_signals(signals, channels)

    legend = [s.name for s in signals]
    times = []
    values = []
    for s, c in zip(signals, channels):
        # Get values from specified channel
        value_vector = s.as_continuous()[c]
        # Convert indices to absolute time based on sampling frequency
        time_vector = np.arange(0, len(value_vector)) / s.fs
        times.append(time_vector)
        values.append(value_vector)
    plot_timeseries(times, values, xlabel, ylabel, legend, ax=ax, title=title)