Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from transportenergy/diagnostic-A003
Compute freight volume diagnostic
- Loading branch information
Showing
18 changed files
with
371 additions
and
12,839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from item.historical import OUTPUT_PATH | ||
from item.utils import convert_units | ||
|
||
|
||
def compute(activity, stock): | ||
"""Quality diagnostic for freight load factor. | ||
Returns the ratio of road freight traffic from :mod:`.T003` and the total number | ||
of freight vehicles from :mod:`.T009`. | ||
Parameters | ||
---------- | ||
activity : pandas.DataFrame | ||
From :mod:`.T003`. | ||
stock : pandas.DataFrame | ||
From :mod:`.T009`. | ||
""" | ||
# Select activity | ||
activity = activity.query("Mode == 'Road' and `Vehicle Type` == 'All'").set_index( | ||
["ISO Code", "Year"] | ||
) | ||
|
||
# Select stock | ||
vehicle_types = [ | ||
"Light goods road vehicles", | ||
"Lorries (vehicle wt over 3500 kg)", | ||
"Road tractors", | ||
] | ||
mask = stock.Fuel.isin(["All"]) & stock["Vehicle Type"].isin(vehicle_types) | ||
stock = stock[mask].groupby(["ISO Code", "Year"]).sum(numeric_only=True) | ||
|
||
df = ( | ||
# Compute ratio, drop nulls | ||
(activity["Value"] / stock["Value"]) | ||
.dropna() | ||
# Restore column names, for convert_units() | ||
.rename("Value") | ||
.reset_index() | ||
.assign(Variable="Load factor", Service="Freight", Fuel="All", Mode="Road") | ||
# To preferred units | ||
.pipe(convert_units, "Gt km / year / kvehicle", "kt km / year / vehicle") | ||
) | ||
|
||
# Save output before returning | ||
df.to_csv(OUTPUT_PATH / "A003.csv") | ||
|
||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.