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


Python TimeSeries.replace_data方法代码示例

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


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

示例1: generate_affine_backtransformation

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def generate_affine_backtransformation(self):
        """ Generate synthetic examples and test them to determine transformation

        This is the key method!
        """
        if type(self.example) == FeatureVector:
            testsample = FeatureVector.replace_data(
                self.example, numpy.zeros(self.example.shape))
            self.offset = numpy.longdouble(self._execute(testsample))
            self.trafo = FeatureVector.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for j in range(len(self.example.feature_names)):
                testsample = FeatureVector.replace_data(
                    self.example,
                    numpy.zeros(self.example.shape))
                testsample[0][j] = 1.0
                self.trafo[0][j] = \
                    numpy.longdouble(self._execute(testsample) - self.offset)
        elif type(self.example) == TimeSeries:
            testsample = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            self.offset = numpy.longdouble(numpy.squeeze(
                self._execute(testsample)))
            self.trafo = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for i in range(self.example.shape[0]):
                for j in range(self.example.shape[1]):
                    testsample = TimeSeries.replace_data(
                        self.example, numpy.zeros_like(self.example))
                    testsample[i][j] = 1.0
                    self.trafo[i][j] = \
                        numpy.longdouble(numpy.squeeze(self._execute(testsample))
                                       - self.offset)
开发者ID:pyspace,项目名称:pyspace,代码行数:35,代码来源:flow_node.py

示例2: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
 def _execute(self, data):
     """ Apply the windowing to the given data and return the result """        
     #Create a window of the correct length for the given data
     if self.num_of_samples is None:
         self.num_of_samples = data.shape[0]
         self.create_window_array()
          
     data_array=data.view(numpy.ndarray)
     #Do the actual windowing
     # TODO: check if windowed_data = (self.window_array.T * data) works also???
     windowed_data = (self.window_array * data_array.T).T
     
     # Skip trailing zeros
     if self.window_has_zeros and self.reduce_window:
         windowed_data = windowed_data[
             range(self.window_not_equal_zero[0],
                   self.window_not_equal_zero[-1] + 1), :]
     
         result_time_series = TimeSeries.replace_data(data, windowed_data)
         
         # Adjust start and end time when chopping was done
         result_time_series.start_time = data.start_time + \
             self.window_not_equal_zero[0] * 1000.0 / data.sampling_frequency
         result_time_series.end_time = \
             data.end_time - (data.shape[0] - self.window_not_equal_zero[-1]
                              - 1) * 1000.0 / data.sampling_frequency
     else:
         result_time_series = TimeSeries.replace_data(data, windowed_data)
                 
     return result_time_series
开发者ID:AlexanderFabisch,项目名称:pyspace,代码行数:32,代码来源:window_func.py

示例3: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def _execute(self, data):
        """ Perform a shift and normalization according
        (whole_data - mean(specific_samples)) / std(specific_samples)
        """
        if self.devariance:
            # code copy from LocalStandardizationNode
            std = numpy.std(data[self.subset],axis=0)
            std = check_zero_division(self, std, tolerance=10**-15, data_ts=data)

            return TimeSeries.replace_data(data,
                        (data-numpy.mean(data[self.subset], axis=0)) / std)
        else:
            return TimeSeries.replace_data(data, \
                        data-numpy.mean(data[self.subset], axis=0))
开发者ID:AlexanderFabisch,项目名称:pyspace,代码行数:16,代码来源:normalization.py

示例4: merge_time_series

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def merge_time_series(self, input_collection):
        """ Merges all timeseries of the input_collection to one big timeseries """
        # Retriev the time series from the input_collection
        input_timeseries = input_collection.get_data(0,0,'test')
        # Get the data from the first timeseries
        output_data = input_timeseries[0][0]
        skiped_range = output_data.start_time

        # Change the endtime of the first timeseries to the one of the last
        # timeseries inside the input_collection
        input_timeseries[0][0].end_time = input_timeseries[-1][0].end_time
        # For all the remaining timeseries

        for ts in input_timeseries[1:]:
            # Concatenate the data...
            output_data = numpy.vstack((output_data,ts[0]))
            # ... and add the marker to the first timeseries
            if(len(ts[0].marker_name) > 0):
                for k in ts[0].marker_name:
                    if(not input_timeseries[0][0].marker_name.has_key(k)):
                        input_timeseries[0][0].marker_name[k] = []
                    for time in ts[0].marker_name[k]:
                        input_timeseries[0][0].marker_name[k].append(time+ts[0].start_time - skiped_range)
        # Use the meta information from the first timeseries e.g. marker start/end_time
        # and create a new timeseries with the concatenated data
        merged_time_series = TimeSeries.replace_data(input_timeseries[0][0],output_data)
        # Change the name of the merged_time_series
        merged_time_series.name = "%s, length %d ms, %s" % (merged_time_series.name.split(',')[0], \
                                                            (len(merged_time_series)*1000.0)/merged_time_series.sampling_frequency,\
                                                            merged_time_series.name.split(',')[-1])
        
        return merged_time_series
