ubc-solar-physics 1.0.3__cp310-cp310-win32.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.
Files changed (52) hide show
  1. core.cp310-win32.pyd +0 -0
  2. physics/__init__.py +12 -0
  3. physics/__version__.py +16 -0
  4. physics/environment/__init__.py +22 -0
  5. physics/environment/environment.rs +2 -0
  6. physics/environment/gis/__init__.py +7 -0
  7. physics/environment/gis/base_gis.py +24 -0
  8. physics/environment/gis/gis.py +337 -0
  9. physics/environment/gis/gis.rs +25 -0
  10. physics/environment/gis.rs +1 -0
  11. physics/environment/meteorology/__init__.py +3 -0
  12. physics/environment/meteorology/base_meteorology.py +69 -0
  13. physics/environment/meteorology/clouded_meteorology.py +601 -0
  14. physics/environment/meteorology/irradiant_meteorology.py +106 -0
  15. physics/environment/meteorology/meteorology.rs +138 -0
  16. physics/environment/meteorology.rs +1 -0
  17. physics/environment/race.py +89 -0
  18. physics/environment.rs +2 -0
  19. physics/lib.rs +98 -0
  20. physics/models/__init__.py +13 -0
  21. physics/models/arrays/__init__.py +7 -0
  22. physics/models/arrays/arrays.rs +0 -0
  23. physics/models/arrays/base_array.py +6 -0
  24. physics/models/arrays/basic_array.py +39 -0
  25. physics/models/arrays.rs +1 -0
  26. physics/models/battery/__init__.py +7 -0
  27. physics/models/battery/base_battery.py +29 -0
  28. physics/models/battery/basic_battery.py +141 -0
  29. physics/models/battery/battery.rs +0 -0
  30. physics/models/battery.rs +1 -0
  31. physics/models/constants.py +23 -0
  32. physics/models/lvs/__init__.py +7 -0
  33. physics/models/lvs/base_lvs.py +6 -0
  34. physics/models/lvs/basic_lvs.py +18 -0
  35. physics/models/lvs/lvs.rs +0 -0
  36. physics/models/lvs.rs +1 -0
  37. physics/models/motor/__init__.py +7 -0
  38. physics/models/motor/base_motor.py +6 -0
  39. physics/models/motor/basic_motor.py +174 -0
  40. physics/models/motor/motor.rs +0 -0
  41. physics/models/motor.rs +1 -0
  42. physics/models/regen/__init__.py +7 -0
  43. physics/models/regen/base_regen.py +6 -0
  44. physics/models/regen/basic_regen.py +39 -0
  45. physics/models/regen/regen.rs +0 -0
  46. physics/models/regen.rs +1 -0
  47. physics/models.rs +5 -0
  48. ubc_solar_physics-1.0.3.dist-info/LICENSE +21 -0
  49. ubc_solar_physics-1.0.3.dist-info/METADATA +136 -0
  50. ubc_solar_physics-1.0.3.dist-info/RECORD +52 -0
  51. ubc_solar_physics-1.0.3.dist-info/WHEEL +5 -0
  52. ubc_solar_physics-1.0.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,601 @@
1
+ from physics.environment.meteorology.base_meteorology import BaseMeteorology
2
+ from physics.environment.gis.gis import calculate_path_distances
3
+ import numpy as np
4
+ from physics.environment.race import Race
5
+ from numba import jit
6
+ import core
7
+ from typing import Optional
8
+ import datetime
9
+
10
+
11
+ class CloudedMeteorology(BaseMeteorology):
12
+ """
13
+ CloudedMeteorology encapsulates meteorological data that includes
14
+ cloud cover, but not solar irradiance (necessitating manual computation).
15
+ """
16
+ def __init__(self, race, weather_forecasts):
17
+ super().__init__()
18
+
19
+ self._latitude: Optional[np.ndarray] = None
20
+ self._longitude: Optional[np.ndarray] = None
21
+ self._unix_time: Optional[np.ndarray] = None
22
+ self._cloud_cover: Optional[np.ndarray] = None
23
+
24
+ self._race = race
25
+ self._weather_forecast = weather_forecasts
26
+
27
+ self.S_0 = 1367.0 # Solar Constant, 1367W/m^2
28
+
29
+ self.last_updated_time = self._weather_forecast[0, 0, 2]
30
+
31
+ def spatially_localize(self, cumulative_distances: np.ndarray) -> None:
32
+ """
33
+
34
+ IMPORTANT: we only have weather coordinates for a discrete set of coordinates. However, the car could be at any
35
+ coordinate in between these available weather coordinates. We need to figure out what coordinate the car is at
36
+ at each timestep and then we can figure out the full weather forecast at each timestep.
37
+
38
+ For example, imagine the car is at some coordinate (10, 20). Further imagine that we have a week's worth of
39
+ weather forecasts for the following five coordinates: (5, 4), (11, 19), (20, 30), (40, 30), (0, 60). Which
40
+ set of weather forecasts should we choose? Well, we should choose the (11, 19) one since our coordinate
41
+ (10, 20) is closest to (11, 19). This is what the following code is accomplishing. However, it is not dealing
42
+ with the coordinates directly but rather is dealing with the distances between the coordinates.
43
+
44
+ Furthermore, once we have chosen a week's worth of weather forecasts for a specific coordinate, we must isolate
45
+ a single weather forecast depending on what time the car is at the coordinate (10, 20). That is the job of the
46
+ `get_weather_forecast_in_time()` method.
47
+
48
+ :param np.ndarray cumulative_distances: NumPy Array representing cumulative distances theoretically achievable for a given input speed array
49
+
50
+ """
51
+
52
+ # if racing FSGP, there is no need for distance calculations. We will return only the origin coordinate
53
+ # This characterizes the weather at every point along the FSGP tracks
54
+ # with the weather at a single coordinate on the track, which is great for reducing the API calls and is a
55
+ # reasonable assumption to make for FSGP only.
56
+ if self._race.race_type == Race.FSGP:
57
+ self._weather_indices = np.zeros_like(cumulative_distances, dtype=int)
58
+ return
59
+
60
+ # a list of all the coordinates that we have weather data for
61
+ weather_coords = self._weather_forecast[:, 0, 0:2]
62
+
63
+ # distances between all the coordinates that we have weather data for
64
+ weather_path_distances = calculate_path_distances(weather_coords)
65
+ cumulative_weather_path_distances = np.cumsum(weather_path_distances)
66
+
67
+ # makes every even-index element negative, this allows the use of np.diff() to calculate the sum of consecutive
68
+ # elements
69
+ cumulative_weather_path_distances[::2] *= -1
70
+
71
+ # contains the average distance between two consecutive elements in the cumulative_weather_path_distances array
72
+ average_distances = np.abs(np.diff(cumulative_weather_path_distances) / 2)
73
+
74
+ return core.closest_weather_indices_loop(cumulative_distances, average_distances)
75
+
76
+ def temporally_localize(self, unix_timestamps, start_time, tick) -> None:
77
+ """
78
+
79
+ Takes in an array of indices of the weather_forecast array, and an array of timestamps. Uses those to figure out
80
+ what the weather forecast is at each time step being simulated.
81
+
82
+ we only have weather at discrete timestamps. The car however can be in any timestamp in
83
+ between. Therefore, we must be able to choose the weather timestamp that is closest to the one that the car is in
84
+ so that we can more accurately determine the weather experienced by the car at that timestamp.
85
+
86
+ For example, imagine the car is at some coordinate (x,y) at timestamp 100. Imagine we know the weather forecast
87
+ at (x,y) for five different timestamps: 0, 30, 60, 90, and 120. Which weather forecast should we
88
+ choose? Clearly, we should choose the weather forecast at 90 since it is the closest to 100. That's what the
89
+ below code is accomplishing.
90
+
91
+ :param np.ndarray unix_timestamps: (int[N]) unix timestamps of the vehicle's journey
92
+ :param int tick: length of a tick in seconds
93
+ :returns:
94
+ - A NumPy array of size [N][9]
95
+ - [9] (latitude, longitude, unix_time, timezone_offset, unix_time_corrected, wind_speed, wind_direction,
96
+ cloud_cover, precipitation, description):
97
+ :rtype: np.ndarray
98
+
99
+ """
100
+ weather_data = core.weather_in_time(unix_timestamps.astype(np.int64), self._weather_indices.astype(np.int64), self._weather_forecast, 4)
101
+ # roll_by_tick = int(3600 / tick) * (24 + start_hour - hour_from_unix_timestamp(weather_data[0, 2]))
102
+ # weather_data = np.roll(weather_data, -roll_by_tick, 0)
103
+
104
+ self._latitude = weather_data[:, 0]
105
+ self._longitude = weather_data[:, 1]
106
+ self._unix_time = weather_data[:, 2]
107
+ self._wind_speed = weather_data[:, 5]
108
+ self._wind_direction = weather_data[:, 6]
109
+ self._cloud_cover = weather_data[:, 7]
110
+
111
+ def calculate_solar_irradiances(self, coords, time_zones, local_times, elevations):
112
+ """
113
+
114
+ Calculates the Global Horizontal Irradiance from the Sun, relative to a location
115
+ on the Earth, for arrays of coordinates, times, elevations and weathers
116
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/calculation-of-solar-insolation
117
+ Note: If local_times and time_zones are both unadjusted for Daylight Savings, the
118
+ calculation will end up just the same
119
+
120
+ :param np.ndarray coords: (float[N][lat, lng]) array of latitudes and longitudes
121
+ :param np.ndarray time_zones: (int[N]) time zones at different locations in seconds relative to UTC
122
+ :param np.ndarray local_times: (int[N]) unix time that the vehicle will be at each location. (Adjusted for Daylight Savings)
123
+ :param np.ndarray elevations: (float[N]) elevation from sea level in m
124
+ :returns: (float[N]) Global Horizontal Irradiance in W/m2
125
+ :rtype: np.ndarray
126
+
127
+ """
128
+ day_of_year, local_time = core.calculate_array_ghi_times(local_times)
129
+
130
+ ghi = self._calculate_GHI(coords[:, 0], coords[:, 1], time_zones,
131
+ day_of_year, local_time, elevations, self._cloud_cover)
132
+
133
+ stationary_irradiance = self._calculate_angled_irradiance(coords[:, 0], coords[:, 1], time_zones, day_of_year,
134
+ local_time, elevations, self._cloud_cover)
135
+
136
+ # Use stationary irradiance when the car is not driving
137
+ effective_irradiance = np.where(
138
+ np.logical_not(self._race.driving_boolean),
139
+ stationary_irradiance,
140
+ ghi)
141
+
142
+ return effective_irradiance
143
+
144
+ @staticmethod
145
+ def _calculate_hour_angle(time_zone_utc, day_of_year, local_time, longitude):
146
+ """
147
+
148
+ Calculates and returns the Hour Angle of the Sun in the sky.
149
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/solar-time
150
+ Note: If local time and time_zone_utc are both unadjusted for Daylight Savings, the
151
+ calculation will end up just the same
152
+ :param np.ndarray time_zone_utc: The UTC time zone of your area in hours of UTC offset.
153
+ :param np.ndarray day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
154
+ :param np.ndarray local_time: The local time in hours from midnight. (Adjust for Daylight Savings)
155
+ :param np.ndarray longitude: The longitude of a location on Earth
156
+ :returns: The Hour Angle in degrees.
157
+ :rtype: np.ndarray
158
+
159
+ """
160
+
161
+ lst = local_time_to_apparent_solar_time(time_zone_utc / 3600, day_of_year,
162
+ local_time, longitude)
163
+
164
+ hour_angle = 15 * (lst - 12)
165
+
166
+ return hour_angle
167
+
168
+ def _calculate_elevation_angle(self, latitude, longitude, time_zone_utc, day_of_year,
169
+ local_time):
170
+ """
171
+
172
+ Calculates the Elevation Angle of the Sun relative to a location on the Earth
173
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/elevation-angle
174
+ Note: If local time and time_zone_utc are both unadjusted for Daylight Savings, the
175
+ calculation will end up just the same
176
+
177
+ :param np.ndarray latitude: The latitude of a location on Earth
178
+ :param np.ndarray longitude: The longitude of a location on Earth
179
+ :param np.ndarray time_zone_utc: The UTC time zone of your area in hours of UTC offset. For example, Vancouver has time_zone_utc = -7
180
+ :param np.ndarray day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
181
+ :param np.ndarray local_time: The local time in hours from midnight. (Adjust for Daylight Savings)
182
+ :returns: The elevation angle in degrees
183
+ :rtype: np.ndarray
184
+
185
+ """
186
+
187
+ # Negative declination angles: Northern Hemisphere winter
188
+ # 0 declination angle : Equinoxes (March 22, Sept 22)
189
+ # Positive declination angle: Northern Hemisphere summer
190
+ declination_angle = calculate_declination_angle(day_of_year)
191
+
192
+ # Negative hour angles: Morning
193
+ # 0 hour angle : Solar noon
194
+ # Positive hour angle: Afternoon
195
+ hour_angle = self._calculate_hour_angle(time_zone_utc, day_of_year,
196
+ local_time, longitude)
197
+ # From: https://en.wikipedia.org/wiki/Hour_angle#:~:text=At%20solar%20noon%20the%20hour,times%201.5%20hours%20before%20noon).
198
+ # "For example, at 10:30 AM local apparent time
199
+ # the hour angle is −22.5° (15° per hour times 1.5 hours before noon)."
200
+
201
+ # mathy part is delegated to a helper function to optimize for numba compilation
202
+ return compute_elevation_angle_math(declination_angle, hour_angle, latitude)
203
+
204
+ def _calculate_zenith_angle(self, latitude, longitude, time_zone_utc, day_of_year,
205
+ local_time):
206
+ """
207
+
208
+ Calculates the Zenith Angle of the Sun relative to a location on the Earth
209
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/azimuth-angle
210
+ Note: If local time and time_zone_utc are both unadjusted for Daylight Savings, the
211
+ calculation will end up just the same
212
+
213
+ :param latitude: The latitude of a location on Earth
214
+ :param longitude: The longitude of a location on Earth
215
+ :param time_zone_utc: The UTC time zone of your area in hours of UTC offset.
216
+ :param day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
217
+ :param local_time: The local time in hours from midnight. (Adjust for Daylight Savings)
218
+ :return: The zenith angle in degrees
219
+ :rtype: float
220
+
221
+ """
222
+
223
+ elevation_angle = self._calculate_elevation_angle(latitude, longitude,
224
+ time_zone_utc, day_of_year, local_time)
225
+
226
+ return 90 - elevation_angle
227
+
228
+ def _calculate_azimuth_angle(self, latitude, longitude, time_zone_utc, day_of_year,
229
+ local_time):
230
+ """
231
+
232
+ Calculates the Azimuth Angle of the Sun relative to a location on the Earth.
233
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/azimuth-angle
234
+ Note: If local time and time_zone_utc are both unadjusted for Daylight Savings, the
235
+ calculation will end up just the same
236
+
237
+ :param latitude: The latitude of a location on Earth
238
+ :param longitude: The longitude of a location on Earth
239
+ :param time_zone_utc: The UTC time zone of your area in hours of UTC offset. For example, Vancouver has time_zone_utc = -7
240
+ :param day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
241
+ :param local_time: The local time in hours from midnight. (Adjust for Daylight Savings)
242
+ :returns: The azimuth angle in degrees
243
+ :rtype: np.ndarray
244
+
245
+ """
246
+
247
+ declination_angle = calculate_declination_angle(day_of_year)
248
+ hour_angle = self._calculate_hour_angle(time_zone_utc, day_of_year,
249
+ local_time, longitude)
250
+
251
+ term_1 = np.sin(np.radians(declination_angle)) * \
252
+ np.sin(np.radians(latitude))
253
+
254
+ term_2 = np.cos(np.radians(declination_angle)) * \
255
+ np.sin(np.radians(latitude)) * \
256
+ np.cos(np.radians(hour_angle))
257
+
258
+ elevation_angle = self._calculate_elevation_angle(latitude, longitude,
259
+ time_zone_utc, day_of_year, local_time)
260
+
261
+ term_3 = np.float_(term_1 - term_2) / \
262
+ np.cos(np.radians(elevation_angle))
263
+
264
+ if term_3 < -1:
265
+ term_3 = -1
266
+ elif term_3 > 1:
267
+ term_3 = 1
268
+
269
+ azimuth_angle = np.arcsin(term_3)
270
+
271
+ return np.degrees(azimuth_angle)
272
+
273
+ # ----- Calculation of sunrise and sunset times -----
274
+
275
+ # ----- Calculation of modes of solar irradiance -----
276
+
277
+ def _calculate_DNI(self, latitude, longitude, time_zone_utc, day_of_year,
278
+ local_time, elevation):
279
+ """
280
+
281
+ Calculates the Direct Normal Irradiance from the Sun, relative to a location
282
+ on the Earth (clearsky)
283
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/calculation-of-solar-insolation
284
+ Note: If local time and time_zone_utc are both unadjusted for Daylight Savings, the
285
+ calculation will end up just the same
286
+
287
+ :param np.ndarray latitude: The latitude of a location on Earth
288
+ :param np.ndarray longitude: The longitude of a location on Earth
289
+ :param np.ndarray time_zone_utc: The UTC time zone of your area in hours of UTC offset.
290
+ :param np.ndarray day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
291
+ :param np.ndarray local_time: The local time in hours from midnight. (Adjust for Daylight Savings)
292
+ :param np.ndarray elevation: The local elevation of a location in metres
293
+ :returns: The Direct Normal Irradiance in W/m2
294
+ :rtype: np.ndarray
295
+
296
+ """
297
+
298
+ zenith_angle = self._calculate_zenith_angle(latitude, longitude,
299
+ time_zone_utc, day_of_year, local_time)
300
+ a = 0.14
301
+
302
+ # https://www.pveducation.org/pvcdrom/properties-of-sunlight/air-mass
303
+ # air_mass = 1 / (math.cos(math.radians(zenith_angle)) + \
304
+ # 0.50572*pow((96.07995 - zenith_angle), -1.6364))
305
+
306
+ with np.errstate(invalid="ignore"):
307
+ air_mass = np.float_(1) / (np.float_(np.cos(np.radians(zenith_angle)))
308
+ + 0.50572*np.power((96.07995 - zenith_angle), -1.6364))
309
+
310
+ with np.errstate(over="ignore"):
311
+ DNI = self.S_0 * ((1 - a * elevation * 0.001) * np.power(0.7, np.power(air_mass, 0.678))
312
+ + a * elevation * 0.001)
313
+
314
+ return np.where(zenith_angle > 90, 0, DNI)
315
+
316
+ def _calculate_DHI(self, latitude, longitude, time_zone_utc, day_of_year,
317
+ local_time, elevation):
318
+ """
319
+
320
+ Calculates the Diffuse Horizontal Irradiance from the Sun, relative to a location
321
+ on the Earth (clearsky)
322
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/calculation-of-solar-insolation
323
+ Note: If local time and time_zone_utc are both unadjusted for Daylight Savings, the
324
+ calculation will end up just the same
325
+
326
+ :param np.ndarray latitude: The latitude of a location on Earth
327
+ :param np.ndarray longitude: The longitude of a location on Earth
328
+ :param np.ndarray time_zone_utc: The UTC time zone of your area in hours of UTC offset.
329
+ :param np.ndarray np.ndarray day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
330
+ :param np.ndarray local_time: The local time in hours from midnight
331
+ :param np.ndarray elevation: The local elevation of a location in metres
332
+ :returns: The Diffuse Horizontal Irradiance in W/m2
333
+ :rtype: np.ndarray
334
+
335
+ """
336
+
337
+ DNI = self._calculate_DNI(latitude, longitude, time_zone_utc, day_of_year,
338
+ local_time, elevation)
339
+
340
+ DHI = 0.1 * DNI
341
+
342
+ return DHI
343
+
344
+ def _calculate_GHI(self, latitude, longitude, time_zone_utc, day_of_year,
345
+ local_time, elevation, cloud_cover):
346
+ """
347
+
348
+ Calculates the Global Horizontal Irradiance from the Sun, relative to a location
349
+ on the Earth
350
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/calculation-of-solar-insolation
351
+ Note: If local time and time_zone_utc are both unadjusted for Daylight Savings, the
352
+ calculation will end up just the same
353
+
354
+ :param np.ndarray latitude: The latitude of a location on Earth
355
+ :param np.ndarray longitude: The longitude of a location on Earth
356
+ :param np.ndarray time_zone_utc: The UTC time zone of your area in hours of UTC offset, without including the effects of Daylight Savings Time. For example, Vancouver has time_zone_utc = -8 year-round.
357
+ :param np.ndarray day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
358
+ :param np.ndarray local_time: The local time in hours from midnight.
359
+ :param np.ndarray elevation: The local elevation of a location in metres
360
+ :param np.ndarray cloud_cover: A NumPy array representing cloud cover as a percentage from 0 to 100
361
+ :returns: The Global Horizontal Irradiance in W/m^2
362
+ :rtype: np.ndarray
363
+
364
+ """
365
+
366
+ DHI = self._calculate_DHI(latitude, longitude, time_zone_utc, day_of_year,
367
+ local_time, elevation)
368
+
369
+ DNI = self._calculate_DNI(latitude, longitude, time_zone_utc, day_of_year,
370
+ local_time, elevation)
371
+
372
+ zenith_angle = self._calculate_zenith_angle(latitude, longitude,
373
+ time_zone_utc, day_of_year, local_time)
374
+
375
+ GHI = DNI * np.cos(np.radians(zenith_angle)) + DHI
376
+
377
+ return self._apply_cloud_cover(GHI=GHI, cloud_cover=cloud_cover)
378
+
379
+ @staticmethod
380
+ def _apply_cloud_cover(GHI, cloud_cover):
381
+ """
382
+
383
+ Applies a cloud cover model to the GHI data.
384
+
385
+ Cloud cover adjustment follows the equation laid out here:
386
+ http://www.shodor.org/os411/courses/_master/tools/calculators/solarrad/
387
+
388
+ :param np.ndarray GHI: Global Horizontal Index in W/m^2
389
+ :param np.ndarray cloud_cover: A NumPy array representing cloud cover as a percentage from 0 to 100
390
+
391
+ :returns: GHI after considering cloud cover data
392
+ :rtype: np.ndarray
393
+
394
+ """
395
+
396
+ assert np.logical_and(cloud_cover >= 0, cloud_cover <= 100).all()
397
+
398
+ scaled_cloud_cover = cloud_cover / 100
399
+
400
+ assert np.logical_and(scaled_cloud_cover >= 0,
401
+ scaled_cloud_cover <= 1).all()
402
+
403
+ return GHI * (1 - (0.75 * np.power(scaled_cloud_cover, 3.4)))
404
+
405
+ # ----- Calculation of modes of solar irradiance, but returning numpy arrays -----
406
+ @staticmethod
407
+ def _date_convert(date):
408
+ """
409
+
410
+ Convert a date into local time.
411
+
412
+ :param datetime.datetime date: date to be converted
413
+ :return: a date converted into local time.
414
+ :rtype: int
415
+
416
+ """
417
+
418
+ return date.hour + (float(date.minute * 60 + date.second) / 3600)
419
+
420
+ def _calculate_angled_irradiance(self, latitude, longitude, time_zone_utc, day_of_year,
421
+ local_time, elevation, cloud_cover, array_angles=np.array([0, 15, 30, 45])):
422
+ """
423
+
424
+ Determine the direct and diffuse irradiance on an array which can be mounted at different angles.
425
+ During stationary charging, the car can mount the array at different angles, resulting in a higher
426
+ component of direct irradiance captured.
427
+
428
+ Uses the GHI formula, GHI = DNI*cos(zenith)+DHI but with an 'effective zenith',
429
+ the angle between the mounted panel's normal and the sun.
430
+
431
+ :param np.ndarray latitude: The latitude of a location on Earth
432
+ :param np.ndarray longitude: The longitude of a location on Earth
433
+ :param np.ndarray time_zone_utc: The UTC time zone of your area in hours of UTC offset, without including the effects of Daylight Savings Time. For example, Vancouver has time_zone_utc = -8 year-round.
434
+ :param np.ndarray day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
435
+ :param np.ndarray local_time: The local time in hours from midnight.
436
+ :param np.ndarray elevation: The local elevation of a location in metres
437
+ :param np.ndarray cloud_cover: A NumPy array representing cloud cover as a percentage from 0 to 100
438
+ :param np.ndarray array_angles: An array containing the discrete angles on which the array can be mounted
439
+ :returns: The "effective Global Horizontal Irradiance" in W/m^2
440
+ :rtype: np.ndarray
441
+
442
+ """
443
+
444
+ DHI = self._calculate_DHI(latitude, longitude, time_zone_utc, day_of_year,
445
+ local_time, elevation)
446
+
447
+ DNI = self._calculate_DNI(latitude, longitude, time_zone_utc, day_of_year,
448
+ local_time, elevation)
449
+
450
+ zenith_angle = self._calculate_zenith_angle(latitude, longitude,
451
+ time_zone_utc, day_of_year, local_time)
452
+
453
+ # Calculate the absolute differences
454
+ differences = np.abs(zenith_angle[:, np.newaxis] - array_angles)
455
+
456
+ # Find the minimum difference for each element in zenith_angle
457
+ effective_zenith = np.min(differences, axis=1)
458
+
459
+ # Now effective_zenith contains the minimum absolute difference for each element in zenith_angle
460
+
461
+ GHI = DNI * np.cos(np.radians(effective_zenith)) + DHI
462
+
463
+ return self._apply_cloud_cover(GHI=GHI, cloud_cover=cloud_cover)
464
+
465
+
466
+ def local_time_to_apparent_solar_time(time_zone_utc, day_of_year, local_time,
467
+ longitude):
468
+ """
469
+
470
+ Converts between the local time to the apparent solar time and returns the apparent
471
+ solar time.
472
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/solar-time
473
+
474
+ Note: If local time and time_zone_utc are both unadjusted for Daylight Savings, the
475
+ calculation will end up just the same
476
+
477
+ :param np.ndarray time_zone_utc: The UTC time zone of your area in hours of UTC offset.
478
+ :param np.ndarray day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
479
+ :param np.ndarray local_time: The local time in hours from midnight (Adjust for Daylight Savings)
480
+ :param np.ndarray longitude: The longitude of a location on Earth
481
+ :returns: The Apparent Solar Time of a location, in hours from midnight
482
+ :rtype: np.ndarray
483
+
484
+ """
485
+
486
+ lstm = calculate_LSTM(time_zone_utc)
487
+ eot = calculate_eot_correction(day_of_year)
488
+
489
+ # local solar time
490
+ lst = local_time + np.float_(longitude - lstm) / 15 + np.float_(eot) / 60
491
+
492
+ return lst
493
+
494
+
495
+ @jit(nopython=True)
496
+ def calculate_LSTM(time_zone_utc):
497
+ """
498
+
499
+ Calculates and returns the LSTM, or Local Solar Time Meridian.
500
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/solar-time
501
+
502
+ :param np.ndarray time_zone_utc: The UTC time zone of your area in hours of UTC offset.
503
+ :returns: The Local Solar Time Meridian in degrees
504
+ :rtype: np.ndarray
505
+
506
+ """
507
+
508
+ return 15 * time_zone_utc
509
+
510
+
511
+ @jit(nopython=True)
512
+ def calculate_eot_correction(day_of_year):
513
+ """
514
+
515
+ Approximates and returns the correction factor between the apparent
516
+ solar time and the mean solar time
517
+
518
+ :param np.ndarray day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
519
+ :returns: The Equation of Time correction EoT in minutes, where apparent Solar Time = Mean Solar Time + EoT
520
+ :rtype: np.ndarray
521
+
522
+ """
523
+
524
+ b = np.radians((np.float_(360) / 364) * (day_of_year - 81))
525
+
526
+ eot = 9.87 * np.sin(2 * b) - 7.83 * np.cos(b) - 1.5 * np.sin(b)
527
+
528
+ return eot
529
+
530
+
531
+ def get_day_of_year_map(date):
532
+ """
533
+
534
+ Extracts day, month, year, from datetime object
535
+
536
+ :param datetime.date date: date to be decomposed
537
+
538
+ """
539
+ return get_day_of_year(date.day, date.month, date.year)
540
+
541
+
542
+ def get_day_of_year(day, month, year):
543
+ """
544
+
545
+ Calculates the day of the year, given the day, month and year.
546
+ Day refers to a number representing the nth day of the year. So, Jan 1st will be the 1st day of the year
547
+
548
+ :param int day: nth day of the year
549
+ :param int month: month
550
+ :param int year: year
551
+ :returns: day of year
552
+ :rtype: int
553
+
554
+ """
555
+
556
+ return (datetime.date(year, month, day) - datetime.date(year, 1, 1)).days + 1
557
+
558
+
559
+ @jit(nopython=True)
560
+ def calculate_declination_angle(day_of_year):
561
+ """
562
+
563
+ Calculates the Declination Angle of the Earth at a given day
564
+ https://www.pveducation.org/pvcdrom/properties-of-sunlight/declination-angle
565
+
566
+ :param np.ndarray day_of_year: The number of the day of the current year, with January 1 being the first day of the year.
567
+ :returns: The declination angle of the Earth relative to the Sun, in degrees
568
+ :rtype: np.ndarray
569
+
570
+ """
571
+
572
+ declination_angle = -23.45 * np.cos(np.radians((np.float_(360) / 365) *
573
+ (day_of_year + 10)))
574
+
575
+ return declination_angle
576
+
577
+
578
+ @jit(nopython=True)
579
+ def compute_elevation_angle_math(declination_angle, hour_angle, latitude):
580
+ """
581
+
582
+ Gets the two terms to calculate and return elevation angle, given the
583
+ declination angle, hour angle, and latitude.
584
+
585
+ This method separates the math part of the calculation from its caller
586
+ method to optimize for numba compilation.
587
+
588
+ :param np.ndarray latitude: array of latitudes
589
+ :param np.ndarray declination_angle: The declination angle of the Earth relative to the Sun
590
+ :param np.ndarray hour_angle: The hour angle of the sun in the sky
591
+ :returns: The elevation angle in degrees
592
+ :rtype: np.ndarray
593
+
594
+ """
595
+
596
+ term_1 = np.sin(np.radians(declination_angle)) * np.sin(np.radians(latitude))
597
+ term_2 = np.cos(np.radians(declination_angle)) * np.cos(np.radians(latitude)) * np.cos(np.radians(hour_angle))
598
+ elevation_angle = np.arcsin(term_1 + term_2)
599
+
600
+ return np.degrees(elevation_angle)
601
+