Skip to content
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

Add tests for module compression_heatpumps_and_chillers #57

Merged
merged 11 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
35 changes: 29 additions & 6 deletions src/oemof/thermal/compression_heatpumps_and_chillers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
file, available from its original location:
oemof-thermal/src/oemof/thermal/compression_heatpumps_and_chillers.py
"""
import pandas as pd


def calc_cops(temp_high, temp_low, quality_grade, temp_threshold_icing=2,
Expand Down Expand Up @@ -40,9 +41,9 @@ def calc_cops(temp_high, temp_low, quality_grade, temp_threshold_icing=2,

Parameters
----------
temp_high : list of numerical values
temp_high : list or pandas.Series of numerical values
jakob-wo marked this conversation as resolved.
Show resolved Hide resolved
Temperature of the high temperature reservoir in :math:`^\circ C`
temp_low : list of numerical values
temp_low : list or pandas.Series of numerical values
Temperature of the low temperature reservoir in :math:`^\circ C`
quality_grade : numerical value
Factor that scales down the efficiency of the real heat pump
Expand All @@ -66,7 +67,28 @@ def calc_cops(temp_high, temp_low, quality_grade, temp_threshold_icing=2,


"""
# Make both lists (temp_low and temp_high) have the same length and
# Check if input arguments have proper type and length
jakob-wo marked this conversation as resolved.
Show resolved Hide resolved
if type(temp_low) == pd.Series:
jakob-wo marked this conversation as resolved.
Show resolved Hide resolved
pass
elif not isinstance(temp_low, list):
raise TypeError('Argument temp_low is not of type list!')
if type(temp_high) == pd.Series:
pass
elif not isinstance(temp_high, list):
raise TypeError('Argument temp_high is not of type list!')
if len(temp_high) != len(temp_low):
if (len(temp_high) != 1) and ((len(temp_low) != 1)):
raise IndexError('Arguments temp_low and '
'temp_high have to be of same '
'length or one has to be of length 1 !')
if factor_icing is not None and consider_icing is False:
jakob-wo marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError('Argument factor_icing can not be used without '
'setting consider_icing=True!')
if factor_icing is None and consider_icing is True:
raise ValueError('Icing cannot be considered because argument '
'factor_icing has value None!')

