8000 [DRAFT] Allow arbitrary IAM function in pvlib.iam.marion_diffuse by markcampanelli · Pull Request #2050 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

[DRAFT] Allow arbitrary IAM function in pvlib.iam.marion_diffuse #2050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2a50a63
Add iam_pchip function and callable model for marion_diffuse
markcampanelli May 12, 2024
398a8ff
Tidy up
markcampanelli May 12, 2024
ed79db8
Appease flake8
markcampanelli May 12, 2024
d596e28
Pin flake8 to match github workflow
markcampanelli May 12, 2024
3e3f0d6
Tidy up more
markcampanelli May 12, 2024
f63a018
Improve test
markcampanelli May 12, 2024
bc519be
Only use pchip in tests
markcampanelli May 15, 2024
d97d077
flake8 ftw
markcampanelli May 15, 2024
c4c18d7
flake8 more ftw
markcampanelli May 15, 2024
8727b04
Remove unused lines in test
markcampanelli May 15, 2024
e726eed
Merge branch 'markcampanelli/main' into marion_diffuse_dep_inj
markcampanelli Jun 30, 2024
6322523
Update builtin models and models' parameters maps
markcampanelli Jun 30, 2024
fe7833b
Appease flake8
markcampanelli Jun 30, 2024
5d218d5
Appease flake8 more
markcampanelli Jun 30, 2024
bcc8429
Undo function moves
markcampanelli Jun 30, 2024
deb466e
Revert to better exception message
markcampanelli Jun 30, 2024
05319f3
Make iam_model required for ModelChain
markcampanelli Jul 1, 2024
dd8408f
Restore infer_aoi_model
markcampanelli Jul 1, 2024
1bd8f0d
Revert additional changes
markcampanelli Jul 1, 2024
0aff7c7
Address failing test and minimize diff
markcampanelli Jul 1, 2024
567374f
Get ModelChain codecov
markcampanelli Jul 1, 2024
e41621a
Add/improve test coverage
markcampanelli Jul 1, 2024
6a0d14d
Add docstring and cover bad model name
markcampanelli Jul 1, 2024
a580ec6
Appease flake8
markcampanelli Jul 1, 2024
2bb3fb6
Cover required params check
markcampanelli Jul 1, 2024
b6fe2bf
Minimize unrelated diff
markcampanelli Jul 1, 2024
2c0d11b
Test get_builtin_models
markcampanelli Jul 1, 2024
083c3c9
Improve comment
markcampanelli Jul 1, 2024
ce7577c
Remove spurious function
markcampanelli Jul 1, 2024
d49ee79
Merge branch 'main' into marion_diffuse_dep_inj
markcampanelli Dec 21, 2024
a037bae
Update modelchain docstrings
markcampanelli Dec 21, 2024
ec3790b
Make sapm iam function use common interface
markcampanelli Dec 21, 2024
0b4a91d
Appease flake8
markcampanelli Dec 21, 2024
c64e6b9
Harmonize IAM and spectral correction and update IAM inference
markcampanelli Dec 22, 2024
08ae199
Appease the linter
markcampanelli Dec 22, 2024
6e8421c
Fix spectral correction example
markcampanelli Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test get_builtin_models
  • Loading branch information
markcampanelli committed Jul 1, 2024
commit 2c0d11b4283cd1fce24bd86d92378a2d67eab743
30 changes: 16 additions & 14 deletions pvlib/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ def get_builtin_models():
info : dict
A dictionary of dictionaries keyed by builtin IAM model name, with
each model dictionary containing:
- callable : callable

* 'func': callable
The callable model function
- params_required : set of str
The callable's required parameters
- params_optional : set of str
The callable's optional parameters
* 'params_required': set of str
The model function's required parameters
* 'params_optional': set of str
The model function's optional parameters

