Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Nov 18, 2021
1 parent e51d3b0 commit 11a721c
Showing 1 changed file with 73 additions and 32 deletions.
105 changes: 73 additions & 32 deletions carculator_truck/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

DEFAULT_MAPPINGS = {
"electric": {"BEV", "PHEV-e"},
"combustion": {"HEV-d", "ICEV-g", "ICEV-d", "PHEV-c-d",},
"combustion": {
"HEV-d",
"ICEV-g",
"ICEV-d",
"PHEV-c-d",
},
"combustion_wo_cng": {"HEV-d", "ICEV-d", "PHEV-c-d"},
"pure_combustion": {"ICEV-g", "ICEV-d"},
"petrol": {"PHEV-c-p"},
Expand Down Expand Up @@ -150,7 +155,9 @@ def __init__(
if s in self.array.coords["size"].values
],
)
] *= (1 - 0.67)
] *= (
1 - 0.67
)

if any(
s in self.array.coords["size"].values for s in ["32t", "40t", "60t"]
Expand All @@ -164,7 +171,9 @@ def __init__(
if s in self.array.coords["size"].values
],
)
] *= (1 - 0.33)
] *= (
1 - 0.33
)

if self.cycle == "Urban delivery":
self.array.loc[dict(parameter="kilometers per year")] *= 1 - 0.39
Expand All @@ -182,7 +191,9 @@ def __init__(
if s in self.array.coords["size"].values
],
)
] *= (1 - 0.67)
] *= (
1 - 0.67
)

if any(
s in self.array.coords["size"].values for s in ["32t", "40t", "60t"]
Expand All @@ -196,7 +207,9 @@ def __init__(
if s in self.array.coords["size"].values
],
)
] *= (1 - 0.33)
] *= (
1 - 0.33
)

def __call__(self, key):
"""
Expand Down Expand Up @@ -322,7 +335,7 @@ def set_all(self):
print("'*' ICEV that do not comply with the set energy reduction target.")
print("'/' vehicles not available for the specified year.")

self["is_compliant"] *= (self["driving mass"] < self["gross mass"])
self["is_compliant"] *= self["driving mass"] < self["gross mass"]

# If the number of remaining non-compliant vehicles is not zero, then
if len([y for y in self.array.year.values if y > 2020]) > 0:
Expand Down Expand Up @@ -386,7 +399,9 @@ def set_all(self):
self.array.sel(
parameter="driving mass", powertrain=pt, year=y, value=0
).values
< self.array.sel(parameter="gross mass", powertrain=pt, year=y, value=0)
< self.array.sel(
parameter="gross mass", powertrain=pt, year=y, value=0
)
),
vals,
"-",
Expand Down Expand Up @@ -481,13 +496,16 @@ def adjust_combustion_power_share(self):
)

if arr.sum() > 0:
new_shares = self.array.loc[
dict(
powertrain=l_pwt,
parameter="combustion power share",
year=actual_years,
)
] - (arr * 0.02)
new_shares = (
self.array.loc[
dict(
powertrain=l_pwt,
parameter="combustion power share",
year=actual_years,
)
]
- (arr * 0.02)
)
self.array.loc[
dict(
powertrain=l_pwt,
Expand Down Expand Up @@ -575,7 +593,11 @@ def adjust_cost(self):
# Correction of combustion powertrain cost for ICEV-g
if "ICEV-g" in self.array.powertrain.values:
self.array.loc[
:, ["ICEV-g"], "combustion powertrain cost per kW", :, :,
:,
["ICEV-g"],
"combustion powertrain cost per kW",
:,
:,
] = np.reshape(
(5.92e160 * np.exp(-0.1819 * self.array.year.values) + 26.76)
* cost_factor,
Expand All @@ -591,7 +613,15 @@ def drop_hybrid(self):
l_pwt = [
p
for p in self.array.powertrain.values
if p in ["ICEV-d", "ICEV-g", "PHEV-d", "FCEV", "BEV", "HEV-d",]
if p
in [
"ICEV-d",
"ICEV-g",
"PHEV-d",
"FCEV",
"BEV",
"HEV-d",
]
]
self.array = self.array.sel(powertrain=l_pwt)

Expand Down Expand Up @@ -685,11 +715,10 @@ def calculate_ttw_energy(self):
if len(l_pwt) > 0:

self.energy.loc[dict(parameter="power load", powertrain=l_pwt)] = (
(motive_power.T[:, idx, ...] + recuperated_power.T[:, idx, ...])
/ self.array.sel(parameter="electric power", powertrain=l_pwt).values[
..., None
]
)
motive_power.T[:, idx, ...] + recuperated_power.T[:, idx, ...]
) / self.array.sel(parameter="electric power", powertrain=l_pwt).values[
..., None
]

self.energy.loc[dict(parameter="power load")] = np.clip(
self.energy.loc[dict(parameter="power load")], 0, 1
Expand Down Expand Up @@ -719,7 +748,10 @@ def calculate_ttw_energy(self):
if len(l_pwt) > 0:

self.energy.loc[
dict(parameter="engine efficiency", powertrain=l_pwt,)
dict(
parameter="engine efficiency",
powertrain=l_pwt,
)
] = np.clip(
np.interp(
self.energy.loc[dict(parameter="power load", powertrain=l_pwt)],
Expand Down Expand Up @@ -747,12 +779,9 @@ def calculate_ttw_energy(self):
if "ICEV-g" in self.array.powertrain.values:
self.energy.loc[
dict(parameter="engine efficiency", powertrain="ICEV-g")
] *= (
1
- self.array.sel(
parameter="CNG engine efficiency correction factor",
powertrain="ICEV-g",
)
] *= 1 - self.array.sel(
parameter="CNG engine efficiency correction factor",
powertrain="ICEV-g",
)

# correction for BEVs and FCEVs
Expand Down Expand Up @@ -1758,12 +1787,18 @@ def set_hot_emissions(self):

if len(l_pwt) > 0:
self.array.loc[
dict(powertrain=l_pwt, parameter=list_direct_emissions,)
dict(
powertrain=l_pwt,
parameter=list_direct_emissions,
)
] = hem.get_emissions_per_powertrain(
powertrain_type="diesel",
euro_classes=l_y,
lifetime_km=self.array.loc[
dict(powertrain=l_pwt, parameter="lifetime kilometers",)
dict(
powertrain=l_pwt,
parameter="lifetime kilometers",
)
],
energy_consumption=self.energy.sel(
powertrain=l_pwt,
Expand All @@ -1784,7 +1819,10 @@ def set_hot_emissions(self):
powertrain_type="cng",
euro_classes=l_y,
lifetime_km=self.array.loc[
dict(powertrain="ICEV-g", parameter="lifetime kilometers",)
dict(
powertrain="ICEV-g",
parameter="lifetime kilometers",
)
],
energy_consumption=self.energy.sel(
powertrain=["ICEV-g"],
Expand Down Expand Up @@ -2019,7 +2057,10 @@ def get_share_biofuel(self):

share_biofuel = (
self.bs.biofuel.sel(
region=region, value=0, fuel_type="Biomass fuel", scenario=scenario,
region=region,
value=0,
fuel_type="Biomass fuel",
scenario=scenario,
)
.interp(
year=self.array.coords["year"].values,
Expand Down

0 comments on commit 11a721c

Please sign in to comment.