diff --git a/pvlib/modelchain.py b/pvlib/modelchain.py index 885353a230..990598ae1e 100644 --- a/pvlib/modelchain.py +++ b/pvlib/modelchain.py @@ -1519,10 +1519,14 @@ def _prepare_temperature(self, data=None): if not isinstance(data, tuple): # broadcast data to all arrays data = (data,) * self.system.num_arrays + # data is tuple, so temperature_model_parameters must also be + # tuple. system.temperature_model_parameters is reduced to a dict + # if system.num_arrays == 1, so manually access parameters. GH 1192 + t_mod_params = tuple(array.temperature_model_parameters + for array in self.system.arrays) # find where cell or module temperature is specified in input data given_cell_temperature = tuple(itertools.starmap( - self._get_cell_temperature, - zip(data, poa, self.system.temperature_model_parameters) + self._get_cell_temperature, zip(data, poa, t_mod_params) )) # If cell temperature has been specified for all arrays return # immediately and do not try to compute it. diff --git a/pvlib/tests/test_modelchain.py b/pvlib/tests/test_modelchain.py index 7b96b409d7..d4cb14814e 100644 --- a/pvlib/tests/test_modelchain.py +++ b/pvlib/tests/test_modelchain.py @@ -830,6 +830,38 @@ def test__prepare_temperature(sapm_dc_snl_ac_system, location, weather, assert_series_equal(mc.results.cell_temperature, data['cell_temperature']) +def test__prepare_temperature_len1_weather_tuple( + sapm_dc_snl_ac_system, location, weather, total_irrad): + # GH 1192 + weather['module_temperature'] = [40., 30.] + data = weather.copy() + + mc = ModelChain(sapm_dc_snl_ac_system, location, aoi_model='no_loss', + spectral_model='no_loss') + mc.run_model([data]) + expected = pd.Series([42.617244212941394, 30.0], index=data.index) + assert_series_equal(mc.results.cell_temperature[0], expected) + + data = weather.copy().rename( + columns={ + "ghi": "poa_global", "dhi": "poa_diffuse", "dni": "poa_direct"} + ) + mc = ModelChain(sapm_dc_snl_ac_system, location, aoi_model='no_loss', + spectral_model='no_loss') + mc.run_model_from_poa([data]) + expected = pd.Series([41.5, 30.0], index=data.index) + assert_series_equal(mc.results.cell_temperature[0], expected) + + data = weather.copy()[["module_temperature", "ghi"]].rename( + columns={"ghi": "effective_irradiance"} + ) + mc = ModelChain(sapm_dc_snl_ac_system, location, aoi_model='no_loss', + spectral_model='no_loss') + mc.run_model_from_effective_irradiance([data]) + expected = pd.Series([41.5, 30.0], index=data.index) + assert_series_equal(mc.results.cell_temperature[0], expected) + + def test__prepare_temperature_arrays_weather(sapm_dc_snl_ac_system_same_arrays, location, weather, total_irrad):