Ejemplo n.º 1
0
    def manipulate_cos_phi(self):
        if self.last_ts > 0:
            return None

        for e in self.events_cos_phi:
            interval, interval_i, ts_list, bus_id, bus_tag, load_mapping, load_ids, cos_phi = self._get_cos_phi_vars(
                e)

            print('+++' * 10)
            string = 'From {} (idx: {}) change cos phi from load {} at bus {} with cos_phi of {} ' \
                     'until {} (idx: {})'.format(interval[0], interval_i[0], load_ids, bus_id,
                                                 cos_phi, interval[1], interval_i[1])
            print(string)
            print('Use load mapping: {}'.format(load_mapping))

            tmp_data = self.unscaled_data.loc[interval[0]:interval[1]]
            print('Manipulate {} samples!'.format(len(tmp_data)))

            list_q = []
            list_p = []

            for i, val in enumerate(load_mapping):
                prod_p = np.dot(
                    val, self.unscaled_data[self.unscaled_data.columns[i]].
                    loc[interval[0]:interval[1]].T)
                list_p.append(prod_p)

                if i in load_ids:
                    reactive_power = gu.compute_q(prod_p, cos_phi=cos_phi)
                else:
                    reactive_power = gu.compute_q(prod_p)

                list_q.append(reactive_power)

            assert len(list_p) == len(list_q)

            summed_p = np.zeros(len(list_p[0]))
            summed_q = np.zeros(len(list_q[0]))

            for val_p, val_q in zip(list_p, list_q):
                summed_p += val_p
                summed_q += val_q

            assert len(summed_p) == len(summed_q) == len(tmp_data)

            ### replace old data by drifted data with q vals with new cos phi
            for t_step, q_val, p_val in zip(ts_list, summed_q, summed_p):
                self.data.loc[(t_step, bus_id - 1)] = [bus_tag, p_val, q_val]

            print('+++' * 10)

        return self.data
Ejemplo n.º 2
0
    def manipulate_load_mapping(self):
        """
        Manipulates the load mapping. Loops over all given load mapping events and manipulates the data by
        multiplying new load mapping times unscaled data and finally replaces the old data by new manipulated data.
        :return: the manipulated data with new load mapping as pandas DataFrame
        """

        if self.last_ts > 0:
            return None

        for event in self.events_load_mapping:
            start_ts = self.timestamp_list[event['at_time_idx']]
            end_ts = self.timestamp_list[event['until_time_idx']]
            start_ts_i = event['at_time_idx']
            end_ts_i = event['until_time_idx']

            if end_ts_i == -1:
                ts_list = self.timestamp_list[start_ts_i:]
            else:
                end_ts_i += 1
                ts_list = self.timestamp_list[start_ts_i:end_ts_i]

            bus_id = event['bus_id']
            bus_tag = 'AGG_BUS_{}'.format(bus_id)
            new_load_mapping = event['load_mapping']
            old_load_mapping = self.initial_load_mapping[bus_id]

            print('+++' * 10)
            print('On {} change load mapping at bus: {} until {}'.format(
                start_ts, bus_id, end_ts))
            print('Old load mapping was: {}'.format(old_load_mapping))
            print('New load mapping is: {}'.format(new_load_mapping))

            assert len(new_load_mapping) == len(old_load_mapping)

            tmp_data = self.unscaled_data.loc[start_ts:end_ts]
            agg_data_p = np.dot(new_load_mapping, tmp_data.T)
            print('Manipulate {} samples!'.format(len(agg_data_p)))
            print('+++' * 10)

            q_list = []
            for val in agg_data_p:
                q = gu.compute_q(val)
                q_list.append(q)

            assert len(ts_list) == len(q_list) == len(agg_data_p)

            for t_step, q_val, p_val in zip(ts_list, q_list, agg_data_p):
                self.data.loc[(t_step, bus_id - 1)] = [bus_tag, p_val, q_val]

        return self.data