Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
  • Loading branch information
geofjamg committed Sep 21, 2023
1 parent 6624d0e commit 5ec9b89
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pypowsybl/network/impl/perunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,13 @@ def _per_unit_g(self, df: pd.DataFrame, columns: List[str], nominal_v: pd.Series
for col in columns:
df[col] *= factor

def y(self, df: pd.DataFrame, r_col: str, x_col: str):
return df.apply(lambda row: np.reciprocal(np.complex128(row[r_col] + row[x_col] * 1j)), axis=1)
def y(self, df: pd.DataFrame, r_col: str, x_col: str) -> pd.Series:
return df.apply(lambda row: np.reciprocal(np.complex128(row[r_col] + row[x_col] * 1j)), axis = 1)

def _per_unit_g_not_same_nom_v(self, df: pd.DataFrame, column: str, r_col: str, x_col: str, nominal_v1: pd.Series, nominal_v2: pd.Series) -> None:
ytr = self.y(df, r_col, x_col)
def _per_unit_g_not_same_nom_v(self, df: pd.DataFrame, column: str, ytr: pd.Series, nominal_v1: pd.Series, nominal_v2: pd.Series) -> None:
df[column] = (df[column] * nominal_v1 * nominal_v1 + (nominal_v1 - nominal_v2) * nominal_v1 * ytr.apply(lambda row: row.real)) / self.sn

def _per_unit_b_not_same_nom_v(self, df: pd.DataFrame, column: str, r_col: str, x_col: str, nominal_v1: pd.Series, nominal_v2: pd.Series) -> None:
ytr = self.y(df, r_col, x_col)
def _per_unit_b_not_same_nom_v(self, df: pd.DataFrame, column: str, ytr: pd.Series, nominal_v1: pd.Series, nominal_v2: pd.Series) -> None:
df[column] = (df[column] * nominal_v1 * nominal_v1 + (nominal_v1 - nominal_v2) * nominal_v1 * ytr.apply(lambda row: row.imag)) / self.sn

def _per_unit_i(self, df: pd.DataFrame, columns: List[str], nominal_v: pd.Series) -> None:
Expand Down Expand Up @@ -184,11 +182,12 @@ def get_lines(self) -> pd.DataFrame:
self._per_unit_p(lines, ['p1', 'p2', 'q1', 'q2'])
self._per_unit_i(lines, ['i1'], nominal_v1)
self._per_unit_i(lines, ['i2'], nominal_v2)
self._per_unit_g_not_same_nom_v(lines, 'g1', 'r', 'x', nominal_v1, nominal_v2)
self._per_unit_g_not_same_nom_v(lines, 'g2', 'r', 'x', nominal_v2, nominal_v1)
self._per_unit_b_not_same_nom_v(lines, 'b1', 'r', 'x', nominal_v1, nominal_v2)
self._per_unit_b_not_same_nom_v(lines, 'b2', 'r', 'x', nominal_v2, nominal_v1)
ytr = self.y(lines, 'r', 'x')
self._per_unit_r_not_same_nom_v(lines, ['r', 'x'], nominal_v1, nominal_v2)
self._per_unit_g_not_same_nom_v(lines, 'g1', ytr, nominal_v1, nominal_v2)
self._per_unit_g_not_same_nom_v(lines, 'g2', ytr, nominal_v2, nominal_v1)
self._per_unit_b_not_same_nom_v(lines, 'b1', ytr, nominal_v1, nominal_v2)
self._per_unit_b_not_same_nom_v(lines, 'b2', ytr, nominal_v2, nominal_v1)
return lines

def get_2_windings_transformers(self) -> pd.DataFrame:
Expand Down

0 comments on commit 5ec9b89

Please sign in to comment.