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

Remove usage of deprecated User.Appliance class #142

Merged
merged 8 commits into from
May 14, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install black
run: |
python -m pip install --upgrade pip
pip install black
pip install black[jupyter]==24.4.2
- name: Lint with black
run: |
black . --check
Expand Down
35 changes: 19 additions & 16 deletions docs/notebooks/cooking_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@
"outputs": [],
"source": [
"# soup for lunch\n",
"lunch_window = [12 * 60, 12 * 60+26]\n",
"lunch_window = [12 * 60, 12 * 60 + 26]\n",
"\n",
"soup_1 = user_1.add_appliance(\n",
" name=\"soup for lunch\",\n",
" power=1200, # nominal power of appliance\n",
" func_time=25, # the cooking time\n",
" func_cycle=25, # we always need 25 minute for cooking\n",
" fixed_cycle=1, # the cookstove is not a continus power usage appliance, it has cycles as mentioned earlier \n",
" window_1=lunch_window, # lunch is always prepared from 12\n",
" power=1200, # nominal power of appliance\n",
" func_time=25, # the cooking time\n",
" func_cycle=25, # we always need 25 minute for cooking\n",
" fixed_cycle=1, # the cookstove is not a continus power usage appliance, it has cycles as mentioned earlier\n",
" window_1=lunch_window, # lunch is always prepared from 12\n",
" p_11=1200, # power of the first cycle\n",
" t_11=5, # time needed for the first cycle\n",
" p_12=750, # power of the second cycle\n",
" t_12=20, # time needed for the second cycle\n",
" cw11=lunch_window, # the time window of the working cycle \n",
" cw11=lunch_window, # the time window of the working cycle\n",
")"
]
},
Expand Down Expand Up @@ -194,10 +194,9 @@
"number_of_days = 5\n",
"user_1_profiles = {}\n",
"user_2_profiles = {}\n",
"for day in range(1,number_of_days+1):\n",
"for day in range(1, number_of_days + 1):\n",
" user_1_profiles[f\"day {day}\"] = pd.Series(user_1.generate_single_load_profile())\n",
" user_2_profiles[f\"day {day}\"] = pd.Series(user_2.generate_single_load_profile())\n",
" "
" user_2_profiles[f\"day {day}\"] = pd.Series(user_2.generate_single_load_profile())"
]
},
{
Expand All @@ -218,17 +217,21 @@
}
],
"source": [
"fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 4)) \n",
"fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 4))\n",
"\n",
"\n",
"i = 0\n",
"for name, df in dict(\n",
" user_1_profiles=pd.concat(user_1_profiles,axis=1).iloc[lunch_window[0]-5:lunch_window[1]+5], # take only the lunch window\n",
" user_2_profiles=pd.concat(user_2_profiles,axis=1).iloc[lunch_window[0]-5:lunch_window[1]+5]# take only the lunch window\n",
" ).items():\n",
" df.plot(ax=axes[i],legend=True)\n",
" user_1_profiles=pd.concat(user_1_profiles, axis=1).iloc[\n",
" lunch_window[0] - 5 : lunch_window[1] + 5\n",
" ], # take only the lunch window\n",
" user_2_profiles=pd.concat(user_2_profiles, axis=1).iloc[\n",
" lunch_window[0] - 5 : lunch_window[1] + 5\n",
" ], # take only the lunch window\n",
").items():\n",
" df.plot(ax=axes[i], legend=True)\n",
" axes[i].set_title(name)\n",
" i+=1\n",
" i += 1\n",
"\n",
"plt.tight_layout()\n",
"plt.show()"
Expand Down
21 changes: 9 additions & 12 deletions docs/notebooks/fixed_flat_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
" func_cycle=60,\n",
" fixed=\"yes\", # This means all the 'n' appliances of this kind are always switched-on together\n",
" flat=\"yes\", # This means the appliance is not subject to random variability in terms of total usage time\n",
" window_1 = [1200, 1440], # from 20:00 to 24:00\n",
")\n"
" window_1=[1200, 1440], # from 20:00 to 24:00\n",
")"
]
},
{
Expand Down Expand Up @@ -109,14 +109,12 @@
],
"source": [
"school_case = UseCase(\n",
" users=[school], # users of the usecase\n",
" date_start=\"2023-01-01\", # start date\n",
" )\n",
" users=[school], # users of the usecase\n",
" date_start=\"2023-01-01\", # start date\n",
")\n",
"\n",
"# when both date_start and date_end are not given, you need to initialize the usecase by this method and by passing the number of days as num_days\n",
"school_case.initialize(\n",
" num_days=7\n",
" )"
"school_case.initialize(num_days=7)"
]
},
{
Expand Down Expand Up @@ -221,12 +219,11 @@
}
],
"source": [
"fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(12, 4))\n",
"\n",
"fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(12, 4)) \n",
"\n",
"\n",
"for i, df in enumerate([no_fix_no_flat,fix_no_flat,fixed_flat,no_fixed_flat]):\n",
" df.plot(ax=axes[i],legend=False)\n",
"for i, df in enumerate([no_fix_no_flat, fix_no_flat, fixed_flat, no_fixed_flat]):\n",
" df.plot(ax=axes[i], legend=False)\n",
" axes[i].set_title(df.columns[0])\n",
"\n",
"\n",
Expand Down
28 changes: 8 additions & 20 deletions docs/notebooks/multi_cycle.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"outputs": [],
"source": [
"# creating the appliance\n",
"fridge = household.Appliance(\n",
"fridge = household.add_appliance(\n",
" name=\"Fridge\",\n",
" number=1,\n",
" power=200,\n",
Expand Down Expand Up @@ -123,30 +123,18 @@
"# assiging the specific cycles\n",
"# first cycle: standard cycle\n",
"fridge.specific_cycle_1(\n",
" p_11=200, # power level for the first operation segment\n",
" p_11=200, # power level for the first operation segment\n",
" t_11=10, # duration of the first operation segment\n",
" p_12=5, # power level for the second operation segment\n",
" p_12=5, # power level for the second operation segment\n",
" t_12=20, # duration of the second operation segment\n",
" r_c1=0 # random variability assigned to the duration of each segment\n",
" r_c1=0, # random variability assigned to the duration of each segment\n",
")\n",
"\n",
"# second cycle: intermediate cycle\n",
"fridge.specific_cycle_2(\n",
" p_21=200,\n",
" t_21=15,\n",
" p_22=5,\n",
" t_22=15,\n",
" r_c2=0\n",
")\n",
"fridge.specific_cycle_2(p_21=200, t_21=15, p_22=5, t_22=15, r_c2=0)\n",
"\n",
"# third cycle: intensive cycle\n",
"fridge.specific_cycle_3(\n",
" p_31=200,\n",
" t_31=20,\n",
" p_32=5,\n",
" t_32=10,\n",
" r_c3=0\n",
")"
"fridge.specific_cycle_3(p_31=200, t_31=20, p_32=5, t_32=10, r_c3=0)"
]
},
{
Expand All @@ -166,7 +154,7 @@
"source": [
"# defining cycle behaviour\n",
"fridge.cycle_behaviour(\n",
" cw11=[0, 299], cw12=[1201, 1440], cw21=[300, 479], cw31=[480, 1200]\n",
" cw11=[0, 299], cw12=[1201, 1440], cw21=[300, 479], cw31=[480, 1200]\n",
")"
]
},
Expand Down Expand Up @@ -198,7 +186,7 @@
"source": [
"# days to build the profiles\n",
"days = [\n",
" \"2020-12-16\", # a day in the 'Hot' season, assuming a location in the Southern hemisphere\n",
" \"2020-12-16\", # a day in the 'Hot' season, assuming a location in the Southern hemisphere\n",
"]\n",
"\n",
"profiles = pd.DataFrame(index=range(0, 1440), columns=days)\n",
Expand Down
34 changes: 15 additions & 19 deletions docs/notebooks/occasional_use.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
" number=1,\n",
" power=50,\n",
" num_windows=1,\n",
" func_time=210, # 3.5 hours\n",
" func_cycle=210, \n",
" func_time=210, # 3.5 hours\n",
" func_cycle=210,\n",
" occasional_use=0.5, # 50% chance of occasional use,\n",
" window_1=[480, 750], # start from 8AM\n",
" window_1=[480, 750], # start from 8AM\n",
")"
]
},
Expand All @@ -81,10 +81,10 @@
" number=1,\n",
" power=50,\n",
" num_windows=1,\n",
" func_time=210, # 3.5 hours\n",
" func_cycle=210, \n",
" func_time=210, # 3.5 hours\n",
" func_cycle=210,\n",
" occasional_use=1, # always present in the mix of appliances,\n",
" window_1=[480, 750], # start from 8AM\n",
" window_1=[480, 750], # start from 8AM\n",
")"
]
},
Expand Down Expand Up @@ -117,14 +117,10 @@
"household_profiles = []\n",
"school_profiles = []\n",
"\n",
"for day in range(1,number_of_days+1):\n",
" household_profiles.extend(\n",
" household.generate_single_load_profile(prof_i=day)\n",
" )\n",
"for day in range(1, number_of_days + 1):\n",
" household_profiles.extend(household.generate_single_load_profile(prof_i=day))\n",
"\n",
" school_profiles.extend(\n",
" school.generate_single_load_profile(prof_i=day)\n",
" )"
" school_profiles.extend(school.generate_single_load_profile(prof_i=day))"
]
},
{
Expand All @@ -145,20 +141,20 @@
}
],
"source": [
"fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 4)) \n",
"fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 4))\n",
"\n",
"\n",
"i = 0\n",
"for name, df in dict(\n",
" household_profiles=pd.DataFrame(household_profiles),\n",
" school_profiles=pd.DataFrame(school_profiles)\n",
" ).items():\n",
" df.plot(ax=axes[i],legend=False)\n",
" school_profiles=pd.DataFrame(school_profiles),\n",
").items():\n",
" df.plot(ax=axes[i], legend=False)\n",
" axes[i].set_title(name)\n",
" i+=1\n",
" i += 1\n",
"\n",
"plt.tight_layout()\n",
"plt.show()\n"
"plt.show()"
]
},
{
Expand Down
32 changes: 14 additions & 18 deletions docs/notebooks/random_seed.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@
"from ramp.example.input_file_1 import User_list\n",
"\n",
"# Build use case 1 with non-fixed seed\n",
"uc_1 = UseCase(\n",
" users=deepcopy(User_list),\n",
" random_seed=None\n",
")\n",
"uc_1 = UseCase(users=deepcopy(User_list), random_seed=None)\n",
"# Initialize and generate load profile\n",
"uc_1.initialize(peak_enlarge=0.15, num_days=3)\n",
"uc_1_lp = uc_1.generate_daily_load_profiles()"
Expand Down Expand Up @@ -92,19 +89,13 @@
"cell_type": "code",
"source": [
"# Build use case 2 and fixed random seed\n",
"uc_2 = UseCase(\n",
" users=deepcopy(User_list),\n",
" random_seed=1\n",
")\n",
"uc_2 = UseCase(users=deepcopy(User_list), random_seed=1)\n",
"# Initialize and generate load profile\n",
"uc_2.initialize(peak_enlarge=0.15, num_days=3)\n",
"uc_2_lp = uc_2.generate_daily_load_profiles()\n",
"\n",
"# Build use case 3 and same fixed random seed as uc_2\n",
"uc_3 = UseCase(\n",
" users=deepcopy(User_list),\n",
" random_seed=1\n",
")\n",
"uc_3 = UseCase(users=deepcopy(User_list), random_seed=1)\n",
"\n",
"# Initialize and generate load profile\n",
"uc_3.initialize(peak_enlarge=0.15, num_days=3)\n",
Expand Down Expand Up @@ -147,12 +138,17 @@
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"\n",
"lp_df = pd.DataFrame({'UseCase_1: non_fixed_seed': uc_1_lp,\n",
" 'UseCase_2: fixed_seed': uc_2_lp,\n",
" 'UseCase_3: fixed_seed': uc_3_lp,\n",
" 'diff UseCase_2 - UseCase_1': uc_2_lp - uc_1_lp, # difference between uc_1 and uc_2 is not zero\n",
" 'diff UseCase_2 - UseCase_3': uc_2_lp - uc_3_lp # difference between uc_2 and uc_3 is zero\n",
" })\n",
"lp_df = pd.DataFrame(\n",
" {\n",
" \"UseCase_1: non_fixed_seed\": uc_1_lp,\n",
" \"UseCase_2: fixed_seed\": uc_2_lp,\n",
" \"UseCase_3: fixed_seed\": uc_3_lp,\n",
" \"diff UseCase_2 - UseCase_1\": uc_2_lp\n",
" - uc_1_lp, # difference between uc_1 and uc_2 is not zero\n",
" \"diff UseCase_2 - UseCase_3\": uc_2_lp\n",
" - uc_3_lp, # difference between uc_2 and uc_3 is zero\n",
" }\n",
")\n",
"lp_df.plot()\n",
"plt.show()"
],
Expand Down
34 changes: 16 additions & 18 deletions docs/notebooks/simple_bulb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@
"source": [
"# add_appliance is meth\n",
"indoor_bulb = household.add_appliance(\n",
" name=\"Indoor Light Bulb\", # the name of the appliance\n",
" number=6, # how many of this appliance each user has in this user category\n",
" power=7, # the power (in Watt) of each single appliance. RAMP does not deal with units of measures, you should check the consistency of the unit of measures throughout your model\n",
" num_windows=2, # how many usage time windows throughout the day?\n",
" func_time=120, # the total usage time of appliances\n",
" func_cycle=10, # the minimum usage time after a switch on event\n",
" name=\"Indoor Light Bulb\", # the name of the appliance\n",
" number=6, # how many of this appliance each user has in this user category\n",
" power=7, # the power (in Watt) of each single appliance. RAMP does not deal with units of measures, you should check the consistency of the unit of measures throughout your model\n",
" num_windows=2, # how many usage time windows throughout the day?\n",
" func_time=120, # the total usage time of appliances\n",
" func_cycle=10, # the minimum usage time after a switch on event\n",
" window_1=[0, 30], # from 24 to 00:30\n",
" window_2=[1170, 1440], # from 19:30 to 24:00\n",
" random_var_w=0.35, # Variability of the windows in percentage\n",
" time_fraction_random_variability=0.2, # randomizes the total time the appliance is on (between 0 and 1)\n",
" random_var_w=0.35, # Variability of the windows in percentage\n",
" time_fraction_random_variability=0.2, # randomizes the total time the appliance is on (between 0 and 1)\n",
")"
]
},
Expand Down Expand Up @@ -186,10 +186,12 @@
],
"source": [
"use_case = UseCase(\n",
" users=[household], # A list of all the user categories to be included in the simulation. In this case, we only have household user category\n",
" date_start=\"2020-01-01\", # starting date of the simulation\n",
" date_end=\"2020-12-31\", # end date of the simulation\n",
" )\n"
" users=[\n",
" household\n",
" ], # A list of all the user categories to be included in the simulation. In this case, we only have household user category\n",
" date_start=\"2020-01-01\", # starting date of the simulation\n",
" date_end=\"2020-12-31\", # end date of the simulation\n",
")"
]
},
{
Expand Down Expand Up @@ -283,9 +285,7 @@
}
],
"source": [
"single_profile = household.generate_single_load_profile(\n",
" day_type=0\n",
" )"
"single_profile = household.generate_single_load_profile(day_type=0)"
]
},
{
Expand Down Expand Up @@ -337,9 +337,7 @@
"metadata": {},
"outputs": [],
"source": [
"aggregated_profile = household.generate_aggregated_load_profile(\n",
" day_type=0\n",
")"
"aggregated_profile = household.generate_aggregated_load_profile(day_type=0)"
]
},
{
Expand Down
Loading
Loading