开发者ID:Crespo911,项目名称:pyspace,代码行数:34,代码来源:time_series_sink.py

示例5: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def _execute(self, x):
        """ Compute the energy of the given signal x using the TKEO """
        #Determine the indices of the channels which will be filtered
        #Done only once...
        if(self.selected_channel_indices == None):
            self.selected_channels = self.selected_channels \
            if self.selected_channels != None else x.channel_names
            self.selected_channel_indices = [x.channel_names.index(channel_name) \
                                            for channel_name in self.selected_channels]
            self.old_data = numpy.zeros((2,len(self.selected_channel_indices)))

        filtered_data = numpy.zeros(x.shape)
        channel_counter = -1
        for channel_index in self.selected_channel_indices:
            channel_counter += 1
            for i in range(len(x)):
                if i==0:
                    filtered_data[i][channel_index] = math.pow(self.old_data[1][channel_counter],2) - (self.old_data[0][channel_counter] * x[0][channel_index])
                elif i==1:
                    filtered_data[i][channel_index] = math.pow(x[0][channel_index],2) - (self.old_data[1][channel_counter] * x[1][channel_index])
                else:
                    filtered_data[i][channel_index] = math.pow(x[i-1][channel_index],2) - (x[i-2][channel_index] * x[i][channel_index])
            self.old_data[0][channel_counter] = x[-2][channel_index]
            self.old_data[1][channel_counter] = x[-1][channel_index]
        result_time_series = TimeSeries.replace_data(x, filtered_data)

        return result_time_series
开发者ID:AlexanderFabisch,项目名称:pyspace,代码行数:29,代码来源:filtering.py

示例6: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
 def _execute(self, x):
     """
     f' = (f(x+h)-f(x))
     """
     if self.datapoints == None:
         self.datapoints = len(x)
     
     #create new channel names
     new_names = []
     for channel in range(len(x.channel_names)):
         new_names.append("%s'" %  (x.channel_names[channel]))
     #Derive the f' d2 from data x
     timeSeries = []
     for datapoint in range(self.datapoints):
         temp = []
         if((datapoint+1)<self.datapoints):
             for channel in range(len(x.channel_names)):
                 temp.append(x[datapoint+1][channel]-x[datapoint][channel])#*8*sampling_frequency
             timeSeries.append(temp)
     #padding with zero's if the original length of the time series have to remain equal.
     if self.keep_number_of_samples:
         temp = []
         for i in range(len(x.channel_names)):
             temp.append(0)
         timeSeries.append(temp)
     #Create a new time_series with the new data and channel names
     result_time_series = TimeSeries.replace_data(x, numpy.array(timeSeries))
     result_time_series.channel_names = new_names
     #if necessary adjust the length of the time series
     if not self.keep_number_of_samples:
         result_time_series.end_time -= 1
     
     return result_time_series
开发者ID:AlexanderFabisch,项目名称:pyspace,代码行数:35,代码来源:differentiation.py