See Also
--------
Expand All @@ -44,32 +45,33 @@ def get_builtin_models():
"""
return {
'ashrae': {
'callable': ashrae,
'func': ashrae,
'params_required': set(),
'params_optional': {'b'},
},
'interp': {
'callable': interp,
'func': interp,
'params_required': {'theta_ref', 'iam_ref'},
'params_optional': {'method', 'normalize'},
},
'martin_ruiz': {
'callable': martin_ruiz,
'func': martin_ruiz,
'params_required': set(),
'params_optional': {'a_r'},
},
'physical': {
'callable': physical,
'func': physical,
'params_required': set(),
'params_optional': {'n', 'K', 'L', 'n_ar'},
},
'sapm': {
'callable': sapm,
'func': sapm,
# param_required must appear in module parameter.
'params_required': {'B0', 'B1', 'B2', 'B3', 'B4', 'B5'},
'params_optional': {'upper'},
},
'schlick': {
'callable': schlick,
'func': schlick,
'params_required': set(),
'params_optional': set(),
},
Expand Down Expand Up @@ -687,7 +689,7 @@ def marion_diffuse(model, surface_tilt, **kwargs):
"""
if callable(model):
# A callable IAM model function was specified.
model_callable = model
func = model
else:
# Check that a builtin IAM function was specified.
builtin_models = get_builtin_models()
Expand All @@ -699,9 +701,9 @@ def marion_diffuse(model, surface_tilt, **kwargs):
f'model must be one of: {builtin_models.keys()}'
) from exc

model_callable = model["callable"]
func = model["func"]

iam_function = functools.partial(model_callable, **kwargs)
iam_function = functools.partial(func, **kwargs)

return {
region: marion_integrate(iam_function, surface_tilt, region)
Expand Down
4 changes: 2 additions & 2 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,15 +1184,15 @@ def get_iam(self, aoi, iam_model='physical'):

if model == "sapm":
# sapm has exceptional interface requiring module_parameters.
return model_info["callable"](
return model_info["func"](
aoi, self.module_parameters, **params_optional
)

params_required = _build_kwargs(
model_info["params_required"], self.module_parameters
)

return model_info["callable"](
return model_info["func"](
aoi, **params_required, **params_optional
)

Expand Down
52 changes: 52 additions & 0 deletions pvlib/tests/test_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: cwhanse
"""
import inspect

import numpy as np
import pandas as pd
Expand All @@ -15,6 +16,57 @@
from pvlib import iam as _iam


def test_get_builtin_models():
builtin_models = _iam.get_builtin_models()

models = set(builtin_models.keys())
models_expected = {
"ashrae", "interp", "martin_ruiz", "physical", "sapm", "schlick"
}
assert set(models) == models_expected

for model in models:
builtin_model = builtin_models[model]

if model == "sapm":
# sapm has exceptional interface requiring module_parameters.
params_required_expected = set(
k for k, v in inspect.signature(
builtin_model["func"]
).parameters.items() if v.default is inspect.Parameter.empty
)
assert {"aoi", "module"} == params_required_expected, model

assert builtin_model["params_required"] == \
{'B0', 'B1', 'B2', 'B3', 'B4', 'B5'}, model
else:
params_required_expected = set(
k for k, v in inspect.signature(
builtin_model["func"]
).parameters.items() if v.default is inspect.Parameter.empty
)
assert builtin_model["params_required"].union(
{"aoi"}
) == params_required_expected, model

params_optional_expected = set(
k for k, v in inspect.signature(
builtin_model["func"]
).parameters.items() if v.default is not inspect.Parameter.empty
)
assert builtin_model["params_optional"] == \
params_optional_expected, model


def get_default_args(func):
signature = inspect.signature(func)
return {

Check warning on line 63 in pvlib/tests/test_iam.py

View check run for this annotation

Codecov / codecov/patch

pvlib/tests/test_iam.py#L62-L63

Added lines #L62 - L63 were not covered by tests
k: v.default
for k, v in signature.parameters.items()
if v.default is not inspect.Parameter.empty
}


def test_ashrae():
thetas = np.array([-90., -67.5, -45., -22.5, 0., 22.5, 45., 67.5, 89., 90.,
np.nan])
Expand Down
Loading
0