2024-07-24 15:04:58 +00:00
|
|
|
# -*- 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
|
|
|
|
|
|
|
import numpy as np
|
2024-07-29 16:29:27 +00:00
|
|
|
import pandas as pd
|
2024-07-24 15:04:58 +00:00
|
|
|
import xarray as xr
|
|
|
|
from _helpers import set_scenario_config
|
2024-07-24 13:03:44 +00:00
|
|
|
from CentralHeatingCopApproximator import CentralHeatingCopApproximator
|
|
|
|
from DecentralHeatingCopApproximator import DecentralHeatingCopApproximator
|
|
|
|
|
2024-07-29 16:29:27 +00:00
|
|
|
|
|
|
|
def get_cop(
|
|
|
|
heat_system_type: str,
|
|
|
|
heat_source: str,
|
|
|
|
source_inlet_temperature_celsius: xr.DataArray,
|
|
|
|
) -> xr.DataArray:
|
|
|
|
if heat_system_type == "decentral":
|
|
|
|
return DecentralHeatingCopApproximator(
|
|
|
|
forward_temperature_celsius=snakemake.params.heat_pump_sink_T_decentral_heating,
|
|
|
|
source_inlet_temperature_celsius=source_inlet_temperature_celsius,
|
|
|
|
source_type=heat_source,
|
|
|
|
).approximate_cop()
|
|
|
|
|
|
|
|
elif heat_system_type == "central":
|
|
|
|
return CentralHeatingCopApproximator(
|
|
|
|
forward_temperature_celsius=snakemake.params.forward_temperature_central_heating,
|
|
|
|
return_temperature_celsius=snakemake.params.return_temperature_central_heating,
|
|
|
|
source_inlet_temperature_celsius=source_inlet_temperature_celsius,
|
|
|
|
source_outlet_temperature_celsius=source_inlet_temperature_celsius
|
|
|
|
- snakemake.params.heat_source_cooling_central_heating,
|
|
|
|
).approximate_cop()
|
|
|
|
else:
|
|
|
|
raise ValueError(
|
|
|
|
f"Invalid heat system type '{heat_system_type}'. Must be one of ['decentral', 'central']"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-07-24 13:03:44 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if "snakemake" not in globals():
|
|
|
|
from _helpers import mock_snakemake
|
|
|
|
|
|
|
|
snakemake = mock_snakemake(
|
|
|
|
"build_cop_profiles",
|
|
|
|
simpl="",
|
|
|
|
clusters=48,
|
|
|
|
)
|
|
|
|
|
|
|
|
set_scenario_config(snakemake)
|
|
|
|
|
2024-07-29 16:29:27 +00:00
|
|
|
cop_all_system_types = []
|
|
|
|
for heat_system_type, heat_sources in snakemake.params.heat_pump_sources.items():
|
|
|
|
cop_this_system_type = []
|
|
|
|
for heat_source in heat_sources:
|
|
|
|
source_inlet_temperature_celsius = xr.open_dataarray(
|
|
|
|
snakemake.input[f"temp_{heat_source.replace('ground', 'soil')}_total"]
|
|
|
|
)
|
|
|
|
cop_da = get_cop(
|
|
|
|
heat_system_type=heat_system_type,
|
|
|
|
heat_source=heat_source,
|
|
|
|
source_inlet_temperature_celsius=source_inlet_temperature_celsius,
|
|
|
|
)
|
|
|
|
cop_this_system_type.append(cop_da)
|
|
|
|
cop_all_system_types.append(
|
|
|
|
xr.concat(
|
|
|
|
cop_this_system_type, dim=pd.Index(heat_sources, name="heat_source")
|
|
|
|
)
|
2024-07-24 15:04:58 +00:00
|
|
|
)
|
2024-07-24 13:03:44 +00:00
|
|
|
|
2024-07-29 16:29:27 +00:00
|
|
|
cop_dataarray = xr.concat(
|
|
|
|
cop_all_system_types,
|
|
|
|
dim=pd.Index(snakemake.params.heat_pump_sources.keys(), name="heat_system"),
|
|
|
|
)
|
2024-07-24 13:03:44 +00:00
|
|
|
|
2024-07-29 16:29:27 +00:00
|
|
|
cop_dataarray.to_netcdf(snakemake.output.cop_profiles)
|