A collection of electric system components classes for simulation purposes
Project description
ElectricSystemClasses
A Python package providing a collection of classes for simulating electric systems. The library includes components like electric vehicles (EVs), generators, grids, storage systems, and loads. It is designed for use in simulations and modeling of power systems, focusing on flexible, easy-to-use components for energy management scenarios.
Features
- Electric Vehicles (EVs): Model and manage electric vehicle characteristics such as power, state-of-charge, and classification.
- Generators: Simulate electricity generation profiles, including scaling and adjusting the length of the profiles.
- Grid: Model the power exchange between the system and the grid, tracking the energy flow.
- Storage Systems: Simulate energy storage components, including charging and discharging behaviors.
- Constant Load: A basic class for representing time-invariant loads.
- Variable Load: A class representing time-variant loads.
- Programmable Load With Activation: A class for representing time-programmed loads with reactivation availability.
Full DOC
At the bottom.
Installation
You can install the electricsystemclasses package via pip.
pip install electricsystemclasses
License
This project is licensed under the Server Side Public License (SSPL), Version 1.0. You may not use this file except in compliance with the License.
Contributing
I welcome contributions to this project! If you'd like to contribute contact me. Ensure that your code adheres to the coding style of the project, and that you have tested your changes.
Contact
email: rmmenichelli@gmail.com Feel free to ask for clarification.
Full DOC
The package provides a full simulation engine to study the behaviour of multiple electric components. Each component is represented by instances of different classes, each requiring different attributes.
The simulation is iterative-based and works around two main components, the simulate function and a user defined function representing a single time frame of simulation. The simulate function takes as arguments:
step_size: the step size of the simulation in seconds s. Type int or float.
period: the amount of hours to be simulated. The simulation works starting from zero and finishing at the value of period. The total simulated steps will be period * 3600 / step_size.
user_timeframe: a function that needs to be defined by the user representing the logics within each timeframe. The name could be any, usually timeframe is chosen. This function need to be defined as:
def timeframe(i, h, t):
#user code
The function needs to be defined with three arguments representing in order:
-
the iteration
iof the simulation. To be used for any purposes and as argument of some classes methods. -
the current simulated step in hours, usually
h. To be used for any purposes and as argument of some classes methods. -
the step size in hours, usually
t. To be used for any purposes and as argument of some classes methods.
In each simulated step, the logics defined inside the timeframe function are applied. All attributes containing the power history and state of charge of instances are updated each step.
Classes
Constant Load
The ConstantLoad class represents simple loads having constant power consumption.
The __init__ takes as arguments:
id: could be of any type. Can be used to implement logics based on numerical ids or to add descriptive informations about the load kind.
e.g. 1 or "hvac".
required_power: the power consumption of the load in kW. Type float or int.
Attributes
All the arguments of the __init__.
power_history: a list containing all the simulated power values of the instance, inkW. It gets filled during the simulation.
Class Attributes
all_loads: a list containing all instances of the class.
Class Methods
-
get_allLoads(cls): returns a list containing all instances of the class. -
update(cls, i): takes as arument the iterationiprovided by the simulation engine. It updates the attributepower_historyif not supplied during the user defined timeframe.
Instance Methods
supply(self, input_power): if theinput_poweris less than therequired_powerthe function raises an error. The load can't be supplied. In any other cases it returns the excess power, difference ofinput_powerandrequired_power.
Electric Vehicle (EV)
The EV class represents electric vehicles.
The __init__ takes as arguments:
id: could be of any type. Can be used to implement logics based on numerical ids or to add descriptive informations about the load kind.
e.g. 1 or "EV1".
max_discharge_power: the maximum power dischargeable by the vehicle in kW. Type float or int.
max_charge_power: the maximum power the vehicle can charge at, in kW. Type float or int.
opt_power: the optimal charge and discharge power of the vehicle in kW. Type float or int.
capacity: the capacity of the vehicle in kWh. Type float or int.
t_depart: the departure time of the vehicle in h. Type float or int.
t_arrival: the arriving time of the vehicle in h. Type float or int.
soc_lim_kwh: the minimum target state of charge to be reached during the time between t_arrival and t_depart, in kwh. It is not guaranteed due to the max_charge_power limitation.
soc_min_kwh: the state of charge below which the vehicle is classified as critical, meaning having really low state of charge.
Attributes
All the arguments of the __init__.
soc_history_kwh: a list containing all values of the state of charge in kWh. It gets filled during the simulation.
power_history: a list containing all the simulated power values of the instance, in kW. It gets filled during the simulation.
Class Attributes
-
all_EV: a list containing all instances of the class. -
crit_EV: a list containing all vehicles having state of charge belowsoc_min_kwh. -
norm_EV: a list containing all vehicles having state of charge abovesoc_min_kwhand belowsoc_lim_kwh. -
major_EV: a list containing all vehicles having state of charge abovesoc_lim_kwh. -
prior_EV: a list containing all vehicles having state of charge such that if recharged atopt_powerthey will not reach the targetsoc_lim_kwh, therefore having a priority state overnorm_EV.
Class Methods
-
classify_EV(cls, h): a method that classifies the instances of the class based on the logics ofcrit_EV,norm_EV,prior_EV,major_EV, at instanceh.his the current simulated time in hours given as attribute of the functiontimeframe. -
charge_group(cls, group, power, t): a method that charges a group of vehicles equally dividing the input power. It returns the power that could had not be handled by the vehicles in the group due to power or capacity limitations. Arguments:group: a list containing instances of the class. Could also be one of the classifying groups such asnorm_EV. Typelist.power: the input power inkW. Typeintorfloat.t: the step size in hours. Given as argument of the functiontimeframe. -
discharge_group(cls, group, power, t): a method that discharges a group of vehicles equally dividing the requested power. It returns the requested power that could had not be handled by the vehicles in the group due to power or capacity limitations. Arguments:group: a list containing instances of the class. Could also be one of the classifying groups such asnorm_EV. Typelist.power: the requested power inkW. Typeintorfloat.t: the step size in hours. Given as argument of the functiontimeframe. -
discharge_group_prop(cls, group, power, t): a method that discharges a group of vehicles proportionally, dividing the requested power based on themax_discharge_powerof the instances. It returns the requested power that could had not be handled by the vehicles in the group due to power or capacity limitations. Arguments:group: a list containing instances of the class. Could also be one of the classifying groups such asnorm_EV. Typelist.power: the requested power inkW. Typeintorfloat.t: the step size in hours. Given as argument of the functiontimeframe. -
get_allEV(cls): returns a list containing all instances of the class. -
getCritEV(cls): returns the listcrit_EV. -
getNormEV(cls): returns the listnorm_EV. -
getPriorEV(cls): returns the listprior_EV. -
getMajorEV(cls): returns the listmajor_EV. -
updateAllEV(cls, i): takes as arument the iterationiprovided by the simulation engine. It updates the attributespower_historyandsoc_history_kwhif untouched during the user defined timeframe.
Instance Methods
-
charge(self, power, t): a method that charges an instance of the class. Takes as arguments an input powerpower, and the step size in hourstgiven in the functiontimeframe. It return the excess power that could had not be handled by the vehicle due to power or capacity limitations. -
discharge(self, power, t): a method that discharges an instance of the class. Takes as arguments a discharge powerpower, and the step size in hourstgiven in the functiontimeframe. It return the excess discharge power that could had not be handled by the vehicle due to power or capacity limitations.
Generator
A class representing generators.
The __init__ takes as arguments:
id: could be of any type. Can be used to implement logics based on numerical ids or to add descriptive informations about the load kind.
e.g. 1 or "pv1".
profile: a list containing the values of the generated power in kW. Type list containing int or float. The length must be equal or greater than the number of simulated steps. Can be scaled and resized using instance methods scale_profile, resize_profile, and resize_profile_to_simulation.
Attributes
All the arguments of the __init__.
Class Attributes
all_gen: list containing all instances of the class.
Class Methods
-
getAllGen(cls): returns a list of all instances of the class. -
from_csv_column(cls, gen_id, filepath, col_index, delimiter=",", has_header=False): a method that creates an instance of the class based on values contained in a csv column. Takes as arguments anidof any type, thefilepathof the csv file,col_indexthe column index starting from 0, the delimiter of the csv file (default=","),and a boolean representing if an header is present and needs to be skipped (default=False). -
from_csv_row(cls, gen_id, filepath, row_index, delimiter=",", has_header=False): a method that creates an instance of the class based on values contained in a csv row. Takes as arguments anidof any type, thefilepathof the csv file,row_indexthe row index starting from 0, the delimiter of the csv file (default=","),and a boolean representing if an header is present and needs to be skipped (default=False).
Instance Methods
-
scale_profile(self, factor): a method that scales the profile. Takes as input the scale factorfactor, typeintorfloat. -
resize_profile(self, new_len): adapts the dimensions of the profile to a new length. If the new length is smaller than the current one, it randomly deletes elements, otherwise it randomly adds elements by taking the average of the two neighbours. -
resize_profile_to_simulation(self, new_len): adapts the dimensions of the profile to the one needed in the simulation, defined bystepandperiod. If the required length is smaller than the current one, it randomly deletes elements, otherwise it randomly adds elements by taking the average of the two neighbours. -
derivative(self, i): returns the derivative of the instanceprofileat iterationi, takesithe iteration given in thetimeframeas argument.
Grid
A class representing an infinite power grid.
The __init__ takes as arguments:
id: could be of any type. Can be used to implement logics based on numerical ids or to add descriptive informations about the load kind.
e.g. 1 or "poc1".
Attributes
All the arguments of the __init__.
power_history: a list containing all values of the grid power in kW. It gets filled during the simulation.
Class Attributes
all_grids: list containing all instances of the class.
Class Methods
getAllGrids(cls): returns a list of all instances of the class.
Instance Methods
-
withdraw(self, power_value): a method that represents withdrawing power from a grid instance. -
inject(self, power_value): a method that represents injecting power from a grid instance. -
update(cls): a method that updates the instancepower_historyattribute if unchanged by the user defined logic.
Programmable Load With Reactivation
A class representing a programmable load defined:
-
a period of activation in hours, defined by a start time and an end time. This is the period in which the load can be activated, the period is defined representing as 0 hours the start of the simulation. Therefore in a simulation of a single day starting from midnight, a load that wants to be activated only between 10am and 3 pm will have start time 10 and end time 15. Only between this period the
activate(h)function will execute. -
a minimum of active time in hours, if greater than zero the load will not be disactivated before this time has passed.
-
a reactivation boolean, representing if the load needs to be reactivated when a repeated call of the activate method happens.
-
a deactivation delay active only for reactivable loads in seconds.
The __init__ takes as arguments:
id: could be of any type. Can be used to implement logics based on numerical ids or to add descriptive informations about the load kind.
e.g. 1 or "poc1".
Attributes
All the arguments of the __init__.
power_history: a list containing all values of the grid power in kW. It gets filled during the simulation.
Class Attributes
all_grids: list containing all instances of the class.
Class Methods
getAllGrids(cls): returns a list of all instances of the class.
Instance Methods
-
withdraw(self, power_value): a method that represents withdrawing power from a grid instance. -
inject(self, power_value): a method that represents injecting power from a grid instance. -
update(cls): a method that updates the instancepower_historyattribute if unchanged by the user defined logic.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file electricsystemclasses-2.0.3.tar.gz.
File metadata
- Download URL: electricsystemclasses-2.0.3.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cef641b36c1d4c572f4d6b0f8fdcb83d7e1e308b5eb107db825eab54153691c3
|
|
| MD5 |
afb30f8d309ca7bc0d287ea2642eea65
|
|
| BLAKE2b-256 |
8aa5a139d882ec1028f60cc802f2e11d8666f7fe91447d6ee9ea003eeae23f4a
|
File details
Details for the file electricsystemclasses-2.0.3-py3-none-any.whl.
File metadata
- Download URL: electricsystemclasses-2.0.3-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f1633969d50b66aa3e83c31ff9c6eb237143f8734517567d57b26670c4a4fe9
|
|
| MD5 |
040642f8b5f87ec933cfc2c414f8b3e3
|
|
| BLAKE2b-256 |
caaebe5d3a9ccc9de66d89cad2917a9cad836607d00fd9b8f90bf48cab193297
|