Skip to content

Commit c17f728

Browse files
authored
fix modelchain with module temperature and arrays (#1193)
* fix modelchain with module temperature and arrays * refactor to directly build from arrays * add test * improve test * fix test
1 parent 684b247 commit c17f728

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

pvlib/modelchain.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,10 +1519,14 @@ def _prepare_temperature(self, data=None):
15191519
if not isinstance(data, tuple):
15201520
# broadcast data to all arrays
15211521
data = (data,) * self.system.num_arrays
1522+
# data is tuple, so temperature_model_parameters must also be
1523+
# tuple. system.temperature_model_parameters is reduced to a dict
1524+
# if system.num_arrays == 1, so manually access parameters. GH 1192
1525+
t_mod_params = tuple(array.temperature_model_parameters
1526+
for array in self.system.arrays)
15221527
# find where cell or module temperature is specified in input data
15231528
given_cell_temperature = tuple(itertools.starmap(
1524-
self._get_cell_temperature,
1525-
zip(data, poa, self.system.temperature_model_parameters)
1529+
self._get_cell_temperature, zip(data, poa, t_mod_params)
15261530
))
15271531
# If cell temperature has been specified for all arrays return
15281532
# immediately and do not try to compute it.

pvlib/tests/test_modelchain.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,38 @@ def test__prepare_temperature(sapm_dc_snl_ac_system, location, weather,
830830
assert_series_equal(mc.results.cell_temperature, data['cell_temperature'])
831831

832832

833+
def test__prepare_temperature_len1_weather_tuple(
834+
sapm_dc_snl_ac_system, location, weather, total_irrad):
835+
# GH 1192
836+
weather['module_temperature'] = [40., 30.]
837+
data = weather.copy()
838+
839+
mc = ModelChain(sapm_dc_snl_ac_system, location, aoi_model='no_loss',
840+
spectral_model='no_loss')
841+
mc.run_model([data])
842+
expected = pd.Series([42.617244212941394, 30.0], index=data.index)
843+
assert_series_equal(mc.results.cell_temperature[0], expected)
844+
845+
data = weather.copy().rename(
846+
columns={
847+
"ghi": "poa_global", "dhi": "poa_diffuse", "dni": "poa_direct"}
848+
)
849+
mc = ModelChain(sapm_dc_snl_ac_system, location, aoi_model='no_loss',
850+
spectral_model='no_loss')
851+
mc.run_model_from_poa([data])
852+
expected = pd.Series([41.5, 30.0], index=data.index)
853+
assert_series_equal(mc.results.cell_temperature[0], expected)
854+
855+
data = weather.copy()[["module_temperature", "ghi"]].rename(
856+
columns={"ghi": "effective_irradiance"}
857+
)
858+
mc = ModelChain(sapm_dc_snl_ac_system, location, aoi_model='no_loss',
859+
spectral_model='no_loss')
860+
mc.run_model_from_effective_irradiance([data])
861+
expected = pd.Series([41.5, 30.0], index=data.index)
862+
assert_series_equal(mc.results.cell_temperature[0], expected)
863+
864+
833865
def test__prepare_temperature_arrays_weather(sapm_dc_snl_ac_system_same_arrays,
834866
location, weather,
835867
total_irrad):

0 commit comments

Comments
 (0)