Created
June 19, 2023 21:52
-
-
Save ValentinMouret/382f4be4fc26943414d76bce42898e86 to your computer and use it in GitHub Desktop.
Program which plots the solar flux given some parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import matplotlib.pyplot as plt | |
def calculate_solar_flux(latitude, longitude, panel_orientation, panel_tilt, hour, day_of_year): | |
# Convertit tous les angles en radians | |
latitude = math.radians(latitude) | |
panel_orientation = math.radians(panel_orientation) | |
panel_tilt = math.radians(panel_tilt) | |
declination = math.radians(23.45 * math.sin(2 * math.pi * (day_of_year - 81) / 365.0)) | |
hour_angle = math.radians(15 * (12 - hour)) | |
# Calcul de l'angle d'incidence | |
cos_incidence_angle = (math.sin(declination) * math.sin(latitude) * math.cos(panel_tilt) | |
- math.sin(declination) * math.cos(latitude) * math.sin(panel_tilt) * math.cos(panel_orientation) | |
+ math.cos(declination) * math.cos(latitude) * math.cos(panel_tilt) * math.cos(hour_angle) | |
+ math.cos(declination) * math.sin(latitude) * math.sin(panel_tilt) * math.cos(panel_orientation) * math.cos(hour_angle) | |
+ math.cos(declination) * math.sin(panel_tilt) * math.sin(panel_orientation) * math.sin(hour_angle)) | |
# Calcul du flux solaire | |
solar_flux = 1000 * cos_incidence_angle # 1000 W/m^2 est le flux solaire à midi par ciel clair | |
# On ne peut pas avoir de flux solaire négatif, donc si le cosinus de l'angle d'incidence est négatif, on met le flux solaire à zéro | |
solar_flux = max(0, solar_flux) | |
return solar_flux | |
def calculate_solar_flux_2(latitude, longitude, panel_orientation, panel_tilt, hour, day_of_year): | |
# Convertit tous les angles en radians | |
latitude = math.radians(latitude) | |
panel_orientation = math.radians(panel_orientation) | |
panel_tilt = math.radians(panel_tilt) | |
declination = math.radians(23.45 * math.sin(2 * math.pi * (day_of_year - 81) / 365.0)) | |
# Correction de l'heure pour obtenir l'heure solaire vraie | |
timezone_longitude = round(longitude / 15) * 15 # Approximation : chaque fuseau horaire s'étend sur 15 degrés de longitude | |
equation_of_time = -7.655 * math.sin(2 * math.pi * (day_of_year - 8) / 365.0) + 9.873 * math.sin(4 * math.pi * (day_of_year - 8) / 365.0) | |
solar_time = hour + (timezone_longitude - longitude) / 15 + equation_of_time / 60 | |
# Calcul de l'angle horaire | |
hour_angle = math.radians(15 * (12 - solar_time)) | |
# Calcul de l'angle d'incidence | |
cos_incidence_angle = (math.sin(declination) * math.sin(latitude) * math.cos(panel_tilt) | |
- math.sin(declination) * math.cos(latitude) * math.sin(panel_tilt) * math.cos(panel_orientation) | |
+ math.cos(declination) * math.cos(latitude) * math.cos(panel_tilt) * math.cos(hour_angle) | |
+ math.cos(declination) * math.sin(latitude) * math.sin(panel_tilt) * math.cos(panel_orientation) * math.cos(hour_angle) | |
+ math.cos(declination) * math.sin(panel_tilt) * math.sin(panel_orientation) * math.sin(hour_angle)) | |
# Calcul du flux solaire | |
solar_flux = 1000 * cos_incidence_angle # 1000 W/m^2 est le flux solaire à midi par ciel clair | |
# On ne peut pas avoir de flux solaire négatif, donc si le cosinus de l'angle d'incidence est négatif, on met le flux solaire à zéro | |
solar_flux = max(0, solar_flux) | |
return solar_flux | |
# Exemple d'utilisation | |
flux = calculate_solar_flux(48.8566, 2.3522, 0, 30, 12, 170) # Coordonnées de Paris, orientation sud, inclinaison 30°, midi, 170ème jour de l'année | |
# Exemple d'utilisation | |
flux = calculate_solar_flux(48.8566, 2.3522, 0, 30, 12, 170) # Coordonnées de Paris, orientation sud, inclinaison 30°, midi, 170ème jour de l'année | |
points = [ | |
(f"{day}_{hour}", calculate_solar_flux(48.8566, 2.3522, 0, 30, hour, day), calculate_solar_flux_2(48.8566, 2.3522, 0, 30, hour, day)) | |
for day in range(120, 300, 10) | |
for hour in range(6, 22) | |
] | |
days, flux_1, flux_2 = zip(*points) | |
plt.plot(days, flux_1) | |
plt.plot(days, flux_2) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment