@@ -224,7 +224,7 @@ def run_optimization_14a(edisgo):
224224
225225grid_path = "/home/carlos/LoMa/exec_folder/results/MGB_quo_model_pypsa"
226226
227- edisgo = EDisGo (pypsa_csv_dir = grid_path , snapshot_range = (0 , 2 ))
227+ edisgo = EDisGo (pypsa_csv_dir = grid_path , snapshot_range = (0 , 23 ))
228228mv_grid_geom = gpd .read_file (
229229 "/home/carlos/LoMa/exec_folder/data/Input_files/MV_grid_district/husum_district.shp"
230230)
@@ -295,6 +295,33 @@ def run_optimization_14a(edisgo):
295295edisgo = run_optimization_14a (edisgo )
296296edisgo .analyze ()
297297
298+ # ── Slack diagnosis ────────────────────────────────────────────────────────────
299+ slacks = edisgo .opf_results .grid_slacks_t
300+ print ("\n === OPF Slack Diagnosis (v5) ===" )
301+ for name , df in [
302+ ("gen_nd_crt (renewable curtailment)" , slacks .gen_nd_crt ),
303+ ("gen_d_crt (disp. gen curtailment)" , slacks .gen_d_crt ),
304+ ("load_shed (load shedding)" , slacks .load_shedding ),
305+ ("hp_shed (HP load shedding)" , slacks .hp_load_shedding ),
306+ ]:
307+ total = df .abs ().sum (axis = 1 )
308+ if (total > 5e-3 ).any ():
309+ print (f" { name } : { total :.4f} MW ← NON-ZERO" )
310+ else :
311+ print (f" { name } : 0 (not used)" )
312+
313+ print ("\n === Voltage after OPF (edisgo.results.v_res) ===" )
314+ v = edisgo .results .v_res
315+ print (f" Min: { v .min ().min ():.4f} p.u." )
316+ print (f" Max: { v .max ().max ():.4f} p.u." )
317+ viol = (v < 0.9 ) | (v > 1.1 )
318+ if viol .any ().any ():
319+ print (f" Violations:{ v .where (viol ).stack ().dropna ().to_string ()} " )
320+ print ()
321+ else :
322+ print (" No voltage violations." )
323+ # ── End diagnosis ──────────────────────────────────────────────────────────────
324+
298325# Plot
299326for ts in edisgo .timeseries .timeindex :
300327 plot_network (edisgo , show = False , snapshot = str (ts ))
0 commit comments