import pvlib
import pandas as pd
import numpy as np
# Define PV Types and Locations
pv_types = {
'Amorphous Silicon': {'Efficiency': 0.0990, 'NOCT': 45.0},
'Monocrystalline Silicon': {'Efficiency': 0.2010, 'NOCT': 42.0},
'Polycrystalline Silicon': {'Efficiency': 0.1700, 'NOCT': 44.0},
'Other Thin Films': {'Efficiency': 0.2285, 'NOCT': 44.0},
'Thin Film Cadmium-Telluride': {'Efficiency': 0.1200, 'NOCT': 42.8},
'Thin Film Copper-Indium-Gallium-Selenide': {'Efficiency': 0.1300, 'NOCT': 42.8}
}
# Load EPW file for local weather data
epw_file_path = 'IRL_Dublin.039690_IWEC.epw' # Adjust the filename as needed
weather_data, metadata = pvlib.iotools.read_epw(epw_file_path, coerce_year=2023)
# Extract necessary data
times = weather_data.index
ghi = weather_data['ghi']
dni = weather_data['dni']
dhi = weather_data['dhi']
dni_extra = pvlib.irradiance.get_extra_radiation(times) # Calculate dni_extra
latitude, longitude, tz = metadata['latitude'], metadata['longitude'], metadata['TZ']
# User inputs for PV type and output type
print("Select the PV type:")
for idx, pv_type in enumerate(pv_types, 1):
print(f"{idx}. {pv_type}")
pv_type_index = int(input("Enter the number corresponding to the PV type: ")) - 1
pv_type_name = list(pv_types.keys())[pv_type_index]
pv_type = pv_types[pv_type_name]
output_type = input("Enter 'timeseries', 'total', or 'monthly': ").strip().lower()
# Simulation settings
powers = range(5, 125, 5)
inclinations = range(0, 35, 5)
orientations = [0,180, 225, 135] # South, South-West, South-East
# Prepare data collection
all_data = {'Datetime': times}
column_names = []
# Perform the simulation
location = pvlib.location.Location(latitude, longitude, tz)
solpos = location.get_solarposition(times)
for power in powers:
for inclination in inclinations:
for orientation in orientations:
poa_irradiance = pvlib.irradiance.get_total_irradiance(
surface_tilt=inclination,
surface_azimuth=orientation,
solar_zenith=solpos['apparent_zenith'],
solar_azimuth=solpos['azimuth'],
dni=dni, ghi=ghi, dhi=dhi, dni_extra=dni_extra, # Include dni_extra here
model='perez' # Using Perez model for better accuracy
)
system_output = power * pv_type['Efficiency'] * poa_irradiance['poa_global']
col_name = f'{power}_{inclination}_{orientation}_{pv_type_name}'
column_names.append(col_name)
all_data[col_name] = system_output
# Convert dictionary to DataFrame
results = pd.DataFrame(all_data)
results.set_index('Datetime', inplace=True)
# Handle output based on user choice
if output_type == 'timeseries':
results.to_csv('solar_simulation_time_series_results.csv')
elif output_type == 'total':
total_generation = results.sum().to_frame(name='Total Generation')
total_generation.to_csv('solar_simulation_total_generation_results.csv')
elif output_type == 'monthly':
monthly_totals = results.resample('M').sum()
monthly_totals.to_csv('solar_simulation_monthly_totals.csv')
print(f"Simulation completed and results are saved according to selected output type: {output_type}.")
weather file from Energy Plus