Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
# Run ruff to lint and format
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.13.3
rev: v0.14.10
hooks:
# Run the linter.
- id: ruff
Expand Down
4 changes: 2 additions & 2 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import os
import re
import time
from collections.abc import Callable
from functools import partial, wraps
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Callable, Union

import atlite
import fiona
Expand Down Expand Up @@ -1058,7 +1058,7 @@ def rename_techs(label: str) -> str:


def load_cutout(
cutout_files: Union[str, list[str]], time: Union[None, pd.DatetimeIndex] = None
cutout_files: str | list[str], time: None | pd.DatetimeIndex = None
) -> atlite.Cutout:
"""
Load and optionally combine multiple cutout files.
Expand Down
6 changes: 3 additions & 3 deletions scripts/build_co2_sequestration_potentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
database_en>`_.
"""

from typing import Any, Union
from typing import Any

import geopandas as gpd
import numpy as np
Expand All @@ -19,8 +19,8 @@


def convert_to_2d(
geom: Union[sg.base.BaseGeometry, Any],
) -> Union[sg.base.BaseGeometry, Any]:
geom: sg.base.BaseGeometry | Any,
) -> sg.base.BaseGeometry | Any:
"""
Remove the third dimension (z-coordinate) from a shapely geometry object.

Expand Down
17 changes: 8 additions & 9 deletions scripts/build_cop_profiles/BaseCopApproximator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# SPDX-License-Identifier: MIT

from abc import ABC, abstractmethod
from typing import Union

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -35,8 +34,8 @@ class BaseCopApproximator(ABC):

def __init__(
self,
sink_outlet_temperature_celsius: Union[xr.DataArray, np.array],
source_inlet_temperature_celsius: Union[xr.DataArray, np.array],
sink_outlet_temperature_celsius: xr.DataArray | np.array,
source_inlet_temperature_celsius: xr.DataArray | np.array,
):
"""
Initialize CopApproximator.
Expand All @@ -51,7 +50,7 @@ def __init__(
pass

@abstractmethod
def approximate_cop(self) -> Union[xr.DataArray, np.array]:
def approximate_cop(self) -> xr.DataArray | np.array:
"""
Approximate heat pump coefficient of performance (COP).

Expand All @@ -64,8 +63,8 @@ def approximate_cop(self) -> Union[xr.DataArray, np.array]:

@staticmethod
def celsius_to_kelvin(
t_celsius: Union[float, xr.DataArray, np.array],
) -> Union[float, xr.DataArray, np.array]:
t_celsius: float | xr.DataArray | np.array,
) -> float | xr.DataArray | np.array:
"""
Convert temperature from Celsius to Kelvin.

Expand All @@ -87,9 +86,9 @@ def celsius_to_kelvin(

@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]:
t_hot: float | xr.DataArray | np.ndarray,
t_cold: float | xr.DataArray | np.ndarray,
) -> float | xr.DataArray | np.ndarray:
"""
Calculate the logarithmic mean temperature difference.

Expand Down
38 changes: 18 additions & 20 deletions scripts/build_cop_profiles/CentralHeatingCopApproximator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# SPDX-License-Identifier: MIT


from typing import Union

import numpy as np
import xarray as xr

Expand Down Expand Up @@ -110,10 +108,10 @@ class CentralHeatingCopApproximator(BaseCopApproximator):

def __init__(
self,
sink_outlet_temperature_celsius: Union[xr.DataArray, np.array],
source_inlet_temperature_celsius: Union[xr.DataArray, np.array],
sink_inlet_temperature_celsius: Union[xr.DataArray, np.array],
source_outlet_temperature_celsius: Union[xr.DataArray, np.array],
sink_outlet_temperature_celsius: xr.DataArray | np.array,
source_inlet_temperature_celsius: xr.DataArray | np.array,
sink_inlet_temperature_celsius: xr.DataArray | np.array,
source_outlet_temperature_celsius: xr.DataArray | np.array,
refrigerant: str,
delta_t_pinch_point: float,
isentropic_compressor_efficiency: float,
Expand Down Expand Up @@ -163,7 +161,7 @@ def __init__(
self.delta_t_pinch = delta_t_pinch_point
self.min_delta_t_lift = min_delta_t_lift

def approximate_cop(self) -> Union[xr.DataArray, np.array]:
def approximate_cop(self) -> xr.DataArray | np.array:
"""
Calculate the coefficient of performance (COP) for the system.

Expand Down Expand Up @@ -203,7 +201,7 @@ def approximate_cop(self) -> Union[xr.DataArray, np.array]:
)

@property
def t_sink_mean_kelvin(self) -> Union[xr.DataArray, np.array]:
def t_sink_mean_kelvin(self) -> xr.DataArray | np.array:
"""
Calculate the logarithmic mean temperature difference between the cold
and hot sinks.
Expand All @@ -218,7 +216,7 @@ def t_sink_mean_kelvin(self) -> Union[xr.DataArray, np.array]:
)

@property
def t_source_mean_kelvin(self) -> Union[xr.DataArray, np.array]:
def t_source_mean_kelvin(self) -> xr.DataArray | np.array:
"""
Calculate the logarithmic mean temperature of the heat source.

Expand All @@ -232,7 +230,7 @@ def t_source_mean_kelvin(self) -> Union[xr.DataArray, np.array]:
)

