pythonplotmodelpvlib

Keyerror while plotting with pvlib


I´m doing an school project with the pvlib library for a real PV installation, but when I tried to plot the modelchain for the AC generation I got the error as shown below in the code. I hope someone can help me with this. Thanks a lot.

import pvlib
from pvlib import clearsky, atmosphere, solarposition
from pvlib.modelchain import ModelChain
from pvlib.location import Location
from pvlib.pvsystem import PVSystem, Array, SingleAxisTrackerMount, AbstractMount, FixedMount
from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS

location = Location(latitude = 40.30117520975112, longitude = -3.6973221576701967, tz = "Europe/Madrid", altitude = 660, name = 'Ormazabal Getafe')
modules = pvlib.pvsystem.retrieve_sam('CECMod')
inverters = pvlib.pvsystem.retrieve_sam('CECInverter')
module = modules['JA_Solar_JAP72S01_330_SC'] 
inverter = inverters['SMA_America__STP_33_US_41__480V_'] 
temp_par = TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_glass']
system = PVSystem(surface_tilt = 19, surface_azimuth = 170, module_parameters = module, inverter_parameters = inverter,
                  temperature_model_parameters = temp_par, modules_per_string = 17, strings_per_inverter = 6) 
modelchain = ModelChain(system, location, aoi_model = 'physical')

times = pd.date_range(start = '2023-06-01', end = '2023-12-15', freq = 'h', tz = location.tz)
solar_position = location.get_solarposition(times)
clearsky = location.get_clearsky(times)
clearsky.plot(figsize = (20, 8))
plt.ylabel('Irradiance $W/m^2$')
plt.title('Irradiance in the location')
plt.show()

modelchain.run_model(clearsky)
modelchain.results.ac.plot(figsize = (20, 8))
plt.show()

----> 26 modelchain.run_model(clearsky)
KeyError: 'precipitable_water'


Solution

  • This happens because the 'spectral_model' is not set explicitly. To get past the error, either spectral_model='no_loss', spectral_model='sapm' (but you have to get coefficients from somewhere) or spectral_model='first_solar' (but you have to add 'precipitable_water' to your weather data).

    This behavior is unintended and should be addressed in pvlib. See https://github.com/pvlib/pvlib-python/issues/2017#issue-2263654247