Edinburgh Explorer PyLESA: A Python modelling tool for planning-level Local, integrated, and smart Energy Systems Analysis

PyLESA is a modelling tool for the planning-level design of local, integrated and smart energy systems. It was developed to tackle gaps in existing planning-level tools: (i) adaptable and transparent source code; (ii) temperature dependence for heat pump models; (iii) stratification model for thermal storage models; (iv) modelling of evolving electricity markets; and (v) model predictive control. PyLESA uses a flexible object-orientated approach to model thermal and electrical supply, demand, and storage technologies following fixed order and model predictive control strategies. Functionality is illustrated to size heat pumps and hot water tanks for a wind power integrated district heating system.


Motivation and significance
The importance of energy modelling tools has increased in recent years as energy systems become more complex due to the increase in the deployment of distributed and stochastic renewable generation [1]. Planning-level modelling tools have been used to quantify the performance of concept designs in scoping/parametric/scenario analysis which typically include complex interaction between renewable generation and demands [2]. These tools need to be able to fully capture the potential benefits of concept designs while often relying on limited available * Corresponding author.
E-mail address: andrew.lyden@ed.ac.uk (Andrew Lyden). data. In this paper a novel planning-level modelling tool, PyLESA (Python for Local Energy Systems Analysis) is described which is capable of modelling energy systems which are local, integrated, and smart. The performance of these types of systems need to be explored as they can have a vital role in aiding the transition to a net zero energy system.
Local energy systems consist of energy production units and demand side management (DSM) enabling technologies colocated with demands [3]. Integration of these local energy systems within wider national energy system should be considered at the design stage due to the increasing renewable generating capacity on national grids (e.g. in Scotland renewable sources accounted for 74.6% of gross electricity consumption in 2018 [4] to very large capacities of expensive storage technologies being installed [5].
Integrated energy systems can participate with wider electricity markets as a way of adding value to the wider energy system. Electricity markets are changing to reflect the transition from dispatchable power generation to stochastic, renewable power generation. Traditional tariffs such as flat rate or day/night periods are being challenged by emerging half hourly time-of-use tariffs which are issued a day ahead and are linked to the wholesale market. These incentivise users with reduced prices during periods of surplus zero marginal cost renewable generation, and correspondingly dis-incentivise with increased prices during periods of peak demand and low renewable generation. This reflects pricing already being seen in wholesale markets with negative pricing in high wind and low demand periods [6]. Additionally, grid services which provide response to stress events to ensure grid stability could in the future be aided by local energy systems.
Smart energy systems enable synergistic benefits from multisector integration (i.e. electricity, heat, transport) [7]. Energy sectors which have been historically considered in silo can benefit from being designed holistically with other sectors. For example, this could be designing a system consisting of a heat pump with a thermal store controlled to turn on when there is local excess generation of wind power [8]. These require connected systems to facilitate logic decisions based on external signals [9]. Tools such as EnergyPLAN [10] have been used to model smart energy systems, however, this tool is better suited at the national-scale and relies primarily on exogenous supply and demand profile inputs.
A plethora of tools have been developed to model energy systems across a range of spatial (e.g. building , district, national) and temporal (e.g. minutely, hourly, yearly) ranges in order to capture the different technologies, environmental influences, and human behaviours which influence the ability of the system to meet demands under chosen performance criteria [11][12][13][14]. 51 energy system modelling tools were previously reviewed by the authors against their ability to model local energy systems incorporating storage and demand side management (DSM), and the following gaps were identified [2].
• Ability to adapt source code and import or exploit functionality from elsewhere.
• Temperature dependence for the heat pump models. • Detailed model with temperature characteristics for the thermal storage models.
• Ability to model the evolving electricity markets and tariffs.
• Ability to explore model predictive controls. This paper presents PyLESA which is open-source and contains the required functionality to address these gaps. PyLESA is capable of modelling systems containing both electrical and thermal sector technologies in hourly timesteps. The choice of hourly timesteps stems from the typically limited availability of data available at the planning-stage, i.e., weather or demand inputs are only available in hourly timesteps. The development of the tool has so far focussed on systems with heat pumps and thermal storage alongside time-of-use electricity tariffs and model predictive control. The open-source and object-orientated modelling tool architecture offers scope for future development and reuse. For example, it is anticipated that the tool provides a useful framework for future development such as participation in grid balancing mechanisms. The tool has been applied to a UK local energy system, and while the tool has not yet been applied in other countries, it is expected to be applicable to local energy systems in other countries with heat and electricity demands.

Software description
The architecture and functionality of PyLESA are described in this section at a high-level and in terms of the interaction of the different model classes and assessment methods used to model a local energy system. Detailed descriptions of the mathematical models implemented, and associated validations, can be seen in Appendix A.

Software architecture 2.2. Software functionalities
The functionality of PyLESA (first steps were introduced in [15]) is described in Table 1 which shows the modelling and assessment capabilities, and highlights, with bold text, the capabilities which address the gaps in existing modelling tools (described briefly below). The heat pump model uses standard test data to generate performance maps using multiple variable linear regression analysis with explicit temperature dependence. Thermal storage is modelled using a multi-node approach to represent the stratification and to incorporate thermal characteristics through state of charge dependence on node temperatures. The tariff generator function in PyLESA can be used to perform analysis of future energy system scenarios which may include electricity pricing structures which are highly differential and based on renewable power generation. Model Predictive Control (MPC) is included as a supervisory control strategy which can capture dynamic influences and optimise the performance of the components according to least cost. The MPC optimises based on cost and therefore does not preferentially treat any generation unit, and local renewable sources are assigned zero marginal cost. However, the Fixed Order Control (FOC) allows the user to set a priority order of dispatch and use of storage.

Illustrative example
PyLESA, has been applied to a sizing study for a proposed design of a residential district heating scheme consisting of electrical and heat demands, on-site PV, grid-connection, heat pump, and hot water tank (initial results using the fixed order control strategy were reported in [16]). A central aim was to investigate the optimal cost size combinations of heat pump and hot water tank. Results indicate that Model Predictive Control (MPC) offers savings over Fixed Order Control (FOC) for all investigated electricity tariffs. The lowest levelized cost of heat for the existing tariffs modelled was obtained for a time-of-use tariff, 750 kW heat pump and 500 m 3 hot water tank combination. For a future wind-influenced tariff, a 1000 kW heat pump and 2000 m 3 hot water tank was cost optimal and showed MPC strongly benefits over FOC with levelized heat costs reducing by 41%, and heat demand met by renewables increasing by 18%.
The operation of the MPC with the wind tariff is displayed in Fig. 2 for a winter 10-day period with an 8-day windless spell from the end of day 2. The displayed configuration uses a 168hour prediction horizon, the wind-based tariff, along with a 3000 kW heat pump and 3000 m 3 hot water tank size combination.
Looking at Fig. 2, in the first two days (50 h) there are periods of high wind resulting in low cost, as seen in dips on the 3rd graph from the top. During these periods the heat pump (red line on 1st graph) operates at maximum output to fill storage and meet demand. Additionally, the auxiliary electric heat (blue line on 1st graph) turns on because the direct electric heat is cheaper in these periods than operating the heat pump in the high-cost periods. The hot water tank is then used to cover a large proportion of the 8-day high-cost period, as can be seen by the trend of reducing node temperatures (2nd graph). However, there is not enough capacity to cover this entire period and the heat pump occasionally operates to charge the hot water tank. This occurs during the highest heat pump performance periods which are when the air temperature is highest. 3D plots of key performance indicators such as Levelized Cost of Heat (LCOH) are output from PyLESA, as in Fig. 3. The LCOH optimum size combination for a wind tariff is a 1000 kW heat pump and a 2000 m 3 hot water tank, marking a significant increase in optimal hot water tank size and similar optimal heat pump size compared to existing tariffs. The wind tariff incentivises load shifting by offering high price differentials between windy and non-windy periods, in addition to the day/night differential. The MPC with the wind tariff uses a 168-hour prediction horizon which allows the operation to account for long periods of lots of wind or no wind.

Impact
PyLESA has been developed to address the identified gaps of existing planning-level local energy system modelling tools, and these are discussed in turn in this section.

Ability to adapt source code and import or exploit functionality from elsewhere
PyLESA was written in the programming language Python which was chosen because it is open source and widely used across science and engineering fields [17]. This meant that PyLESA could build on the state of the art, utilising energy system models previously built, as well as providing a platform from which the developed models can be shared with other researchers in the energy system modelling community (see [18]). As compared to the reviewed tools which were primarily written in programming languages which require expert software development skills, or are completely closed source, PyLESA offers the explicit ability for others to adapt the source code or to easily couple PyLESA with other energy system models developed in Python.

Temperature dependence for the heat pump models
PyLESA uses a more detailed heat pump modelling approach which uses standard test data [19] to generate performance maps using multiple variable linear regression analysis which incorporates explicit dependence on both flow and heat source temperature. This method captures the COP across a range of flow and heat source temperatures using multiple data inputs which should be available from standard test data. It builds on the approach of tools such as EnergyPRO which calculates COP for the range of flow and heat source temperatures from the input COP under a single set of conditions.

Detailed stratification model for the thermal storage models
The multi-node modelling approach used by PyLESA includes thermal characteristics modelled in more detail and advances on the simple energetic models typically used by existing tools. In the multi-node model, the state of charge and heat loss of the hot water tank is dependent on the node temperatures [20]. This approach means that a hot water tank can be represented with more detail while maintaining low input requirements which is helpful at the planning stage.

Ability to model the evolving electricity markets and tariffs
PyLESA can generate a range of electricity tariffs which could be obtained from an energy supplier (e.g., domestic) including those which reflect existing and emerging tariffs such as the flat rates, variable periods, and time-of-use tariffs. Additionally, a wind-based electricity tariff generator can be used and is an example of a tariff which could exist in the UK in the future. This is an advancement on the ability of existing modelling tools which either have in-built simple tariffs which use fixed prices and unlimited import and export or allow the input of external user-generated tariffs. Balancing and ancillary services are not currently included but functionality for this is planned as future tool development.

Ability to explore model predictive controls
In PyLESA an economic MPC strategy was developed and incorporated [21]. A distinct disadvantage of the existing modelling tools was the lack of options for control strategies with a notable gap for utilising predictive controls. These typically use simple rule-based controls which need to be adjusted by an expert in order to minimise import costs. There are also cases where on-site renewable production competes with a variable electricity tariff which makes it difficult to identify a low-cost operation schedule. Modelling local energy systems including a model predictive control strategy allows the performance to be optimised. MPC enables the operation to minimise cost, even when multiple competing dynamic influences are active, such as heat pump performance, variable tariffs, and on-site renewable power generation.

Conclusions
PyLESA is a modelling tool which can usefully aid the planninglevel design of local, integrated, and smart energy systems. It has contributed to tackling several gaps which were identified in a review of the modelling capabilities of existing energy system tools. PyLESA contains the following extendable and adaptable functionality: resources and demand assessment methods; electricity production technologies; heat pumps; hot water tanks; electricity tariffs; fixed order controls; model predictive controls; and key performance indicators. It has been used in the illustrative example where it shows the advantage of combining flexible tariffs with optimally sized heat pumps and thermal storage.

Declaration of competing interest
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Funding
This work was supported by the UK Engineering and Physical Sciences Research Council (EPSRC) grant no. EP/M508159/1.