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

Refactor the code and move some functions into class methods #1

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bddfba7
Merge pull request #34 from rl-institut/feature/import-export
FLomb Jul 8, 2022
3d0e557
Change variable names and refactor Appliance class
Bachibouzouk Jul 6, 2022
7f77bfb
Add a parser of xlsx input files
Bachibouzouk Jun 3, 2022
d72e4bc
Define windows_curve as property of User class
Bachibouzouk May 18, 2022
714b13a
Rename function according to original paper
Bachibouzouk May 19, 2022
345786f
Refactor the random windows calculation
Bachibouzouk Jul 6, 2022
d71cafa
Refactor the window method of Appliance
Bachibouzouk Jul 6, 2022
ab8e4e2
Move code to get switch on to Appliance class
Bachibouzouk Jul 6, 2022
e6d6052
Move repeated code into Appliance class as a method
Bachibouzouk May 19, 2022
29234b5
Move calculation of coincident switch on into a method
Bachibouzouk Jul 6, 2022
3669bac
Move calculation of daily_use update on into a method
Bachibouzouk Jul 6, 2022
1c94e76
Move the rand_total_time_of_use within a method
Bachibouzouk May 19, 2022
142bcdc
Use for loop to simplify code readability
Bachibouzouk May 19, 2022
e8bec25
Move the code defining random cycles to a method
Bachibouzouk May 19, 2022
3ad2015
Remove redundant code in assign_random_cycles method
Bachibouzouk Jul 6, 2022
33f82df
Refactor long if statement
Bachibouzouk May 19, 2022
c172072
Move switch on calibration parameters into a function
Bachibouzouk Jun 3, 2022
1e5a9f0
Move code to generate appliance profile inside a method
Bachibouzouk May 19, 2022
e8da39a
Move code for single user load profile in a method
Bachibouzouk Jul 6, 2022
d5a9910
Move iteration over user number into a method
Bachibouzouk Jun 3, 2022
a99b594
Fix circular import error
Bachibouzouk Jul 6, 2022
8b6fd9b
Fix typos in refactoring
Bachibouzouk May 19, 2022
a511234
Fix docstrings
Bachibouzouk May 19, 2022
2722edd
Add .idea and .pyc to gitignore
Bachibouzouk May 19, 2022
39a56c8
Introduce function random_variation
Bachibouzouk Jul 6, 2022
f4a842d
Improve docstrings and make variable name PEP8 compatible
Bachibouzouk Jul 6, 2022
739515a
Change coincident switch on
Bachibouzouk May 31, 2022
34da4d4
Change default cycle windows values
Bachibouzouk Jul 6, 2022
cc5d192
add input file related to issue #9
dhungelgd May 30, 2022
a6791cf
Refactor assign_random_cycles to remove the unusual spike related to #9
Bachibouzouk Jul 6, 2022
99175f1
Introduce two utils function
Bachibouzouk Jul 6, 2022
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode
.vscode
.idea
*.pyc
3 changes: 2 additions & 1 deletion ramp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
num_profiles = num_profiles * len(input_files_to_run)
else:
if len(num_profiles) != len(input_files_to_run):
raise ValueError("The number of profiles parameters should match the number of input files provided")
raise ValueError(
"The number of profiles parameters should match the number of input files provided")
else:
num_profiles = [None] * len(input_files_to_run)

Expand Down
22 changes: 22 additions & 0 deletions ramp/core/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
def switch_on_parameters():
"""
Calibration parameters. These can be changed in case the user has some real data against which the model can be calibrated
They regulate the probability of coincident switch-on within the peak window

mu_peak corresponds to \mu_{%} in [1], p.8
s_peak corresponds to \sigma_{%} in [1], p.8

Notes
-----
[1] F. Lombardi, S. Balderrama, S. Quoilin, E. Colombo,
Generating high-resolution multi-energy load profiles for remote areas with an open-source stochastic model,
Energy, 2019, https://doi.org/10.1016/j.energy.2019.04.097.
"""

