pypsa-eur/scripts/build_cop_profiles/BaseCopApproximator.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
3.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2024-07-25 13:10:45 +00:00
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
2024-07-24 13:03:44 +00:00
from abc import ABC, abstractmethod
from typing import Union
2024-07-24 13:03:44 +00:00
import numpy as np
import xarray as xr
2024-07-24 13:03:44 +00:00
class BaseCopApproximator(ABC):
"""
Abstract class for approximating the coefficient of performance (COP) of a
heat pump.
2024-07-31 15:01:27 +00:00
Attributes:
----------
forward_temperature_celsius : Union[xr.DataArray, np.array]
The forward temperature in Celsius.
source_inlet_temperature_celsius : Union[xr.DataArray, np.array]
The source inlet temperature in Celsius.
Methods:
-------
__init__(self, forward_temperature_celsius, source_inlet_temperature_celsius)
Initialize CopApproximator.
approximate_cop(self)
Approximate heat pump coefficient of performance (COP).
celsius_to_kelvin(t_celsius)
Convert temperature from Celsius to Kelvin.
logarithmic_mean(t_hot, t_cold)
Calculate the logarithmic mean temperature difference.
"""
2024-07-24 13:03:44 +00:00
def __init__(
self,
forward_temperature_celsius: Union[xr.DataArray, np.array],
source_inlet_temperature_celsius: Union[xr.DataArray, np.array],
):
"""
Initialize CopApproximator.
Parameters:
----------
forward_temperature_celsius : Union[xr.DataArray, np.array]
The forward temperature in Celsius.
2024-07-31 15:01:27 +00:00
source_inlet_temperature_celsius : Union[xr.DataArray, np.array]
The source inlet temperature in Celsius.
"""
pass
2024-07-24 13:03:44 +00:00
@abstractmethod
def approximate_cop(self) -> Union[xr.DataArray, np.array]:
"""
Approximate heat pump coefficient of performance (COP).
2024-07-24 13:03:44 +00:00
Returns:
-------
Union[xr.DataArray, np.array]
The calculated COP values.
"""
pass
2024-07-24 13:03:44 +00:00
@staticmethod
def celsius_to_kelvin(
t_celsius: Union[float, xr.DataArray, np.array]
) -> Union[float, xr.DataArray, np.array]:
2024-07-31 15:01:27 +00:00
"""
Convert temperature from Celsius to Kelvin.
Parameters:
----------
t_celsius : Union[float, xr.DataArray, np.array]
Temperature in Celsius.
Returns:
-------
Union[float, xr.DataArray, np.array]
Temperature in Kelvin.
"""
2024-07-24 13:03:44 +00:00
if (np.asarray(t_celsius) > 200).any():
raise ValueError(
"t_celsius > 200. Are you sure you are using the right units?"
)
2024-07-24 13:03:44 +00:00
return t_celsius + 273.15
@staticmethod
def logarithmic_mean(
t_hot: Union[float, xr.DataArray, np.ndarray],
t_cold: Union[float, xr.DataArray, np.ndarray],
) -> Union[float, xr.DataArray, np.ndarray]:
2024-07-31 15:01:27 +00:00
"""
Calculate the logarithmic mean temperature difference.
Parameters:
----------
t_hot : Union[float, xr.DataArray, np.ndarray]
Hot temperature.
t_cold : Union[float, xr.DataArray, np.ndarray]
Cold temperature.
Returns:
-------
Union[float, xr.DataArray, np.ndarray]
Logarithmic mean temperature difference.
"""
2024-07-24 13:03:44 +00:00
if (np.asarray(t_hot <= t_cold)).any():
raise ValueError("t_hot must be greater than t_cold")
return (t_hot - t_cold) / np.log(t_hot / t_cold)