# Make temp_low and temp_high have the same length and
# convert unit to Kelvin.
length = max([len(temp_high), len(temp_low)])
if len(temp_high) == 1:
Expand Down Expand Up @@ -98,9 +120,7 @@ def calc_cops(temp_high, temp_low, quality_grade, temp_threshold_icing=2,
if t_l >= temp_threshold_icing + 273.15:
cops = cops + [quality_grade * t_h / (t_h - t_l)]
elif mode == "chiller":
# Combining 'consider_icing' and mode 'chiller' is not possible!
cops = None

raise ValueError('Argument consider_icing must be set False for mode=chiller!')
return cops


Expand Down Expand Up @@ -139,6 +159,9 @@ def calc_max_Q_dot_chill(nominal_conditions, cops):


"""
if not isinstance(cops, list):
raise TypeError('Argument cops is not of type list!')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise TypeError('Argument cops is not of type list!')
raise TypeError("Argument 'cops' is not of type list!")


nominal_cop = (nominal_conditions['nominal_Q_chill'] / nominal_conditions[
'nominal_el_consumption'])
max_Q_chill = [actual_cop / nominal_cop for actual_cop in cops]
Expand Down
166 changes: 166 additions & 0 deletions tests/test_compression_heatpumps_and_chillers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import oemof.thermal.compression_heatpumps_and_chillers as cmpr_hp_chllr
import pytest


def test_cop_calculation_hp():
cops_HP = cmpr_hp_chllr.calc_cops(
temp_high=[40],
temp_low=[12],
quality_grade=0.4,
mode='heat_pump')
assert cops_HP == [4.473571428571428]


def test_cop_calculation_hp_list_input_01():
cops_HP = cmpr_hp_chllr.calc_cops(
temp_high=[40, 40],
temp_low=[12],
quality_grade=0.4,
mode='heat_pump')
assert cops_HP == [4.473571428571428, 4.473571428571428]


def test_cop_calculation_hp_list_input_02():
cops_HP = cmpr_hp_chllr.calc_cops(
temp_high=[40],
temp_low=[12, 12],
quality_grade=0.4,
mode='heat_pump')
assert cops_HP == [4.473571428571428, 4.473571428571428]


def test_cop_calculation_airsource_hp_with_icing_01():
cops_ASHP = cmpr_hp_chllr.calc_cops(
temp_high=[40],
temp_low=[1.3],
quality_grade=0.5,
mode='heat_pump',
consider_icing=True,
temp_threshold_icing=2,
factor_icing=0.8)
assert cops_ASHP == [3.236692506459949]


def test_cop_calculation_airsource_hp_with_icing_02():
cops_ASHP = cmpr_hp_chllr.calc_cops(
temp_high=[40],
temp_low=[2.3],
quality_grade=0.5,
mode='heat_pump',
consider_icing=True,
temp_threshold_icing=2,
factor_icing=0.8)
assert cops_ASHP == [4.15318302387268]


def test_cop_calculation_chiller():
cops_chiller = cmpr_hp_chllr.calc_cops(
temp_high=[35],
temp_low=[17],
quality_grade=0.45,
mode='chiller')
assert cops_chiller == [7.25375]


def test_raised_exception_01():
"""Test if an exception is raised if temp_low is not a list."""
with pytest.raises(TypeError):
cmpr_hp_chllr.calc_cops(
temp_high=[40],
temp_low=12, # ERROR - temp_low has to be a list!
quality_grade=0.4,
mode='heat_pump',
consider_icing=True,
temp_threshold_icing=2,
factor_icing=0.8)


def test_raised_exception_02():
"""Test if an exception is raised if temp_high is not a list."""
with pytest.raises(TypeError):
cmpr_hp_chllr.calc_cops(
temp_high=40, # ERROR - temp_high has to be a list!
temp_low=[12],
quality_grade=0.4,
mode='heat_pump',
consider_icing=True,
temp_threshold_icing=2,
factor_icing=0.8)


def test_raised_exception_03():
"""Test if an exception is raised if temp_high and
temp_low have different length AND none of them is of length 1."""
with pytest.raises(IndexError):
cmpr_hp_chllr.calc_cops(
temp_high=[40, 39, 39],
temp_low=[12, 10], # ERROR - len(temp_low) has
# to be 1 or equal to len(temp_high)
quality_grade=0.4,
mode='heat_pump',
consider_icing=True,
temp_threshold_icing=2,
factor_icing=0.8)


def test_raised_exception_04():
"""Test if an exception is raised if ... """
with pytest.raises(ValueError):
cmpr_hp_chllr.calc_cops(
temp_high=[39],
temp_low=[17],
quality_grade=0.4,
mode='chiller',
consider_icing=True,
temp_threshold_icing=2,
factor_icing=0.8)


def test_raised_exception_05():
"""Test if an exception is raised if ... """
with pytest.raises(ValueError):
cmpr_hp_chllr.calc_cops(
temp_high=[39],
temp_low=[17],
quality_grade=0.4,
mode='chiller',
temp_threshold_icing=2,
factor_icing=0.8)


def test_calc_max_Q_dot_chill():
nominal_conditions = {
'nominal_Q_chill': 20,
'nominal_el_consumption': 5}
actual_cop = [4.5]
max_Q_chill = cmpr_hp_chllr.calc_max_Q_dot_chill(nominal_conditions,
cops=actual_cop)
assert max_Q_chill == [1.125]


def test_raised_exceptions_05():
with pytest.raises(TypeError):
actual_cop = 4.5 # ERROR - has to be of type list!
nom_cond = {'nominal_Q_chill': 20, 'nominal_el_consumption': 5}
cmpr_hp_chllr.calc_max_Q_dot_chill(nominal_conditions=nom_cond,
cops=actual_cop)


def test_calc_max_Q_dot_heat():
nom_cond = {
'nominal_Q_hot': 20,
'nominal_el_consumption': 5}
actual_cop = [4.5]
max_Q_hot = cmpr_hp_chllr.calc_max_Q_dot_heat(nominal_conditions=nom_cond,
cops=actual_cop)
assert max_Q_hot == [1.125]


def test_calc_chiller_quality_grade():
nom_cond = {
'nominal_Q_chill': 20,
'nominal_el_consumption': 5,
't_high_nominal': 35,
't_low_nominal': 7}
q_grade = cmpr_hp_chllr.calc_chiller_quality_grade(nominal_conditions=nom_cond)
assert q_grade == 0.39978582902016785