8000 Accept albedo in weather input to ModelChain.run_model method by cwhanse · Pull Request #1469 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Accept albedo in weather input to ModelChain.run_model method #1469

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 16 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
work on modelchain
  • Loading branch information
cwhanse committed Jun 10, 2022
commit e64a9403e0952a5f6f4760d6ed7493b860d17510
26 changes: 18 additions & 8 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,14 +1500,24 @@ def prepare_inputs(self, weather):
--------
ModelChain.complete_irradiance
"""
# transfer albedo to weather if needed
if 'albedo' in weather.columns:
for array in self.system.Arrays:
if array.albedo:
raise ValueError('albedo found in both weather and on'
' PVsystem. Provide albedo on one or'
' on neither, but not on both.')
array.albedo = weather['albedo']
# transfer albedo from weather to mc.system.arrays if needed
if isinstance(weather, pd.DataFrame):
if 'albedo' in weather.columns:
for array in self.system.arrays:
if hasattr('array', 'albedo'):
raise ValueError('albedo found in both weather and on'
' PVsystem.Array Provide albedo on'
' one or on neither, but not both.')
array.albedo = weather['albedo']
else: # weather is a list or tuple
for w, a in zip(weather, self.system.arrays):
if 'albedo' in w.columns:
if hasattr('a', 'albedo'):
raise ValueError('albedo found in both weather and on'
' PVsystem.Array Provide albedo on'
' one or on neither, but not both.')
a.albedo = weather['albedo']

weather = _to_tuple(weather)
self._check_multiple_input(weather, strict=False)
self._verify_df(weather, required=['ghi', 'dni', 'dhi'])
Expand Down
29 changes: 29 additions & 0 deletions pvlib/tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,35 @@ def test_prepare_inputs_multi_weather(
assert len(mc.results.total_irrad) == num_arrays


@pytest.mark.parametrize("input_type", [tuple, list])
def test_prepare_inputs_transfer_albedo(
sapm_dc_snl_ac_system_Array, location, input_type):
times = pd.date_range(start='20160101 1200-0700',
end='20160101 1800-0700', freq='6H')
mc = ModelChain(sapm_dc_snl_ac_system_Array, location)
# albedo on pvsystem but not in weather
weather = pd.DataFrame({'ghi': 1, 'dhi': 1, 'dni': 1},
index=times)
Copy link
Member

Choose a reason for hiding this comment

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

FYI this comment doesn't match the test code

mc.prepare_inputs(input_type((weather, weather)))
num_arrays = sapm_dc_snl_ac_system_Array.num_arrays
assert len(mc.results.total_irrad) == num_arrays
# albedo on both weather and system
weather['albedo'] = 0.5
with pytest.raises(ValueError, match='albedo found in both weather'):
mc.prepare_inputs(input_type((weather, weather)))
# albedo on weather but not system
pvsystem = sapm_dc_snl_ac_system_Array
for a in pvsystem.arrays:
del a.albedo
mc = ModelChain(pvsystem, location)
mc = mc.prepare_inputs(weather)
assert mc.system.arrays[0].albedo==0.5
mc = ModelChain(pvsystem, location)
mc = mc.prepare_inputs(input_type((weather, weather)))
for a in mc.system_arrays:
assert a.albedo==0.5


def test_prepare_inputs_no_irradiance(sapm_dc_snl_ac_system, location):
mc = ModelChain(sapm_dc_snl_ac_system, location)
weather = pd.DataFrame()
Expand Down
0