From fd009947e7a3f20d7642087d1f8b5e2864e00571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Tr=C3=B6ndle?= Date: Wed, 13 Mar 2024 15:41:00 +0100 Subject: [PATCH] Remove unused data from annual transport demand calculations In the rule annual_transport_demand three variables where calculated: distance, vehicles, and efficiency. We do not need the latter two. In addition, there seemed to be a problem with the calculation of vehicles. In fact, it was equal to distance. See: https://github.com/calliope-project/sector-coupled-euro-calliope/blob/4eeff47ec3b285e0280a4131f6c381cd9028cf75/src/construct/annual_transport_demand.py#L204 I now removed vehicles and efficiency where unneeded. --- rules/transport.smk | 5 +- scripts/transport/annual_transport_demand.py | 81 ++++---------------- 2 files changed, 16 insertions(+), 70 deletions(-) diff --git a/rules/transport.smk b/rules/transport.smk index 521d1deb..9b04f4f5 100644 --- a/rules/transport.smk +++ b/rules/transport.smk @@ -7,16 +7,13 @@ rule annual_transport_demand: energy_balances = "build/data/annual-energy-balances.csv", jrc_road_energy = "build/data/jrc-idees/transport/processed-road-energy.csv", jrc_road_distance = "build/data/jrc-idees/transport/processed-road-distance.csv", - jrc_road_vehicles = "build/data/jrc-idees/transport/processed-road-vehicles.csv", params: fill_missing_values = config["parameters"]["transport"]["fill-missing-values"], efficiency_quantile = config["parameters"]["transport"]["future-vehicle-efficiency-percentile"] conda: "../envs/default.yaml" output: distance = "build/data/transport/annual-road-transport-distance-demand.csv", - vehicles = "build/data/transport/annual-road-transport-vehicles.csv", - efficiency = "build/data/transport/annual-road-transport-efficiency.csv", - road_electricity_historic = "build/data/transport/annual-road-transport-historic-electrification.csv", + distance_historic_electrification = "build/data/transport/annual-road-transport-historic-electrification.csv", script: "../scripts/transport/annual_transport_demand.py" diff --git a/scripts/transport/annual_transport_demand.py b/scripts/transport/annual_transport_demand.py index a2bb1a3d..52c4ecde 100644 --- a/scripts/transport/annual_transport_demand.py +++ b/scripts/transport/annual_transport_demand.py @@ -44,7 +44,7 @@ class Carrier(str, Enum): def get_all_distance_efficiency(energy_balance: pd.Series, other_transport_road: pd.Series, road_energy: pd.Series, road_distance: pd.Series, fill_missing_values: dict[str, str] - ) -> tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]: + ) -> tuple[pd.DataFrame, pd.DataFrame]: # Add transport energy demand from agriculture and 'not elsewhere specified' (military) (OTHER_TRANSPORT_ROAD) transport_energy_balance = ( energy_balance @@ -110,27 +110,7 @@ def get_all_distance_efficiency(energy_balance: pd.Series, .sum() ) - return total_transport_distance, transport_efficiency, transport_energy_per_mode - - -def get_all_vehicles(total_road_distance: pd.DataFrame, road_vehicles: pd.Series, - fill_missing_values: dict[str, str]) -> tuple[pd.DataFrame, pd.DataFrame]: - total_vehicle_distance = fill_missing_countries_and_years( - road_vehicles.div(road_vehicles), - fill_missing_values - ) - total_road_vehicles = total_road_distance.mul( - total_vehicle_distance - .mean(level=['vehicle_type', 'vehicle_subtype', 'country_code', 'year']) - ) - total_road_distance = total_road_distance.sum( - level=['vehicle_type', 'country_code', 'year'] - ) - total_road_vehicles = total_road_vehicles.sum( - level=['vehicle_type', 'country_code', 'year'] - ) - - return total_road_vehicles, total_road_distance + return total_transport_distance, transport_energy_per_mode def fill_missing_countries_and_years(jrc_data: pd.DataFrame, fill_missing_values: dict[str, str]) -> pd.DataFrame: @@ -150,33 +130,6 @@ def fill_missing_countries_and_years(jrc_data: pd.DataFrame, fill_missing_values return jrc_data.stack() -def road_efficiency_cleanup(road_efficiency: pd.DataFrame, efficiency_quantile: float) -> pd.DataFrame: - return ( - (1 / road_efficiency.xs(2015, level='year')) - .unstack(['vehicle_type', 'vehicle_subtype']) - .quantile(efficiency_quantile) - .unstack(0) - .groupby({ - 'Diesel oil engine': 'diesel', - 'Battery electric vehicles': 'electricity', - 'Domestic': 'diesel', - 'International': 'diesel', - 'Gasoline engine': 'petrol', - 'Plug-in hybrid electric': 'petrol' - }).mean() - .stack() - ) - - -def get_historic_road_electricity_consumption(road_historic_consumption: pd.DataFrame) -> pd.DataFrame: - return ( - road_historic_consumption - .groupby(level=['carrier', 'vehicle_type', 'country_code', 'year']) - .sum() - .xs('electricity') - ) - - if __name__ == "__main__": energy_balances = pd.read_csv( snakemake.input.energy_balances, @@ -190,10 +143,6 @@ def get_historic_road_electricity_consumption(road_historic_consumption: pd.Data snakemake.input.jrc_road_distance, index_col=["section", "vehicle_type", "vehicle_subtype", "country_code", "year"] ).squeeze() - road_vehicles = pd.read_csv( - snakemake.input.jrc_road_vehicles, - index_col=["section", "vehicle_type", "vehicle_subtype", "country_code", "year"] - ) # Used to add transport energy demand from agriculture and 'not elsewhere specified' (military) # ASSUME: agriculture oil use goes to 'road' transport demand; # 'not elsewhere specified' oil use goes predominantly to 'road' transport, except kerosene which goes to aviation @@ -217,7 +166,7 @@ def get_historic_road_electricity_consumption(road_historic_consumption: pd.Data fill_missing_values = snakemake.params.fill_missing_values # Calculate total road distance, road efficiency and historically electrified road consumption - total_road_distance, road_efficiency, road_historically_electrified_consumption = get_all_distance_efficiency( + total_road_distance, road_historically_electrified_consumption = get_all_distance_efficiency( energy_balance=energy_balances, other_transport_road=other_transport_road, road_energy=road_energy, @@ -225,21 +174,21 @@ def get_historic_road_electricity_consumption(road_historic_consumption: pd.Data fill_missing_values=fill_missing_values ) - # Calculate total road vehicles and aggregate total road distance - total_road_vehicles, total_road_distance = get_all_vehicles( - total_road_distance, - road_vehicles, - fill_missing_values + # Calculate total road distance + total_road_distance = ( + total_road_distance + .groupby(['vehicle_type', 'country_code', 'year']) + .sum() ) - # Some cleanup that's specific to road data for road efficiency - road_efficiency = road_efficiency_cleanup(road_efficiency, snakemake.params.efficiency_quantile) - # Extract historical electricity consumption - road_electricity_historic = get_historic_road_electricity_consumption(road_historically_electrified_consumption) + total_historically_electrified_distance = ( + road_historically_electrified_consumption + .groupby(level=['carrier', 'vehicle_type', 'country_code', 'year']) + .sum() + .xs('electricity') + ) # Create CSV Files for calculated data total_road_distance.rename("value").to_csv(snakemake.output.distance) - total_road_vehicles.rename("value").to_csv(snakemake.output.vehicles) - road_efficiency.rename("value").to_csv(snakemake.output.efficiency) - road_electricity_historic.rename("value").to_csv(snakemake.output.road_electricity_historic) + total_historically_electrified_distance.rename("value").to_csv(snakemake.output.distance_historic_electrification)