8000 Create iam.py, consistent naming for IAM functions by cwhanse · Pull Request #783 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Create iam.py, consistent naming for IAM functions #783

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

Merged
merged 35 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
73f4638
move iam functions to iam.py
cwhanse Oct 2, 2019
a89cc01
move function tests to test_iam.py
cwhanse Oct 2, 2019
0f1c90c
adjust PVSystem methods, add deprecation for functions and PVSystem m…
cwhanse Oct 2, 2019
0a55b54
adjust PVSystem tests, test for function deprecation
cwhanse Oct 2, 2019
8505a0d
move sapm aoi function, adjust ModelChain methods
cwhanse Oct 2, 2019
f48742c
remove _ typo
cwhanse Oct 2, 2019
1bcde31
lint fixes
cwhanse Oct 2, 2019
c51bc08
move fixture to correct place
cwhanse Oct 2, 2019
5e01712
move sapm_module_params fixture to conftest.py
cwhanse Oct 2, 2019
e5bebe1
fix cut/paste errors
8000 cwhanse Oct 3, 2019
549fc2c
add missing keys to fixture, add missing text to pvsystem.sapm docstring
cwhanse Oct 3, 2019
42210e4
fix and update pvsystem.sapm tests
cwhanse Oct 3, 2019
1475db6
remove DataFrame test for sapm, lint fixes
cwhanse Oct 3, 2019
006768d
implement PVSystem.get_iam, add deprecation test for pvsystem.sapm_ao…
cwhanse Oct 3, 2019
c10af4c
lint
cwhanse Oct 3, 2019
b9e39ac
Merge branch 'master' into iam
cwhanse Oct 3, 2019
ab1fbbc
test fixes, add Material to sapm_module_params fixture
cwhanse Oct 3, 2019
4dadd4b
test fixes
cwhanse Oct 4, 2019
7f14c95
add martin_ruiz to modelchain
cwhanse Oct 4, 2019
9164592
finish adding martin_ruiz to modelchain
cwhanse Oct 4, 2019
2fe7396
add test for ModelChain.infer_aoi_model, improve coverage
cwhanse Oct 4, 2019
3d6bcf5
repair delete mistake
cwhanse Oct 4, 2019
64a6b3c
test for invalid aoi model parameters in ModelChain
cwhanse Oct 4, 2019
152ef7a
update api, whatsnew
cwhanse Oct 4, 2019
46db9d7
test fix
cwhanse Oct 4, 2019
ea6fe81
fixture for aoi_model tests
cwhanse Oct 4, 2019
2529351
bad indent
cwhanse Oct 4, 2019
f641cd0
docstring and lint
cwhanse Oct 4, 2019
f331949
lint
cwhanse Oct 4, 2019
ec723c6
module docstring, changes to tests
cwhanse Oct 15, 2019
cf998ea
test fixes
cwhanse Oct 15, 2019
23f2677
another test fix
cwhanse Oct 16, 2019
1e63f04
improve coverage
cwhanse Oct 16, 2019
5fb7cc8
fix exception test
cwhanse Oct 16, 2019
b43b28c
fix the fix
cwhanse Oct 16, 2019
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
add test for ModelChain.infer_aoi_model, improve coverage
  • Loading branch information
cwhanse committed Oct 4, 2019
commit 2fe7396a458dada43afa297275eb94ec2236d2be
10 changes: 5 additions & 5 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ class ModelChain(object):
aoi_model: None, str, or function, default None
If None, the model will be inferred from the contents of
system.module_parameters. Valid strings are 'physical',
'ashrae', 'sapm', 'no_loss'. The ModelChain instance will be
passed as the first argument to a user-defined function.
'ashrae', 'sapm', 'martin_ruiz', 'no_loss'. The ModelChain instance
will be passed as the first argument to a user-defined function.

spectral_model: None, str, or function, default None
If None, the model will be inferred from the contents of
Expand Down Expand Up @@ -563,9 +563,9 @@ def infer_aoi_model(self):
raise ValueError('could not infer AOI model from '
'system.module_parameters. Check that the '
'system.module_parameters contain parameters for '
'the physical, aoi, or ashrae model; explicitly '
'set model with aoi_model kwarg; or set '
'aoi_model="no_loss".')
'the physical, aoi, ashrae or martin_ruiz model; '
'explicitly set the model with the aoi_model '
'kwarg; or set aoi_model="no_loss".')

def ashrae_aoi_loss(self):
self.aoi_modifier = self.system.get_iam(self.aoi, iam_model='ashrae')
Expand Down
29 changes: 25 additions & 4 deletions pvlib/test/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pandas as pd

from pvlib import modelchain, pvsystem, temperature
from pvlib import iam, modelchain, pvsystem, temperature
from pvlib.modelchain import ModelChain
from pvlib.pvsystem import PVSystem
from pvlib.tracking import SingleAxisTracker
Expand All @@ -16,7 +16,7 @@
from conftest import fail_on_pvlib_version, requires_scipy, requires_tables