@property
def delta_t_mean_lift(self) -> Union[xr.DataArray, np.array]:
def delta_t_mean_lift(self) -> xr.DataArray | np.array:
"""
Calculate the temperature lift as the difference between the
logarithmic sink and source temperatures.
Expand All @@ -245,15 +243,15 @@ def delta_t_mean_lift(self) -> Union[xr.DataArray, np.array]:
return self.t_sink_mean_kelvin - self.t_source_mean_kelvin

@property
def delta_t_lift(self) -> Union[xr.DataArray, np.array]:
def delta_t_lift(self) -> xr.DataArray | np.array:
"""
Calculate the temperature lift as the difference between the
sink and source temperatures.
"""
return self.t_sink_out_kelvin - self.t_source_in_kelvin

@property
def ideal_lorenz_cop(self) -> Union[xr.DataArray, np.array]:
def ideal_lorenz_cop(self) -> xr.DataArray | np.array:
"""
Ideal Lorenz coefficient of performance (COP).

Expand All @@ -268,7 +266,7 @@ def ideal_lorenz_cop(self) -> Union[xr.DataArray, np.array]:
return self.t_sink_mean_kelvin / self.delta_t_mean_lift

@property
def delta_t_refrigerant_source(self) -> Union[xr.DataArray, np.array]:
def delta_t_refrigerant_source(self) -> xr.DataArray | np.array:
"""
Calculate the temperature difference between the refrigerant source
inlet and outlet.
Expand All @@ -283,7 +281,7 @@ def delta_t_refrigerant_source(self) -> Union[xr.DataArray, np.array]:
)

@property
def delta_t_refrigerant_sink(self) -> Union[xr.DataArray, np.array]:
def delta_t_refrigerant_sink(self) -> xr.DataArray | np.array:
"""
Temperature difference between the refrigerant and the sink based on
approximation.
Expand All @@ -296,7 +294,7 @@ def delta_t_refrigerant_sink(self) -> Union[xr.DataArray, np.array]:
return self._approximate_delta_t_refrigerant_sink(self.refrigerant)

@property
def ratio_evaporation_compression_work(self) -> Union[xr.DataArray, np.array]:
def ratio_evaporation_compression_work(self) -> xr.DataArray | np.array:
"""
Calculate the ratio of evaporation to compression work based on
approximation.
Expand All @@ -309,7 +307,7 @@ def ratio_evaporation_compression_work(self) -> Union[xr.DataArray, np.array]:
return self._ratio_evaporation_compression_work_approximation(self.refrigerant)

@property
def delta_t_sink(self) -> Union[xr.DataArray, np.array]:
def delta_t_sink(self) -> xr.DataArray | np.array:
"""
Calculate the temperature difference at the sink.

Expand All @@ -321,8 +319,8 @@ def delta_t_sink(self) -> Union[xr.DataArray, np.array]:
return self.t_sink_out_kelvin - self.t_sink_in_kelvin

def _approximate_delta_t_refrigerant_source(
self, delta_t_source: Union[xr.DataArray, np.array]
) -> Union[xr.DataArray, np.array]:
self, delta_t_source: xr.DataArray | np.array
) -> xr.DataArray | np.array:
"""
Approximates the temperature difference between the refrigerant and the
source.
Expand All @@ -345,7 +343,7 @@ def _approximate_delta_t_refrigerant_sink(
a: float = {"ammonia": 0.2, "isobutane": -0.0011},
b: float = {"ammonia": 0.2, "isobutane": 0.3},
c: float = {"ammonia": 0.016, "isobutane": 2.4},
) -> Union[xr.DataArray, np.array]:
) -> xr.DataArray | np.array:
"""
Approximates the temperature difference between the refrigerant and
heat sink.
Expand Down Expand Up @@ -394,7 +392,7 @@ def _ratio_evaporation_compression_work_approximation(
a: float = {"ammonia": 0.0014, "isobutane": 0.0035},
b: float = {"ammonia": -0.0015, "isobutane": -0.0033},
c: float = {"ammonia": 0.039, "isobutane": 0.053},
) -> Union[xr.DataArray, np.array]:
) -> xr.DataArray | np.array:
"""
Calculate the ratio of evaporation to compression work approximation.

Expand Down
12 changes: 5 additions & 7 deletions scripts/build_cop_profiles/DecentralHeatingCopApproximator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# SPDX-License-Identifier: MIT


from typing import Union

import numpy as np
import xarray as xr

Expand Down Expand Up @@ -45,8 +43,8 @@ class DecentralHeatingCopApproximator(BaseCopApproximator):

def __init__(
self,
sink_outlet_temperature_celsius: Union[xr.DataArray, np.array],
source_inlet_temperature_celsius: Union[xr.DataArray, np.array],
sink_outlet_temperature_celsius: xr.DataArray | np.array,
source_inlet_temperature_celsius: xr.DataArray | np.array,
source_type: str,
):
"""
Expand All @@ -70,7 +68,7 @@ def __init__(
else:
self.source_type = source_type

def approximate_cop(self) -> Union[xr.DataArray, np.array]:
def approximate_cop(self) -> xr.DataArray | np.array:
"""
Compute the COP values using quadratic regression for air-/ground-
source heat pumps.
Expand All @@ -85,7 +83,7 @@ def approximate_cop(self) -> Union[xr.DataArray, np.array]:
elif self.source_type == "ground":
return self._approximate_cop_ground_source()

def _approximate_cop_air_source(self) -> Union[xr.DataArray, np.array]:
def _approximate_cop_air_source(self) -> xr.DataArray | np.array:
"""
Evaluate quadratic regression for an air-sourced heat pump.

Expand All @@ -98,7 +96,7 @@ def _approximate_cop_air_source(self) -> Union[xr.DataArray, np.array]:
"""
return 6.81 - 0.121 * self.delta_t + 0.000630 * self.delta_t**2

def _approximate_cop_ground_source(self) -> Union[xr.DataArray, np.array]:
def _approximate_cop_ground_source(self) -> xr.DataArray | np.array:
"""
Evaluate quadratic regression for a ground-sourced heat pump.

Expand Down
Loading