Ejemplo n.º 1
0
    def build_statistics_channels(self, windows, statistics, name=""):


        channel_list = []

        for stat in statistics:
            #print(stat)
            channel_names = pampro_utilities.design_variable_names(self.name, stat)
            #print(channel_names)
            for cn in channel_names:
                channel_list.append(Channel.Channel(cn))

        num_expected_results = len(channel_list)

        for window in windows:

            results = self.window_statistics(window.start_timestamp, window.end_timestamp, statistics)
            if len(results) != num_expected_results:
                raise Exception("Incorrect number of statistics yielded. {} expected, {} given. Channel: {}. Statistics: {}.".format(num_expected_results, len(results), self.name, statistics))

            for i in range(len(results)):
                #print len(results)
                channel_list[i].append_data(window.start_timestamp, results[i])

        for channel in channel_list:
            channel.calculate_timeframe()
            channel.data = np.array(channel.data)
            channel.timestamps = np.array(channel.timestamps)

        ts = Time_Series.Time_Series(name)
        ts.add_channels(channel_list)
        return ts
Ejemplo n.º 2
0
    def build_statistics_channels(self, windows, statistics, name=""):
        """ Describe the contents of this channel in the given time windows using the given statistics  """

        using_indices = True
        if str(type(windows[0])) == "<class 'pampro.Bout.Bout'>":
            using_indices = False

        channel_list = []

        for stat in statistics:
            # For each statistic, decide what should it be called
            channel_names = pampro_utilities.design_variable_names(self.name, stat)

            # Create a Channel for each output
            for cn in channel_names:
                channel_list.append(Channel(cn))

        num_expected_results = len(channel_list)

        for window in windows:

            if using_indices:
                results = self.window_statistics(window[0], window[1], statistics)

            else:

                results = self.window_statistics(window.start_timestamp, window.end_timestamp, statistics)

            if len(results) != num_expected_results:

                raise Exception("Incorrect number of statistics yielded. {} expected, {} given. Channel: {}. Statistics: {}.".format(num_expected_results, len(results), self.name, statistics))

            if using_indices:
                for i in range(len(results)):
                    channel_list[i].append_data(window[0], results[i])

            else:

                for i in range(len(results)):
                    channel_list[i].append_data(window.start_timestamp, results[i])

        for channel in channel_list:
            channel.missing_value = -1
            channel.data = np.array(channel.data)
            channel.timestamps = np.array(channel.timestamps)
            channel.calculate_timeframe()

        ts = Time_Series.Time_Series(name)
        ts.add_channels(channel_list)
        return ts