merge add_nice_carrier_names with add_missing_carrier to become add_missing_carrier_with_nice_names(n, config)
This commit is contained in:
parent
e24ca89a05
commit
72b75fd9fe
@ -121,13 +121,26 @@ def calculate_annuity(n, r):
|
||||
return 1 / n
|
||||
|
||||
|
||||
def add_missing_carrier(n):
|
||||
def add_missing_carriers_with_nice_names(n,config):
|
||||
components = [n.buses, n.generators, n.lines, n.links, n.storage_units, n.stores]
|
||||
for c in components:
|
||||
missing_carrier = np.setdiff1d(c.carrier.unique(), n.carriers.index)
|
||||
if len(missing_carrier):
|
||||
n.madd("Carrier", missing_carrier)
|
||||
|
||||
carrier_i = n.carriers.index
|
||||
nice_names = (
|
||||
pd.Series(config["plotting"]["nice_names"])
|
||||
.reindex(carrier_i)
|
||||
.fillna(carrier_i.to_series().str.title())
|
||||
)
|
||||
n.carriers["nice_name"] = nice_names
|
||||
colors = pd.Series(config["plotting"]["tech_colors"]).reindex(carrier_i)
|
||||
if colors.isna().any():
|
||||
missing_i = list(colors.index[colors.isna()])
|
||||
logger.warning(f"tech_colors for carriers {missing_i} not defined in config.")
|
||||
n.carriers["color"] = colors
|
||||
|
||||
|
||||
def _add_missing_carriers_from_costs(n, costs, carriers):
|
||||
missing_carriers = pd.Index(carriers).difference(n.carriers.index)
|
||||
@ -694,21 +707,6 @@ def estimate_renewable_capacities(n, config):
|
||||
)
|
||||
|
||||
|
||||
def add_nice_carrier_names(n, config):
|
||||
carrier_i = n.carriers.index
|
||||
nice_names = (
|
||||
pd.Series(config["plotting"]["nice_names"])
|
||||
.reindex(carrier_i)
|
||||
.fillna(carrier_i.to_series().str.title())
|
||||
)
|
||||
n.carriers["nice_name"] = nice_names
|
||||
colors = pd.Series(config["plotting"]["tech_colors"]).reindex(carrier_i)
|
||||
if colors.isna().any():
|
||||
missing_i = list(colors.index[colors.isna()])
|
||||
logger.warning(f"tech_colors for carriers {missing_i} not defined in config.")
|
||||
n.carriers["color"] = colors
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if "snakemake" not in globals():
|
||||
from _helpers import mock_snakemake
|
||||
@ -841,8 +839,7 @@ if __name__ == "__main__":
|
||||
|
||||
update_p_nom_max(n)
|
||||
|
||||
add_missing_carrier(n)
|
||||
add_nice_carrier_names(n, snakemake.config)
|
||||
add_missing_carriers_with_nice_names(n, snakemake.config)
|
||||
|
||||
n.meta = snakemake.config
|
||||
n.export_to_netcdf(snakemake.output[0])
|
||||
|
@ -22,7 +22,7 @@ import numpy as np
|
||||
import pypsa
|
||||
import xarray as xr
|
||||
from _helpers import override_component_attrs, update_config_with_sector_opts
|
||||
from add_electricity import add_missing_carrier
|
||||
from add_electricity import add_missing_carriers_with_nice_names
|
||||
from prepare_sector_network import cluster_heat_buses, define_spatial, prepare_costs
|
||||
|
||||
cc = coco.CountryConverter()
|
||||
@ -668,6 +668,6 @@ if __name__ == "__main__":
|
||||
|
||||
n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards)))
|
||||
|
||||
add_missing_carrier(n)
|
||||
add_missing_carriers_with_nice_names(n, snakemake.config)
|
||||
|
||||
n.export_to_netcdf(snakemake.output[0])
|
||||
|
@ -58,8 +58,7 @@ import pypsa
|
||||
from _helpers import configure_logging
|
||||
from add_electricity import (
|
||||
_add_missing_carriers_from_costs,
|
||||
add_missing_carrier,
|
||||
add_nice_carrier_names,
|
||||
add_missing_carriers_with_nice_names,
|
||||
load_costs,
|
||||
)
|
||||
|
||||
@ -253,9 +252,7 @@ if __name__ == "__main__":
|
||||
attach_stores(n, costs, elec_config)
|
||||
attach_hydrogen_pipelines(n, costs, elec_config)
|
||||
|
||||
add_missing_carrier(n)
|
||||
|
||||
add_nice_carrier_names(n, snakemake.config)
|
||||
add_missing_carriers_with_nice_names(n, snakemake.config)
|
||||
|
||||
n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards)))
|
||||
n.export_to_netcdf(snakemake.output[0])
|
||||
|
@ -22,7 +22,7 @@ from _helpers import (
|
||||
override_component_attrs,
|
||||
update_config_with_sector_opts,
|
||||
)
|
||||
from add_electricity import add_missing_carrier
|
||||
from add_electricity import add_missing_carriers_with_nice_names
|
||||
from build_energy_totals import build_co2_totals, build_eea_co2, build_eurostat_co2
|
||||
from networkx.algorithms import complement
|
||||
from networkx.algorithms.connectivity.edge_augmentation import k_edge_augmentation
|
||||
@ -3400,6 +3400,6 @@ if __name__ == "__main__":
|
||||
|
||||
n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards)))
|
||||
|
||||
add_missing_carrier(n)
|
||||
add_missing_carriers_with_nice_names(n, snakemake.config)
|
||||
|
||||
n.export_to_netcdf(snakemake.output[0])
|
||||
|
Loading…
Reference in New Issue
Block a user