[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-03-04 08:44:51 +00:00
parent 04d3164d7f
commit 4242a0841c
3 changed files with 129 additions and 96 deletions

View File

@ -39,11 +39,10 @@ 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(
@ -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)
) )
@ -154,6 +151,7 @@ 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():

View File

@ -1512,8 +1512,15 @@ def check_land_transport_shares(shares):
"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.
@ -1531,8 +1538,17 @@ def get_temp_efficency(car_efficiency, temperature, deadband_lw, deadband_up,
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")
@ -1545,14 +1561,17 @@ def add_EVs(n, nodes, avail_profile, dsm_profile, p_set, electric_share,
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(
car_efficiency,
temperature,
options["transport_heating_deadband_lower"], options["transport_heating_deadband_lower"],
options["transport_heating_deadband_upper"], options["transport_heating_deadband_upper"],
options["EV_lower_degree_factor"], options["EV_lower_degree_factor"],
options["EV_upper_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()
@ -1573,7 +1592,6 @@ def add_EVs(n, nodes, avail_profile, dsm_profile, p_set, electric_share,
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
n.madd( n.madd(
@ -1621,16 +1639,20 @@ def add_EVs(n, nodes, avail_profile, dsm_profile, p_set, electric_share,
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(
car_efficiency,
temperature,
options["transport_heating_deadband_lower"], options["transport_heating_deadband_lower"],
options["transport_heating_deadband_upper"], options["transport_heating_deadband_upper"],
options["ICE_lower_degree_factor"], options["ICE_lower_degree_factor"],
options["ICE_upper_degree_factor"]) options["ICE_upper_degree_factor"],
)
suffix = " land transport fuel cell" suffix = " land transport fuel cell"
@ -1660,16 +1682,18 @@ def add_ice_cars(n, nodes, p_set, ice_share, temperature):
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(
car_efficiency,
temperature,
options["transport_heating_deadband_lower"], options["transport_heating_deadband_lower"],
options["transport_heating_deadband_upper"], options["transport_heating_deadband_upper"],
options["ICE_lower_degree_factor"], options["ICE_lower_degree_factor"],
options["ICE_upper_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,
@ -1684,6 +1708,7 @@ def add_ice_cars(n, nodes, p_set, ice_share, temperature):
p_nom=p_nom, p_nom=p_nom,
) )
def add_land_transport(n, costs): def add_land_transport(n, costs):
# TODO options? # TODO options?
@ -1707,8 +1732,7 @@ def add_land_transport(n, costs):
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)
@ -1718,12 +1742,14 @@ def add_land_transport(n, costs):
# 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(
"Bus",
nodes, nodes,
location=nodes, location=nodes,
suffix=" land transport", suffix=" land transport",
carrier="land transport demand", carrier="land transport demand",
unit="MWh_kinetic") unit="MWh_kinetic",
)
p_set = transport[nodes] p_set = transport[nodes]
@ -1741,8 +1767,16 @@ def add_land_transport(n, costs):
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)
@ -1751,7 +1785,6 @@ def add_land_transport(n, costs):
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):
heat_demand_shape = ( heat_demand_shape = (
xr.open_dataset(snakemake.input.hourly_heat_demand_total) xr.open_dataset(snakemake.input.hourly_heat_demand_total)
@ -3643,6 +3676,7 @@ 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():

View File

@ -921,6 +921,7 @@ 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():