Example #1
0
    def get_index_loading_cdf(self, max_val=1.0):
        """
        Find the elements where the CDF is greater or equal to a value
        :param max_val: value to compare
        :return: indices, associated probability
        """

        # turn the loading real values into CDF
        cdf = CDF(np.abs(self.Sbr_points.real))

        n = cdf.arr.shape[1]
        idx = list()
        val = list()
        prob = list()
        for i in range(n):
            # Find the indices that surpass max_val
            many_idx = np.where(cdf.arr[:, i] > max_val)[0]

            # if there are indices, pick the first; store it and its associated probability
            if len(many_idx) > 0:
                idx.append(i)
                val.append(cdf.arr[many_idx[0], i])
                prob.append(
                    1 - cdf.prob[many_idx[0]]
                )  # the CDF stores the chance of beign leq than the value, hence the overload is the complementary

        return idx, val, prob, cdf.arr[-1, :]
Example #2
0
def make_monte_carlo_input(numerical_input_island: CalculationInputs):
    """
    Generate a monte carlo input instance
    :param numerical_input_island:
    :return:
    """
    n = numerical_input_island.nbus
    Scdf = [None] * n
    Icdf = [None] * n
    Ycdf = [None] * n

    for i in range(n):
        Scdf[i] = CDF(numerical_input_island.Sbus_prof[i, :])
        Icdf[i] = CDF(numerical_input_island.Ibus_prof[i, :])
        Ycdf[i] = CDF(numerical_input_island.Ysh_prof[i, :])

    return MonteCarloInput(n, Scdf, Icdf, Ycdf)
Example #3
0
def make_monte_carlo_input(numerical_input_island: TimeCircuit):
    """
    Generate a monte carlo input instance
    :param numerical_input_island:
    :return:
    """
    n = numerical_input_island.nbus
    Scdf = [None] * n
    Icdf = [None] * n
    Ycdf = [None] * n

    for i in range(n):
        Scdf[i] = CDF(numerical_input_island.Sbus[i, :])
        Icdf[i] = CDF(numerical_input_island.Ibus[i, :])
        Ycdf[i] = CDF(numerical_input_island.Yshunt_from_devices[i, :])

    return StochasticPowerFlowInput(n, Scdf, Icdf, Ycdf)
