Skip to content

Commit 4df4890

Browse files
committed
Make LV line catalogue script self contained
1 parent 4242793 commit 4df4890

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

scripts/generate_lv_line_parameters_catalogue.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "polars>=1.38.1",
5+
# "roseau-load-flow>=0.14.0",
6+
# ]
7+
# ///
8+
# Run with: `uv run scripts/generate_lv_line_parameters_catalogue.py``
19
import math
210
import statistics
311
import warnings
@@ -73,7 +81,7 @@ def extrapolate[X: float](table: dict[X, float], x: X) -> None:
7381
if x in table:
7482
warnings.warn(f"Value for x={x} already exists in the table, no extrapolation needed.", stacklevel=2)
7583
return
76-
lr = statistics.linear_regression(list(table.keys()), list(table.values()))
84+
lr = statistics.linear_regression(table.keys(), table.values())
7785
table[x] = x * lr.slope + lr.intercept
7886

7987

@@ -433,15 +441,9 @@ def generate_c33210_lv_underground_parameters() -> pl.DataFrame:
433441

434442

435443
if __name__ == "__main__":
436-
import io
437-
438444
twisted_df = generate_c33209_lv_twisted_parameters()
439445
underground_df = generate_c33210_lv_underground_parameters()
440446
all_df = pl.concat([twisted_df, underground_df], how="vertical")
441447

442-
s = io.StringIO()
443-
all_df.with_columns(
444-
# Round float columns for better CSV readability
445-
pl.col(pl.Float64).round(10)
446-
).write_csv(s)
447-
print(s.getvalue())
448+
# Round float columns for better CSV readability
449+
print(all_df.with_columns(pl.col(pl.Float64).round(10)).write_csv(), end="")

0 commit comments

Comments
 (0)