[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
04d3164d7f
commit
4242a0841c
@ -21,7 +21,7 @@ logger = logging.getLogger(__name__)
|
|||||||
def build_nodal_transport_data(fn, pop_layout):
|
def build_nodal_transport_data(fn, pop_layout):
|
||||||
# get numbers of car and fuel efficieny per country
|
# get numbers of car and fuel efficieny per country
|
||||||
transport_data = pd.read_csv(fn, index_col=0)
|
transport_data = pd.read_csv(fn, index_col=0)
|
||||||
|
|
||||||
# break number of cars down to nodal level based on population density
|
# break number of cars down to nodal level based on population density
|
||||||
nodal_transport_data = transport_data.loc[pop_layout.ct].fillna(0.0)
|
nodal_transport_data = transport_data.loc[pop_layout.ct].fillna(0.0)
|
||||||
nodal_transport_data.index = pop_layout.index
|
nodal_transport_data.index = pop_layout.index
|
||||||
@ -39,12 +39,11 @@ def build_nodal_transport_data(fn, pop_layout):
|
|||||||
|
|
||||||
def build_transport_demand(traffic_fn, airtemp_fn, nodes, nodal_transport_data):
|
def build_transport_demand(traffic_fn, airtemp_fn, nodes, nodal_transport_data):
|
||||||
"""
|
"""
|
||||||
returns transport demand per bus in unit kinetic energy.
|
Returns transport demand per bus in unit kinetic energy.
|
||||||
"""
|
"""
|
||||||
# averaged weekly counts from the year 2010-2015
|
# averaged weekly counts from the year 2010-2015
|
||||||
traffic = pd.read_csv(traffic_fn, skiprows=2,
|
traffic = pd.read_csv(traffic_fn, skiprows=2, usecols=["count"]).squeeze("columns")
|
||||||
usecols=["count"]).squeeze("columns")
|
|
||||||
|
|
||||||
# create annual profile take account time zone + summer time
|
# create annual profile take account time zone + summer time
|
||||||
transport_shape = generate_periodic_profiles(
|
transport_shape = generate_periodic_profiles(
|
||||||
dt_index=snapshots,
|
dt_index=snapshots,
|
||||||
@ -65,7 +64,6 @@ def build_transport_demand(traffic_fn, airtemp_fn, nodes, nodal_transport_data):
|
|||||||
options["ICE_upper_degree_factor"],
|
options["ICE_upper_degree_factor"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# divide out the heating/cooling demand from ICE totals
|
# divide out the heating/cooling demand from ICE totals
|
||||||
ice_correction = (transport_shape * (1 + dd_ICE)).sum() / transport_shape.sum()
|
ice_correction = (transport_shape * (1 + dd_ICE)).sum() / transport_shape.sum()
|
||||||
|
|
||||||
@ -75,9 +73,8 @@ def build_transport_demand(traffic_fn, airtemp_fn, nodes, nodal_transport_data):
|
|||||||
- pop_weighted_energy_totals["electricity rail"]
|
- pop_weighted_energy_totals["electricity rail"]
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (transport_shape.multiply(energy_totals_transport) * 1e6 * nyears).divide(
|
||||||
(transport_shape.multiply(energy_totals_transport) * 1e6 * nyears)
|
nodal_transport_data["average fuel efficiency"] * ice_correction
|
||||||
.divide(nodal_transport_data["average fuel efficiency"] * ice_correction)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -141,7 +138,7 @@ def bev_availability_profile(fn, snapshots, nodes, options):
|
|||||||
|
|
||||||
def bev_dsm_profile(snapshots, nodes, options):
|
def bev_dsm_profile(snapshots, nodes, options):
|
||||||
dsm_week = np.zeros((24 * 7,))
|
dsm_week = np.zeros((24 * 7,))
|
||||||
|
|
||||||
# assuming that at a certain time ("bev_dsm_restriction_time") EVs have to
|
# assuming that at a certain time ("bev_dsm_restriction_time") EVs have to
|
||||||
# be charged to a minimum value (defined in bev_dsm_restriction_value)
|
# be charged to a minimum value (defined in bev_dsm_restriction_value)
|
||||||
dsm_week[(np.arange(0, 7, 1) * 24 + options["bev_dsm_restriction_time"])] = options[
|
dsm_week[(np.arange(0, 7, 1) * 24 + options["bev_dsm_restriction_time"])] = options[
|
||||||
@ -154,7 +151,8 @@ def bev_dsm_profile(snapshots, nodes, options):
|
|||||||
weekly_profile=dsm_week,
|
weekly_profile=dsm_week,
|
||||||
)
|
)
|
||||||
|
|
||||||
#%%
|
|
||||||
|
# %%
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if "snakemake" not in globals():
|
if "snakemake" not in globals():
|
||||||
from _helpers import mock_snakemake
|
from _helpers import mock_snakemake
|
||||||
|
@ -1505,15 +1505,22 @@ def add_storage_and_grids(n, costs):
|
|||||||
|
|
||||||
def check_land_transport_shares(shares):
|
def check_land_transport_shares(shares):
|
||||||
# Sums up the shares, ignoring None values
|
# Sums up the shares, ignoring None values
|
||||||
total_share = sum(filter(None, shares))
|
total_share = sum(filter(None, shares))
|
||||||
if total_share != 1:
|
if total_share != 1:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Total land transport shares sum up to {total_share:.2%},"
|
f"Total land transport shares sum up to {total_share:.2%},"
|
||||||
"corresponding to increased or decreased demand assumptions."
|
"corresponding to increased or decreased demand assumptions."
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_temp_efficency(car_efficiency, temperature, deadband_lw, deadband_up,
|
|
||||||
degree_factor_lw, degree_factor_up):
|
def get_temp_efficency(
|
||||||
|
car_efficiency,
|
||||||
|
temperature,
|
||||||
|
deadband_lw,
|
||||||
|
deadband_up,
|
||||||
|
degree_factor_lw,
|
||||||
|
degree_factor_up,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Correct temperature depending on heating and cooling for respective car
|
Correct temperature depending on heating and cooling for respective car
|
||||||
type.
|
type.
|
||||||
@ -1526,14 +1533,23 @@ def get_temp_efficency(car_efficiency, temperature, deadband_lw, deadband_up,
|
|||||||
degree_factor_lw,
|
degree_factor_lw,
|
||||||
degree_factor_up,
|
degree_factor_up,
|
||||||
)
|
)
|
||||||
|
|
||||||
temp_eff = 1 / (1+dd)
|
temp_eff = 1 / (1 + dd)
|
||||||
|
|
||||||
return car_efficiency * temp_eff
|
return car_efficiency * temp_eff
|
||||||
|
|
||||||
def add_EVs(n, nodes, avail_profile, dsm_profile, p_set, electric_share,
|
|
||||||
number_cars, temperature):
|
def add_EVs(
|
||||||
|
n,
|
||||||
|
nodes,
|
||||||
|
avail_profile,
|
||||||
|
dsm_profile,
|
||||||
|
p_set,
|
||||||
|
electric_share,
|
||||||
|
number_cars,
|
||||||
|
temperature,
|
||||||
|
):
|
||||||
|
|
||||||
n.add("Carrier", "Li ion")
|
n.add("Carrier", "Li ion")
|
||||||
|
|
||||||
n.madd(
|
n.madd(
|
||||||
@ -1544,35 +1560,37 @@ def add_EVs(n, nodes, avail_profile, dsm_profile, p_set, electric_share,
|
|||||||
carrier="Li ion",
|
carrier="Li ion",
|
||||||
unit="MWh_el",
|
unit="MWh_el",
|
||||||
)
|
)
|
||||||
|
|
||||||
car_efficiency = costs.at['Battery electric (passenger cars)', 'efficiency']
|
car_efficiency = costs.at["Battery electric (passenger cars)", "efficiency"]
|
||||||
|
|
||||||
# temperature corrected efficiency
|
# temperature corrected efficiency
|
||||||
efficiency = get_temp_efficency(car_efficiency, temperature,
|
efficiency = get_temp_efficency(
|
||||||
options["transport_heating_deadband_lower"],
|
car_efficiency,
|
||||||
options["transport_heating_deadband_upper"],
|
temperature,
|
||||||
options["EV_lower_degree_factor"],
|
options["transport_heating_deadband_lower"],
|
||||||
options["EV_upper_degree_factor"])
|
options["transport_heating_deadband_upper"],
|
||||||
|
options["EV_lower_degree_factor"],
|
||||||
|
options["EV_upper_degree_factor"],
|
||||||
|
)
|
||||||
suffix = " land transport EV"
|
suffix = " land transport EV"
|
||||||
|
|
||||||
p_nom = electric_share * p_set.div(efficiency).max()
|
p_nom = electric_share * p_set.div(efficiency).max()
|
||||||
|
|
||||||
profile = p_set.div(efficiency)/p_set.div(efficiency).max()
|
profile = p_set.div(efficiency) / p_set.div(efficiency).max()
|
||||||
|
|
||||||
n.madd(
|
n.madd(
|
||||||
"Link",
|
"Link",
|
||||||
nodes,
|
nodes,
|
||||||
suffix=suffix,
|
suffix=suffix,
|
||||||
bus0=nodes + " EV battery",
|
bus0=nodes + " EV battery",
|
||||||
bus1=nodes + " land transport",
|
bus1=nodes + " land transport",
|
||||||
carrier="land transport EV",
|
carrier="land transport EV",
|
||||||
efficiency=efficiency,
|
efficiency=efficiency,
|
||||||
p_min_pu=profile,
|
p_min_pu=profile,
|
||||||
p_max_pu=profile,
|
p_max_pu=profile,
|
||||||
p_nom=p_nom,
|
p_nom=p_nom,
|
||||||
p_nom_extendable=False,
|
p_nom_extendable=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
p_nom = number_cars * options.get("bev_charge_rate", 0.011) * electric_share
|
p_nom = number_cars * options.get("bev_charge_rate", 0.011) * electric_share
|
||||||
|
|
||||||
@ -1600,7 +1618,7 @@ def add_EVs(n, nodes, avail_profile, dsm_profile, p_set, electric_share,
|
|||||||
p_max_pu=avail_profile[nodes],
|
p_max_pu=avail_profile[nodes],
|
||||||
efficiency=options.get("bev_charge_efficiency", 0.9),
|
efficiency=options.get("bev_charge_efficiency", 0.9),
|
||||||
)
|
)
|
||||||
|
|
||||||
if options["bev_dsm"]:
|
if options["bev_dsm"]:
|
||||||
e_nom = (
|
e_nom = (
|
||||||
number_cars
|
number_cars
|
||||||
@ -1608,7 +1626,7 @@ def add_EVs(n, nodes, avail_profile, dsm_profile, p_set, electric_share,
|
|||||||
* options["bev_availability"]
|
* options["bev_availability"]
|
||||||
* electric_share
|
* electric_share
|
||||||
)
|
)
|
||||||
|
|
||||||
n.madd(
|
n.madd(
|
||||||
"Store",
|
"Store",
|
||||||
nodes,
|
nodes,
|
||||||
@ -1620,56 +1638,62 @@ def add_EVs(n, nodes, avail_profile, dsm_profile, p_set, electric_share,
|
|||||||
e_max_pu=1,
|
e_max_pu=1,
|
||||||
e_min_pu=dsm_profile[nodes],
|
e_min_pu=dsm_profile[nodes],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_fuel_cell_cars(n, nodes, p_set, fuel_cell_share, temperature):
|
def add_fuel_cell_cars(n, nodes, p_set, fuel_cell_share, temperature):
|
||||||
|
|
||||||
car_efficiency = options["transport_fuel_cell_efficiency"]
|
car_efficiency = options["transport_fuel_cell_efficiency"]
|
||||||
|
|
||||||
# temperature corrected efficiency
|
# temperature corrected efficiency
|
||||||
efficiency = get_temp_efficency(car_efficiency, temperature,
|
efficiency = get_temp_efficency(
|
||||||
options["transport_heating_deadband_lower"],
|
car_efficiency,
|
||||||
options["transport_heating_deadband_upper"],
|
temperature,
|
||||||
options["ICE_lower_degree_factor"],
|
options["transport_heating_deadband_lower"],
|
||||||
options["ICE_upper_degree_factor"])
|
options["transport_heating_deadband_upper"],
|
||||||
|
options["ICE_lower_degree_factor"],
|
||||||
|
options["ICE_upper_degree_factor"],
|
||||||
|
)
|
||||||
|
|
||||||
suffix = " land transport fuel cell"
|
suffix = " land transport fuel cell"
|
||||||
|
|
||||||
p_nom = fuel_cell_share * p_set.div(efficiency).max()
|
p_nom = fuel_cell_share * p_set.div(efficiency).max()
|
||||||
|
|
||||||
profile = p_set.div(efficiency)/p_set.div(efficiency).max()
|
profile = p_set.div(efficiency) / p_set.div(efficiency).max()
|
||||||
|
|
||||||
n.madd(
|
n.madd(
|
||||||
"Link",
|
"Link",
|
||||||
nodes,
|
nodes,
|
||||||
suffix=suffix,
|
suffix=suffix,
|
||||||
bus0=spatial.h2.nodes,
|
bus0=spatial.h2.nodes,
|
||||||
bus1=nodes + " land transport",
|
bus1=nodes + " land transport",
|
||||||
carrier="land transport fuel cell",
|
carrier="land transport fuel cell",
|
||||||
efficiency=efficiency,
|
efficiency=efficiency,
|
||||||
p_nom_extendable=False,
|
p_nom_extendable=False,
|
||||||
p_nom=p_nom,
|
p_nom=p_nom,
|
||||||
p_min_pu=profile,
|
p_min_pu=profile,
|
||||||
p_max_pu=profile,
|
p_max_pu=profile,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_ice_cars(n, nodes, p_set, ice_share, temperature):
|
def add_ice_cars(n, nodes, p_set, ice_share, temperature):
|
||||||
|
|
||||||
add_carrier_buses(n, "oil")
|
add_carrier_buses(n, "oil")
|
||||||
|
|
||||||
car_efficiency = options["transport_internal_combustion_efficiency"]
|
car_efficiency = options["transport_internal_combustion_efficiency"]
|
||||||
|
|
||||||
# temperature corrected efficiency
|
# temperature corrected efficiency
|
||||||
efficiency = get_temp_efficency(car_efficiency, temperature,
|
efficiency = get_temp_efficency(
|
||||||
options["transport_heating_deadband_lower"],
|
car_efficiency,
|
||||||
options["transport_heating_deadband_upper"],
|
temperature,
|
||||||
options["ICE_lower_degree_factor"],
|
options["transport_heating_deadband_lower"],
|
||||||
options["ICE_upper_degree_factor"])
|
options["transport_heating_deadband_upper"],
|
||||||
|
options["ICE_lower_degree_factor"],
|
||||||
|
options["ICE_upper_degree_factor"],
|
||||||
|
)
|
||||||
suffix = " land transport ICE"
|
suffix = " land transport ICE"
|
||||||
|
|
||||||
p_nom = ice_share * p_set.div(efficiency).max()
|
p_nom = ice_share * p_set.div(efficiency).max()
|
||||||
|
|
||||||
|
|
||||||
n.madd(
|
n.madd(
|
||||||
"Link",
|
"Link",
|
||||||
nodes,
|
nodes,
|
||||||
@ -1683,12 +1707,13 @@ def add_ice_cars(n, nodes, p_set, ice_share, temperature):
|
|||||||
p_nom_extendable=False,
|
p_nom_extendable=False,
|
||||||
p_nom=p_nom,
|
p_nom=p_nom,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_land_transport(n, costs):
|
def add_land_transport(n, costs):
|
||||||
# TODO options?
|
# TODO options?
|
||||||
|
|
||||||
logger.info("Add land transport")
|
logger.info("Add land transport")
|
||||||
|
|
||||||
# read in transport demand in units kinetic energy
|
# read in transport demand in units kinetic energy
|
||||||
transport = pd.read_csv(
|
transport = pd.read_csv(
|
||||||
snakemake.input.transport_demand, index_col=0, parse_dates=True
|
snakemake.input.transport_demand, index_col=0, parse_dates=True
|
||||||
@ -1702,54 +1727,62 @@ def add_land_transport(n, costs):
|
|||||||
dsm_profile = pd.read_csv(
|
dsm_profile = pd.read_csv(
|
||||||
snakemake.input.dsm_profile, index_col=0, parse_dates=True
|
snakemake.input.dsm_profile, index_col=0, parse_dates=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# exogenous share of passenger car type
|
# exogenous share of passenger car type
|
||||||
engine_types = ["fuel_cell", "electric", "ice"]
|
engine_types = ["fuel_cell", "electric", "ice"]
|
||||||
shares = pd.Series()
|
shares = pd.Series()
|
||||||
for engine in engine_types:
|
for engine in engine_types:
|
||||||
shares[engine] = get(options[f"land_transport_{engine}_share"],
|
shares[engine] = get(options[f"land_transport_{engine}_share"], investment_year)
|
||||||
investment_year)
|
|
||||||
logger.info(f"{engine} share: {shares[engine]*100}%")
|
logger.info(f"{engine} share: {shares[engine]*100}%")
|
||||||
|
|
||||||
check_land_transport_shares(shares)
|
check_land_transport_shares(shares)
|
||||||
|
|
||||||
nodes = spatial.nodes
|
nodes = spatial.nodes
|
||||||
|
|
||||||
# Add load for transport demand
|
# Add load for transport demand
|
||||||
n.add("Carrier", "land transport demand")
|
n.add("Carrier", "land transport demand")
|
||||||
|
|
||||||
n.madd("Bus",
|
n.madd(
|
||||||
nodes,
|
"Bus",
|
||||||
location=nodes,
|
nodes,
|
||||||
suffix=" land transport",
|
location=nodes,
|
||||||
carrier="land transport demand",
|
suffix=" land transport",
|
||||||
unit="MWh_kinetic")
|
carrier="land transport demand",
|
||||||
|
unit="MWh_kinetic",
|
||||||
|
)
|
||||||
|
|
||||||
p_set = transport[nodes]
|
p_set = transport[nodes]
|
||||||
|
|
||||||
# add demand
|
# add demand
|
||||||
n.madd(
|
n.madd(
|
||||||
"Load",
|
"Load",
|
||||||
nodes,
|
nodes,
|
||||||
suffix=" land transport",
|
suffix=" land transport",
|
||||||
bus=nodes + " land transport",
|
bus=nodes + " land transport",
|
||||||
carrier="land transport demand",
|
carrier="land transport demand",
|
||||||
p_set=p_set,
|
p_set=p_set,
|
||||||
)
|
)
|
||||||
|
|
||||||
# temperature for correction factor for heating/cooling
|
# temperature for correction factor for heating/cooling
|
||||||
temperature = xr.open_dataarray(snakemake.input.temp_air_total).to_pandas()
|
temperature = xr.open_dataarray(snakemake.input.temp_air_total).to_pandas()
|
||||||
|
|
||||||
if shares["electric"] > 0:
|
if shares["electric"] > 0:
|
||||||
add_EVs(n, nodes, avail_profile, dsm_profile, p_set, shares["electric"],
|
add_EVs(
|
||||||
number_cars, temperature)
|
n,
|
||||||
|
nodes,
|
||||||
|
avail_profile,
|
||||||
|
dsm_profile,
|
||||||
|
p_set,
|
||||||
|
shares["electric"],
|
||||||
|
number_cars,
|
||||||
|
temperature,
|
||||||
|
)
|
||||||
|
|
||||||
if shares["fuel_cell"] > 0:
|
if shares["fuel_cell"] > 0:
|
||||||
add_fuel_cell_cars(n, nodes, p_set, shares["fuel_cell"], temperature)
|
add_fuel_cell_cars(n, nodes, p_set, shares["fuel_cell"], temperature)
|
||||||
|
|
||||||
if shares["ice"] > 0:
|
if shares["ice"] > 0:
|
||||||
add_ice_cars(n, nodes, p_set, shares["ice"], temperature)
|
add_ice_cars(n, nodes, p_set, shares["ice"], temperature)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_heat_demand(n):
|
def build_heat_demand(n):
|
||||||
@ -3643,7 +3676,8 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}):
|
|||||||
-compression_per_1000km * n.links.loc[carrier_i, "length_original"] / 1e3
|
-compression_per_1000km * n.links.loc[carrier_i, "length_original"] / 1e3
|
||||||
)
|
)
|
||||||
|
|
||||||
#%%
|
|
||||||
|
# %%
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if "snakemake" not in globals():
|
if "snakemake" not in globals():
|
||||||
from _helpers import mock_snakemake
|
from _helpers import mock_snakemake
|
||||||
|
@ -921,7 +921,8 @@ def solve_network(n, config, solving, **kwargs):
|
|||||||
|
|
||||||
return n
|
return n
|
||||||
|
|
||||||
#%%
|
|
||||||
|
# %%
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if "snakemake" not in globals():
|
if "snakemake" not in globals():
|
||||||
from _helpers import mock_snakemake
|
from _helpers import mock_snakemake
|
||||||
|
Loading…
Reference in New Issue
Block a user