Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Aug 21, 2024
1 parent 34d99d7 commit 929bfa6
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions premise/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ def get_battery_size() -> dict:
for each vehicle type and powertrain.
:return: dictionary with battery sizes
"""
with open(DATA_DIR / "transport" / "battery_size.yaml", "r", encoding="utf-8") as stream:
with open(
DATA_DIR / "transport" / "battery_size.yaml", "r", encoding="utf-8"
) as stream:
out = yaml.safe_load(stream)
return out


def get_average_truck_load_factors() -> Dict[str, Dict[str, Dict[str, float]]]:
"""
Load average load factors for trucks
Expand Down Expand Up @@ -503,7 +506,9 @@ def create_vehicle_markets(self) -> list:
ws.equals("unit", "ton kilometer"),
):

new_name = self.mapping["truck"]["old_trucks"][exc["name"]][self.model]
new_name = self.mapping["truck"]["old_trucks"][exc["name"]][
self.model
]
new_loc = self.geo.ecoinvent_to_iam_location(dataset["location"])

if (new_name, new_loc) in list_created_vehicles:
Expand All @@ -512,26 +517,30 @@ def create_vehicle_markets(self) -> list:
exc["location"] = new_loc
else:
print(f"Could not find dataset for {new_name} in {new_loc}.")
exc["name"] = "transport, freight, lorry, unspecified, long haul"
exc["name"] = (
"transport, freight, lorry, unspecified, long haul"
)
exc["product"] = "transport, freight, lorry"
exc["location"] = "World"


# also we need to empty the old transport datasets
for dataset in ws.get_many(
self.database,
ws.either(
*[
ws.equals("name", v)
for v in self.mapping["truck"]["old_trucks"]
]
*[ws.equals("name", v) for v in self.mapping["truck"]["old_trucks"]]
),
):
dataset["exchanges"] = [e for e in dataset["exchanges"] if e["type"] == "production"]
dataset["comment"] = "This dataset has been replaced by new fleet-average vehicles."
dataset["exchanges"] = [
e for e in dataset["exchanges"] if e["type"] == "production"
]
dataset["comment"] = (
"This dataset has been replaced by new fleet-average vehicles."
)

# add new truck as exchange
new_name = self.mapping["truck"]["old_trucks"][dataset["name"]][self.model]
new_name = self.mapping["truck"]["old_trucks"][dataset["name"]][
self.model
]
new_loc = self.geo.ecoinvent_to_iam_location(dataset["location"])

if (new_name, new_loc) in list_created_vehicles:
Expand Down Expand Up @@ -622,9 +631,13 @@ def adjust_battery_size(self, ds):
size = [s for s in self.battery_size["truck"] if s in ds["name"]][0]

if self.year < min(self.battery_size["truck"][size].keys()):
battery_size = self.battery_size["truck"][size][min(self.battery_size["truck"][size].keys())]
battery_size = self.battery_size["truck"][size][
min(self.battery_size["truck"][size].keys())
]
elif self.year > max(self.battery_size["truck"][size].keys()):
battery_size = self.battery_size["truck"][size][max(self.battery_size["truck"][size].keys())]
battery_size = self.battery_size["truck"][size][
max(self.battery_size["truck"][size].keys())
]
else:
battery_size = np.interp(
self.year,
Expand All @@ -637,8 +650,6 @@ def adjust_battery_size(self, ds):

ds["comment"] += f" Battery size adjusted to {battery_size} kWh."



def write_log(self, dataset, status="created"):
"""
Write log file.
Expand Down

0 comments on commit 929bfa6

Please sign in to comment.