diff --git a/ramp/__init__.py b/ramp/__init__.py index 3f23af7e..d3753eb8 100644 --- a/ramp/__init__.py +++ b/ramp/__init__.py @@ -13,7 +13,6 @@ - random """ - from ramp._version import __version__ from ramp.core.core import UseCase, User, Appliance from ramp.core.utils import yearly_pattern, get_day_type diff --git a/ramp/core/core.py b/ramp/core/core.py index e21047b2..2e69110b 100644 --- a/ramp/core/core.py +++ b/ramp/core/core.py @@ -1033,6 +1033,14 @@ def __init__( self.name = name self.number = number self.num_windows = num_windows + + if func_time == 0: + warnings.warn( + UserWarning( + f"Func_time of appliance '{self.name}' is defined as 0. Ignore if this is intended" + ) + ) + self.func_time = func_time self.time_fraction_random_variability = time_fraction_random_variability self.func_cycle = func_cycle @@ -1799,6 +1807,8 @@ def generate_load_profile(self, prof_i, peak_time_range, day_type, power): or (self.pref_index != 0 and self.user.rand_daily_pref != self.pref_index) # checks if the app is allowed in the given yearly behaviour pattern or self.wd_we_type not in [day_type, 2] + # skip if the app has a func_time of 0 + or self.func_time == 0 ): return @@ -1845,7 +1855,7 @@ def generate_load_profile(self, prof_i, peak_time_range, day_type, power): ] tot_time = 0 - while tot_time <= rand_time: + while tot_time <= rand_time and rand_time != 0: # one option could be to generate a lot of them at once indexes = self.rand_switch_on_window( rand_time=rand_time, # TODO maybe only consider rand_time-tot_time ... diff --git a/tests/test_func_time_zero.py b/tests/test_func_time_zero.py new file mode 100644 index 00000000..0cf1d0af --- /dev/null +++ b/tests/test_func_time_zero.py @@ -0,0 +1,42 @@ +import numpy as np +import pytest +from ramp import UseCase, User + + +def test_skip_when_func_time_zero(): + # Generate test user and appliance + user = User(user_name="Test User", num_users=1) + appliance = user.add_appliance( + name="Test Appliance", + func_time=0, # Set func_time to be 0 + func_cycle=20, + time_fraction_random_variability=0.1, + ) + + # Add to use_case + use_case = UseCase(name="test_use_case", users=[user]) + + # Calculate peak time range for this use_case + peak_time_range = use_case.calc_peak_time_range() + + # Generated one load profile of this appliance + power = 1000 + appliance.generate_load_profile( + prof_i=0, peak_time_range=peak_time_range, day_type=0, power=power + ) + + # Check that no use of this appliance is simulated -> the appliances load profile is always smaller than it's power + # (Checking for the load_profile to always be 0 might be unreliable, since the RAMP core "marks" potential usage + # windows with small power values larger 0) + assert np.max(appliance.daily_use) < power + + +def test_warning_when_func_time_zero(): + user = User(user_name="Test User", num_users=1) + with pytest.warns(): + appliance = user.add_appliance( + name="Test Appliance", + func_time=0, # Set func_time to be 0 + func_cycle=20, + time_fraction_random_variability=0.1, + )