本文整理汇总了Python中timeseries.TimeSeries.remove_buffer方法的典型用法代码示例。如果您正苦于以下问题:Python TimeSeries.remove_buffer方法的具体用法?Python TimeSeries.remove_buffer怎么用?Python TimeSeries.remove_buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timeseries.TimeSeries
的用法示例。
在下文中一共展示了TimeSeries.remove_buffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_event_data
# 需要导入模块: from timeseries import TimeSeries [as 别名]
# 或者: from timeseries.TimeSeries import remove_buffer [as 别名]
#.........这里部分代码省略.........
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',
self.samplerate,dims=dims)
# filter if desired
if not(filt_freq is None):
# filter that data
eventdata = eventdata.filtered(filt_freq,
filt_type=filt_type,
order=filt_order)
# resample if desired
if (not(resampled_rate is None) and
not(resampled_rate == eventdata.samplerate)):
# resample the data
eventdata = eventdata.resampled(resampled_rate)
# remove the buffer and set the time range
if buf > 0 and not(keep_buffer):
# remove the buffer
eventdata = eventdata.remove_buffer(buf)
# return the timeseries
return eventdata
示例2: get_event_data
# 需要导入模块: from timeseries import TimeSeries [as 别名]
# 或者: from timeseries.TimeSeries import remove_buffer [as 别名]
#.........这里部分代码省略.........
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 '+
str(len(bad_evs))+' events.')
# process the channels
if isinstance(channels, dict):
# turn into indices
ch_info = self.channels
key = channels.keys()[0]
channels = [np.nonzero(ch_info[key]==c)[0][0] for c in channels[key]]
elif isinstance(channels, str):
# find that channel by name
channels = np.nonzero(self.channels['name']==channels)[0][0]
if channels is None or len(np.atleast_1d(channels))==0:
channels = np.arange(self.nchannels)
channels = np.atleast_1d(channels)
channels.sort()
# 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(self.channels[channels],'channels'), # can index into channels
Dim(events,'events'),
Dim(time_range,'time')]
eventdata = TimeSeries(np.asarray(eventdata),
'time',
self.samplerate,dims=dims)
# filter if desired
if not(filt_freq is None):
# filter that data
eventdata = eventdata.filtered(filt_freq,
filt_type=filt_type,
order=filt_order)
# resample if desired
if (not(resampled_rate is None) and
not(resampled_rate == eventdata.samplerate)):
# resample the data
eventdata = eventdata.resampled(resampled_rate,
loop_axis=loop_axis,
num_mp_procs=num_mp_procs)
# remove the buffer and set the time range
if buf > 0 and not(keep_buffer):
# remove the buffer
eventdata = eventdata.remove_buffer(buf)
# return the timeseries
return eventdata