mu_peak = 0.5 # median value of gaussian distribution [0,1] by which the number of coincident switch_ons is randomly selected
s_peak = 0.5 # standard deviation (as percentage of the median value) of the gaussian distribution [0,1] above mentioned
op_factor = 0.5 # off-peak coincidence calculation parameter

return mu_peak, s_peak, op_factor


OLD_TO_NEW_MAPPING = {
"name": "user_name",
"n_users": "num_users",
Expand Down
380 changes: 372 additions & 8 deletions ramp/core/core.py

Large diffs are not rendered by default.

97 changes: 55 additions & 42 deletions ramp/core/initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,78 @@

#%% Initialisation of a model instance

import numpy as np
import numpy as np
import importlib
from ramp.core.core import UseCase


def yearly_pattern():
'''
Definition of a yearly pattern of weekends and weekdays, in case some appliances have specific wd/we behaviour
'''
#Yearly behaviour pattern
Year_behaviour = np.zeros(365)
Year_behaviour[5:365:7] = 1
Year_behaviour[6:365:7] = 1

return(Year_behaviour)
"""Definition of a yearly pattern of weekends and weekdays, in case some appliances have specific wd/we behaviour"""

year_behaviour = np.zeros(365)
year_behaviour[5:365:7] = 1
year_behaviour[6:365:7] = 1

return year_behaviour


def user_defined_inputs(j=None, fname=None):
'''
Imports an input file and returns a processed User_list
'''
"""Imports an input file and returns a processed user_list

Parameters
----------
j: int
the index of a .py input file that is in the format input_files/input_file_j.py
fname: path
path to a .xlsx input file
if provided, overrides the loading of input_files/input_file_j.py

Returns
-------
A list of User instances
"""

# Back compatibility with old code
if j is not None:
file_module = importlib.import_module(f'ramp.input_files.input_file_{j}')
User_list = file_module.User_list
file_module = importlib.import_module(f"ramp.input_files.input_file_{j}")
user_list = file_module.User_list

if fname is not None:
usecase = UseCase()
usecase.load(fname)
User_list = usecase.users
user_list = usecase.users

return(User_list)
return user_list


def Initialise_model(num_profiles):
'''
The model is ready to be initialised
'''
def initialise_inputs(j=None, fname=None, num_profiles=None):
"""Loads the provided input file and prompt the user for number of profiles if not defined

if num_profiles is None:
num_profiles = int(input("please indicate the number of profiles to be generated: ")) #asks the user how many profiles (i.e. code runs) he wants
print('Please wait...')
Profile = [] #creates an empty list to store the results of each code run, i.e. each stochastically generated profile

return (Profile, num_profiles)

def Initialise_inputs(j=None, fname=None):
Year_behaviour = yearly_pattern()
Parameters
----------
j: int
the index of a .py input file that is in the format input_files/input_file_j.py
fname: path
path to a .xlsx input file
if provided, overrides the loading of input_files/input_file_j.py
num_profiles: int
the number of different usecase profiles which need to be generated

Returns
-------

"""

year_behaviour = yearly_pattern()
user_list = user_defined_inputs(j, fname)

# Calibration parameters
'''
Calibration parameters. These can be changed in case the user has some real data against which the model can be calibrated
They regulate the probabilities defining the largeness of the peak window and the probability of coincident switch-on within the peak window
'''
peak_enlarg = 0.15 #percentage random enlargement or reduction of peak time range length
mu_peak = 0.5 #median value of gaussian distribution [0,1] by which the number of coincident switch_ons is randomly selected
s_peak = 0.5 #standard deviation (as percentage of the median value) of the gaussian distribution [0,1] above mentioned
op_factor = 0.5 #off-peak coincidence calculation parameter

return (peak_enlarg, mu_peak, s_peak, op_factor, Year_behaviour, user_list)

peak_enlarge = 0.15 # percentage random enlargement or reduction of peak time range length, corresponds to \delta_{peak} in [1], p.7

if num_profiles is None:
# asks the user how many profiles (i.e. code runs) they want
num_profiles = int(
input("please indicate the number of profiles to be generated: ")
)
print("Please wait...")

return (peak_enlarge, year_behaviour, user_list, num_profiles)
Loading