Example #4
0
    def mdl(self, result_type: ResultTypes) -> "ResultsModel":
        """
        Plot the results
        :param result_type:
        :param ax:
        :param indices:
        :param names:
        :return:
        """
        cdf_result_types = [
            ResultTypes.BusVoltageCDF, ResultTypes.BusPowerCDF,
            ResultTypes.BranchPowerCDF, ResultTypes.BranchLoadingCDF,
            ResultTypes.BranchLossesCDF
        ]

        if result_type == ResultTypes.BusVoltageAverage:
            labels = self.bus_names
            y = self.v_avg_conv[1:-1, :]
            y_label = '(p.u.)'
            x_label = 'Sampling points'
            title = 'Bus voltage \naverage convergence'

        elif result_type == ResultTypes.BranchPowerAverage:
            labels = self.branch_names
            y = self.s_avg_conv[1:-1, :]
            y_label = '(MW)'
            x_label = 'Sampling points'
            title = 'Branch power \naverage convergence'

        elif result_type == ResultTypes.BranchLoadingAverage:
            labels = self.branch_names
            y = self.l_avg_conv[1:-1, :]
            y_label = '(%)'
            x_label = 'Sampling points'
            title = 'Branch loading \naverage convergence'

        elif result_type == ResultTypes.BranchLossesAverage:
            labels = self.branch_names
            y = self.loss_avg_conv[1:-1, :]
            y_label = '(MVA)'
            x_label = 'Sampling points'
            title = 'Branch losses \naverage convergence'

        elif result_type == ResultTypes.BusVoltageStd:
            labels = self.bus_names
            y = self.v_std_conv[1:-1, :]
            y_label = '(p.u.)'
            x_label = 'Sampling points'
            title = 'Bus voltage standard \ndeviation convergence'

        elif result_type == ResultTypes.BranchPowerStd:
            labels = self.branch_names
            y = self.s_std_conv[1:-1, :]
            y_label = '(MW)'
            x_label = 'Sampling points'
            title = 'Branch power standard \ndeviation convergence'

        elif result_type == ResultTypes.BranchLoadingStd:
            labels = self.branch_names
            y = self.l_std_conv[1:-1, :]
            y_label = '(%)'
            x_label = 'Sampling points'
            title = 'Branch loading standard \ndeviation convergence'

        elif result_type == ResultTypes.BranchLossesStd:
            labels = self.branch_names
            y = self.loss_std_conv[1:-1, :]
            y_label = '(MVA)'
            x_label = 'Sampling points'
            title = 'Branch losses standard \ndeviation convergence'

        elif result_type == ResultTypes.BusVoltageCDF:
            labels = self.bus_names
            cdf = CDF(np.abs(self.V_points))
            y_label = '(p.u.)'
            x_label = 'Probability $P(X \leq x)$'
            title = result_type.value[0]

        elif result_type == ResultTypes.BranchLoadingCDF:
            labels = self.branch_names
            cdf = CDF(np.abs(self.loading_points.real))
            y_label = '(p.u.)'
            x_label = 'Probability $P(X \leq x)$'
            title = result_type.value[0]

        elif result_type == ResultTypes.BranchLossesCDF:
            labels = self.branch_names
            cdf = CDF(np.abs(self.losses_points))
            y_label = '(MVA)'
            x_label = 'Probability $P(X \leq x)$'
            title = result_type.value[0]

        elif result_type == ResultTypes.BranchPowerCDF:
            labels = self.branch_names
            cdf = CDF(self.Sbr_points.real)
            y_label = '(MW)'
            x_label = 'Probability $P(X \leq x)$'
            title = result_type.value[0]

        elif result_type == ResultTypes.BusPowerCDF:
            labels = self.bus_names
            cdf = CDF(self.S_points.real)
            y_label = '(p.u.)'
            x_label = 'Probability $P(X \leq x)$'
            title = result_type.value[0]

        else:
            x_label = ''
            y_label = ''
            title = ''

        if result_type not in cdf_result_types:

            # assemble model
            index = np.arange(0, y.shape[0], 1)
            mdl = ResultsModel(data=np.abs(y),
                               index=index,
                               columns=labels,
                               title=title,
                               ylabel=y_label,
                               xlabel=x_label,
                               units=y_label)

        else:
            mdl = ResultsModel(data=cdf.arr,
                               index=cdf.prob,
                               columns=labels,
                               title=title,
                               ylabel=y_label,
                               xlabel=x_label,
                               units=y_label)
        return mdl
