-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPV.py
More file actions
113 lines (103 loc) · 4.43 KB
/
PV.py
File metadata and controls
113 lines (103 loc) · 4.43 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
import pandas as pd
import numpy as np
from tqdm import tqdm
from __utils__ import Array, Bifacial, Opaque, Organic, Module, Cell
from shading import calculate_self_shading, calculate_crop_shading
__all__ = (
"System",
"calculate_system_performance",
)
class System:
def __init__(self, Arrays: list[Array]):
self.no_arrays = len(Arrays)
self.arrays: list[Array] = Arrays
# Takes in a list of arrays. The arrangement of all the arrays and how they are connected to each other if they are.
pass
def calculate_system_performance(
pvSystem: System,
solar_irradiance: np.ndarray,
Time: tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray],
temperature: float,
crop_shading_calculation: bool = True,
self_shading_calculation: bool = True,
resolution=1,
ground_coordinates=np.array([]),
) -> tuple[np.ndarray, dict[Array, np.ndarray], dict[Array, np.ndarray]]:
"""
Cycles through arrays in the pv system and calculates the power generated and the shading in their respective areas
Parameters
----------
pvSystem: System
Holds list of pv arrays
solar_irradiance: ndarray
direct irradiance of the sun
Time: tuple[ndarray, ndarray, ndarray, ndarray]
Tuple that holds all the years, months, days and hours of each individaul time point
to be calculated. Most importantly, for each hour the respective year, month and day
must be added to set of arrays. The length of each array in the Time tuple must be the same!
temperature: float
Avergae temperature of cells
crop_shading_calculations: bool
if true function does crop shading calculation
self_shading_calculation: bool
If true takes self shading into account when calculating array power
Returns
----------
system_power: ndarray
total power of arrays in system
array_power_dict: dict[Array, ndarray]
dictionary of the power of each seperate array
crop_illumination_dict: dict[Array, ndarray]
dictionary of shaded area of array
"""
system_power = 0
crop_illumination_dict = {}
array_power_dict = {}
# 1. For each array in pvSystem
for i, pv_array in enumerate(pvSystem.arrays):
# 2. Find self shading
dicts = calculate_self_shading(pv_array, solar_irradiance, Time)
if self_shading_calculation == True:
# If we do self shading use the new illumination given by self shading function
if pv_array.Module.type == "Bifacial":
array_power = pv_array.calculate_output_power(
dicts["illumination"],
dicts["front row illumination"],
temperature,
dicts["back illumination"],
dicts["back row illumination"],
)
else:
array_power = pv_array.calculate_output_power(
dicts["illumination"], dicts["front row illumination"], temperature
)
else:
# if we don't want the self shading we just do the calculations with the front and back row illumination
if pv_array.Module.type == "Bifacial":
array_power = pv_array.calculate_output_power(
dicts["front row illumination"],
dicts["front row illumination"],
temperature,
dicts["back illumination"],
dicts["back row illumination"],
)
else:
array_power = pv_array.calculate_output_power(
dicts["front row illumination"],
dicts["front row illumination"],
temperature,
)
# 3. Calculate crop shading if necessary
if crop_shading_calculation == True:
_, crop_irradiance = calculate_crop_shading(
pv_array, solar_irradiance, Time, resolution=resolution
)
crop_illumination_dict[pv_array] = crop_irradiance
system_power += array_power
array_power_dict[pv_array] = array_power
print(f"{pv_array.name} calculations are complete!\n")
# 5. Output Total Power generated, percentage of crops shaded, individual array output power, and individual crop shading
if crop_shading_calculation == True:
return system_power, array_power_dict, crop_illumination_dict
else:
return system_power, array_power_dict