procsimulator package¶
Submodules¶
procsimulator.CommunityGenerator module¶
-
class
procsimulator.CommunityGenerator.
CommunityGenerator
(path_steps_minutes)[source]¶ Bases:
object
-
calculate_netload
(netload_df)[source]¶ Calculates the netload (Demand-Production) of the community and saves in the netload.csv file. This file contains 4 columns: Date, Demand, Production and Netload.
- Parameters
netload_df – dataframe containing at least 3 columns (Date, Demand and Production)
- Returns
netload dataframe with an extra column “Netload”
-
procsimulator.CommunityManager module¶
-
class
procsimulator.CommunityManager.
CommunityManager
[source]¶ Bases:
abc.ABC
-
calculate_bin_used_capacity
(bins_capacities, placed_timeslots, production_baseload, n_bins_per_hour)[source]¶ Updates the bin capacity for the second part of the optimization (increases the production_baseload to the bin capacity of the first part, and subtracts the energy of the placed timeslots in the first step.
- Parameters
bins_capacities – bin capacities of the bins in the 1st step of the optimization
placed_timeslots – placed timeslots in the 1st step (in order to subtract the energy of them to the bin capacity) - if they are placed, the bin capacity decreases
production_baseload – value to increment in the bin capacities, which corresponds to the value of energy that can be acquired from the grid in the 2nd step
n_bins_per_hour – number of bins per hour (parameter of the strategy) to know the quantity of bins in a day (e.g. if bins of 30 minutes, n_bins_per_hour = 2)
- Returns
array with x positions in a day (where the number of positions is 24*n_bins_per_hour) with the bin capacity of each bin
-
create_profiles_after_strategy
(placed_timeslots, all_timeslots_objects, initial_path, final_path, short_initial_path, short_final_path, remove_flex_cons, n_bins_per_hour, fact)[source]¶ Implementing the abstract function (from the parent) which updates the profiles after applying the strategy.
- Parameters
placed_timeslots – array of the placed timeslots
all_timeslots_objects – array of all timeslots with all the information (Start, End, Appliance, Power, House, etc)
initial_path – path of the minutes (1/60Hz) dataframe (e.g. “(…)/output/minute”)
final_path – path of the dataframe after the strategy (e.g. “(…)/output/afteroptimization”)
short_initial_path – folder of the minutes (1/60Hz) dataframe (e.g. “minutes”)
short_final_path – folder of the dataframe after the strategy e.g. “afteroptimization”)
remove_flex_cons – if True, the flexible consumption will be removed, otherwise the flexible consumption will not be removed (in 1st step, it was True to remove the flexible consumption and in the 2nd step it was False because the flexible consumption has already been removed)
n_bins_per_hour – number of bins per hour (parameter of the strategy) to know the quantity of bins in a day (e.g. if bins of 30 minutes, n_bins_per_hour = 2)
fact – minutes of each bin (e.g. if bins of 30 minutes, fact = 30)
- Returns
output of update_consumption_profiles_based_on_optimization function
-
abstract
execute
(*args)[source]¶ This function should be implemented in a class which inherits from this one. This goal is to define all the steps necessary to implement the provided strategy which will allow to do a good management of the renewable resources of the community.
- Parameters
args – can have as many arguments as you want
-
get_production_max_after_first_optimization
(netload_second_optim, fd, production_baseload, n_bins_per_hour, fact)[source]¶ Calculates the maximum production peak for each bin of the second step (calculates the maximum in the netload dataframe after updating the profiles of 1st step, and have to increase the production_baseload and decrease the energy of the placed timeslots of the 1st step)
- Parameters
netload_second_optim – dataframe which contains the netload after updating the profiles of the 1st step (to calculate the maximum peak in the 2nd step)
fd – consumption profile date (to
production_baseload – value to increment in the bin capacities, which corresponds to the value of energy that can be acquired from the grid in the 2nd step
n_bins_per_hour – number of bins per hour (parameter of the strategy) to know the quantity of bins in a day (e.g. if bins of 30 minutes, n_bins_per_hour = 2)
fact – minutes of each bin (e.g. if bins of 30 minutes, fact = 30)
- Returns
array with x positions in a day (where the number of positions is 24*n_bins_per_hour) with the bin maximum production peak of each bin
-
prepare_inputs
(fact, save_to_file=False, import_prices_hour=[], export_prices_hour=[])[source]¶ Prepares the inputs for the optimization problem. :return:
-
remove_flexible_consumption
()[source]¶ Removes the flexible consumption of the consumption profile, in order to have the baseload consumption (that consumption that can not be shifted. In order to do this, the consumption of the flexible appliances are subtracted from the netload and community dataframes (notice that each flexible has it own consumption profile for each house)
- Returns
netload dataframe with the non-flexible consumption
-
update_consumption_profiles_based_on_optimization
(placed_timeslots, all_timeslots_objects, initial_path, final_path, short_initial_path, short_final_path, remove_flex_cons, n_bins_per_hour, fact)[source]¶ Implementing the function which updates the profiles after applying the strategy.
- Parameters
placed_timeslots – array of the placed timeslots
all_timeslots_objects – array of all timeslots with all the information (Start, End, Appliance, Power, House, etc)
initial_path – path of the minutes (1/60Hz) dataframe (e.g. “(…)/output/minute”)
final_path – path of the dataframe after the strategy (e.g. “(…)/output/afteroptimization”)
short_initial_path – folder of the minutes (1/60Hz) dataframe (e.g. “minutes”)
short_final_path – folder of the dataframe after the strategy e.g. “afteroptimization”)
remove_flex_cons – if True, the flexible consumption will be removed, otherwise the flexible consumption will not be removed (in 1st step, it was True to remove the flexible consumption and in the 2nd step it was False because the flexible consumption has already been removed)
n_bins_per_hour – number of bins per hour (parameter of the strategy) to know the quantity of bins in a day (e.g. if bins of 30 minutes, n_bins_per_hour = 2)
fact – minutes of each bin (e.g. if bins of 30 minutes, fact = 30)
- Returns
array of the placed timeslots [0] and flexible dataframe [1]
- Return type
array with 2 positions
-
procsimulator.CommunityManagerStrategy module¶
-
class
procsimulator.CommunityManagerStrategy.
CommunityManagerStrategy
(cg, path_steps_minutes, path_steps_after_first, path_steps_after_second)[source]¶ Bases:
CommunityManager.CommunityManager
-
execute
()[source]¶ Executes the optimization process (implemented strategy using Multiple Knapsack): 1) First step - Prepares the input (arrays) for the process (bin_capacities, bin_maximums, timeslots_number, flexibitilies, items_max, etc) - Calls the Knapsack class with the input processed (execute_knapsack function) - Updates the consumption profiles based on the output of the knapsack 2) Second Step - Prepares the input (arrays) for the process (bin_capacities, bin_maximums, timeslots_number, flexibitilies, items_max, etc) - Calls the Knapsack class with the input processed (execute_knapsack function) - Updates the consumption profiles based on the output of the knapsack
-
procsimulator.CommunitySpecificator module¶
procsimulator.ConsumptionGenerator module¶
-
class
procsimulator.ConsumptionGenerator.
ConsumptionGenerator
(configuration_file, path_steps_seconds, path_steps_minutes)[source]¶ Bases:
object
-
calculate_community_baseload_consumption
(community)[source]¶ Creates a community_baseload.csv file with the baseload consumption of the community
- Parameters
community – community information (read from the JSON file)
-
calculate_community_energy_consumption
(community)[source]¶ Creates a community.csv file with the aggregate consumption of the community
- Parameters
community – community information (read from the JSON file)
-
calculate_community_not_baseload_consumption
()[source]¶ Creates a community_not_baseload.csv file with the non-baseload consumption of the community
-
calculate_contracted_power
(community)[source]¶ Calculates the contracted power of the community by summing all the contracted powers of each house presented in the json configuration file.
- Parameters
community – community information (read from the JSON file)
- Returns
contracted power of the whole community
-
calculate_energy
(contracted_power)[source]¶ Creates a energy.csv file with the total contracted power of the community
- Parameters
contracted_power – total contracted power of the community
-
calculate_max_of_a_timeslot
(start_date, end_date, appliance, house)[source]¶ Calculates the maximum power of an activity based on the consumption profile
- Parameters
start_date – start date of the activity (when the appliance is being used)
end_date – end date of the activity (when the appliance stops being used)
appliance – name of the appliance (corresponds to the name of the appliance folder of the dataset)
house – number of the house of the activity
- Returns
maximum power achieved by the appliance in this specific activity
-
convert_data_to_steps_of_one_minute
(community, just_a_day=False, database_files=False)[source]¶ Resample the consumption profiles from 1Hz (1 value per second) to 1/60Hz (1 value per minute)
- Parameters
community – community information (read from the JSON file)
just_a_day – if true, only 1 day is considered, otherwise all the days are considered
database_files – if true, converts the database files, otherwise convertes the community files (false should be used)
-
create_consumption_profiles
(community, days, config_files_path)[source]¶ Creates the consumption profiles based on the house and users files (.conf). The files are stored with a frequency of 1Hz and a folder for each house will be created (e.g. folders house0, house1, house2, etc)
- Parameters
community – community information (read from the JSON file)
days – number of days to generate data
config_files_path – path/folder where there are the house configuration files (.conf)
-
create_houses_files
(community)[source]¶ Creates house files with the extension “.conf” using ANTGen based on community configuration file. The files are generated and saved in the houses folder (e.g. house4).
- Parameters
community – community information (read from the JSON file)
-
create_users_files
(community)[source]¶ Creates users files with the extension “.conf” using ANTGen based on community configuration file. The files are generated and saved in the users folder (e.g. house2_Ann.conf).
- Parameters
community – community information (read from the JSON file)
-
date_ranges_overlap
(start1, end1, start2, end2)[source]¶ Checks if two date ranges overlap
- Parameters
start1 – Start of first date
end1 – End of first date
start2 – Start of second date
end2 – End of second date
- Returns
true if the date ranges overlap, and false otherwise
-
datetime_range
(start, end, delta)[source]¶ Generates a list between start and end times, with a specific step
- Parameters
start – start time
end – end time
delta – step between start and end
-
execute
(days, config_files_path, just_a_day=False, database_files=False)[source]¶ Executes a step of functions in order to create the consumption profiles of the dataset. 1) Gets the community information (from the JSON file) - get_community function 2) Creates the user files (with .conf extension) - create_users_files function 3) Creates the house files (with .conf extension) - create_houses_files function 4) Calculates the total contracted power of the community - calculate_contracted_power function 5) Creates the consumption profiles at 1Hz from ANTGen - create_consumption_profiles function 6) Converts the consumption profiles to 1/60Hz - convert_data_to_steps_of_one_minute function 7) Calculates community.csv with the aggregate consumption of the community - calculate_community_energy_consumption function 8) Calculates community_baseload.csv with the baseload of the community - calculate_community_baseload_consumption function 9) Calculates the community_not_baseload.csv with the non-baseload of the community - calculate_community_not_baseload_consumption function 10) Calculates energy.csv with the contracted power of the community - calculate_energy function 11) Plots the community baseline, baseload and non_baseload consumption - show_community_baseload_graph function
- Parameters
days – number of the days to generate data (profiles)
config_files_path – path/folder where there are the house configuration files (.conf)
just_a_day – if true, only 1 day is considered, otherwise all the days are considered
database_files – if true, converts the database files, otherwise convertes the community files (false should be used)
-
get_community
()[source]¶ Reads the community configuration file to get the community information It only reads the file in the first time. The rest of the times it just returns.
- Returns
community information (activities, schedules, people, appliances, etc)
-
get_community_flexibility
(community)[source]¶ Returns the flexibility of all houses of the community
- Parameters
community – community information (read from the JSON file)
- Returns
array containing all the flexibilities of all houses
-
get_timeslots
(community, is_flexible)[source]¶ Gets all the activities of the community (i.e. of all houses of the community). Based on the consumption files of each house, it extracts the activities done (start, end, duration, max_power, power, appliance and house)
- Parameters
community – community information (read from the JSON file)
is_flexible – if True, only the activities of the flexible appliances are extracted (Dishwasher, Vaccum Cleaner, Washing Machine, Dryer, Iron and Cooking Stove), otherwise all the appliances are extracted (Amplifier, Breadcutter, CD Player, Coffe Maker, Cooking Stove, Dishwasher, Dryer, Freezer, Iron, Kettle, Microwave, PC, Printer, Refrigerator, Toaster, TV, Vaccum Cleaner and Washing Machine)
- Returns
array containing all the activities
-
show_community_baseload_graph
(community, days)[source]¶ Plots the community baseline, baseload and non_baseload
- Parameters
community – community information (read from the JSON file)
days – number of days to simulate
-
procsimulator.DataAcquisition module¶
-
class
procsimulator.DataAcquisition.
DataAcquisition
[source]¶ Bases:
abc.ABC
-
filter_data
(data, start_date, end_date)[source]¶ Filters dataframe according to the start and end dates
- Parameters
data – dataframe to be filtered
start_date – start date (to be filtered)
end_date – end date (to be filtered)
-
procsimulator.DataFromAPI module¶
procsimulator.DataFromCSV module¶
procsimulator.DataFromModel module¶
procsimulator.DataFromSmile module¶
procsimulator.Evaluation module¶
-
class
procsimulator.Evaluation.
Evaluation
(reg, dataframe, production_baseload=0)[source]¶ Bases:
object
-
get_average_power_not_used_from_pv
()[source]¶ Gets the average power not used (wasted) from the PV in the consumption profile (dataframe).
- Returns
average power not used (wasted) from the PV (in kW)
-
get_average_power_used_from_grid
()[source]¶ Gets the average power used from the grid in the consumption profile (dataframe).
- Returns
average power used from the grid (in kW)
-
get_average_power_used_from_pv
()[source]¶ Gets the average power used from the PV in the consumption profile (dataframe).
- Returns
average power used from the PV (in kW)
-
get_costs
(degradation_cost)[source]¶ Calculates the costs of the system according to the degradation cost and the energy used from the grid. :param degradation_cost: degradation cost for each kWh :return:
-
get_energy_exported_to_grid
()[source]¶ Gets the total energy not used from the production in kWh :return:
-
get_energy_imported_from_grid
()[source]¶ Gets the total energy imported from the grid in kWh :return:
-
get_energy_not_used_from_pv
()[source]¶ Gets the total energy not used (wasted) from the PV in the consumption profile (dataframe) in 24 hours.
- Returns
total energy not used (wasted) from the PV (in kWh)
-
get_energy_of_timeslots_list
(list_timeslots)[source]¶ Gets the total energy used from the timeslots/activities presented in the list. It can be used in order to calculate the quantity of energy used from the placed timeslots (using, for instance, the placed_timeslots list) or to calculate the quantity of energy of the timeslots that were not placed (using, for instance, the not_placed_timeslots list)
- Parameters
list_timeslots – list of timeslots/activities
- Returns
total energy of the timeslots/activities of the list (in kWh)
-
get_energy_used_from_grid
()[source]¶ Gets the total energy used from the grid in the consumption profile (dataframe) in 24 hours.
- Returns
total energy used from the grid (in kWh)
-
get_energy_used_from_production
()[source]¶ Gets the total energy used from the production in kWh :return:
-
get_energy_used_from_pv
()[source]¶ Gets the total energy used from the PV in the consumption profile (dataframe) in 24 hours.
- Returns
total energy used from the PV (in kWh)
-
get_maximum_grid_peak
()[source]¶ Gets the maximum grid peak in the consumption profile (dataframe). Returns the maximum consumption when the energy acquired from the grid is higher than the production_baseload parameter
- Returns
maximum grid peak (in kW)
-
get_maximum_magnitude_peak
()[source]¶ Gets the maximum magnitude peak in the consumption profile (dataframe). Returns the maximum value of energy acquired from the grid when the total is higher than the production_baseload parameter
- Returns
maximum magnitude peak (in kW)
-
get_minimum_grid_peak
()[source]¶ Gets the minimum grid peak in the consumption profile (dataframe). Returns the minimum consumption when the energy acquired from the grid is higher than the production_baseload parameter
- Returns
minimum grid peak (in kW)
-
get_minimum_magnitude_peak
()[source]¶ Gets the minimum magnitude peak in the consumption profile (dataframe). Returns the minimum value of energy acquired from the grid when the total is higher than the production_baseload parameter
- Returns
minimum magnitude peak (in kW)
-
get_peaks_number
()[source]¶ Gets the number of peaks in the consumption profile (dataframe). A peak is considered when the power acquired from the grid in a specific minute exceeds the production_baseload parameter (i.e. when the netload is higher than the production_dataframe parameter)
- Returns
number of peaks
-
get_self_consumption
()[source]¶ Calculates the Self Consumption according to 2 metrics of this class: energy used from the PV and energy not used (wasted) from the PV. The Self-Consumption (SC) is the amount of electricity generated and consumed with respect to the total generation.
- Returns
self consumption
-
get_self_sufficiency
()[source]¶ Calculates the Self Sufficiency according to 2 metrics of this class: energy used from the PV and energy used from the grid. The Self Sufficiency (SS) measures the consumption amount supplied by generation with respect to the total consumption (independence from the grid).
- Returns
self sufficiency
-
get_ss_with_storage
()[source]¶ Calculates the Self Sufficiency in % considering storage (considering charge, dsicharge, losses, eficiency, delta SOC, etc) :return:
-
get_timeslots_list_number
(list_timeslots)[source]¶ Gets the number of timeslots/activities in a specific list. It can be used in order to identify the number of placed timeslots (using, for instance, the placed_timeslots list) or to identify the number of unplaced timeslots (using, for instance, the not_placed_timeslots list).
- Parameters
list_timeslots – list of timeslots/activities
- Returns
number of timeslots/activities in a list
-
procsimulator.Knapsack module¶
-
class
procsimulator.Knapsack.
Knapsack
(dates, items, bin_capacities, numbers, bins_maximum, items_maximum, baseload, fact, n_bins_per_hour, flexibilities)[source]¶ Bases:
object
-
create_data_model
()[source]¶ Creates the data model for the Multi Knapsack problem, according to the input received in the constructor
- Returns
data model (list with different arrays and values)
-
execute_knapsack
(step)[source]¶ Executes the Multi Knapsack problem in order to retrieve the optimal solution. 1) Creates the solver 2) Creates the data model (using the function create_data_model) 3) Defines the variables and matrix 4) Defines the constraint(s) 5) Defines the objective function(s) 6) Solves the problem 7) Gets the result 8) Gets some information from the output
- Parameters
step – 1 if refers to the 1st step of the optimization or 2 if refers to the 2nd one
- Returns
array with all timeslots [0], array with the placed timeslots [1] and array with the unplaced timeslots [2]
- Return type
an array with 3 positions
-
show_results
(objective, title, type)[source]¶ Shows graphically the results (curves) of different objective functions, in order to understand their behaviour.
- Parameters
objective – objective function (equation)
title – title of the graph
type – “min” or “max”, depending if want to identify the min or the max values of the function
-