heliostack 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
heliostack/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ """HelioStack: Deterministic open-source solar PV, 3D shading, thermal, and ESS engine."""
2
+
3
+ __all__ = ["__version__"]
4
+ __version__ = "0.3.0"
heliostack/audit.py ADDED
@@ -0,0 +1,221 @@
1
+ """Deterministic RO-Crate 1.1, SHA-256 manifest, JSON audit, and printable HTML report."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import html
7
+ import json
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ from heliostack import __version__
12
+ from heliostack.models import SimulationResult
13
+
14
+
15
+ def _sha256_file(path: Path) -> str:
16
+ return hashlib.sha256(path.read_bytes()).hexdigest()
17
+
18
+
19
+ def _render_monthly_svg(monthly_ac: list[float], monthly_curt_no: list[float], monthly_curt_with: list[float]) -> str:
20
+ """Render clean standalone SVG monthly yield and curtailment chart."""
21
+ w, h = 680, 220
22
+ pad_l, pad_r, pad_t, pad_b = 54, 16, 20, 32
23
+ plot_w = w - pad_l - pad_r
24
+ plot_h = h - pad_t - pad_b
25
+ max_val = max(100.0, max((a + c for a, c in zip(monthly_ac, monthly_curt_no, strict=True)), default=100.0) * 1.12)
26
+ labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
27
+ step = plot_w / 12.0
28
+ bar_w = step * 0.62
29
+
30
+ bars: list[str] = []
31
+ for i, label in enumerate(labels):
32
+ x = pad_l + i * step + (step - bar_w) * 0.5
33
+ ac_h = (monthly_ac[i] / max_val) * plot_h
34
+ y_ac = pad_t + plot_h - ac_h
35
+ bars.append(
36
+ f'<rect x="{x:.1f}" y="{y_ac:.1f}" width="{bar_w:.1f}" height="{ac_h:.1f}" '
37
+ f'rx="3" fill="#0f766e" opacity="0.88" />'
38
+ )
39
+ if monthly_curt_with[i] > 1.0:
40
+ ch = (monthly_curt_with[i] / max_val) * plot_h
41
+ bars.append(
42
+ f'<rect x="{x:.1f}" y="{y_ac:.1f}" width="{bar_w:.1f}" height="{min(ac_h, ch):.1f}" '
43
+ f'rx="2" fill="#d97706" opacity="0.92" />'
44
+ )
45
+ bars.append(
46
+ f'<text x="{x + bar_w * 0.5:.1f}" y="{h - 10}" text-anchor="middle" '
47
+ f'font-size="11" fill="#475569">{label}</text>'
48
+ )
49
+
50
+ grid_lines: list[str] = []
51
+ for frac in (0.0, 0.25, 0.5, 0.75, 1.0):
52
+ yv = pad_t + plot_h * (1.0 - frac)
53
+ val_kwh = max_val * frac / 1000.0
54
+ grid_lines.append(
55
+ f'<line x1="{pad_l}" y1="{yv:.1f}" x2="{w - pad_r}" y2="{yv:.1f}" stroke="#e2e8f0" stroke-width="1" />'
56
+ )
57
+ grid_lines.append(
58
+ f'<text x="{pad_l - 6}" y="{yv + 4:.1f}" text-anchor="end" font-size="10" fill="#64748b">{val_kwh:.1f} MWh</text>'
59
+ )
60
+
61
+ return (
62
+ f'<svg viewBox="0 0 {w} {h}" width="100%" role="img" aria-label="Monthly PV Yield Chart">'
63
+ + "".join(grid_lines)
64
+ + "".join(bars)
65
+ + "</svg>"
66
+ )
67
+
68
+
69
+ def render_bankable_html(result: SimulationResult) -> str:
70
+ """Generate a deterministic, zero-CDN standalone HTML engineering report."""
71
+ s = result.site
72
+ wf = result.loss_waterfall
73
+ ess = result.ess_metrics
74
+ svg = _render_monthly_svg(
75
+ result.monthly_ac_kwh,
76
+ result.monthly_curtailed_no_ess_kwh,
77
+ result.monthly_curtailed_with_ess_kwh,
78
+ )
79
+ esc = html.escape
80
+ payback_txt = f"{ess.simple_payback_ess_yr:.2f} yr" if ess.simple_payback_ess_yr is not None else "N/A"
81
+ weather_sha = str(result.weather_provenance.get("payload_sha256", ""))[:16]
82
+
83
+ return f"""<!DOCTYPE html>
84
+ <html lang="en">
85
+ <head>
86
+ <meta charset="utf-8" />
87
+ <title>HelioStack Bankable Engineering Report — {esc(s.site_name)}</title>
88
+ <style>
89
+ body {{ font-family: system-ui, -apple-system, sans-serif; margin: 0; padding: 24px; color: #0f172a; background: #f8fafc; }}
90
+ .wrap {{ max-width: 920px; margin: 0 auto; background: #ffffff; border: 1px solid #cbd5e1; border-radius: 12px; padding: 28px; }}
91
+ h1 {{ margin: 0 0 6px; font-size: 1.55rem; }}
92
+ .sub {{ color: #475569; margin: 0 0 18px; font-size: 0.92rem; }}
93
+ .grid {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }}
94
+ .kpi {{ border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px; background: #f8fafc; }}
95
+ .kpi .v {{ font-size: 1.28rem; font-weight: 700; color: #0f766e; }}
96
+ .kpi .k {{ font-size: 0.8rem; color: #475569; margin-top: 2px; }}
97
+ table {{ width: 100%; border-collapse: collapse; margin: 14px 0 22px; font-size: 0.9rem; }}
98
+ th, td {{ border-bottom: 1px solid #e2e8f0; padding: 8px 10px; text-align: left; }}
99
+ th {{ background: #f1f5f9; font-weight: 600; }}
100
+ .foot {{ font-size: 0.8rem; color: #64748b; border-top: 1px solid #e2e8f0; padding-top: 12px; }}
101
+ </style>
102
+ </head>
103
+ <body>
104
+ <div class="wrap">
105
+ <h1>HelioStack v{esc(__version__)} — Bankable Yield &amp; ESS Audit Report</h1>
106
+ <p class="sub">{esc(s.site_name)} ({s.latitude:.4f}, {s.longitude:.4f}) &middot; Mode: <strong>{esc(s.mounting_mode)}</strong> &middot; {s.dc_kwp:.1f} kWp DC / {s.grid_export_limit_kw:.1f} kW Export Cap</p>
107
+ <div class="grid">
108
+ <div class="kpi"><div class="v">{wf.specific_yield_kwh_kwp:,.1f}</div><div class="k">Specific Yield (kWh/kWp/yr)</div></div>
109
+ <div class="kpi"><div class="v">{wf.performance_ratio * 100:.2f}%</div><div class="k">Performance Ratio (PR)</div></div>
110
+ <div class="kpi"><div class="v">{wf.p90_kwh_yr / 1000.0:,.2f} MWh</div><div class="k">P90 Annual Exceedance</div></div>
111
+ <div class="kpi"><div class="v">{ess.curtailment_recovery_pct:.1f}%</div><div class="k">ESS Curtailment Recovery</div></div>
112
+ <div class="kpi"><div class="v">EUR {ess.lcoe_eur_kwh:.4f}/kWh</div><div class="k">20-Year LCOE</div></div>
113
+ </div>
114
+ <h2>Monthly AC Energy &amp; Remaining Curtailment</h2>
115
+ {svg}
116
+ <h2>Energy Loss Waterfall &amp; Thermal Summary</h2>
117
+ <table>
118
+ <tr><th>Metric</th><th>Value</th><th>Notes</th></tr>
119
+ <tr><td>Horizontal Irradiation (GHI)</td><td>{wf.ghi_kwh_m2:.1f} kWh/m&sup2;</td><td>Source: {esc(str(result.weather_provenance.get("source", "PVGIS")))} (SHA {esc(weather_sha)})</td></tr>
120
+ <tr><td>Global Tilted POA (Unshaded)</td><td>{wf.poa_global_kwh_m2:.1f} kWh/m&sup2;</td><td>Transposition gain: {wf.transposition_gain_pct:+.2f}%</td></tr>
121
+ <tr><td>3D Beam Shading + Diffuse SVF</td><td>-{wf.shading_loss_pct:.2f}%</td><td>Diffuse Sky-View Factor: {wf.diffuse_svf:.3f}</td></tr>
122
+ <tr><td>IAM + Soiling + Bifacial Gain</td><td>-{wf.iam_loss_pct:.2f}% / -{wf.soiling_loss_pct:.2f}% / +{wf.bifacial_gain_pct:.2f}%</td><td>Module bifaciality: {result.module.bifaciality_factor:.2f}</td></tr>
123
+ <tr><td>Thermal Loss &amp; Daytime T<sub>cell</sub></td><td>-{wf.thermal_loss_pct:.2f}% ({wf.mean_cell_temp_day_c:.1f} &deg;C)</td><td>Mounting thermal physics: {esc(s.mounting_mode)}</td></tr>
124
+ <tr><td>Inverter Eff. &amp; Clipping Losses</td><td>-{wf.inverter_eff_loss_pct:.2f}% / -{wf.clipping_loss_pct:.2f}%</td><td>{esc(result.inverter.manufacturer)} {esc(result.inverter.model)}</td></tr>
125
+ <tr><td>P50 / P75 / P90 / P99 Yield</td><td>{wf.p50_kwh_yr:,.0f} / {wf.p75_kwh_yr:,.0f} / {wf.p90_kwh_yr:,.0f} / {wf.p99_kwh_yr:,.0f} kWh</td><td>Combined 1-sigma 4.40% analytical uncertainty</td></tr>
126
+ </table>
127
+ <h2>8,760-Hour HiGHS ESS &amp; Curtailment Dispatch</h2>
128
+ <table>
129
+ <tr><th>Metric</th><th>Baseline (No ESS)</th><th>Optimized ({s.ess_energy_kwh:.0f} kWh / {s.ess_power_kw:.0f} kW)</th></tr>
130
+ <tr><td>Curtailed Energy</td><td>{ess.curtailed_no_ess_kwh_yr:,.1f} kWh/yr</td><td>{ess.curtailed_with_ess_kwh_yr:,.1f} kWh/yr ({ess.curtailment_recovery_pct:.1f}% recovered)</td></tr>
131
+ <tr><td>Net Grid Export</td><td>{ess.net_export_no_ess_kwh_yr:,.1f} kWh/yr</td><td>{ess.net_export_with_ess_kwh_yr:,.1f} kWh/yr</td></tr>
132
+ <tr><td>Annual Cycles &amp; HVAC Aux</td><td>0.0 / 0.0 kWh</td><td>{ess.annual_cycles:.1f} cycles / {ess.ess_hvac_aux_kwh_yr:,.1f} kWh aux</td></tr>
133
+ <tr><td>Annual Export Revenue &amp; Payback</td><td>EUR {ess.revenue_no_ess_eur_yr:,.0f}/yr</td><td>EUR {ess.revenue_with_ess_eur_yr:,.0f}/yr (+{ess.revenue_uplift_eur_yr:,.0f}/yr, ESS payback {esc(payback_txt)})</td></tr>
134
+ </table>
135
+ <div class="foot">
136
+ Deterministic execution with 0% generative AI at runtime &middot; HiGHS LP max hourly residual: {ess.max_hourly_conservation_err_kw:.2e} kW &middot; Verified MIT Open Source (`heliostack` v{esc(__version__)}).
137
+ </div>
138
+ </div>
139
+ </body>
140
+ </html>
141
+ """
142
+
143
+
144
+ def write_audit_bundle(
145
+ result: SimulationResult,
146
+ output_dir: Path,
147
+ input_files: list[Path] | None = None,
148
+ ) -> dict[str, Path]:
149
+ """Write deterministic audit JSON, bankable HTML, SHA-256 manifest, and RO-Crate 1.1."""
150
+ output_dir.mkdir(parents=True, exist_ok=True)
151
+ audit_path = output_dir / "audit_report.json"
152
+ html_path = output_dir / "bankable_report.html"
153
+ repro_path = output_dir / "repro-manifest.json"
154
+ rocrate_path = output_dir / "ro-crate-metadata.json"
155
+
156
+ audit_data = result.to_dict()
157
+ audit_data["ess_metrics"].pop("solve_time_s", None)
158
+ audit_path.write_text(json.dumps(audit_data, indent=2, sort_keys=True) + "\n", encoding="utf-8")
159
+ html_path.write_text(render_bankable_html(result), encoding="utf-8")
160
+
161
+ artifacts: list[dict[str, Any]] = [
162
+ {"relative_path": "audit_report.json", "role": "simulation_result", "sha256": _sha256_file(audit_path)},
163
+ {"relative_path": "bankable_report.html", "role": "bankable_report", "sha256": _sha256_file(html_path)},
164
+ ]
165
+ for fpath in input_files or []:
166
+ if fpath.is_file():
167
+ artifacts.append(
168
+ {
169
+ "relative_path": fpath.name,
170
+ "role": "input_specification",
171
+ "sha256": _sha256_file(fpath),
172
+ }
173
+ )
174
+
175
+ repro_payload = {
176
+ "schema": "heliostack.repro-manifest.v1",
177
+ "engine_version": __version__,
178
+ "license": "MIT",
179
+ "runtime_environment": {
180
+ "external_llm_used_at_runtime": False,
181
+ "deterministic_physics_solver": "pvlib_single_diode + scipy_highs_lp",
182
+ },
183
+ "weather_provenance": result.weather_provenance,
184
+ "artifacts": artifacts,
185
+ }
186
+ repro_path.write_text(json.dumps(repro_payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
187
+
188
+ graph: list[dict[str, Any]] = [
189
+ {
190
+ "@id": "ro-crate-metadata.json",
191
+ "@type": "CreativeWork",
192
+ "conformsTo": {"@id": "https://w3id.org/ro/crate/1.1"},
193
+ "about": {"@id": "./"},
194
+ },
195
+ {
196
+ "@id": "./",
197
+ "@type": "Dataset",
198
+ "name": f"HelioStack Bankable Simulation Audit: {result.site.site_name}",
199
+ "license": "https://opensource.org/licenses/MIT",
200
+ "hasPart": [
201
+ {"@id": "audit_report.json"},
202
+ {"@id": "bankable_report.html"},
203
+ {"@id": "repro-manifest.json"},
204
+ ],
205
+ },
206
+ {"@id": "audit_report.json", "@type": "File", "encodingFormat": "application/json"},
207
+ {"@id": "bankable_report.html", "@type": "File", "encodingFormat": "text/html"},
208
+ {"@id": "repro-manifest.json", "@type": "File", "encodingFormat": "application/json"},
209
+ ]
210
+ rocrate_payload = {
211
+ "@context": "https://w3id.org/ro/crate/1.1/context",
212
+ "@graph": graph,
213
+ }
214
+ rocrate_path.write_text(json.dumps(rocrate_payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
215
+
216
+ return {
217
+ "audit_report": audit_path,
218
+ "bankable_report": html_path,
219
+ "repro_manifest": repro_path,
220
+ "ro_crate": rocrate_path,
221
+ }
heliostack/cli.py ADDED
@@ -0,0 +1,193 @@
1
+ """Command-line entrypoint for HelioStack equipment validation, simulation, and preview."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import functools
7
+ import http.server
8
+ import json
9
+ import sys
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ from heliostack import __version__
14
+ from heliostack.audit import write_audit_bundle
15
+ from heliostack.ess_optimizer import run_full_simulation
16
+ from heliostack.formats import parse_ond, parse_pan, validate_equipment_path
17
+ from heliostack.models import ObstacleBox3D, SiteConfig
18
+ from heliostack.terrain import (
19
+ compare_horizon_profiles,
20
+ fetch_copernicus_dem_horizon,
21
+ fetch_pvgis_horizon,
22
+ )
23
+ from heliostack.weather import fetch_pvgis_tmy, load_cached_tmy
24
+
25
+
26
+ def _load_site_from_json(path: Path) -> tuple[SiteConfig, Path | None, Path | None]:
27
+ raw: dict[str, Any] = json.loads(path.read_text(encoding="utf-8"))
28
+ obstacles = [ObstacleBox3D(**obs) for obs in raw.pop("obstacles", [])]
29
+ pan_path = Path(raw.pop("module_file")) if "module_file" in raw else None
30
+ ond_path = Path(raw.pop("inverter_file")) if "inverter_file" in raw else None
31
+ if pan_path and not pan_path.is_absolute():
32
+ pan_path = (path.parent / pan_path).resolve()
33
+ if ond_path and not ond_path.is_absolute():
34
+ ond_path = (path.parent / ond_path).resolve()
35
+ site = SiteConfig(**raw, obstacles=obstacles)
36
+ return site, pan_path, ond_path
37
+
38
+
39
+ def _cmd_validate(args: argparse.Namespace) -> int:
40
+ target = Path(args.target)
41
+ if not target.exists():
42
+ print(f"Path not found: {target}", file=sys.stderr)
43
+ return 2
44
+ records, code = validate_equipment_path(target)
45
+ if args.json:
46
+ print(json.dumps({"exit_code": code, "files": records}, indent=2))
47
+ else:
48
+ for rec in records:
49
+ tag = "PASS" if rec["passed"] else "FAIL"
50
+ print(f"[{tag}] {rec['file']} ({rec['kind']}): errors={rec['errors']}, warnings={rec['warnings']}")
51
+ for issue in rec["issues"]:
52
+ print(f" - {issue['severity']} [{issue['code']}]: {issue['message']}")
53
+ return code
54
+
55
+
56
+ def _cmd_simulate(args: argparse.Namespace) -> int:
57
+ cfg_path = Path(args.config)
58
+ if not cfg_path.is_file():
59
+ print(f"Config not found: {cfg_path}", file=sys.stderr)
60
+ return 2
61
+
62
+ site, pan_path, ond_path = _load_site_from_json(cfg_path)
63
+ pkg_root = Path(__file__).resolve().parent.parent.parent
64
+ pan_file = pan_path or (pkg_root / "fixtures" / "equipment" / "ref_550w_bifacial.pan")
65
+ ond_file = ond_path or (pkg_root / "fixtures" / "equipment" / "ref_250kw_inverter.ond")
66
+
67
+ mod, mod_issues = parse_pan(pan_file)
68
+ inv, inv_issues = parse_ond(ond_file)
69
+ if mod is None or inv is None:
70
+ print("Equipment validation failed:", mod_issues + inv_issues, file=sys.stderr)
71
+ return 1
72
+
73
+ if args.weather:
74
+ weather, prov = load_cached_tmy(Path(args.weather))
75
+ else:
76
+ cache_dir = Path(args.cache_dir) if args.cache_dir else None
77
+ weather, prov = fetch_pvgis_tmy(site.latitude, site.longitude, cache_dir=cache_dir)
78
+
79
+ auto_hor = getattr(args, "auto_horizon", "none")
80
+ if auto_hor != "none":
81
+ hor_cache = Path(args.cache_dir) if args.cache_dir else None
82
+ if auto_hor == "copernicus":
83
+ site.horizon_elev_deg_36, _ = fetch_copernicus_dem_horizon(
84
+ site.latitude, site.longitude, cache_dir=hor_cache
85
+ )
86
+ elif auto_hor == "pvgis":
87
+ site.horizon_elev_deg_36, _ = fetch_pvgis_horizon(
88
+ site.latitude, site.longitude, cache_dir=hor_cache
89
+ )
90
+
91
+ result = run_full_simulation(
92
+ weather=weather,
93
+ weather_provenance=prov,
94
+ site=site,
95
+ module=mod,
96
+ inverter=inv,
97
+ )
98
+ out_dir = Path(args.output)
99
+ paths = write_audit_bundle(result, out_dir, input_files=[cfg_path, pan_file, ond_file])
100
+ wf = result.loss_waterfall
101
+ ess = result.ess_metrics
102
+ print(
103
+ f"HelioStack v{__version__} | {site.site_name} ({site.mounting_mode}): "
104
+ f"{wf.specific_yield_kwh_kwp:.1f} kWh/kWp/yr | PR={wf.performance_ratio:.3f} | "
105
+ f"Curtailment Recovery={ess.curtailment_recovery_pct:.1f}% | LCOE=EUR {ess.lcoe_eur_kwh:.4f}/kWh"
106
+ )
107
+ print(f"RO-Crate bundle written to: {paths['ro_crate']}")
108
+ return 0
109
+
110
+
111
+ def _cmd_horizon(args: argparse.Namespace) -> int:
112
+ cache_dir = Path(args.cache_dir) if args.cache_dir else None
113
+ h_cop, meta_cop = fetch_copernicus_dem_horizon(args.lat, args.lon, cache_dir=cache_dir)
114
+ h_pvgis, meta_pvg = fetch_pvgis_horizon(args.lat, args.lon, cache_dir=cache_dir)
115
+ stats = compare_horizon_profiles(h_cop, h_pvgis)
116
+ payload = {
117
+ "latitude": args.lat,
118
+ "longitude": args.lon,
119
+ "comparison": stats,
120
+ "copernicus_meta": meta_cop,
121
+ "pvgis_meta": meta_pvg,
122
+ "copernicus_horizon_deg_36": h_cop,
123
+ "pvgis_horizon_deg_36": h_pvgis,
124
+ }
125
+ if args.json:
126
+ print(json.dumps(payload, indent=2))
127
+ else:
128
+ print(
129
+ f"Horizon ({args.lat:.4f}, {args.lon:.4f}) | Elev={meta_cop['site_elevation_m']} m | "
130
+ f"Copernicus mean={stats['mean_copernicus_deg']:.2f} deg vs PVGIS mean={stats['mean_pvgis_deg']:.2f} deg | "
131
+ f"MAE={stats['mae_deg']:.2f} deg, RMSE={stats['rmse_deg']:.2f} deg"
132
+ )
133
+ return 0
134
+
135
+
136
+ def _cmd_serve(args: argparse.Namespace) -> int:
137
+ serve_dir = Path(args.dir)
138
+ if not serve_dir.is_dir():
139
+ print(f"Directory not found: {serve_dir}", file=sys.stderr)
140
+ return 2
141
+ handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=str(serve_dir))
142
+ with http.server.ThreadingHTTPServer(("127.0.0.1", args.port), handler) as httpd:
143
+ print(f"Serving HelioStack UI at http://127.0.0.1:{args.port}/ (Ctrl+C to stop)")
144
+ httpd.serve_forever()
145
+ return 0
146
+
147
+
148
+ def build_parser() -> argparse.ArgumentParser:
149
+ parser = argparse.ArgumentParser(prog="heliostack", description="HelioStack open solar PV & ESS simulation CLI")
150
+ parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
151
+ sub = parser.add_subparsers(dest="command", required=True)
152
+
153
+ p_val = sub.add_parser("validate", help="Validate .pan/.ond/.json equipment specifications")
154
+ p_val.add_argument("target", help="File or directory to validate")
155
+ p_val.add_argument("--json", action="store_true", help="Emit structured JSON validation report")
156
+ p_val.set_defaults(func=_cmd_validate)
157
+
158
+ p_sim = sub.add_parser("simulate", help="Run 8,760-hr PV + 3D shading + ESS optimization and emit RO-Crate audit")
159
+ p_sim.add_argument("--config", required=True, help="Site JSON configuration file")
160
+ p_sim.add_argument("-o", "--output", default="outputs/run", help="Output bundle directory")
161
+ p_sim.add_argument("--weather", default="", help="Optional cached CSV/PVGIS JSON weather file")
162
+ p_sim.add_argument("--cache-dir", default="", help="Optional cache directory for PVGIS downloads")
163
+ p_sim.add_argument(
164
+ "--auto-horizon",
165
+ choices=("none", "pvgis", "copernicus"),
166
+ default="none",
167
+ help="Automatically fetch 36-azimuth terrain horizon from Copernicus DEM or EU PVGIS",
168
+ )
169
+ p_sim.set_defaults(func=_cmd_simulate)
170
+
171
+ p_hor = sub.add_parser("horizon", help="Compute Copernicus DEM horizon and compare with EU PVGIS")
172
+ p_hor.add_argument("--lat", type=float, required=True, help="Site latitude")
173
+ p_hor.add_argument("--lon", type=float, required=True, help="Site longitude")
174
+ p_hor.add_argument("--cache-dir", default="", help="Optional cache directory for elevation downloads")
175
+ p_hor.add_argument("--json", action="store_true", help="Emit JSON payload")
176
+ p_hor.set_defaults(func=_cmd_horizon)
177
+
178
+ p_srv = sub.add_parser("serve", help="Serve static standalone Web UI locally")
179
+ p_srv.add_argument("--dir", default="docs", help="Directory containing index.html")
180
+ p_srv.add_argument("--port", type=int, default=8780, help="Local HTTP port")
181
+ p_srv.set_defaults(func=_cmd_serve)
182
+
183
+ return parser
184
+
185
+
186
+ def main(argv: list[str] | None = None) -> int:
187
+ parser = build_parser()
188
+ args = parser.parse_args(argv)
189
+ return int(args.func(args))
190
+
191
+
192
+ if __name__ == "__main__":
193
+ raise SystemExit(main())
@@ -0,0 +1,198 @@
1
+ {
2
+ "solver": "OpenFOAM 14 (foamRun -solver fluid, steady kOmegaSST, heRhoThermo ideal gas air, 28-deg tilted PV)",
3
+ "domain_m": {
4
+ "x": [
5
+ -4.0,
6
+ 10.0
7
+ ],
8
+ "y": [
9
+ 0.0,
10
+ 5.5
11
+ ],
12
+ "tilt_deg": 28.0,
13
+ "chord_m": 2.0
14
+ },
15
+ "cells": 5910,
16
+ "t_amb_c": 25.0,
17
+ "t_sky_c": 13.0,
18
+ "t_panel_c": 50.0,
19
+ "natural_convection_h_w_m2k": 6.402,
20
+ "thermal_absorptance_factor": 0.729,
21
+ "total_wall_s": 171.59,
22
+ "surfaces": {
23
+ "land_rack": {
24
+ "ground_boundary_temp_c": 35.0,
25
+ "clearance_m": 0.85,
26
+ "radiative_effective_h_w_m2k": 11.738,
27
+ "cases": [
28
+ {
29
+ "surface": "land_rack",
30
+ "wind_speed_ms": 1.0,
31
+ "clearance_m": 0.85,
32
+ "t_ground_k": 308.15,
33
+ "final_step": 800,
34
+ "q_panel_top_w_m2": 104.476,
35
+ "q_panel_bottom_w_m2": 62.604,
36
+ "h_conv_top_w_m2k": 4.179,
37
+ "h_conv_bottom_w_m2k": 2.504,
38
+ "h_conv_total_w_m2k": 6.683,
39
+ "h_rad_eff_w_m2k": 11.738,
40
+ "h_total_with_rad_w_m2k": 18.421,
41
+ "elapsed_s": 23.71,
42
+ "foam_log_sha256": "b49c199232b3ae49e6bfb517b9664405493f32f34257fca33f247888839f5686",
43
+ "step_bot": 800
44
+ },
45
+ {
46
+ "surface": "land_rack",
47
+ "wind_speed_ms": 2.0,
48
+ "clearance_m": 0.85,
49
+ "t_ground_k": 308.15,
50
+ "final_step": 800,
51
+ "q_panel_top_w_m2": 184.37,
52
+ "q_panel_bottom_w_m2": 100.121,
53
+ "h_conv_top_w_m2k": 7.375,
54
+ "h_conv_bottom_w_m2k": 4.005,
55
+ "h_conv_total_w_m2k": 11.38,
56
+ "h_rad_eff_w_m2k": 11.738,
57
+ "h_total_with_rad_w_m2k": 23.117,
58
+ "elapsed_s": 20.49,
59
+ "foam_log_sha256": "0d6aac8049e24c1ac556d1177f87b1f49ceb8a015e739eaf6529b1398345fddc",
60
+ "step_bot": 800
61
+ },
62
+ {
63
+ "surface": "land_rack",
64
+ "wind_speed_ms": 4.0,
65
+ "clearance_m": 0.85,
66
+ "t_ground_k": 308.15,
67
+ "final_step": 800,
68
+ "q_panel_top_w_m2": 317.551,
69
+ "q_panel_bottom_w_m2": 164.802,
70
+ "h_conv_top_w_m2k": 12.702,
71
+ "h_conv_bottom_w_m2k": 6.592,
72
+ "h_conv_total_w_m2k": 19.294,
73
+ "h_rad_eff_w_m2k": 11.738,
74
+ "h_total_with_rad_w_m2k": 31.032,
75
+ "elapsed_s": 20.97,
76
+ "foam_log_sha256": "4807da931136a644f2e529886196058be8f955600e93561735e429693f633d91",
77
+ "step_bot": 800
78
+ },
79
+ {
80
+ "surface": "land_rack",
81
+ "wind_speed_ms": 6.0,
82
+ "clearance_m": 0.85,
83
+ "t_ground_k": 308.15,
84
+ "final_step": 800,
85
+ "q_panel_top_w_m2": 436.816,
86
+ "q_panel_bottom_w_m2": 221.335,
87
+ "h_conv_top_w_m2k": 17.473,
88
+ "h_conv_bottom_w_m2k": 8.853,
89
+ "h_conv_total_w_m2k": 26.326,
90
+ "h_rad_eff_w_m2k": 11.738,
91
+ "h_total_with_rad_w_m2k": 38.064,
92
+ "elapsed_s": 20.13,
93
+ "foam_log_sha256": "a429fe0161eadb0e8bbdef1c941d691ba836358fb05bd5f14f125a6570fe89ce",
94
+ "step_bot": 800
95
+ }
96
+ ],
97
+ "h_conv_raw_linear_fit_w_m2k": {
98
+ "c0": 3.228,
99
+ "c1": 3.905
100
+ },
101
+ "h_conv_linear_fit_w_m2k": {
102
+ "c0": 4.705,
103
+ "c1": 3.648
104
+ },
105
+ "faiman_equivalent": {
106
+ "u0": 22.56,
107
+ "u1": 5.0
108
+ }
109
+ },
110
+ "floating_pv": {
111
+ "ground_boundary_temp_c": 21.0,
112
+ "clearance_m": 0.25,
113
+ "radiative_effective_h_w_m2k": 14.688,
114
+ "cases": [
115
+ {
116
+ "surface": "floating_pv",
117
+ "wind_speed_ms": 1.0,
118
+ "clearance_m": 0.25,
119
+ "t_ground_k": 294.15,
120
+ "final_step": 800,
121
+ "q_panel_top_w_m2": 106.716,
122
+ "q_panel_bottom_w_m2": 79.699,
123
+ "h_conv_top_w_m2k": 4.269,
124
+ "h_conv_bottom_w_m2k": 3.188,
125
+ "h_conv_total_w_m2k": 7.457,
126
+ "h_rad_eff_w_m2k": 14.688,
127
+ "h_total_with_rad_w_m2k": 22.144,
128
+ "elapsed_s": 19.15,
129
+ "foam_log_sha256": "69ed9e1b60e55221c4dae48133c99f22976a5362be215f8c97a586ce0d44628a",
130
+ "step_bot": 800
131
+ },
132
+ {
133
+ "surface": "floating_pv",
134
+ "wind_speed_ms": 2.0,
135
+ "clearance_m": 0.25,
136
+ "t_ground_k": 294.15,
137
+ "final_step": 800,
138
+ "q_panel_top_w_m2": 190.248,
139
+ "q_panel_bottom_w_m2": 108.233,
140
+ "h_conv_top_w_m2k": 7.61,
141
+ "h_conv_bottom_w_m2k": 4.329,
142
+ "h_conv_total_w_m2k": 11.939,
143
+ "h_rad_eff_w_m2k": 14.688,
144
+ "h_total_with_rad_w_m2k": 26.627,
145
+ "elapsed_s": 20.31,
146
+ "foam_log_sha256": "5cf9d50970dad5c57ae32bdb9baf67e15c318c5f01c847e0a2c83a0f576c9d5f",
147
+ "step_bot": 800
148
+ },
149
+ {
150
+ "surface": "floating_pv",
151
+ "wind_speed_ms": 4.0,
152
+ "clearance_m": 0.25,
153
+ "t_ground_k": 294.15,
154
+ "final_step": 800,
155
+ "q_panel_top_w_m2": 326.685,
156
+ "q_panel_bottom_w_m2": 194.032,
157
+ "h_conv_top_w_m2k": 13.067,
158
+ "h_conv_bottom_w_m2k": 7.761,
159
+ "h_conv_total_w_m2k": 20.829,
160
+ "h_rad_eff_w_m2k": 14.688,
161
+ "h_total_with_rad_w_m2k": 35.517,
162
+ "elapsed_s": 22.01,
163
+ "foam_log_sha256": "a96d80041dab530526249d9541a8bc5415063bd66c11aa2ba63ba69ef5829a68",
164
+ "step_bot": 800
165
+ },
166
+ {
167
+ "surface": "floating_pv",
168
+ "wind_speed_ms": 6.0,
169
+ "clearance_m": 0.25,
170
+ "t_ground_k": 294.15,
171
+ "final_step": 800,
172
+ "q_panel_top_w_m2": 461.611,
173
+ "q_panel_bottom_w_m2": 237.907,
174
+ "h_conv_top_w_m2k": 18.464,
175
+ "h_conv_bottom_w_m2k": 9.516,
176
+ "h_conv_total_w_m2k": 27.981,
177
+ "h_rad_eff_w_m2k": 14.688,
178
+ "h_total_with_rad_w_m2k": 42.669,
179
+ "elapsed_s": 21.9,
180
+ "foam_log_sha256": "e7b969ef509db4f0e177c45174d95a151a10ade9e72a6aded0ad8d2e2b8139f7",
181
+ "step_bot": 800
182
+ }
183
+ ],
184
+ "h_conv_raw_linear_fit_w_m2k": {
185
+ "c0": 3.64,
186
+ "c1": 4.127
187
+ },
188
+ "h_conv_linear_fit_w_m2k": {
189
+ "c0": 4.912,
190
+ "c1": 3.906
191
+ },
192
+ "faiman_equivalent": {
193
+ "u0": 26.89,
194
+ "u1": 5.36
195
+ }
196
+ }
197
+ }
198
+ }