|
3 | 3 | import numpy as np |
4 | 4 | import pandas as pd |
5 | 5 |
|
6 | | -from pvlib import iam, modelchain, pvsystem, temperature |
| 6 | +from pvlib import iam, modelchain, pvsystem, temperature, inverter |
7 | 7 | from pvlib.modelchain import ModelChain |
8 | 8 | from pvlib.pvsystem import PVSystem |
9 | 9 | from pvlib.tracking import SingleAxisTracker |
@@ -480,7 +480,7 @@ def test_ModelChain_invalid_inverter_params_arrays( |
480 | 480 | sapm_dc_snl_ac_system_same_arrays.inverter_parameters = \ |
481 | 481 | inverter_params[inverter] |
482 | 482 | with pytest.raises(ValueError, |
483 | | - match=r'Only sandia and pvwatts inverter models'): |
| 483 | + match=r'adr inverter function cannot'): |
484 | 484 | ModelChain(sapm_dc_snl_ac_system_same_arrays, location) |
485 | 485 |
|
486 | 486 |
|
@@ -1235,27 +1235,36 @@ def acdc(mc): |
1235 | 1235 | mc.results.ac = mc.results.dc |
1236 | 1236 |
|
1237 | 1237 |
|
1238 | | -@pytest.mark.parametrize('ac_model', ['sandia', 'adr', |
1239 | | - 'pvwatts', 'sandia_multi', |
1240 | | - 'pvwatts_multi']) |
| 1238 | +@pytest.mark.parametrize('inverter_model', ['sandia', 'adr', |
| 1239 | + 'pvwatts', 'sandia_multi', |
| 1240 | + 'pvwatts_multi']) |
1241 | 1241 | def test_ac_models(sapm_dc_snl_ac_system, cec_dc_adr_ac_system, |
1242 | | - pvwatts_dc_pvwatts_ac_system, location, ac_model, |
1243 | | - weather, mocker): |
| 1242 | + pvwatts_dc_pvwatts_ac_system, cec_dc_snl_ac_arrays, |
| 1243 | + pvwatts_dc_pvwatts_ac_system_arrays, |
| 1244 | + location, inverter_model, weather, mocker): |
1244 | 1245 | ac_systems = {'sandia': sapm_dc_snl_ac_system, |
1245 | | - 'sandia_multi': sapm_dc_snl_ac_system, |
| 1246 | + 'sandia_multi': cec_dc_snl_ac_arrays, |
1246 | 1247 | 'adr': cec_dc_adr_ac_system, |
1247 | 1248 | 'pvwatts': pvwatts_dc_pvwatts_ac_system, |
1248 | | - 'pvwatts_multi': pvwatts_dc_pvwatts_ac_system} |
1249 | | - ac_method_name = {'sandia': 'snlinverter', |
1250 | | - 'sandia_multi': 'sandia_multi', |
1251 | | - 'adr': 'adrinverter', |
1252 | | - 'pvwatts': 'pvwatts_ac', |
1253 | | - 'pvwatts_multi': 'pvwatts_multi'} |
1254 | | - system = ac_systems[ac_model] |
1255 | | - |
| 1249 | + 'pvwatts_multi': pvwatts_dc_pvwatts_ac_system_arrays} |
| 1250 | + inverter_to_ac_model = { |
| 1251 | + 'sandia': 'sandia', |
| 1252 | + 'sandia_multi': 'sandia', |
| 1253 | + 'adr': 'adr', |
| 1254 | + 'pvwatts': 'pvwatts', |
| 1255 | + 'pvwatts_multi': 'pvwatts'} |
| 1256 | + ac_model = inverter_to_ac_model[inverter_model] |
| 1257 | + system = ac_systems[inverter_model] |
| 1258 | + |
| 1259 | + mc_inferred = ModelChain(system, location, |
| 1260 | + aoi_model='no_loss', spectral_model='no_loss') |
1256 | 1261 | mc = ModelChain(system, location, ac_model=ac_model, |
1257 | 1262 | aoi_model='no_loss', spectral_model='no_loss') |
1258 | | - m = mocker.spy(system, ac_method_name[ac_model]) |
| 1263 | + |
| 1264 | + # tests ModelChain.infer_ac_model |
| 1265 | + assert mc_inferred.ac_model.__name__ == mc.ac_model.__name__ |
| 1266 | + |
| 1267 | + m = mocker.spy(inverter, inverter_model) |
1259 | 1268 | mc.run_model(weather) |
1260 | 1269 | assert m.call_count == 1 |
1261 | 1270 | assert isinstance(mc.results.ac, pd.Series) |
@@ -1447,7 +1456,7 @@ def test_losses_models_no_loss(pvwatts_dc_pvwatts_ac_system, location, weather, |
1447 | 1456 |
|
1448 | 1457 | def test_invalid_dc_model_params(sapm_dc_snl_ac_system, cec_dc_snl_ac_system, |
1449 | 1458 | pvwatts_dc_pvwatts_ac_system, location): |
1450 | | - kwargs = {'dc_model': 'sapm', 'ac_model': 'snlinverter', |
| 1459 | + kwargs = {'dc_model': 'sapm', 'ac_model': 'sandia', |
1451 | 1460 | 'aoi_model': 'no_loss', 'spectral_model': 'no_loss', |
1452 | 1461 | 'temperature_model': 'sapm', 'losses_model': 'no_loss'} |
1453 | 1462 | sapm_dc_snl_ac_system.module_parameters.pop('A0') # remove a parameter |
@@ -1488,9 +1497,9 @@ def test_bad_get_orientation(): |
1488 | 1497 | def test_with_sapm_pvsystem_arrays(sapm_dc_snl_ac_system_Array, location, |
1489 | 1498 | weather): |
1490 | 1499 | mc = ModelChain.with_sapm(sapm_dc_snl_ac_system_Array, location, |
1491 | | - ac_model='sandia_multi') |
| 1500 | + ac_model='sandia') |
1492 | 1501 | assert mc.dc_model == mc.sapm |
1493 | | - assert mc.ac_model == mc.sandia_multi_inverter |
| 1502 | + assert mc.ac_model == mc.sandia_inverter |
1494 | 1503 | mc.run_model(weather) |
1495 | 1504 | assert mc.results |
1496 | 1505 |
|
@@ -1625,7 +1634,7 @@ def test_ModelChain___repr__(sapm_dc_snl_ac_system, location, strategy, |
1625 | 1634 | ' solar_position_method: nrel_numpy', |
1626 | 1635 | ' airmass_model: kastenyoung1989', |
1627 | 1636 | ' dc_model: sapm', |
1628 | | - ' ac_model: snlinverter', |
| 1637 | + ' ac_model: sandia_inverter', |
1629 | 1638 | ' aoi_model: sapm_aoi_loss', |
1630 | 1639 | ' spectral_model: sapm_spectral_loss', |
1631 | 1640 | ' temperature_model: sapm_temp', |
@@ -1778,7 +1787,7 @@ def test_inconsistent_array_params(location, |
1778 | 1787 | ) |
1779 | 1788 | with pytest.raises(ValueError, match=temperature_error): |
1780 | 1789 | ModelChain(different_temp_system, location, |
1781 | | - ac_model='sandia_multi', |
| 1790 | + ac_model='sandia', |
1782 | 1791 | aoi_model='no_loss', spectral_model='no_loss', |
1783 | 1792 | temperature_model='sapm') |
1784 | 1793 |
|
|
0 commit comments