Home

Awesome

optihood: energy modelling and optimization framework

optihood provides a complete python-based framework to OPTImize the investment in alternative energy technologies (heat pump, solar thermal, PV, etc.) as well as the operation of available energy resources (natural gas, sun, grid electricity, etc.) for decentralized energy networks on a neighbourHOOD-scale. It is designed to facilitate the researchers and energy planners in optimizing an energy neighbourhood in terms of cost and/or environmental criteria. It enables the users to perform both single-objective and multi-objective optimization and analysis. The energy model and it's associated parameters can be defined easily using an excel file. Additionally, a variety of plotting methods are defined for easy and fast result visualization.

Documentation

The documentation can be found on https://optihood.readthedocs.io/.

Prerequisites

In order to use optihood, the following prerequisites are needed on your machine:

Installation

As of now, optihood is available as an open source code and needs to be installed from source. Please follow the instructions mentioned below to complete the installation. The commands given below are suited for the Windows platform and should be run from within the optihood directory in a Command Prompt. For other platforms, similar alternative commands could be used.

  1. Clone the optihood repo to a folder called 'optihood' on your local machine:

    git clone https://github.com/SPF-OST/OptiHood.git
    
  2. All the next commands should be run from within the optihood folder. Create a virtual environment and activate it:

    py -3.12 -m venv venv
    venv\Scripts\activate
    

    If using python version other than 3.12, replace -3.12 with -3.X (3.X being the python version).

  3. Install the requirements into the created virtual environment. The requirements.txt file needs Python 3.12. If using another version, use pip tools to compile the provided requirements.in file before installing the requirements:

    venv\Scripts\python.exe -m pip install --upgrade pip
    pip install wheel
    pip install -r requirements.txt
    

    It might be required to install C++ build tools. To do that, click on the link that appears with the error message and follow the instructions (it is the lapack package that is missing). In order to be able to install the missing package, it is required to have a complete Visual Studio instance and installing it with the "Desktop development with C++" workload.

  4. Verify the installation of the oemof package and the solver by running the installation test in your virtual environment:

    oemof_installation_test
    

    If the installation is successful a message similar to the following would display (the installed solver would be marked as working):

    *****************************
    Solver installed with oemof
    cbc: not working
    glpk: not working
    gurobi: working
    cplex: not working
    
    *****************************
    oemof successfully installed.
    *****************************
    
  5. To test whether the installation worked well, you could run a basic example.

  6. Run the test suite using:

    pytest

Defining an energy network

Optihood offers a several functionalities to define an energy network, optimize it and visualize the results, which provides the user with a complete framework for optimization without the need to code by hand.

An energy network can be defined as an object of the EnergyNetworkIndiv class or the EnergyNetworkGroup class. This object then acts as the primary container for the model. The EnergyNetworkClass is the main parent class, from which two child classes EnergyNetworkIndiv and EnergyNetworkGroup are inherited. Either EnergyNetworkIndiv class or EnergyNetworkGroup class could be used to define an energy network. The choice mainly depends on whether the buildings are linked together (electrically and/or thermally) or not.

If the buildings within an energy network do not share electricity and/or heat, EnergyNetworkIndiv class is used:

import EnergyNetworkIndiv
network = EnergyNetworkIndiv(dateTimeIndex, tSH=35, tDHW=55)

Otherwise, if the buildings are expected to share energy (electrical and/or heat), EnergyNetworkGroup class is used:

import EnergyNetworkGroup
network = EnergyNetworkGroup(dateTimeIndex, tSH=35, tDHW=55)

The first parameter to be passed in both the cases is a Datetime index. This parameter gives the time range for an optimization model. The Datetime index could be defined using date_range() in pandas:

import pandas as pd
dateTimeIndex = pd.date_range('2021-01-01 00:00:00', '2021-12-31 23:00:00', freq="60min")

The second and the third parameters tSH and tDHW define the temperatures for space heating and domestic hot water production, respectively.

Once the 'network' object has been created, the next step then is to build the model from an input excel file which defines different components which constitute the model, how they are connected and their associated parameters:

network.setFromExcel(inputExcelFilePath, numberOfBuildings, clusterSize, opt)

'inputExcelFilePath' gives the path of the excel input file. 'numberofBuildings' is an integer parameter specifying the number of buildings defined in the excel file. The last two parameters clusterSize and opt are optional. The 'opt' parameter could be either 'costs' (default value) or 'env' depending on which criteria should be optimized. The 'clusterSize' parameter is used to provide a selected number of days which could be assumed representative of the entire time range. For example: two typical days could be selected to model the entire year, which could represent two clusters summer and winter. This would improve the optimization speed. If not given during the function call, the default value of the clusterSize parameter assumes no day clusters.

Input Excel File

The input excel file is used to define an optimization model and set the model parameters. Each sheet of this excel file is structured to defin different components, such as buses, storages and transformers, their respective parameters, connections between these components and the building to which they belong.

The input excel file typically has 9-10 sheets, each defining a different component type of the model.

buses

This excel sheet defines the buses used in the energy network. Buses define the connections between different components. Each row of this excel sheet represents a bus node in the model.

commodity_sources

This sheet defines the different commodity sources which serve as an energy input to the model. The parameters label, active and building are analogous to the parameters described earlier for buses.

demand

The nodes related to the energy demand i.e. sink are defined in this sheet. The parameters label, active and building are analogous to the parameters described earlier for buses.

transformers

The nodes related to the energy conversion units (or transformers) such as CHP, heat pump, etc. are given in this excel sheet. The parameters label, active and building are analogous to the parameters described earlier for buses.

solar

This excel sheet defines the parameters related to the solar components such as solar thermal collector and PV panels. The parameters label, active and building are analogous to the parameters described earlier for buses. from and to parameters have been previously defined for commodity sources and demand sheets, respectively, while the cost and environmental impact paramaters are described under transformers sheet.

storages

This excel sheet defines the parameters related to the energy storage units such as battery and hot water tank. label, active and building have been defined previously for buses excel sheet. A description of from and to has been given in commodity sources and demand sheets, respectively. The cost and environmental impact parameters are described in the transformers sheet section. capacity_min and capacity_max are described in the solar excel sheet section.

stratified_storage

This excel sheet defines the parameters relevant to stratified thermal storage. The pre-calculations given in oemof-thermal have been used to linearize the thermal hot water storage. The parameter names used here are similar to the parameters defined in oemof-thermal.

links

This excel sheet defines the parameters for electricity and space heating links. The buildings could share electricity production and/or space heat production. Links allow this sharing to be possible. label and active have been defined already for buses excel sheet. invest_base and invest_cap parameters (defined in the transformers sheet section) are only relevant for space heating links in the present stage of development.

csv_data

The paths to CSV files containing demand profiles, weather data and electricity impact data are to be given in this excel sheet. INFO gives further information about each row.

grid_connection

This excel sheet should not be modified by the users. It defines the separation of the flows from electricity grid and the produced electricity flows to make sure that the grid electricity is not stored in batteries.

Collaborators

SPF/OST & HEIG-VD