-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add consistency tests to ModelChain.dc_model #548
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
Changes from 11 commits
d3c1ae3
6884555
1c4ac04
a04e111
3e1116b
1fa1be3
121a8b1
10a5f7d
c0f58c3
ae3d572
e11d1c5
743c621
669d4bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| from pvlib import (solarposition, pvsystem, clearsky, atmosphere, tools) | ||
| from pvlib.tracking import SingleAxisTracker | ||
| import pvlib.irradiance # avoid name conflict with full import | ||
| from pvlib.pvsystem import DC_MODEL_PARAMS | ||
|
|
||
|
|
||
| def basic_chain(times, latitude, longitude, | ||
|
|
@@ -360,29 +361,44 @@ def dc_model(self): | |
|
|
||
| @dc_model.setter | ||
| def dc_model(self, model): | ||
| # guess at model if None | ||
| if model is None: | ||
| self._dc_model = self.infer_dc_model() | ||
| elif isinstance(model, str): | ||
| self._dc_model, model = self.infer_dc_model() | ||
|
|
||
| # Set model and validate parameters | ||
| if isinstance(model, str): | ||
| model = model.lower() | ||
| if model == 'sapm': | ||
| self._dc_model = self.sapm | ||
| elif model == 'singlediode': | ||
| self._dc_model = self.singlediode | ||
| elif model == 'pvwatts': | ||
| self._dc_model = self.pvwatts_dc | ||
| if model in DC_MODEL_PARAMS.keys(): | ||
| # validate module parameters | ||
| missing_params = DC_MODEL_PARAMS[model] - \ | ||
| set(self.system.module_parameters.keys()) | ||
| if missing_params: # some parameters are not in module.keys() | ||
| raise ValueError(model + ' selected for the DC model but ' | ||
| 'one or more required parameters ' | ||
| ' are missing : ' + | ||
|
||
| str(missing_params)) | ||
| if model == 'sapm': | ||
| self._dc_model = self.sapm | ||
| elif model == 'singlediode': | ||
| self._dc_model = self.singlediode | ||
| elif model == 'pvwatts': | ||
| self._dc_model = self.pvwatts_dc | ||
| else: | ||
| raise ValueError(model + ' is not a valid DC power model') | ||
| else: | ||
| self._dc_model = partial(model, self) | ||
|
|
||
| def infer_dc_model(self): | ||
| # returns both model function object and model string, could drop | ||
| # model function object in the future since the model function object | ||
| # will be set in dc_model after validating parameter consistency | ||
| params = set(self.system.module_parameters.keys()) | ||
| if set(['A0', 'A1', 'C7']) <= params: | ||
| return self.sapm | ||
| return self.sapm, 'sapm' | ||
| elif set(['a_ref', 'I_L_ref', 'I_o_ref', 'R_sh_ref', 'R_s']) <= params: | ||
| return self.singlediode | ||
| return self.singlediode, 'singlediode' | ||
| elif set(['pdc0', 'gamma_pdc']) <= params: | ||
| return self.pvwatts_dc | ||
| return self.pvwatts_dc, 'pvwatts' | ||
| else: | ||
| raise ValueError('could not infer DC model from ' | ||
| 'system.module_parameters') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,14 +21,18 @@ | |
| from test_pvsystem import sam_data | ||
| from conftest import requires_scipy | ||
|
|
||
| import copy | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def system(sam_data): | ||
| modules = sam_data['sandiamod'] | ||
| module_parameters = modules['Canadian_Solar_CS5P_220M___2009_'].copy() | ||
| module = 'Canadian_Solar_CS5P_220M___2009_' | ||
| module_parameters = modules[module].copy() | ||
| inverters = sam_data['cecinverter'] | ||
| inverter = inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'].copy() | ||
| system = PVSystem(surface_tilt=32.2, surface_azimuth=180, | ||
| module=module, | ||
| module_parameters=module_parameters, | ||
| inverter_parameters=inverter) | ||
| return system | ||
|
|
@@ -37,13 +41,15 @@ def system(sam_data): | |
| @pytest.fixture | ||
| def cec_dc_snl_ac_system(sam_data): | ||
| modules = sam_data['cecmod'] | ||
| module_parameters = modules['Canadian_Solar_CS5P_220M'].copy() | ||
| module = 'Canadian_Solar_CS5P_220M' | ||
| module_parameters = modules[module].copy() | ||
| module_parameters['b'] = 0.05 | ||
| module_parameters['EgRef'] = 1.121 | ||
| module_parameters['dEgdT'] = -0.0002677 | ||
| inverters = sam_data['cecinverter'] | ||
| inverter = inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'].copy() | ||
| system = PVSystem(surface_tilt=32.2, surface_azimuth=180, | ||
| module=module, | ||
| module_parameters=module_parameters, | ||
| inverter_parameters=inverter) | ||
| return system | ||
|
|
@@ -52,13 +58,15 @@ def cec_dc_snl_ac_system(sam_data): | |
| @pytest.fixture | ||
| def cec_dc_adr_ac_system(sam_data): | ||
| modules = sam_data['cecmod'] | ||
| module_parameters = modules['Canadian_Solar_CS5P_220M'].copy() | ||
| module = 'Canadian_Solar_CS5P_220M' | ||
| module_parameters = modules[module].copy() | ||
| module_parameters['b'] = 0.05 | ||
| module_parameters['EgRef'] = 1.121 | ||
| module_parameters['dEgdT'] = -0.0002677 | ||
| inverters = sam_data['adrinverter'] | ||
| inverter = inverters['Zigor__Sunzet_3_TL_US_240V__CEC_2011_'].copy() | ||
| system = PVSystem(surface_tilt=32.2, surface_azimuth=180, | ||
| module=module, | ||
| module_parameters=module_parameters, | ||
| inverter_parameters=inverter) | ||
| return system | ||
|
|
@@ -365,6 +373,30 @@ def test_losses_models_no_loss(pvwatts_dc_pvwatts_ac_system, location, weather, | |
| assert mc.losses == 1 | ||
|
|
||
|
|
||
| def test_invalid_dc_model_params(system, cec_dc_snl_ac_system, | ||
cwhanse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pvwatts_dc_pvwatts_ac_system, location): | ||
| kwargs = {'dc_model': 'sapm', 'ac_model': 'snlinverter', | ||
| 'aoi_model': 'no_loss', 'spectral_model': 'no_loss', | ||
| 'temp_model': 'sapm', 'losses_model': 'no_loss'} | ||
| tmp = copy.deepcopy(system) | ||
|
||
| tmp.module_parameters.pop('A0') # remove a parameter | ||
| with pytest.raises(ValueError): | ||
| mc = ModelChain(tmp, location, **kwargs) | ||
|
|
||
| kwargs['dc_model'] = 'singlediode' | ||
| tmp = copy.deepcopy(cec_dc_snl_ac_system) | ||
| tmp.module_parameters.pop('a_ref') # remove a parameter | ||
| with pytest.raises(ValueError): | ||
| mc = ModelChain(tmp, location, **kwargs) | ||
|
|
||
| kwargs['dc_model'] = 'pvwatts' | ||
| kwargs['ac_model'] = 'pvwatts' | ||
| tmp = copy.deepcopy(pvwatts_dc_pvwatts_ac_system) | ||
| tmp.module_parameters.pop('pdc0') | ||
| with pytest.raises(ValueError): | ||
| mc = ModelChain(tmp, location, **kwargs) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('model', [ | ||
| 'dc_model', 'ac_model', 'aoi_model', 'spectral_model', 'losses_model', | ||
| 'temp_model', 'losses_model' | ||
|
|
@@ -376,7 +408,7 @@ def test_invalid_models(model, system, location): | |
| kwargs[model] = 'invalid' | ||
| with pytest.raises(ValueError): | ||
| mc = ModelChain(system, location, **kwargs) | ||
|
|
||
|
||
|
|
||
| def test_bad_get_orientation(): | ||
| with pytest.raises(ValueError): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.