Refactor module structure
This commit is contained in:
parent
76b377b2d1
commit
bbf64a2fde
@ -8,7 +8,7 @@ import pandas as pd
|
||||
import xarray as xr
|
||||
from _helpers import set_scenario_config
|
||||
import sys; sys.path.append("..")
|
||||
from scripts._entities import HeatSystemType
|
||||
from scripts.enums.HeatSystemType import HeatSystemType
|
||||
from CentralHeatingCopApproximator import CentralHeatingCopApproximator
|
||||
from DecentralHeatingCopApproximator import DecentralHeatingCopApproximator
|
||||
|
||||
|
25
scripts/enums/HeatSector.py
Normal file
25
scripts/enums/HeatSector.py
Normal file
@ -0,0 +1,25 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from enum import Enum
|
||||
|
||||
class HeatSector(Enum):
|
||||
"""
|
||||
Enumeration class representing different heat sectors.
|
||||
|
||||
Attributes:
|
||||
RESIDENTIAL (str): Represents the residential heat sector.
|
||||
SERVICES (str): Represents the services heat sector.
|
||||
"""
|
||||
|
||||
RESIDENTIAL = "residential"
|
||||
SERVICES = "services"
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""
|
||||
Returns the string representation of the heat sector.
|
||||
|
||||
Returns:
|
||||
str: The string representation of the heat sector.
|
||||
"""
|
||||
return self.value
|
||||
|
218
scripts/enums/HeatSystem.py
Normal file
218
scripts/enums/HeatSystem.py
Normal file
@ -0,0 +1,218 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from .HeatSystemType import HeatSystemType
|
||||
from .HeatSector import HeatSector
|
||||
|
||||
class HeatSystem(Enum):
|
||||
"""
|
||||
Enumeration representing different heat systems.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
RESIDENTIAL_RURAL : str
|
||||
Heat system for residential areas in rural locations.
|
||||
SERVICES_RURAL : str
|
||||
Heat system for service areas in rural locations.
|
||||
RESIDENTIAL_URBAN_DECENTRAL : str
|
||||
Heat system for residential areas in urban decentralized locations.
|
||||
SERVICES_URBAN_DECENTRAL : str
|
||||
Heat system for service areas in urban decentralized locations.
|
||||
URBAN_CENTRAL : str
|
||||
Heat system for urban central areas.
|
||||
|
||||
Methods
|
||||
-------
|
||||
__str__()
|
||||
Returns the string representation of the heat system.
|
||||
central_or_decentral()
|
||||
Returns whether the heat system is central or decentralized.
|
||||
system_type()
|
||||
Returns the type of the heat system.
|
||||
sector()
|
||||
Returns the sector of the heat system.
|
||||
rural()
|
||||
Returns whether the heat system is for rural areas.
|
||||
urban_decentral()
|
||||
Returns whether the heat system is for urban decentralized areas.
|
||||
urban()
|
||||
Returns whether the heat system is for urban areas.
|
||||
heat_demand_weighting(urban_fraction=None, dist_fraction=None)
|
||||
Calculates the heat demand weighting based on urban fraction and distribution fraction.
|
||||
heat_pump_costs_name(heat_source)
|
||||
Generates the name for the heat pump costs based on the heat source.
|
||||
"""
|
||||
|
||||
RESIDENTIAL_RURAL = "residential rural"
|
||||
SERVICES_RURAL = "services rural"
|
||||
RESIDENTIAL_URBAN_DECENTRAL = "residential urban decentral"
|
||||
SERVICES_URBAN_DECENTRAL = "services urban decentral"
|
||||
URBAN_CENTRAL = "urban central"
|
||||
|
||||
def __init__(self, *args):
|
||||
super().__init__(*args)
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""
|
||||
Returns the string representation of the heat system.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
The string representation of the heat system.
|
||||
"""
|
||||
return self.value
|
||||
|
||||
@property
|
||||
def central_or_decentral(self) -> str:
|
||||
"""
|
||||
Returns whether the heat system is central or decentralized.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
"central" if the heat system is central, "decentral" otherwise.
|
||||
"""
|
||||
if self == HeatSystem.URBAN_CENTRAL:
|
||||
return "central"
|
||||
else:
|
||||
return "decentral"
|
||||
|
||||
@property
|
||||
def system_type(self) -> HeatSystemType:
|
||||
"""
|
||||
Returns the type of the heat system.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
The type of the heat system.
|
||||
|
||||
Raises
|
||||
------
|
||||
RuntimeError
|
||||
If the heat system is invalid.
|
||||
"""
|
||||
if self == HeatSystem.URBAN_CENTRAL:
|
||||
return HeatSystemType.URBAN_CENTRAL
|
||||
elif self == HeatSystem.RESIDENTIAL_URBAN_DECENTRAL or self == HeatSystem.SERVICES_URBAN_DECENTRAL:
|
||||
return HeatSystemType.URBAN_DECENTRAL
|
||||
elif self == HeatSystem.RESIDENTIAL_RURAL or self == HeatSystem.SERVICES_RURAL:
|
||||
return HeatSystemType.RURAL
|
||||
else:
|
||||
raise RuntimeError(f"Invalid heat system: {self}")
|
||||
|
||||
@property
|
||||
def sector(self) -> HeatSector:
|
||||
"""
|
||||
Returns the sector of the heat system.
|
||||
|
||||
Returns
|
||||
-------
|
||||
HeatSector
|
||||
The sector of the heat system.
|
||||
"""
|
||||
if (
|
||||
self == HeatSystem.RESIDENTIAL_RURAL
|
||||
or self == HeatSystem.RESIDENTIAL_URBAN_DECENTRAL
|
||||
):
|
||||
return HeatSector.RESIDENTIAL
|
||||
elif (
|
||||
self == HeatSystem.SERVICES_RURAL
|
||||
or self == HeatSystem.SERVICES_URBAN_DECENTRAL
|
||||
):
|
||||
return HeatSector.SERVICES
|
||||
else:
|
||||
'tot'
|
||||
|
||||
@property
|
||||
def is_rural(self) -> bool:
|
||||
"""
|
||||
Returns whether the heat system is for rural areas.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
True if the heat system is for rural areas, False otherwise.
|
||||
"""
|
||||
if self == HeatSystem.RESIDENTIAL_RURAL or self == HeatSystem.SERVICES_RURAL:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_urban_decentral(self) -> bool:
|
||||
"""
|
||||
Returns whether the heat system is for urban decentralized areas.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
True if the heat system is for urban decentralized areas, False otherwise.
|
||||
"""
|
||||
if self == HeatSystem.RESIDENTIAL_URBAN_DECENTRAL or self == HeatSystem.SERVICES_URBAN_DECENTRAL:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_urban(self) -> bool:
|
||||
"""
|
||||
Returns whether the heat system is for urban areas.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool True if the heat system is for urban areas, False otherwise. """
|
||||
return not self.is_rural
|
||||
|
||||
def heat_demand_weighting(self, urban_fraction=None, dist_fraction=None) -> float:
|
||||
"""
|
||||
Calculates the heat demand weighting based on urban fraction and distribution fraction.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
urban_fraction : float, optional
|
||||
The fraction of urban heat demand.
|
||||
dist_fraction : float, optional
|
||||
The fraction of distributed heat demand.
|
||||
|
||||
Returns
|
||||
-------
|
||||
float
|
||||
The heat demand weighting.
|
||||
|
||||
Raises
|
||||
------
|
||||
RuntimeError
|
||||
If the heat system is invalid.
|
||||
"""
|
||||
if "rural" in self.value:
|
||||
return 1 - urban_fraction
|
||||
elif "urban central" in self.value:
|
||||
return dist_fraction
|
||||
elif "urban decentral" in self.value:
|
||||
return urban_fraction - dist_fraction
|
||||
else:
|
||||
raise RuntimeError(f"Invalid heat system: {self}")
|
||||
|
||||
def heat_pump_costs_name(self, heat_source: str) -> str:
|
||||
"""
|
||||
Generates the name for the heat pump costs based on the heat source.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
heat_source : str
|
||||
The heat source.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
The name for the heat pump costs.
|
||||
"""
|
||||
return f"{self.central_or_decentral} {heat_source}-sourced heat pump"
|
||||
|
||||
|
35
scripts/enums/HeatSystemType.py
Normal file
35
scripts/enums/HeatSystemType.py
Normal file
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from enum import Enum
|
||||
|
||||
class HeatSystemType(Enum):
|
||||
"""
|
||||
Enumeration representing different types of heat systems.
|
||||
"""
|
||||
|
||||
URBAN_CENTRAL = "urban central"
|
||||
URBAN_DECENTRAL = "urban decentral"
|
||||
RURAL = "rural"
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""
|
||||
Returns the string representation of the heat system type.
|
||||
|
||||
Returns:
|
||||
str: The string representation of the heat system type.
|
||||
"""
|
||||
return self.value
|
||||
|
||||
@property
|
||||
def is_central(self) -> bool:
|
||||
"""
|
||||
Returns whether the heat system type is central.
|
||||
|
||||
Returns:
|
||||
bool: True if the heat system type is central, False otherwise.
|
||||
"""
|
||||
return self == HeatSystemType.URBAN_CENTRAL
|
||||
|
@ -22,7 +22,9 @@ from _helpers import (
|
||||
set_scenario_config,
|
||||
update_config_from_wildcards,
|
||||
)
|
||||
from _entities import HeatSystem, HeatSector
|
||||
from scripts.enums.HeatSystem import HeatSystem
|
||||
from scripts.enums.HeatSystemType import HeatSystemType
|
||||
from scripts.enums.HeatSector import HeatSector
|
||||
from add_electricity import calculate_annuity, sanitize_carriers, sanitize_locations
|
||||
from build_energy_totals import (
|
||||
build_co2_totals,
|
||||
|
Loading…
Reference in New Issue
Block a user