Example #5
0
    def plot(self,
             result_type: ResultTypes,
             ax=None,
             indices=None,
             names=None):
        """
        Plot the results
        :param result_type:
        :param ax:
        :param indices:
        :param names:
        :return:
        """

        if ax is None:
            fig = plt.figure()
            ax = fig.add_subplot(111)

        p, n = self.V_points.shape

        cdf_result_types = [
            ResultTypes.BusVoltageCDF, ResultTypes.BusPowerCDF,
            ResultTypes.BranchCurrentCDF, ResultTypes.BranchLoadingCDF,
            ResultTypes.BranchLossesCDF
        ]

        if indices is None:
            if names is None:
                indices = np.arange(0, n, 1)
                labels = None
            else:
                indices = np.array(range(len(names)))
                labels = names[indices]
        else:
            labels = names[indices]

        if len(indices) > 0:

            y_label = ''
            title = ''
            if result_type == ResultTypes.BusVoltageAverage:
                y = self.v_avg_conv[1:-1, indices]
                y_label = '(p.u.)'
                x_label = 'Sampling points'
                title = 'Bus voltage \naverage convergence'

            elif result_type == ResultTypes.BranchCurrentAverage:
                y = self.c_avg_conv[1:-1, indices]
                y_label = '(p.u.)'
                x_label = 'Sampling points'
                title = 'Bus current \naverage convergence'

            elif result_type == ResultTypes.BranchLoadingAverage:
                y = self.l_avg_conv[1:-1, indices]
                y_label = '(%)'
                x_label = 'Sampling points'
                title = 'Branch loading \naverage convergence'

            elif result_type == ResultTypes.BranchLossesAverage:
                y = self.loss_avg_conv[1:-1, indices]
                y_label = '(MVA)'
                x_label = 'Sampling points'
                title = 'Branch losses \naverage convergence'

            elif result_type == ResultTypes.BusVoltageStd:
                y = self.v_std_conv[1:-1, indices]
                y_label = '(p.u.)'
                x_label = 'Sampling points'
                title = 'Bus voltage standard \ndeviation convergence'

            elif result_type == ResultTypes.BranchCurrentStd:
                y = self.c_std_conv[1:-1, indices]
                y_label = '(p.u.)'
                x_label = 'Sampling points'
                title = 'Bus current standard \ndeviation convergence'

            elif result_type == ResultTypes.BranchLoadingStd:
                y = self.l_std_conv[1:-1, indices]
                y_label = '(%)'
                x_label = 'Sampling points'
                title = 'Branch loading standard \ndeviation convergence'

            elif result_type == ResultTypes.BranchLossesStd:
                y = self.loss_std_conv[1:-1, indices]
                y_label = '(MVA)'
                x_label = 'Sampling points'
                title = 'Branch losses standard \ndeviation convergence'

            elif result_type == ResultTypes.BusVoltageCDF:
                cdf = CDF(np.abs(self.V_points[:, indices]))
                cdf.plot(ax=ax)
                y_label = '(p.u.)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            elif result_type == ResultTypes.BranchLoadingCDF:
                cdf = CDF(np.abs(self.loading_points.real[:, indices]))
                cdf.plot(ax=ax)
                y_label = '(p.u.)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            elif result_type == ResultTypes.BranchLossesCDF:
                cdf = CDF(np.abs(self.losses_points[:, indices]))
                cdf.plot(ax=ax)
                y_label = '(MVA)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            elif result_type == ResultTypes.BranchCurrentCDF:
                cdf = CDF(np.abs(self.I_points[:, indices]))
                cdf.plot(ax=ax)
                y_label = '(kA)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            elif result_type == ResultTypes.BusPowerCDF:
                cdf = CDF(np.abs(self.S_points[:, indices]))
                cdf.plot(ax=ax)
                y_label = '(p.u.)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            else:
                x_label = ''
                y_label = ''
                title = ''

            if result_type not in cdf_result_types:
                df = pd.DataFrame(data=np.abs(y), columns=labels)
                lines = ax.plot(np.abs(y), linewidth=LINEWIDTH)
                if len(df.columns) < 10:
                    ax.legend(lines, labels, loc='best')
            else:
                df = pd.DataFrame(index=cdf.prob, data=cdf.arr, columns=labels)

            ax.set_title(title)
            ax.set_ylabel(y_label)
            ax.set_xlabel(x_label)

            return df

        else:
            return None