示例7: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def _execute(self, data):
        # Initialize the ringbuffers and variables one for each channel
        if(self.ringbuffer == None):
            self.width /= 1000.0
            self.width = int(self.width * data.sampling_frequency)
            self.nChannels = len(data.channel_names)
            self.ringbuffer = numpy.zeros((self.width,self.nChannels),dtype=numpy.double)
            self.variables = numpy.zeros((2,self.nChannels),dtype=numpy.double)
            self.index = numpy.zeros(self.nChannels,'i')

        # Convert the input data to double
        x = data.view(numpy.ndarray).astype(numpy.double)
        # Initialize the result data array
        filtered_data = numpy.zeros(x.shape)
        # Lists which are passed to the standadization
        # TODO: make self
        processing_filtered_data = None
        processing_ringbuffer = None
        processing_variables = None
        processing_index = None
        if(self.standardization):
            for channel_index in range(self.nChannels):
                # Copy the different data to the processing listst
                processing_filtered_data = numpy.array(filtered_data[:,channel_index],'d')
                processing_ringbuffer = numpy.array(self.ringbuffer[:,channel_index],'d')
                processing_variables = numpy.array(self.variables[:,channel_index],'d')
                processing_index = int(self.index[channel_index])
                if self.var_tools:
                    # Perform the standardization
                    # The module vt (variance_tools) is implemented in c using boost to wrap the code in python
                    # The module is located in trunk/library/variance_tools and have to be compiled
                    self.index[channel_index] = vt.standardization(processing_filtered_data, numpy.array(x[:,channel_index],'d'), processing_ringbuffer, processing_variables, self.width, processing_index)
                else:
                    self.index[channel_index] = self.standardisation(processing_filtered_data, numpy.array(x[:,channel_index],'d'), processing_ringbuffer, processing_variables, self.width, processing_index)
                # Copy the processing lists back to the local variables
                filtered_data[:,channel_index] = processing_filtered_data
                self.ringbuffer[:,channel_index] = processing_ringbuffer
                self.variables[:,channel_index] = processing_variables
        else:
            for channel_index in range(self.nChannels):
                # Copy the different data to the processing listst
                processing_filtered_data = numpy.array(filtered_data[:,channel_index],'d')
                processing_ringbuffer = numpy.array(self.ringbuffer[:,channel_index],'d')
                processing_variables = numpy.array(self.variables[:,channel_index],'d')
                processing_index = int(self.index[channel_index])
                if self.var_tools:
                    # Perform the filtering with the variance
                    # The module vt (variance_tools) is implemented in c using boost to wrap the code in python
                    # The module is located in trunk/library/variance_tools and have to be compiled
                    self.index[channel_index] = vt.filter(processing_filtered_data, numpy.array(x[:,channel_index],'d'), processing_ringbuffer, processing_variables, self.width, processing_index)
                else:
                    self.index[channel_index] = self.variance(processing_filtered_data, numpy.array(x[:,channel_index],'d'), processing_ringbuffer, processing_variables, self.width, processing_index)
                # Copy the processing lists back to the local variables
                filtered_data[:,channel_index] = processing_filtered_data
                self.ringbuffer[:,channel_index] = processing_ringbuffer
                self.variables[:,channel_index] = processing_variables
        # Return the result
        result_time_series = TimeSeries.replace_data(data, filtered_data)
        return result_time_series
开发者ID:Crespo911,项目名称:pyspace,代码行数:61,代码来源:filtering.py

示例8: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
 def _execute(self, data):
     """ Apply the cast """
     #Determine the indices of the channels which will be filtered
     self._log("Cast data")
     casted_data = data.astype(self.datatype)
         
     result_time_series = TimeSeries.replace_data(data, casted_data)
     
     return result_time_series
开发者ID:schevalier,项目名称:pyspace,代码行数:11,代码来源:type_conversion.py

示例9: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
 def _execute(self, data):
     """ Subsample the given data and return a new time series """
     if self.new_len == 0 :
         self.new_len = int(round(self.target_frequency*len(data)/(1.0*data.sampling_frequency)))
     if not self.mirror:
         downsampled_time_series = \
             TimeSeries.replace_data(data, 
                                     scipy.signal.resample(data, self.new_len,
                                                         t=None, axis=0,
                                                         window=self.window))
     else:
         downsampled_time_series = \
             TimeSeries.replace_data(data, 
                                     scipy.signal.resample(numpy.vstack((data,numpy.flipud(data))), self.new_len*2,
                                                         t=None, axis=0,
                                                         window=self.window)[:self.new_len])
     downsampled_time_series.sampling_frequency = self.target_frequency
     return downsampled_time_series
开发者ID:MMKrell,项目名称:pyspace,代码行数:20,代码来源:subsampling.py

示例10: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def _execute(self, data):
        """ Reorder the memory. """

        # exchange data of time series object to correctly ordered data
        buffer = numpy.array(data, order='F')

        if self.convert_type and numpy.dtype('float64') != buffer.dtype:
            buffer = buffer.astype(numpy.float)
        
        data = TimeSeries.replace_data(data,buffer)
        
        return data
开发者ID:AlexanderFabisch,项目名称:pyspace,代码行数:14,代码来源:reorder_memory.py

示例11: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def _execute(self, data):
        """
        Apply the scaling to the given data x
        and return a new time series.
        """
        x = data.view(numpy.ndarray)

        x.clip(self.min_threshold, self.max_threshold, out = x)

        result_time_series = TimeSeries.replace_data(data, x)

        return result_time_series
开发者ID:AlexanderFabisch,项目名称:pyspace,代码行数:14,代码来源:clip.py

