Add decomposition model to Modelchain suite
Is your feature request related to a problem? Please describe. Modelchain does not include the decomposition step, forcing it to be done outside/before the modelchain.
Describe the solution you'd like
Modelchain could allow decomposition as an optional parameter. By default it could be None, keeping the current demand for users to include dhi and dni in the weather data. But if not None only ghi would be asked.
Additional context
I understand that having it as optional allows users to implement their own custom decomposition if they want. Similar to the run_model_from_poa option for users to ingest their own modelled or measured poa data.
I'd like to work on this. Here's the approach I have in mind, to check before opening a PR.
A decomposition_model string keyword on ModelChain, like transposition_model, with default None:
mc = ModelChain(system, location, decomposition_model='erbs')
mc.run_model(weather) # weather only needs 'ghi'
In prepare_inputs, right after the solar position step, if the weather has ghi but neither dni nor dhi, it calls model(ghi, solar_position['zenith'], times) and adds dni and dhi to results.weather. With None, nothing changes.
https://github.com/pvlib/pvlib-python/blob/c5de586d73bbb8875a4e87468894e7b34871a575/pvlib/modelchain.py#L1386-L1389
I tried it locally. It's about 30 lines in modelchain.py. With GHI-only weather, run_model gives the same AC output as running erbs by hand and passing all three columns. Per-array weather tuples work too.
Questions:
- Start with
erbs,erbs_driesse,boland,loucheandorgill_hollands? They return both DNI and DHI.discanddirintonly return DNI (#2865). - Strings only, with no model kwargs for now? Or should it also accept a function, like
aoi_model? - If the weather already has
dnianddhi, I use them as given. If only one is there, I kept the current error. Is that right? - Should this use
get_irradiance_componentsfrom #2850 instead of its own lookup?
It touches the same part of prepare_inputs as #2847, so I can wait for that and rebase.
AI disclosure: I used Claude Code (an AI coding agent) to read the code and prototype this approach.
@aarmens702-hub please do not open a PR. This idea needs to be discussed and agreed upon before going forward.