Skip to content

Commit

Permalink
Fix convert_v2_to_v3 and test all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
alihamdan committed Dec 1, 2024
1 parent b42ed5e commit 0567c1a
Show file tree
Hide file tree
Showing 10 changed files with 2,727 additions and 1,277 deletions.
35 changes: 29 additions & 6 deletions roseau/load_flow/io/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ def network_from_dict( # noqa: C901

version = data.get("version", 0)
if version <= 2:
logger.warning(
warnings.warn(
f"Got an outdated network file (version {version}), trying to update to the current format "
f"(version {NETWORK_JSON_VERSION}). Please save the network again."
f"(version {NETWORK_JSON_VERSION}). Please save the network again.",
category=UserWarning,
stacklevel=find_stack_level(),
)
if version <= 0:
data = v0_to_v1_converter(data)
Expand Down Expand Up @@ -177,11 +179,20 @@ def network_from_dict( # noqa: C901
bus2 = buses[line_data["bus2"]]
geometry = Line._parse_geometry(line_data.get("geometry"))
length = line_data["length"]
max_loading = line_data["max_loading"]
lp = lines_params[line_data["params_id"]]
gid = line_data.get("ground")
ground = grounds[gid] if gid is not None else None
line = Line(
id=id, bus1=bus1, bus2=bus2, parameters=lp, phases=phases, length=length, ground=ground, geometry=geometry
id=id,
bus1=bus1,
bus2=bus2,
parameters=lp,
phases=phases,
length=length,
ground=ground,
geometry=geometry,
max_loading=max_loading,
)
if include_results:
line = _assign_branch_currents(branch=line, branch_data=line_data)
Expand All @@ -196,12 +207,21 @@ def network_from_dict( # noqa: C901
phases1 = transformer_data["phases1"]
phases2 = transformer_data["phases2"]
tap = transformer_data["tap"]
max_loading = transformer_data["max_loading"]
bus1 = buses[transformer_data["bus1"]]
bus2 = buses[transformer_data["bus2"]]
geometry = Transformer._parse_geometry(transformer_data.get("geometry"))
tp = transformers_params[transformer_data["params_id"]]
transformer = Transformer(
id=id, bus1=bus1, bus2=bus2, parameters=tp, phases1=phases1, phases2=phases2, tap=tap, geometry=geometry
id=id,
bus1=bus1,
bus2=bus2,
parameters=tp,
phases1=phases1,
phases2=phases2,
tap=tap,
geometry=geometry,
max_loading=max_loading,
)
if include_results:
transformer = _assign_branch_currents(branch=transformer, branch_data=transformer_data)
Expand Down Expand Up @@ -671,7 +691,10 @@ def v2_to_v3_converter(data: JsonDict) -> JsonDict: # noqa: C901
vg = "Iii0"
transformer_param_data["vg"] = vg
if (max_power := transformer_param_data.pop("max_power", None)) is not None:
transformers_params_max_loading[transformer_param_data["id"]] = max_power / transformer_param_data["sn"]
loading = max_power / transformer_param_data["sn"]
else:
loading = 1
transformers_params_max_loading[transformer_param_data["id"]] = loading
transformers_params.append(transformer_param_data)

# Rename `maximal_current` in `ampacities` and uses array
Expand Down Expand Up @@ -705,7 +728,7 @@ def v2_to_v3_converter(data: JsonDict) -> JsonDict: # noqa: C901
old_transformers = data.get("transformers", [])
transformers = []
for transformer_data in old_transformers:
transformer_data["max_loading"] = transformers_params_max_loading.get(transformer_data["params_id"], 1)
transformer_data["max_loading"] = transformers_params_max_loading[transformer_data["params_id"]]
transformers.append(transformer_data)

results = {
Expand Down
13 changes: 13 additions & 0 deletions roseau/load_flow/io/tests/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Versioned network JSON files for testing

## JSON files

**DO NOT MODIFY** the JSON files in this directory if the tests fail. Adapt the converter functions
in the `roseau.load_flow.io.dict` module instead.

## Generator scripts

Scripts in the _generators_ directory are used to generate the versioned network JSON files. They
are executed using old versions of rlf.

**DO NOT UPGRADE** these scripts when modifying rlf.
Loading

0 comments on commit 0567c1a

Please sign in to comment.