pvlib / pvlib-python

A set of documented functions for simulating the performance of photovoltaic energy systems.
https://pvlib-python.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.16k stars 976 forks source link

Inferring spectral model returns 'first_solar' when not expected #2017

Open cwhanse opened 4 months ago

cwhanse commented 4 months ago

A user reports running a model chain with no spectral model specified and with CEC module parameters. The logic for ModelChain.infer_spectral_model returns first_solar_spectral_loss, which expects 'precipitable_water' to be in the weather input, at which point the user's simulation fails.

To Reproduce Code posted by user to reproduce the error.

import pandas as pd
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)

modelchain.run_model(clearsky)

Expected behavior While the CEC database has enough information (cell technology) to select parameters for the First Solar spectral model, doing so creates an expectation that the user has the inputs for that model. We can't check weather data at the time that ModelChain.spectral_model is set. I am inclined to think that the elif here should go away.

Screenshots If applicable, add screenshots to help explain your problem.

Versions:

mikofski commented 4 months ago

Also reported in stack overflow: https://stackoverflow.com/questions/78382877/keyerror-while-plotting-with-pvlib