Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Feb 11, 2024
2 parents 863d1a6 + f4d7a58 commit 8d17ff5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 42 deletions.
1 change: 0 additions & 1 deletion carculator_utils/background_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
countries over time.
"""


from typing import Dict, List

import numpy as np
Expand Down
6 changes: 2 additions & 4 deletions carculator_utils/energy_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,8 @@ def motive_energy_per_km(
fuel_cell_system_efficiency == 0, 1, fuel_cell_system_efficiency
)

_t = (
lambda x: x.T
if x.shape[-4:] != motive_energy_at_wheels.shape[-4:]
else x
_t = lambda x: (
x.T if x.shape[-4:] != motive_energy_at_wheels.shape[-4:] else x
)

motive_energy = motive_energy_at_wheels / (
Expand Down
16 changes: 10 additions & 6 deletions carculator_utils/hot_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,11 @@ def get_hot_emissions(
if self.non_exhaust is not None:
non_exhaust = self.non_exhaust.sel(
powertrain=[
MAP_PWT[pt]
if MAP_PWT[pt] in self.non_exhaust.powertrain.values
else "BEV"
(
MAP_PWT[pt]
if MAP_PWT[pt] in self.non_exhaust.powertrain.values
else "BEV"
)
for pt in emissions.powertrain.values
],
euro_class=euro_class,
Expand Down Expand Up @@ -401,9 +403,11 @@ def get_hot_emissions(

engine_wear = self.engine_wear.sel(
powertrain=[
MAP_PWT[pt]
if MAP_PWT[pt] in self.engine_wear.powertrain.values
else "BEV"
(
MAP_PWT[pt]
if MAP_PWT[pt] in self.engine_wear.powertrain.values
else "BEV"
)
for pt in emissions.powertrain.values
]
)
Expand Down
48 changes: 26 additions & 22 deletions carculator_utils/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,11 @@ def get_B_matrix(self) -> xr.DataArray:
return xr.DataArray(
B,
coords=[
[2005, 2010, 2020, 2030, 2040, 2050]
if self.scenario != "static"
else [2020],
(
[2005, 2010, 2020, 2030, 2040, 2050]
if self.scenario != "static"
else [2020]
),
np.asarray(list(self.impact_categories.keys()), dtype="object"),
np.asarray(list(self.inputs.keys()), dtype="object"),
],
Expand Down Expand Up @@ -807,26 +809,28 @@ def define_electricity_mix_for_fuel_prep(self) -> np.ndarray:
country = self.vm.country

mix = [
self.bs.electricity_mix.sel(
country=country,
variable=self.electricity_technologies,
)
.interp(
year=use_year[y],
kwargs={"fill_value": "extrapolate"},
)
.mean(axis=0)
.values
if use_year[y][-1] <= 2050
else self.bs.electricity_mix.sel(
country=country,
variable=self.electricity_technologies,
)
.interp(
year=np.arange(year, 2051), kwargs={"fill_value": "extrapolate"}
(
self.bs.electricity_mix.sel(
country=country,
variable=self.electricity_technologies,
)
.interp(
year=use_year[y],
kwargs={"fill_value": "extrapolate"},
)
.mean(axis=0)
.values
if use_year[y][-1] <= 2050
else self.bs.electricity_mix.sel(
country=country,
variable=self.electricity_technologies,
)
.interp(
year=np.arange(year, 2051), kwargs={"fill_value": "extrapolate"}
)
.mean(axis=0)
.values
)
.mean(axis=0)
.values
for y, year in enumerate(self.scope["year"])
]

Expand Down
21 changes: 12 additions & 9 deletions carculator_utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def load_default_specs_for_fuels():


class VehicleModel:

"""
This class represents the entirety of the vehicles considered,
with useful attributes, such as an array that stores
Expand Down Expand Up @@ -1065,11 +1064,15 @@ def check_fuel_blend(self, fuel_blend: dict) -> dict:
secondary = specs.get(
"secondary",
{
"type": default_specs[fuel]["secondary"]
if default_specs[fuel]["secondary"] != primary["type"]
else [
f for f in default_specs[fuel]["all"] if f != primary["type"]
][0],
"type": (
default_specs[fuel]["secondary"]
if default_specs[fuel]["secondary"] != primary["type"]
else [
f
for f in default_specs[fuel]["all"]
if f != primary["type"]
][0]
),
"share": np.array([1]) - primary["share"],
},
)
Expand Down Expand Up @@ -1462,9 +1465,9 @@ def set_noise_emissions(self) -> None:
) as stream:
list_noise_emissions = yaml.safe_load(stream)

self.array.loc[
dict(parameter=list_noise_emissions)
] = nem.get_sound_power_per_compartment()
self.array.loc[dict(parameter=list_noise_emissions)] = (
nem.get_sound_power_per_compartment()
)

def calculate_cost_impacts(self, sensitivity=False) -> xr.DataArray:
"""
Expand Down
1 change: 1 addition & 0 deletions carculator_utils/particulates_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
particulates_emissions.py contains ParticulatesEmissionsModel which calculated the amount of
abrasion particles emitted, given a driving_cycles.
"""

from typing import Union

import numpy as np
Expand Down

0 comments on commit 8d17ff5

Please sign in to comment.