Skip to content

Commit

Permalink
Remove unused data from annual transport demand calculations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timtroendle committed Mar 13, 2024
1 parent 0ffeae5 commit fd00994
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 70 deletions.
5 changes: 1 addition & 4 deletions rules/transport.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
81 changes: 15 additions & 66 deletions scripts/transport/annual_transport_demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -217,29 +166,29 @@ 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,
road_distance=road_distance,
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)

0 comments on commit fd00994

Please sign in to comment.