Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions benchmarking/baselines/toggle_specialist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
sigma under-covers where the method is biased.

Each run writes a per-run folder ``toggle_specialist_<test>_<upgradestart>_<lastdate>/``
(v0-style naming) under ``out_dir`` (a temp dir by default), holding a per-segment data-stats CSV,
a headline results CSV, the per-leg selection and reference-subset CSVs, and -- when
under ``out_dir`` (a temp dir by default), holding CSVs named ``<kind>_<write time>.csv``: a
per-segment data-stats CSV, a headline results CSV, the per-leg selection and reference-subset CSVs, and -- when
``save_plots`` -- four diagnostic plots (a test-vs-reference scatter, a per-segment daily-ratio
timeseries, a per-segment used-data-coverage timeseries, and a pairing-gap histogram).
The rich stats let a human confirm the right data was received and interpreted: each leg's uplift
Expand Down Expand Up @@ -1049,9 +1049,9 @@ def _write_outputs(
)
run_dir = out_root / run_name
run_dir.mkdir(parents=True, exist_ok=True)
ts = pd.Timestamp.utcnow().strftime("%Y%m%d_%H%M%S_%f")
ts = pd.Timestamp.utcnow().strftime("%Y%m%d_%H%M%S")
Comment thread
aclerc marked this conversation as resolved.

stats.to_csv(run_dir / f"{run_name}_data_stats_{ts}.csv", index=False)
stats.to_csv(run_dir / f"data_stats_{ts}.csv", index=False)

used_base = int(stats.loc[stats["segment"] == "baseline", "n_used_timestamps"].iloc[0])
used_up = int(stats.loc[stats["segment"] == "upgraded", "n_used_timestamps"].iloc[0])
Expand Down Expand Up @@ -1080,17 +1080,17 @@ def _write_outputs(
}
]
)
results.to_csv(run_dir / f"{run_name}_results_{ts}.csv", index=False)
results.to_csv(run_dir / f"results_{ts}.csv", index=False)

if est.per_bin is not None:
est.per_bin.to_csv(run_dir / f"{run_name}_by_power_bin_{ts}.csv", index=False)
est.diagnostics.to_csv(run_dir / f"{run_name}_uncertainty_{ts}.csv", index=False)
est.per_bin.to_csv(run_dir / f"by_power_bin_{ts}.csv", index=False)
est.diagnostics.to_csv(run_dir / f"uncertainty_{ts}.csv", index=False)
if subsets is not None:
subsets.to_csv(run_dir / f"{run_name}_reference_subsets_{ts}.csv", index=False)
subsets.to_csv(run_dir / f"reference_subsets_{ts}.csv", index=False)
# Every leg's row selection, so the blend's two selections can be told apart.
pd.concat(
[component.accounting.assign(component=mode) for mode, component in components.items()], ignore_index=True
).to_csv(run_dir / f"{run_name}_selection_{ts}.csv", index=False)
).to_csv(run_dir / f"selection_{ts}.csv", index=False)

if self.save_plots:
# Scatter and ratio plots of one leg's own rows against its own reference.
Expand Down
10 changes: 5 additions & 5 deletions tests/benchmarking/baselines/test_toggle_specialist.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,14 @@ def test_per_bin_csv_is_written(self, tmp_path: Path) -> None:
rated_power_kw=_RATED_KW,
out_dir=tmp_path,
).estimate(MethodInput(scada_df=scada, test_wtg="T1", upgrade_timing=schedule, turbine_col=_TURBINE_COL))
assert list(tmp_path.rglob("*_by_power_bin_*.csv"))
assert list(tmp_path.rglob("by_power_bin_*.csv"))

def test_no_per_bin_csv_when_conditioning_is_off(self, tmp_path: Path) -> None:
scada, schedule, _ = _toggle_case(uplift=0.03)
ToggleSpecialistMethod(columns=_COLUMNS, toggle_period=_CYCLE, toggle_datum=_DATUM, out_dir=tmp_path).estimate(
MethodInput(scada_df=scada, test_wtg="T1", upgrade_timing=schedule, turbine_col=_TURBINE_COL)
)
assert not list(tmp_path.rglob("*_by_power_bin_*.csv"))
assert not list(tmp_path.rglob("by_power_bin_*.csv"))

def test_per_bin_plot_written_with_save_plots(self, tmp_path: Path) -> None:
scada, schedule = _varying_rho_case(uplift=0.05)
Expand Down Expand Up @@ -587,7 +587,7 @@ def test_toggle_coverage_capped_near_duty_cycle(self) -> None:
def _read_only_csv(folder: Path, kind: str) -> pd.DataFrame:
run_dirs = [p for p in Path(folder).iterdir() if p.is_dir()]
assert len(run_dirs) == 1, f"expected exactly one run dir, found {run_dirs}"
matches = list(run_dirs[0].glob(f"*_{kind}_*.csv"))
matches = list(run_dirs[0].glob(f"{kind}_*.csv"))
assert len(matches) == 1, f"expected one {kind} csv, found {matches}"
return pd.read_csv(matches[0])

Expand Down Expand Up @@ -851,15 +851,15 @@ class TestUncertaintyInTheWrittenOutputs:
def test_results_csv_records_the_sigma_and_the_bootstrap_config(self, tmp_path: Path) -> None:
scada, schedule = _noisy_toggle_case()
out = _estimate(scada, schedule, out_dir=tmp_path, block_hours=24.0)
results = pd.concat([pd.read_csv(p) for p in tmp_path.glob("*/*_results_*.csv")])
results = pd.concat([pd.read_csv(p) for p in tmp_path.glob("*/results_*.csv")])
assert results["uplift_sigma_frc"].iloc[0] == pytest.approx(out.sigma_overall)
assert results["block_hours"].iloc[0] == 24.0
assert results["n_resamples"].iloc[0] == 1000

def test_an_uncertainty_csv_is_written(self, tmp_path: Path) -> None:
scada, schedule = _noisy_toggle_case()
_estimate(scada, schedule, out_dir=tmp_path, conditions=("power",), rated_power_kw=_RATED_KW)
written = list(tmp_path.glob("*/*_uncertainty_*.csv"))
written = list(tmp_path.glob("*/uncertainty_*.csv"))
assert len(written) == 1
frame = pd.read_csv(written[0])
assert "n_upgraded_records" in frame.columns
Expand Down
Loading