Skip to content

Commit

Permalink
Using parameters to share curves
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosmc committed Dec 17, 2024
1 parent 6205f88 commit 8b1a1a9
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 56 deletions.
1 change: 1 addition & 0 deletions docs/tutorial/general_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ The *operating condition* directory is structured in:
(dgcv_venv) user@dynawo:~/work/MyTests/Results$ tree PCS_RTE-I10/Islanding/DeltaP10DeltaQ4 -L 1
PCS_RTE-I10/Islanding/DeltaP10DeltaQ4
├── curves_calculated.csv
├── curves_reference.csv
├── Omega.dyd
├── Omega.par
├── outputs
Expand Down
5 changes: 3 additions & 2 deletions src/dgcv/core/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from dgcv.core.validator import Disconnection_Model
from dgcv.electrical.generator_variables import generator_variables
from dgcv.model.producer import Producer
import pandas as pd


def get_cfg_oc_name(pcs_bm_name: str, oc_name: str) -> str:
Expand Down Expand Up @@ -124,7 +125,7 @@ def obtain_reference_curve(
working_oc_dir: Path,
pcs_bm_name: str,
curves: Path,
) -> float:
) -> tuple[float, pd.DataFrame]:
"""Virtual method"""
pass

Expand All @@ -135,7 +136,7 @@ def obtain_simulated_curve(
bm_name: str,
oc_name: str,
reference_event_start_time: float,
) -> tuple[str, dict, int, bool, bool]:
) -> tuple[str, dict, int, bool, bool, pd.DataFrame]:
"""Virtual method"""
pass