示例12: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def _execute(self, data):
        # First check if all channels actually appear in the data

        # Determine the indices of the channels that are the basis for the 
        # average reference.
        if not self.inverse:
            if self.avg_channels == None:
                self.avg_channels = data.channel_names
            channel_indices = [data.channel_names.index(channel_name) 
                                for channel_name in self.avg_channels]
        else:
            channel_indices = [data.channel_names.index(channel_name)
                               for channel_name in data.channel_names
                               if channel_name not in self.avg_channels]

        not_found_channels = \
            [channel_name for channel_name in self.avg_channels 
                     if channel_name not in data.channel_names]
        if not not_found_channels == []:
            warnings.warn("Couldn't find selected channel(s): %s. Ignoring." % 
                            not_found_channels, Warning)
                    
        if self.old_ref is None:
            self.old_ref = 'avg'
        
        # Compute the actual data of the reference channel. This is the sum of all 
        # channels divided by (the number of channels +1).
        ref_chen = -numpy.sum(data[:, channel_indices], axis=1)/(data.shape[1]+1)
        ref_chen = numpy.atleast_2d(ref_chen).T
        # Reference all electrodes against average
        avg_referenced_data = data + ref_chen
        
        # Add average as new channel to the signal if enabled
        if self.keep_average:
            avg_referenced_data = numpy.hstack((avg_referenced_data, ref_chen))
            channel_names = data.channel_names + [self.old_ref]
            result_time_series = TimeSeries(avg_referenced_data, 
                                            channel_names,
                                            data.sampling_frequency, 
                                            data.start_time, data.end_time,
                                            data.name, data.marker_name)
        else:
            result_time_series = TimeSeries.replace_data(data, 
                                                            avg_referenced_data)
        
        return result_time_series
开发者ID:MMKrell,项目名称:pyspace,代码行数:48,代码来源:rereferencing.py

示例13: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def _execute(self, x):
        """ Executes the preprocessing on the given data vector x"""
        #Number of retained channels
        num_channels = numpy.size(x,1)
        if(self.below_threshold == None):
            # When the node is called for the first time initialize all parameters/variables
            self.width_AT = int((self.width_AT*x.sampling_frequency)/1000.)
            
            #Convert the time from ms to samples
            self.time_below_threshold = int((self.time_below_threshold*x.sampling_frequency)/1000.)
            
            #Create and prefill the array which indicates how long a signal was below the threshold
            self.below_threshold = numpy.zeros(num_channels)
            self.below_threshold.fill(self.time_below_threshold+1)
            
            #Create the ringbuffer and the variables list for the adaptive threshold 
            self.ringbuffer_AT=numpy.zeros((self.width_AT,num_channels))
            self.variables_AT=numpy.zeros((4,num_channels))
        data=x.view(numpy.ndarray)
        #Create the array for the thresholded data
        threshold_data = numpy.zeros(data.shape)
        #For each sample of each retained channel
        for i in range(num_channels):
            data_index = 0
            for sample in data[:,i]:
                #calculate the adaptive threshold
                value = self.adaptive_threshold(sample, i)
                #if the actual sample exceeds the threshold...
                if(sample >= value):
                    #and the resting time was observed
                    if(self.below_threshold[i] > self.time_below_threshold):
                        #store a 1 indicating a onset
                        threshold_data[data_index][i] = 1
                    #reset the resting time counter
                    self.below_threshold[i] = 0
                #increase the time the signal was below the signal
                else:
                    self.below_threshold[i] += 1
                data_index += 1

        #return the thresholded data
        result_time_series = TimeSeries.replace_data(x, threshold_data)
        return result_time_series
开发者ID:schevalier,项目名称:pyspace,代码行数:45,代码来源:adaptive_threshold_classifier.py

示例14: _train

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def _train(self, data):
        """ Check which channels have constant values.

        The training data is considered and the invalid channel names
        are removed. The first data entry is saved and the starting
        assumption is that all channels have constant values. When a value
        different from the first data entry for a respective channel is found,
        that channel is removed from the list of channels that have constant
        values.
        """
        # copy the first data value
        if self.data_values is None:
            # copy the first entry
            self.data_values = TimeSeries.replace_data(data, data.get_data()[0])
            # invalidate all the channels in the beginning
            self.selected_channel_names = copy.deepcopy(data.channel_names)

        for channel in self.selected_channel_names:
            if (data.get_channel(channel) != self.data_values.get_channel(channel)[0]).any():
                self.selected_channel_names.remove(channel)
开发者ID:Crespo911,项目名称:pyspace,代码行数:22,代码来源:channel_selection.py

示例15: _execute

# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import replace_data [as 别名]
    def _execute(self, data):
        """
        Exchanges the data with some manually generated data.
        """

        if self.generator is None:
            self.generator = eval(self.generator_expression)

        self.data_item = \
            self.ts_generator.generate_test_data(
                channels=data.shape[1],
                time_points=data.shape[0],
                function=self.generator,
                sampling_frequency=data.sampling_frequency,
                channel_order=True,
                channel_names=data.channel_names,
                dtype=numpy.float)

        result_time_series = TimeSeries.replace_data(data, self.data_item)


        return result_time_series
开发者ID:AlexanderFabisch,项目名称:pyspace,代码行数:24,代码来源:exchange_data.py


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