当前位置: 首页>>代码示例>>Python>>正文


Python TimeSeries.resampled方法代码示例

本文整理汇总了Python中timeseries.TimeSeries.resampled方法的典型用法代码示例。如果您正苦于以下问题:Python TimeSeries.resampled方法的具体用法?Python TimeSeries.resampled怎么用?Python TimeSeries.resampled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在timeseries.TimeSeries的用法示例。


在下文中一共展示了TimeSeries.resampled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_event_data

# 需要导入模块: from timeseries import TimeSeries [as 别名]
# 或者: from timeseries.TimeSeries import resampled [as 别名]
    def get_event_data(self,channels,event_offsets,
                       start_time,end_time,buffer_time=0.0,
                       resampled_rate=None,
                       filt_freq=None,filt_type='stop',filt_order=4,
                       keep_buffer=False):
        """
        Return an TimeSeries containing data for the specified channel
        in the form [events,duration].

        Parameters
        ----------
        channels: {int}
            Channels from which to load data.
        event_offsets: {array_like}
            Array/list of event offsets (in samples) into the data,
            specifying each event onset time.
        start_time: {float}
            Start of epoch to retrieve (in time-unit of the data).
        end_time: {float}
            End of epoch to retrieve (in time-unit of the data).
        buffer_time: {float},optional
            Extra buffer to add on either side of the event in order
            to avoid edge effects when filtering (in time unit of the
            data).
        resampled_rate: {float},optional
            New samplerate to resample the data to after loading.
        filt_freq: {array_like},optional
            The range of frequencies to filter (depends on the filter
            type.)
        filt_type = {scipy.signal.band_dict.keys()},optional
            Filter type.
        filt_order = {int},optional
            The order of the filter.
        keep_buffer: {boolean},optional
            Whether to keep the buffer when returning the data.
        """

        # translate back to dur and offset
        dur = end_time - start_time
        offset = start_time
        buf = buffer_time
        
        # Sanity checks:
        if(dur<0):
            raise ValueError('Duration must not be negative! '+
                             'Specified duration: '+str(dur))
        if(np.min(event_offsets)<0):
            raise ValueError('Event offsets must not be negative!')

        # make sure the events are an actual array
        event_offsets = np.asarray(event_offsets)
        
        # set event durations from rate
        # get the samplesize
        samplesize = 1./self.samplerate

        # get the number of buffer samples
        buf_samp = int(np.ceil(buf/samplesize))

        # calculate the offset samples that contains the desired offset
        offset_samp = int(np.ceil((np.abs(offset)-samplesize*.5)/samplesize)*
                          np.sign(offset))

        # finally get the duration necessary to cover the desired span
        #dur_samp = int(np.ceil((dur - samplesize*.5)/samplesize))
        dur_samp = (int(np.ceil((dur+offset - samplesize*.5)/samplesize)) -
                    offset_samp + 1)
        
        # add in the buffer
        dur_samp += 2*buf_samp
        offset_samp -= buf_samp

        # check that we have all the data we need before every event:
        if(np.min(event_offsets+offset_samp)<0):
            bad_evs = ((event_offsets+offset_samp)<0)
            raise ValueError('The specified values for offset and buffer '+
                             'require more data than is available before '+
                             str(np.sum(bad_evs))+' of all '+
                             str(len(bad_evs))+' events.')

        # process the channels
        if channels is None or len(np.atleast_1d(channels))==0:
            channels = np.arange(self.nchannels)
        channels = np.atleast_1d(channels)

        # load the timeseries (this must be implemented by subclasses)
        eventdata = self._load_data(channels,event_offsets,dur_samp,offset_samp)

        # calc the time range
        # get the samplesize
        samp_start = offset_samp*samplesize
        samp_end = samp_start + (dur_samp-1)*samplesize
        time_range = np.linspace(samp_start,samp_end,dur_samp)

	# make it a timeseries
        dims = [Dim(channels,'channels'),
                Dim(event_offsets,'event_offsets'),
                Dim(time_range,'time')]
        eventdata = TimeSeries(np.asarray(eventdata),
                               'time',
#.........这里部分代码省略.........
开发者ID:Jeff33,项目名称:ptsa,代码行数:103,代码来源:basewrapper.py

示例2: get_event_data

# 需要导入模块: from timeseries import TimeSeries [as 别名]
# 或者: from timeseries.TimeSeries import resampled [as 别名]
    def get_event_data(self,channels,events,
                       start_time,end_time,buffer_time=0.0,
                       resampled_rate=None,
                       filt_freq=None,filt_type='stop',filt_order=4,
                       keep_buffer=False,
                       loop_axis=None,num_mp_procs=0,eoffset='eoffset',
                       eoffset_in_time=True):
        """
        Return an TimeSeries containing data for the specified channel
        in the form [events,duration].

        Parameters
        ----------
        channels: {int} or {dict}
            Channels from which to load data.
        events: {array_like} or {recarray}
            Array/list of event offsets (in time or samples as
            specified by eoffset_in_time; in time by default) into
            the data, specifying each event onset time.
        start_time: {float}
            Start of epoch to retrieve (in time-unit of the data).
        end_time: {float}
            End of epoch to retrieve (in time-unit of the data).
        buffer_time: {float},optional
            Extra buffer to add on either side of the event in order
            to avoid edge effects when filtering (in time unit of the
            data).
        resampled_rate: {float},optional
            New samplerate to resample the data to after loading.
        filt_freq: {array_like},optional
            The range of frequencies to filter (depends on the filter
            type.)
        filt_type = {scipy.signal.band_dict.keys()},optional
            Filter type.
        filt_order = {int},optional
            The order of the filter.
        keep_buffer: {boolean},optional
            Whether to keep the buffer when returning the data.
        eoffset_in_time: {boolean},optional        
            If True, the unit of the event offsets is taken to be
            time (unit of the data), otherwise samples.
        """

        # translate back to dur and offset
        dur = end_time - start_time
        offset = start_time
        buf = buffer_time

        # get the event offsets
        if ((not (hasattr(events,'dtype') or hasattr(events,'columns'))) or
            (hasattr(events,'dtype') and events.dtype.names is None)):
            # they just passed in a list
            event_offsets = events
        elif ((hasattr(events, 'dtype') and (eoffset in events.dtype.names)) or
              (hasattr(events, 'columns') and (eoffset in events.columns))):
            event_offsets = events[eoffset]
        else:
            raise ValueError(eoffset+' must be a valid fieldname '+
                             'specifying the offset for the data.')
        
        # Sanity checks:
        if(dur<0):
            raise ValueError('Duration must not be negative! '+
                             'Specified duration: '+str(dur))
        if(np.min(event_offsets)<0):
            raise ValueError('Event offsets must not be negative!')

        # make sure the events are an actual array:
        event_offsets = np.asarray(event_offsets)
        if eoffset_in_time:
            # convert to samples
            event_offsets = np.atleast_1d(np.int64(
                np.round(event_offsets*self.samplerate)))
        
        # set event durations from rate
        # get the samplesize
        samplesize = 1./self.samplerate

        # get the number of buffer samples
        buf_samp = int(np.ceil(buf/samplesize))

        # calculate the offset samples that contains the desired offset
        offset_samp = int(np.ceil((np.abs(offset)-samplesize*.5)/samplesize)*
                          np.sign(offset))

        # finally get the duration necessary to cover the desired span
        #dur_samp = int(np.ceil((dur - samplesize*.5)/samplesize))
        dur_samp = (int(np.ceil((dur+offset - samplesize*.5)/samplesize)) -
                    offset_samp + 1)
        
        # add in the buffer
        dur_samp += 2*buf_samp
        offset_samp -= buf_samp

        # check that we have all the data we need before every event:
        if(np.min(event_offsets+offset_samp)<0):
            bad_evs = ((event_offsets+offset_samp)<0)
            raise ValueError('The specified values for offset and buffer '+
                             'require more data than is available before '+
                             str(np.sum(bad_evs))+' of all '+
#.........这里部分代码省略.........
开发者ID:ctw,项目名称:ptsa,代码行数:103,代码来源:basewrapper.py


注:本文中的timeseries.TimeSeries.resampled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。