-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_verify_faults.py
More file actions
40 lines (36 loc) · 1.7 KB
/
Copy path_verify_faults.py
File metadata and controls
40 lines (36 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Standalone check: does the classifier label each injected fault correctly,
across a sweep of irradiance and ambient temperature? No network needed."""
import simulator as sim
from pipeline import PVPipeline
p = PVPipeline()
# Note: "none" is gated upstream by is_anomaly (z>threshold), not by
# _classify_fault, so it is not tested here. _classify_fault only runs on
# readings already flagged anomalous.
EXPECT = {
"string_anomaly": "STRING_ANOMALY",
"bypass_diode": "BYPASS_DIODE_FAILURE",
"module_fault": "MODULE_FAULT",
"ground_fault": "GROUND_FAULT",
"gradual_degradation": "GRADUAL_DEGRADATION",
}
LABELS = {0:"NORMAL",1:"STRING_ANOMALY",2:"BYPASS_DIODE_FAILURE",
3:"MODULE_FAULT",4:"GROUND_FAULT",5:"GRADUAL_DEGRADATION"}
from datetime import datetime
ok = True
for mode, want in EXPECT.items():
got_set = set()
for G in (200, 500, 800, 1000):
for tamb in (15, 25, 35, 42):
# afternoon hour so string_anomaly is active
isc_f, voc_f, ff_f = sim._fault_factors(datetime(2024,4,1,13,0), mode)
out = sim._pv_output(G, tamb, isc_f, voc_f, ff_f)
reading = {"power_w": out["power_w"], "voltage": out["voltage"],
"current": out["current"], "fill_factor": out["fill_factor"],
"irradiance": out["irradiance"], "temperature": out["cell_temp"],
"time": "13:00"}
got_set.add(LABELS[p._classify_fault(reading, 3.0)])
status = "OK " if got_set == {want} else "FAIL"
if got_set != {want}:
ok = False
print(f"{status} {mode:22s} expected={want:22s} got={sorted(got_set)}")
print("\nALL PASS" if ok else "\nMISMATCH FOUND")