Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Apr 24, 2023
1 parent 7d37940 commit 8ad132a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
49 changes: 34 additions & 15 deletions carculator_utils/energy_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,27 @@ def calculate_hvac_energy(
battery_cooling_unit,
battery_heating_unit,
) -> tuple[Any, Any, Any, Any]:

if self.ambient_temperature is not None:
if isinstance(self.ambient_temperature, (float, int)):
self.ambient_temperature = np.resize(self.ambient_temperature, (12,))
else:
self.ambient_temperature = np.array(self.ambient_temperature)
assert len(self.ambient_temperature) == 12, "Ambient temperature must be a 12-month array"
assert (
len(self.ambient_temperature) == 12
), "Ambient temperature must be a 12-month array"
else:
self.ambient_temperature = np.resize(get_country_temperature(self.country), (12,))
self.ambient_temperature = np.resize(
get_country_temperature(self.country), (12,)
)

if self.indoor_temperature is not None:
if isinstance(self.indoor_temperature, (float, int)):
self.indoor_temperature = np.resize(self.indoor_temperature, (12,))
else:
self.indoor_temperature = np.array(self.indoor_temperature)
assert len(self.indoor_temperature) == 12, "Indoor temperature must be a 12-month array"
assert (
len(self.indoor_temperature) == 12
), "Indoor temperature must be a 12-month array"

# use ambient temperature if provided, otherwise
# monthly temperature average (12 values)
Expand All @@ -250,7 +255,9 @@ def calculate_hvac_energy(
p_heating = (
np.where(
self.ambient_temperature < self.indoor_temperature,
np.interp(self.ambient_temperature, amb_temp_data_points, pct_power_HVAC),
np.interp(
self.ambient_temperature, amb_temp_data_points, pct_power_HVAC
),
0,
).mean()
* hvac_power
Expand All @@ -261,7 +268,9 @@ def calculate_hvac_energy(
p_cooling = (
np.where(
self.ambient_temperature >= self.indoor_temperature,
np.interp(self.ambient_temperature, amb_temp_data_points, pct_power_HVAC),
np.interp(
self.ambient_temperature, amb_temp_data_points, pct_power_HVAC
),
0,
).mean()
* hvac_power
Expand All @@ -271,11 +280,15 @@ def calculate_hvac_energy(
# and battery heating

# battery cooling occurring above 20C, in W
p_battery_cooling = np.where(self.ambient_temperature > 20, _(battery_cooling_unit), 0)
p_battery_cooling = np.where(
self.ambient_temperature > 20, _(battery_cooling_unit), 0
)
p_battery_cooling = p_battery_cooling.mean(-1)

# battery heating occurring below 5C, in W
p_battery_heating = np.where(self.ambient_temperature < 5, _(battery_heating_unit), 0)
p_battery_heating = np.where(
self.ambient_temperature < 5, _(battery_heating_unit), 0
)
p_battery_heating = p_battery_heating.mean(-1)

return p_cooling, p_heating, p_battery_cooling, p_battery_heating
Expand All @@ -293,7 +306,7 @@ def find_last_driving_second(self) -> ndarray:

for i in range(self.velocity.shape[-1]):
last_index = np.where(self.velocity[..., i] > 0)[0][-1]
driving_time[: last_index, ..., i] = 1
driving_time[:last_index, ..., i] = 1

return driving_time

Expand Down Expand Up @@ -336,8 +349,10 @@ def aux_energy_per_km(

return (
aux_power.T.values * np.where(self.velocity > 0, 1, 0),
(p_cooling / _o(heat_pump_cop_cooling) * cooling_consumption).T.values * self.driving_time,
(p_heating / _o(heat_pump_cop_heating) * heating_consumption).T.values * self.driving_time,
(p_cooling / _o(heat_pump_cop_cooling) * cooling_consumption).T.values
* self.driving_time,
(p_heating / _o(heat_pump_cop_heating) * heating_consumption).T.values
* self.driving_time,
p_battery_cooling.T * self.driving_time,
p_battery_heating.T * self.driving_time,
)
Expand All @@ -346,9 +361,7 @@ def aux_energy_per_km(

# Provide energy in kJ / km (1 J = 1 Ws)
auxiliary_energy = (
_c(aux_power).T[None, ...] # Watts
* 1000 # m / km
/ 1000 # 1 / (J / kJ)
_c(aux_power).T[None, ...] * 1000 / 1000 # Watts # m / km # 1 / (J / kJ)
)

efficiency = _c(efficiency)
Expand Down Expand Up @@ -569,7 +582,13 @@ def motive_energy_per_km(
np.zeros_like(auxiliary_energy),
)
else:
auxiliary_energy, cooling_energy, heating_energy, battery_cooling, battery_heating = self.aux_energy_per_km(
(
auxiliary_energy,
cooling_energy,
heating_energy,
battery_cooling,
battery_heating,
) = self.aux_energy_per_km(
aux_power,
engine_efficiency,
hvac_power,
Expand Down
7 changes: 3 additions & 4 deletions carculator_utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,9 @@ def set_share_recuperated_energy(self) -> None:
_ = lambda x: np.where(x == 0, 1, x)

self["share recuperated energy"] = (
(_(self.energy.sel(parameter="recuperated energy").sum(dim="second"))
/ _(self.energy.sel(parameter="negative motive energy").sum(dim="second"))).T
* (self["combustion power share"] < 1)
)
_(self.energy.sel(parameter="recuperated energy").sum(dim="second"))
/ _(self.energy.sel(parameter="negative motive energy").sum(dim="second"))
).T * (self["combustion power share"] < 1)

if "PHEV-d" in self.array.powertrain:
self.array.loc[
Expand Down

0 comments on commit 8ad132a

Please sign in to comment.