Skip to content

fix modelchain poa tests #1052

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 2 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
# keys that are used to detect input data and assign data to appropriate
# ModelChain attribute
# for ModelChain.weather
WEATHER_KEYS = {'ghi', 'dhi', 'dni', 'wind_speed', 'temp_air',
'precipitable_water'}
WEATHER_KEYS = ('ghi', 'dhi', 'dni', 'wind_speed', 'temp_air',
'precipitable_water')

# for ModelChain.total_irrad
POA_DATA_KEYS = {'poa_global', 'poa_direct', 'poa_diffuse'}
POA_KEYS = ('poa_global', 'poa_direct', 'poa_diffuse')

# Optional keys to communicate temperature data. If provided,
# 'cell_temperature' overrides ModelChain.temperature_model and sets
# ModelChain.cell_temperature to the data. If 'module_temperature' is provdied,
# overrides ModelChain.temperature_model with
# pvlib.temperature.sapm_celL_from_module
TEMPERATURE_KEYS = {'module_temperature', 'cell_temperature'}
TEMPERATURE_KEYS = ('module_temperature', 'cell_temperature')

DATA_KEYS = WEATHER_KEYS | POA_DATA_KEYS | TEMPERATURE_KEYS
DATA_KEYS = WEATHER_KEYS + POA_KEYS + TEMPERATURE_KEYS

# these dictionaries contain the default configuration for following
# established modeling sequences. They can be used in combination with
Expand Down Expand Up @@ -1090,7 +1090,7 @@ def _assign_weather(self, data):
return self

def _assign_total_irrad(self, data):
key_list = [k for k in POA_DATA_KEYS if k in data]
key_list = [k for k in POA_KEYS if k in data]
self.total_irrad = data[key_list].copy()
return self

Expand Down
22 changes: 13 additions & 9 deletions pvlib/tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def weather():
@pytest.fixture
def total_irrad(weather):
return pd.DataFrame({'poa_global': [800., 500.],
'poa_diffuse': [300., 200.],
'poa_direct': [500., 300.]}, index=weather.index)
'poa_direct': [500., 300.],
'poa_diffuse': [300., 200.]}, index=weather.index)


def test_ModelChain_creation(sapm_dc_snl_ac_system, location):
Expand Down Expand Up @@ -336,21 +336,25 @@ def test_run_model_tracker(sapm_dc_snl_ac_system, location, weather, mocker):

def test__assign_total_irrad(sapm_dc_snl_ac_system, location, weather,
total_irrad):
weather[['poa_global', 'poa_diffuse', 'poa_direct']] = total_irrad
data = pd.concat([weather, total_irrad], axis=1)
mc = ModelChain(sapm_dc_snl_ac_system, location)
mc._assign_total_irrad(weather)
for k in modelchain.POA_DATA_KEYS:
assert_series_equal(mc.total_irrad[k], total_irrad[k])
mc._assign_total_irrad(data)
assert_frame_equal(mc.total_irrad, total_irrad)


def test_prepare_inputs_from_poa(sapm_dc_snl_ac_system, location,
weather, total_irrad):
data = weather.copy()
data[['poa_global', 'poa_diffuse', 'poa_direct']] = total_irrad
data = pd.concat([weather, total_irrad], axis=1)
mc = ModelChain(sapm_dc_snl_ac_system, location)
mc.prepare_inputs_from_poa(data)
weather_expected = weather.copy()
weather_expected['temp_air'] = 20
weather_expected['wind_speed'] = 0
# order as expected
weather_expected = weather_expected[
['ghi', 'dhi', 'dni', 'wind_speed', 'temp_air']]
# weather attribute
assert_frame_equal(mc.weather, weather)
assert_frame_equal(mc.weather, weather_expected)
# total_irrad attribute
assert_frame_equal(mc.total_irrad, total_irrad)

Expand Down