-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic central heating temperatures (#1206)
* feat: Add rule to build central heating temperature profiles, adjust build_cop_profiles accordingly * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * style: make new config settings prettier * docs: add file headers * docs: update configtables and module docstring * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * docs: update release notes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore: use smooth ambient temperature through rolling window; remove default vals in class * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update doc/configtables/sector.csv --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Amos Schledorn <a.schledorn@tu-berlin.de> Co-authored-by: Fabian Neumann <fabian.neumann@outlook.de>
- Loading branch information
1 parent
d2f8162
commit bf2d82a
Showing
7 changed files
with
468 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
...ts/build_central_heating_temperature_profiles/central_heating_temperature_approximator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
# -*- coding: utf-8 -*- | ||
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import pandas as pd | ||
import xarray as xr | ||
|
||
|
||
class CentralHeatingTemperatureApproximator: | ||
""" | ||
A class to approximate central heating temperatures based on ambient | ||
temperature. | ||
Attributes | ||
---------- | ||
ambient_temperature : xr.DataArray | ||
The ambient temperature data. | ||
max_forward_temperature : xr.DataArray | ||
The maximum forward temperature. | ||
min_forward_temperature : xr.DataArray | ||
The minimum forward temperature. | ||
fixed_return_temperature : xr.DataArray | ||
The fixed return temperature. | ||
lower_threshold_ambient_temperature : float | ||
Forward temperature is `max_forward_temperature` for ambient temperatures lower-or-equal this threshold. | ||
upper_threshold_ambient_temperature : float | ||
Forward temperature is `min_forward_temperature` for ambient temperatures higher-or-equal this threshold. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
ambient_temperature: xr.DataArray, | ||
max_forward_temperature: float, | ||
min_forward_temperature: float, | ||
fixed_return_temperature: float, | ||
lower_threshold_ambient_temperature: float, | ||
upper_threshold_ambient_temperature: float, | ||
rolling_window_ambient_temperature: int, | ||
) -> None: | ||
""" | ||
Initialize the CentralHeatingTemperatureApproximator. | ||
Parameters | ||
---------- | ||
ambient_temperature : xr.DataArray | ||
The ambient temperature data. | ||
max_forward_temperature : xr.DataArray | ||
The maximum forward temperature. | ||
min_forward_temperature : xr.DataArray | ||
The minimum forward temperature. | ||
fixed_return_temperature : xr.DataArray | ||
The fixed return temperature. | ||
lower_threshold_ambient_temperature : float | ||
Forward temperature is `max_forward_temperature` for ambient temperatures lower-or-equal this threshold. | ||
upper_threshold_ambient_temperature : float | ||
Forward temperature is `min_forward_temperature` for ambient temperatures higher-or-equal this threshold. | ||
rolling_window_ambient_temperature : int | ||
Rolling window size for averaging ambient temperature. | ||
""" | ||
self._ambient_temperature = ambient_temperature | ||
self.max_forward_temperature = max_forward_temperature | ||
self.min_forward_temperature = min_forward_temperature | ||
self.fixed_return_temperature = fixed_return_temperature | ||
self.lower_threshold_ambient_temperature = lower_threshold_ambient_temperature | ||
self.upper_threshold_ambient_temperature = upper_threshold_ambient_temperature | ||
self.rolling_window_ambient_temperature = rolling_window_ambient_temperature | ||
|
||
def ambient_temperature_rolling_mean(self) -> xr.DataArray: | ||
""" | ||
Property to get ambient temperature. | ||
Returns | ||
------- | ||
xr.DataArray | ||
Rolling mean of ambient temperature input. | ||
""" | ||
# bfill to avoid NAs in the beginning | ||
return ( | ||
self._ambient_temperature.rolling( | ||
time=self.rolling_window_ambient_temperature | ||
) | ||
.mean(skip_na=True) | ||
.bfill(dim="time") | ||
) | ||
|
||
@property | ||
def forward_temperature(self) -> xr.DataArray: | ||
""" | ||
Property to get dynamic forward temperature. | ||
Returns | ||
------- | ||
xr.DataArray | ||
Dynamic forward temperatures | ||
""" | ||
return self._approximate_forward_temperature() | ||
|
||
@property | ||
def return_temperature(self) -> float: | ||
""" | ||
Property to get return temperature. | ||
Returns | ||
------- | ||
float | ||
Return temperature. | ||
""" | ||
return self._approximate_return_temperature() | ||
|
||
def _approximate_forward_temperature(self) -> xr.DataArray: | ||
""" | ||
Approximate dynamic forward temperature based on reference curve. Adapted from [Pieper et al. (2019)](https://doi.org/10.1016/j.energy.2019.03.165). | ||
Returns | ||
------- | ||
xr.DataArray | ||
Dynamic forward temperatures. | ||
""" | ||
|
||
forward_temperature = xr.where( | ||
self.ambient_temperature_rolling_mean() | ||
<= self.lower_threshold_ambient_temperature, | ||
self.max_forward_temperature, | ||
xr.where( | ||
self.ambient_temperature_rolling_mean() | ||
>= self.upper_threshold_ambient_temperature, | ||
self.min_forward_temperature, | ||
self.min_forward_temperature | ||
+ (self.max_forward_temperature - self.min_forward_temperature) | ||
* ( | ||
self.upper_threshold_ambient_temperature | ||
- self.ambient_temperature_rolling_mean() | ||
) | ||
/ ( | ||
self.upper_threshold_ambient_temperature | ||
- self.lower_threshold_ambient_temperature | ||
), | ||
), | ||
) | ||
return forward_temperature | ||
|
||
def _approximate_return_temperature(self) -> float: | ||
""" | ||
Approximate return temperature. | ||
Returns | ||
------- | ||
float | ||
Return temperature. | ||
""" | ||
return self.fixed_return_temperature | ||
|
||
@property | ||
def forward_temperature(self) -> xr.DataArray: | ||
""" | ||
Property to get dynamic forward temperature. | ||
Returns | ||
------- | ||
xr.DataArray | ||
Dynamic forward temperatures. | ||
""" | ||
return self._approximate_forward_temperature() | ||
|
||
@property | ||
def return_temperature(self) -> float: | ||
""" | ||
Property to get return temperature. | ||
Returns | ||
------- | ||
float | ||
Return temperature. | ||
""" | ||
return self._approximate_return_temperature() | ||
|
||
def _approximate_forward_temperature(self) -> xr.DataArray: | ||
""" | ||
Approximate dynamic forward temperature. | ||
Returns | ||
------- | ||
xr.DataArray | ||
Dynamic forward temperatures. | ||
""" | ||
forward_temperature = xr.where( | ||
self.ambient_temperature_rolling_mean() | ||
<= self.lower_threshold_ambient_temperature, | ||
self.max_forward_temperature, | ||
xr.where( | ||
self.ambient_temperature_rolling_mean() | ||
>= self.upper_threshold_ambient_temperature, | ||
self.min_forward_temperature, | ||
self.min_forward_temperature | ||
+ (self.max_forward_temperature - self.min_forward_temperature) | ||
* ( | ||
self.upper_threshold_ambient_temperature | ||
- self.ambient_temperature_rolling_mean() | ||
) | ||
/ ( | ||
self.upper_threshold_ambient_temperature | ||
- self.lower_threshold_ambient_temperature | ||
), | ||
), | ||
) | ||
return forward_temperature | ||
|
||
def _approximate_return_temperature(self) -> float: | ||
""" | ||
Approximate return temperature. | ||
Returns | ||
------- | ||
float | ||
Return temperature. | ||
""" | ||
return self.fixed_return_temperature |
Oops, something went wrong.