I am currently working on calculating the total irradiance falling on walls of different orientations (North,South,East,West) in Toronto. For this I have a weather data file that consists of DHI, DNI and GHI data. I prefer using the Perez model to calculate the total irradiance data on these walls. In my weather file that has hourly values of DHI, DNI and GHI during certain hours of the year both DHI and DNI are zero. Because of this my code generates a Division by Zero error…. How can I overcome this?
This happens when I try to calculate the Epsilon parameter (“Ski clearness Bins”) equation provided below. Can you all please assist?
Also I directly tried using pvlib function in python to calculate total radiance on a plane using the perez model and I get severe errors such as discontinuities and unrealistic values…. (I shall attach the code and the picture of the results)
Unrealistic radiation data (units W/m2)
Discontinuity in Data Generation
import pandas as pd
import pvlib
from pvlib.location import Location
from pvlib.irradiance import get_total_irradiance
from datetime import datetime, timedelta
# The location (Toronto)
latitude = 43.7
longitude = -79.4
location = Location(latitude, longitude, 'America/Toronto')
# time range - a whole year
start_date = '2023-01-01 00:00:00'
end_date = '2023-12-31 23:59:59'
timestamps = pd.date_range(start=start_date, end=end_date, freq='H', tz='America/Toronto')
# Read the weather data from the CSV file
weather_data = pd.read_csv('WeatherfileML_tor_1.0.csv')
# Check if the number of rows matches the expected number of hours in a year
assert len(weather_data) == 8760, "The data does not contain 8760 rows, which is required for a full year's hourly data."
# Assign the timestamps to the DataFrame
weather_data.index = timestamps
# Extract the GHI, DNI, and DHI columns
ghi = weather_data['GHI']
dni = weather_data['DNI']
dhi = weather_data['DHI']
# Get extraterrestrial radiation
dni_extra = pvlib.irradiance.get_extra_radiation(weather_data.index)
# Get solar position
solar_position = location.get_solarposition(weather_data.index)
# Define surface tilt and azimuth
surface_tilt = 90
surface_azimuth = 0
# Calculate total irradiance using the Perez model
total_irradiance = get_total_irradiance(
surface_tilt=surface_tilt,
surface_azimuth=surface_azimuth,
solar_zenith=solar_position['zenith'],
solar_azimuth=solar_position['azimuth'],
dni=dni,
ghi=ghi,
dhi=dhi,
dni_extra=dni_extra,
model='perez'
)
# Create a DataFrame to store the results
results = pd.DataFrame(index=weather_data.index)
results['poa_global'] = total_irradiance['poa_global']
# Print the first few results
print(results.head())
results.to_csv('solar_radiation_toronto_2023.csv')
I tried running the code, but the error tends to be there. I searched journals and online sites to rectify the error but no solution was found.
Aynkaran Aymmugan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.