From ffb06ccac53cf2f497a62accdea5aafd033a831d Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Fri, 10 Nov 2023 15:21:45 +0100 Subject: [PATCH] Wip Signed-off-by: Geoffroy Jamgotchian --- pypowsybl/sensitivity/impl/ac_sensitivity_analysis.py | 3 ++- pypowsybl/sensitivity/impl/sensitivity.py | 11 +++++------ .../sensitivity/impl/sensitivity_analysis_result.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pypowsybl/sensitivity/impl/ac_sensitivity_analysis.py b/pypowsybl/sensitivity/impl/ac_sensitivity_analysis.py index ec45168d22..7d03a91f15 100644 --- a/pypowsybl/sensitivity/impl/ac_sensitivity_analysis.py +++ b/pypowsybl/sensitivity/impl/ac_sensitivity_analysis.py @@ -11,6 +11,7 @@ from pypowsybl.loadflow import Parameters as LfParameters from pypowsybl._pypowsybl import ContingencyContextType, SensitivityFunctionType, SensitivityVariableType from .ac_sensitivity_analysis_result import AcSensitivityAnalysisResult +from .sensitivity_analysis_result import DEFAULT_MATRIX_ID from .sensitivity import SensitivityAnalysis from .parameters import Parameters @@ -35,7 +36,7 @@ def set_bus_voltage_factor_matrix(self, bus_ids: List[str], target_voltage_ids: """ self.add_bus_voltage_factor_matrix(bus_ids, target_voltage_ids) - def add_bus_voltage_factor_matrix(self, bus_ids: List[str], target_voltage_ids: List[str], matrix_id: str = 'default') -> None: + def add_bus_voltage_factor_matrix(self, bus_ids: List[str], target_voltage_ids: List[str], matrix_id: str = DEFAULT_MATRIX_ID) -> None: """ Defines buses voltage sensitivities to be computed. diff --git a/pypowsybl/sensitivity/impl/sensitivity.py b/pypowsybl/sensitivity/impl/sensitivity.py index 841d8b8fae..b9105788fb 100644 --- a/pypowsybl/sensitivity/impl/sensitivity.py +++ b/pypowsybl/sensitivity/impl/sensitivity.py @@ -9,11 +9,10 @@ from pypowsybl import _pypowsybl from pypowsybl.security import ContingencyContainer +from .sensitivity_analysis_result import DEFAULT_MATRIX_ID, TO_REMOVE from pypowsybl._pypowsybl import PyPowsyblError, ContingencyContextType, SensitivityFunctionType, SensitivityVariableType from .zone import Zone -TO_REMOVE = 'TO_REMOVE' - class SensitivityAnalysis(ContingencyContainer): """ Base class for sensitivity analysis. Do not instantiate it directly!""" @@ -74,7 +73,7 @@ def set_branch_flow_factor_matrix(self, branches_ids: List[str], variables_ids: self.add_branch_flow_factor_matrix(branches_ids, variables_ids) def add_branch_flow_factor_matrix(self, branches_ids: List[str], variables_ids: List[str], - matrix_id: str = 'default') -> None: + matrix_id: str = DEFAULT_MATRIX_ID) -> None: """ Defines branch active power flow factor matrix, with a list of branches IDs and a list of variables. @@ -92,7 +91,7 @@ def add_branch_flow_factor_matrix(self, branches_ids: List[str], variables_ids: SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, SensitivityVariableType.AUTO_DETECT, matrix_id) def add_precontingency_branch_flow_factor_matrix(self, branches_ids: List[str], variables_ids: List[str], - matrix_id: str = 'default') -> None: + matrix_id: str = DEFAULT_MATRIX_ID) -> None: """ Defines branch active power flow factor matrix for the base case, with a list of branches IDs and a list of variables. @@ -111,7 +110,7 @@ def add_precontingency_branch_flow_factor_matrix(self, branches_ids: List[str], def add_postcontingency_branch_flow_factor_matrix(self, branches_ids: List[str], variables_ids: List[str], contingencies_ids: List[str], - matrix_id: str = 'default') -> None: + matrix_id: str = DEFAULT_MATRIX_ID) -> None: """ Defines branch active power flow factor matrix for specific post contingencies states, with a list of branches IDs and a list of variables. @@ -133,7 +132,7 @@ def add_factor_matrix(self, functions_ids: List[str], variables_ids: List[str], contingency_context_type: ContingencyContextType, sensitivity_function_type: SensitivityFunctionType, sensitivity_variable_type: SensitivityVariableType = SensitivityVariableType.AUTO_DETECT, - matrix_id: str = 'default') -> None: + matrix_id: str = DEFAULT_MATRIX_ID) -> None: """ Defines branch active power factor matrix, with a list of branches IDs and a list of variables. diff --git a/pypowsybl/sensitivity/impl/sensitivity_analysis_result.py b/pypowsybl/sensitivity/impl/sensitivity_analysis_result.py index 708d805a63..488c4fbb71 100644 --- a/pypowsybl/sensitivity/impl/sensitivity_analysis_result.py +++ b/pypowsybl/sensitivity/impl/sensitivity_analysis_result.py @@ -33,10 +33,10 @@ def __init__(self, self.function_data_frame_index = function_data_frame_index @staticmethod - def clean_contingency_id(contingency_id): + def clean_contingency_id(contingency_id: str) -> str: return '' if contingency_id is None else contingency_id - def process_ptdf(self, df, matrix_id): + def process_ptdf(self, df: pd.DataFrame, matrix_id: str) -> pd.DataFrame: # substract second power transfer zone to first one i = 0 while i < len(self.function_data_frame_index[matrix_id]):