Example #6
0
    def mdl(self,
            result_type: ResultTypes,
            indices=None,
            names=None) -> "ResultsModel":
        """
        Plot the results
        :param result_type:
        :param ax:
        :param indices:
        :param names:
        :return:
        """

        p, n = self.V_points.shape

        cdf_result_types = [
            ResultTypes.BusVoltageCDF, ResultTypes.BusPowerCDF,
            ResultTypes.BranchCurrentCDF, ResultTypes.BranchLoadingCDF,
            ResultTypes.BranchLossesCDF
        ]

        if indices is None:
            if names is None:
                indices = np.arange(0, n, 1)
                labels = None
            else:
                indices = np.array(range(len(names)))
                labels = names[indices]
        else:
            labels = names[indices]

        if len(indices) > 0:

            y_label = ''
            title = ''
            if result_type == ResultTypes.BusVoltageAverage:
                y = self.v_avg_conv[1:-1, indices]
                y_label = '(p.u.)'
                x_label = 'Sampling points'
                title = 'Bus voltage \naverage convergence'

            elif result_type == ResultTypes.BranchCurrentAverage:
                y = self.c_avg_conv[1:-1, indices]
                y_label = '(p.u.)'
                x_label = 'Sampling points'
                title = 'Bus current \naverage convergence'

            elif result_type == ResultTypes.BranchLoadingAverage:
                y = self.l_avg_conv[1:-1, indices]
                y_label = '(%)'
                x_label = 'Sampling points'
                title = 'Branch loading \naverage convergence'

            elif result_type == ResultTypes.BranchLossesAverage:
                y = self.loss_avg_conv[1:-1, indices]
                y_label = '(MVA)'
                x_label = 'Sampling points'
                title = 'Branch losses \naverage convergence'

            elif result_type == ResultTypes.BusVoltageStd:
                y = self.v_std_conv[1:-1, indices]
                y_label = '(p.u.)'
                x_label = 'Sampling points'
                title = 'Bus voltage standard \ndeviation convergence'

            elif result_type == ResultTypes.BranchCurrentStd:
                y = self.c_std_conv[1:-1, indices]
                y_label = '(p.u.)'
                x_label = 'Sampling points'
                title = 'Bus current standard \ndeviation convergence'

            elif result_type == ResultTypes.BranchLoadingStd:
                y = self.l_std_conv[1:-1, indices]
                y_label = '(%)'
                x_label = 'Sampling points'
                title = 'Branch loading standard \ndeviation convergence'

            elif result_type == ResultTypes.BranchLossesStd:
                y = self.loss_std_conv[1:-1, indices]
                y_label = '(MVA)'
                x_label = 'Sampling points'
                title = 'Branch losses standard \ndeviation convergence'

            elif result_type == ResultTypes.BusVoltageCDF:
                cdf = CDF(np.abs(self.V_points[:, indices]))
                # cdf.plot(ax=ax)
                y_label = '(p.u.)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            elif result_type == ResultTypes.BranchLoadingCDF:
                cdf = CDF(np.abs(self.loading_points.real[:, indices]))
                # cdf.plot(ax=ax)
                y_label = '(p.u.)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            elif result_type == ResultTypes.BranchLossesCDF:
                cdf = CDF(np.abs(self.losses_points[:, indices]))
                # cdf.plot(ax=ax)
                y_label = '(MVA)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            elif result_type == ResultTypes.BranchCurrentCDF:
                cdf = CDF(np.abs(self.I_points[:, indices]))
                # cdf.plot(ax=ax)
                y_label = '(kA)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            elif result_type == ResultTypes.BusPowerCDF:
                cdf = CDF(np.abs(self.S_points[:, indices]))
                # cdf.plot(ax=ax)
                y_label = '(p.u.)'
                x_label = 'Probability $P(X \leq x)$'
                title = result_type.value[0]

            else:
                x_label = ''
                y_label = ''
                title = ''

            if result_type not in cdf_result_types:

                # assemble model
                index = np.arange(0, y.shape[0], 1)
                mdl = ResultsModel(data=np.abs(y),
                                   index=index,
                                   columns=labels,
                                   title=title,
                                   ylabel=y_label,
                                   xlabel=x_label)

            else:
                mdl = ResultsModel(data=cdf.arr,
                                   index=cdf.prob,
                                   columns=labels,
                                   title=title,
                                   ylabel=y_label,
                                   xlabel=x_label)
            return mdl

        else:
            return None