@pytest.fixture
@pytest.fixture(scope='function')
def system(sapm_module_params, cec_inverter_parameters,
sapm_temperature_cs5p_220m):
module = 'Canadian_Solar_CS5P_220M___2009_'
Expand Down Expand Up @@ -442,8 +442,29 @@ def test_aoi_model_user_func(system, location, weather, mocker):
assert mc.ac[1] < 1


def constant_spectral_loss(mc):
mc.spectral_modifier = 0.9
@pytest.mark.parametrize('aoi_model', [
'sapm', 'ashrae', 'physical', 'martin_ruiz'
])
def test_infer_aoi_model(location, pvwatts_dc_pvwatts_ac_system, aoi_model):
# use pvwatts/pvwatts fixture because it has no AOI model parameters
temp = pvwatts_dc_pvwatts_ac_system.copy()
for k in iam.IAM_MODEL_PARAMS[aoi_model]:
temp.module_parameters.update({k: 1.0})
mc = ModelChain(system, location,
orientation_strategy='None',
spectral_model='no_loss')
assert isinstance(mc, ModelChain)
# remove added parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new system_no_aoi object should be generated for each aoi_model test, so this should not be necessary.

for k in iam.IAM_MODEL_PARAMS[aoi_model]:
system.module_parameters.pop(k)


@requires_scipy
def test_infer_temp_model_invalid(location, system):
system.temperature_model_parameters.pop('a')
with pytest.raises(ValueError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ModelChain initialization is complicated enough that we should probably be more careful in this test by adding a check for the right text in the message. Something like:

with pytest.raises(ValueError) as excinfo:
    ModelChain...
assert 'could not infer AOI model' in str(excinfo.value)  

ModelChain(system, location, orientation_strategy='None',
aoi_model='physical', spectral_model='no_loss')


@requires_scipy
Expand Down
36 changes: 35 additions & 1 deletion pvlib/test/test_pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ def test_PVSystem_get_iam_sapm(sapm_module_params, mocker):
assert_allclose(out, 1.0, atol=0.01)


def test_PVSystem_get_iam_interp(sapm_module_params, mocker):
system = pvsystem.PVSystem(module_parameters=sapm_module_params)
with pytest.raises(ValueError):
system.get_iam(45, iam_model='interp')


def test_PVSystem_get_iam_invalid(sapm_module_params, mocker):
system = pvsystem.PVSystem(module_parameters=sapm_module_params)
with pytest.raises(ValueError):
system.get_iam(45, iam_model='not_a_model')


def test_retrieve_sam_raise_no_parameters():
"""
Raise an exception if no parameters are provided to `retrieve_sam()`.
Expand Down Expand Up @@ -1454,14 +1466,36 @@ def test_deprecated_08():
with pytest.warns(pvlibDeprecationWarning):
pvsystem.pvsyst_celltemp(1000, 25)
module_parameters = {'R_sh_ref': 1, 'a_ref': 1, 'I_o_ref': 1,
'alpha_sc': 1, 'I_L_ref': 1, 'R_s': 1}
'alpha_sc': 1, 'I_L_ref': 1, 'R_s': 1,
'B5': 0.0, 'B4': 0.0, 'B3': 0.0, 'B2': 0.0,
'B1': 0.0, 'B0': 1.0,
'b': 0.05, 'K': 4, 'L': 0.002, 'n': 1.526,
'a_r': 0.16}
temp_model_params = temperature.TEMPERATURE_MODEL_PARAMETERS['sapm'][
'open_rack_glass_glass']
# for missing temperature_model_parameters
with pytest.warns(pvlibDeprecationWarning):
pvsystem.PVSystem(module_parameters=module_parameters,
racking_model='open', module_type='glass_glass')
pv = pvsystem.PVSystem(module_parameters=module_parameters,
temperature_model_parameters=temp_model_params,
racking_model='open', module_type='glass_glass')
# deprecated method PVSystem.ashraeiam
with pytest.warns(pvlibDeprecationWarning):
pv.ashraeiam(45)
# deprecated function ashraeiam
with pytest.warns(pvlibDeprecationWarning):
pvsystem.ashraeiam(45)
# deprecated method PVSystem.physicaliam
with pytest.warns(pvlibDeprecationWarning):
pv.physicaliam(45)
# deprecated function physicaliam
with pytest.warns(pvlibDeprecationWarning):
pvsystem.physicaliam(45)
# deprecated method PVSystem.sapm_aoi_loss
with pytest.warns(pvlibDeprecationWarning):
pv.sapm_aoi_loss(45)
# deprecated function sapm_aoi_loss
with pytest.warns(pvlibDeprecationWarning):
pvsystem.sapm_aoi_loss(45, {'B5': 0.0, 'B4': 0.0, 'B3': 0.0, 'B2': 0.0,
'B1': 0.0, 'B0': 1.0})
Expand Down
0