Expand Down
1 change: 1 addition & 0 deletions src/dgcv/core/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def validate(
sim_output_path: str,
event_params: dict,
fs: float,
curves: dict,
) -> dict:
"""Virtual method"""
pass
Expand Down
29 changes: 17 additions & 12 deletions src/dgcv/curves/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,18 @@ def __obtain_files_curve(
if success:
importer = CurvesImporter(working_oc_dir, get_cfg_oc_name(pcs_bm_name, oc_name))
(
df_imported_curve,
df_imported_curves,
curves_dict,
sim_t_event_end,
fs,
) = importer.get_curves_dataframe(self._producer.get_zone())
if df_imported_curve.empty:
if df_imported_curves.empty:
success = False
has_imported_curves = False

df_imported_curve = df_imported_curve.set_index("time")
if is_reference:
df_imported_curve.to_csv(working_oc_dir / "curves_reference.csv", sep=";")
else:
df_imported_curve.to_csv(working_oc_dir / "curves_calculated.csv", sep=";")
self._generators = self.__get_generators(df_imported_curve)
self._gens = _get_generators_ini(self._generators, df_imported_curve)
if not is_reference:
self._generators = self.__get_generators(df_imported_curves)
self._gens = _get_generators_ini(self._generators, df_imported_curves)

if importer.config.has_option("Curves-Metadata", "is_field_measurements"):
self._is_field_measurements = bool(
Expand Down Expand Up @@ -116,6 +112,7 @@ def __obtain_files_curve(
fault_duration = 0
fs = 0
self._generators_imax = {}
df_imported_curves = pd.DataFrame()

config_section = get_cfg_oc_name(pcs_bm_name, oc_name) + ".Event"
connect_event_to = config.get_value(config_section, "connect_event_to")
Expand All @@ -139,6 +136,7 @@ def __obtain_files_curve(
fs,
success,
has_imported_curves,
df_imported_curves,
)

def obtain_reference_curve(
Expand All @@ -147,7 +145,7 @@ def obtain_reference_curve(
pcs_bm_name: str,
oc_name: str,
curves: Path,
) -> float:
) -> tuple[float, pd.DataFrame]:
"""Read the reference curves.
Parameters
Expand All @@ -165,16 +163,19 @@ def obtain_reference_curve(
-------
float
Instant of time when the event is triggered
DataFrame
Curves imported from the file
"""
(
event_params,
fs,
success,
has_imported_curves,
curves,
) = self.__obtain_files_curve(
working_oc_dir, pcs_bm_name, oc_name, curves, is_reference=True
)
return event_params["start_time"]
return event_params["start_time"], curves

def obtain_simulated_curve(
self,
Expand All @@ -183,7 +184,7 @@ def obtain_simulated_curve(
bm_name: str,
oc_name: str,
reference_event_start_time: float,
) -> tuple[str, dict, float, bool, bool]:
) -> tuple[str, dict, float, bool, bool, pd.DataFrame]:
"""Read the input curves to get the simulated curves.
Parameters
Expand Down Expand Up @@ -213,12 +214,15 @@ def obtain_simulated_curve(
True if simulation is success
bool
True if simulation calculated curves
DataFrame
Simulation calculated curves
"""
(
event_params,
fs,
success,
has_imported_curves,
curves,
) = self.__obtain_files_curve(
working_oc_dir, pcs_bm_name, oc_name, self.get_producer().get_producer_curves()
)
Expand All @@ -229,6 +233,7 @@ def obtain_simulated_curve(
fs,
success,
has_imported_curves,
curves,
)

def get_disconnection_model(self) -> Disconnection_Model:
Expand Down
4 changes: 2 additions & 2 deletions src/dgcv/curves/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ def load(self, remove_file=True):
if remove_file:
file.unlink()

def read(self, data: pd.Dataframe):
def read(self, data: pd.DataFrame):
"""Read and import the data from the file.
Parameters
----------
data: Dataframe
data: DataFrame
Dataframe with all the curves data
"""
self._time_values = data[self._time_name]
Expand Down
21 changes: 3 additions & 18 deletions src/dgcv/dynawo/dynawo.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ def _get_modulus(complex_list: list) -> list:
return np.abs(complex_list).tolist()


def _create_curves(
variable_translations: dict, input_file: Path, output_file: Path, f_nom: float
) -> pd.DataFrame:
def _create_curves(variable_translations: dict, input_file: Path) -> pd.DataFrame:
"""From the curve file generated by the Dynawo dynamic simulator, a new file is created
where the values of the different curves are expressed in the units specified in the file
and/or different curves are added to obtain the required curves.
Expand All @@ -322,10 +320,6 @@ def _create_curves(
Dictionary with correspondences between tool variables and Dynawo variables
input_file: Path
Curve file created by Dynawo
output_file: Path
Curve file for tool analysis
f_nom: float
Nominal frequency
Returns
-------
Expand Down Expand Up @@ -401,11 +395,7 @@ def _create_curves(
else:
curves_dict[i] = list(df_curves[i])

curves_final = pd.DataFrame(curves_dict)
curves_final = curves_final.set_index("time")
curves_final.to_csv(output_file, sep=";")

return curves_final
return pd.DataFrame(curves_dict)


def get_dynawo_version(
Expand Down Expand Up @@ -488,7 +478,6 @@ def run_base_dynawo(
launcher_dwo: Path,
jobs_filename: str,
variable_translations: dict,
f_nom: float,
inputs_path: Path,
output_path: Path,
save_file: bool = True,
Expand All @@ -503,8 +492,6 @@ def run_base_dynawo(
Name of the JOBS file
variable_translations: dict
Dictionary with correspondences between tool variables and Dynawo variables
f_nom: float
Nominal frequency
inputs_path: Path
Directory with Dynawo inputs
output_path: Path
Expand Down Expand Up @@ -541,8 +528,6 @@ def run_base_dynawo(
curves_calculated = _create_curves(
variable_translations,
dynawo_output_dir / "curves/curves.csv",
inputs_path / "curves_calculated.csv",
f_nom,
)

return success, log, has_error, curves_calculated
Expand Down Expand Up @@ -585,7 +570,7 @@ def check_voltage_dip(
if not is_simulation_success:
return -1

time_values = list(curves.index.values)
time_values = list(curves["time"])
voltage_values = list(curves[bus_pdr_voltage])

if fault_duration > time_values[-1]:
Expand Down
10 changes: 6 additions & 4 deletions src/dgcv/dynawo/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ def __execute_dynawo(
self._launcher_dwo,
"TSOModel",
self._curves_dict,
self._f_nom,
working_oc_dir,
jobs_output_dir,
)
Expand Down Expand Up @@ -625,7 +624,7 @@ def __get_hiz_fault(
fault_start,
fault_duration,
last_fault_xpu,
fault_rpu=last_fault_rpu,
last_fault_rpu,
)

def __get_bolted_fault(
Expand Down Expand Up @@ -681,7 +680,6 @@ def __run_time_cct(
self._launcher_dwo,
"TSOModel",
self._curves_dict,
self._f_nom,
working_oc_dir_attempt,
jobs_output_dir,
save_file=False,
Expand Down Expand Up @@ -809,7 +807,7 @@ def obtain_simulated_curve(
bm_name: str,
oc_name: str,
reference_event_start_time: float,
) -> tuple[str, dict, int, bool, bool]:
) -> tuple[str, dict, int, bool, bool, pd.DataFrame]:
"""Runs Dynawo to get the simulated curves.
Parameters
Expand Down Expand Up @@ -837,6 +835,8 @@ def obtain_simulated_curve(
True if simulation is success
bool
True if simulation calculated curves
DataFrame
Simulation calculated curves
"""

# Prepare environment to validate it,
Expand Down Expand Up @@ -896,6 +896,7 @@ def obtain_simulated_curve(
success = False
has_dynawo_curves = False
event_params = dict()
curves_calculated = pd.DataFrame()

self._logger.close_handlers()

Expand All @@ -905,6 +906,7 @@ def obtain_simulated_curve(
0,
success,
has_dynawo_curves,
curves_calculated,
)

def get_disconnection_model(self) -> Disconnection_Model:
Expand Down
4 changes: 4 additions & 0 deletions src/dgcv/model/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ def __validate(
fs: float,
success: bool,
has_simulated_curves: bool,
curves: dict,
):
op_cond_success, results = op_cond.validate(
pcs_benchmark_name,
Expand All @@ -482,6 +483,7 @@ def __validate(
fs,
success,
has_simulated_curves,
curves,
)

# Statuses for the Summary Report
Expand Down Expand Up @@ -534,6 +536,7 @@ def validate(
success,
has_simulated_curves,
has_curves,
curves,
) = op_cond.has_required_curves(pcs_benchmark_name, self._name)
if has_curves == 0:
op_cond_success, results, compliance = self.__validate(
Expand All @@ -545,6 +548,7 @@ def validate(
fs,
success,
has_simulated_curves,
curves,
)
# If there is a correct simulation, the report must be created
success |= op_cond_success
Expand Down
Loading

0 comments on commit 8b1a1a9

Please sign in to comment.