-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
183 lines (141 loc) · 4.94 KB
/
Copy pathutils.py
File metadata and controls
183 lines (141 loc) · 4.94 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import numpy as np
from solar_engine import run_full_simulation
# -------------------------------------------------------
# Rooftop Area Calculation
# -------------------------------------------------------
def calculate_area_from_mask(mask, resolution=0.1):
"""
Estimate rooftop area in square meters.
resolution = meters per pixel
"""
pixel_count = np.sum(mask)
return round(pixel_count * (resolution ** 2), 2)
# -------------------------------------------------------
# PM Surya Ghar Subsidy Model
# -------------------------------------------------------
def calculate_pm_surya_subsidy(system_size_kw, cost_per_kw):
"""
PM Surya Ghar subsidy rules:
- 40% subsidy up to 3 kW
- 20% subsidy for 3–10 kW
"""
if system_size_kw <= 3:
subsidy = system_size_kw * cost_per_kw * 0.40
elif system_size_kw <= 10:
subsidy = (
3 * cost_per_kw * 0.40 +
(system_size_kw - 3) * cost_per_kw * 0.20
)
else:
subsidy = (
3 * cost_per_kw * 0.40 +
7 * cost_per_kw * 0.20
)
return int(subsidy)
# -------------------------------------------------------
# 10-Year Financial Projection
# -------------------------------------------------------
def ten_year_projection(annual_generation_kwh, tariff):
"""
Includes:
- 0.5% annual panel degradation
- 5% annual tariff inflation
"""
degradation_rate = 0.005
inflation_rate = 0.05
yearly_savings = []
cumulative_savings = []
cumulative = 0
for year in range(1, 11):
adjusted_generation = annual_generation_kwh * ((1 - degradation_rate) ** year)
adjusted_tariff = tariff * ((1 + inflation_rate) ** year)
savings = adjusted_generation * adjusted_tariff
cumulative += savings
yearly_savings.append(round(savings, 2))
cumulative_savings.append(round(cumulative, 2))
return yearly_savings, cumulative_savings
# -------------------------------------------------------
# Main Solar Estimation Function
# -------------------------------------------------------
def estimate_solar_metrics(
area_m2,
latitude,
longitude,
tilt,
azimuth,
optimize,
tariff=8.0,
cost_per_kw=55000
):
if area_m2 <= 0:
raise ValueError("Detected rooftop area is zero.")
# ---- System sizing ----
module_efficiency = 0.18
system_size_kw = round(area_m2 * module_efficiency, 2)
if system_size_kw <= 0:
system_size_kw = 0.1
# ---- pvlib Simulation ----
results = run_full_simulation(
latitude,
longitude,
system_size_kw,
tilt,
azimuth
)
annual_generation_kwh = results["annual_real_kwh"]
# ---- Installation Cost ----
installation_cost = int(system_size_kw * cost_per_kw)
# ---- PM Surya Ghar Subsidy ----
subsidy = calculate_pm_surya_subsidy(system_size_kw, cost_per_kw)
net_cost = installation_cost - subsidy
# ---- Net Metering Model ----
self_consumption_ratio = 0.55
export_tariff = tariff * 0.6
self_used_energy = annual_generation_kwh * self_consumption_ratio
exported_energy = annual_generation_kwh * (1 - self_consumption_ratio)
annual_savings = round(
self_used_energy * tariff +
exported_energy * export_tariff,
2
)
# ---- Payback ----
if annual_savings > 0 and net_cost > 0:
payback_years = round(net_cost / annual_savings, 1)
roi = round((annual_savings / net_cost) * 100, 1)
else:
payback_years = float("inf")
roi = 0
# ---- 10-Year Projection ----
degradation_rate = 0.005
inflation_rate = 0.05
yearly_savings = []
cumulative_savings = []
cumulative = 0
for year in range(1, 11):
degraded_generation = annual_generation_kwh * ((1 - degradation_rate) ** (year - 1))
inflated_tariff = tariff * ((1 + inflation_rate) ** (year - 1))
self_used = degraded_generation * self_consumption_ratio
exported = degraded_generation * (1 - self_consumption_ratio)
savings = (
self_used * inflated_tariff +
exported * (inflated_tariff * 0.6)
)
cumulative += savings
yearly_savings.append(round(savings, 2))
cumulative_savings.append(round(cumulative, 2))
metrics = {
"system_size_kw": system_size_kw,
"annual_generation_kwh": round(annual_generation_kwh, 2),
"annual_clear_kwh": results["annual_clear_kwh"],
"weather_loss_percent": results["weather_loss_percent"],
"performance_ratio": results["performance_ratio"],
"installation_cost": installation_cost,
"subsidy": subsidy,
"net_cost": net_cost,
"annual_savings": annual_savings,
"payback_years": payback_years,
"roi_percent": roi,
"yearly_savings": yearly_savings,
"cumulative_savings": cumulative_savings
}
return metrics, results["monthly_generation"]