Skip to content

Commit

Permalink
Some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Apr 9, 2021
1 parent ca6ef53 commit 6241a5d
Show file tree
Hide file tree
Showing 12 changed files with 13,971 additions and 6,951 deletions.
18,840 changes: 12,892 additions & 5,948 deletions carculator_bus/data/default_parameters.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions carculator_bus/data/dict_split.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ components;direct - non-exhaust;name;treatment of brake wear
components;direct - non-exhaust;name;treatment of tyre wear
components;energy chain;name;fuel supply
components;energy chain;name;electricity supply
components;maintenance;name;maintenance, lorry
components;maintenance;name;maintenance, bus
components;glider;name;market for glider
components;glider;name;glider lightweighting
components;glider;name;other components
components;glider;name;frame, blanks and saddle, for lorry
components;glider;name;suspension, for lorry
components;glider;name;cabin, for lorry
components;glider;name;tires and wheels, for lorry
components;powertrain;name;market for charger, electric passenger car
components;powertrain;name;market for inverter, for electric passenger car
Expand All @@ -34,5 +33,5 @@ components;energy storage;name;electricity market for energy storage production
components;energy storage;name;lead acid
components;energy storage;name;fuel tank, for diesel vehicle
components;road;name;market for road
components;EoL;name;treatment of used lorry
components;EoL;name;treatment of used bus
components;EoL;name;market for used li-ion battery
6 changes: 4 additions & 2 deletions carculator_bus/data/extra_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
"noise, octave 8, day time, rural",
"Lead direct emissions, suburban",
"internal noise",
"available payload",
"energy battery mass",
"fuel mass",
"Nitrogen dioxide direct emissions, urban",
Expand Down Expand Up @@ -259,5 +258,8 @@
"Cadmium direct emissions, rural",
"actual passengers capacity",
"daily distance",
"number of trips"
"number of trips",
"distance per trip",
"average speed",
"HVAC mass"
]
Binary file added carculator_bus/data/hot_buses.pickle
Binary file not shown.
27 changes: 11 additions & 16 deletions carculator_bus/energy_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@ def __init__(self, cycle, size=["3.5t", "7.5t", "18t", "26t", "32t", "40t", "60t
self.acceleration = np.zeros_like(self.velocity)
self.acceleration[1:-1] = (self.velocity[2:] - self.velocity[:-2]) / 2




def aux_energy_per_km(self,
hvac_power,
battery_cooling_unit,
battery_heating_unit,
country="CH",
indoor_temp = 21
indoor_temp=21
):

# monthly temperature average (12 values)
Expand All @@ -120,26 +117,24 @@ def aux_energy_per_km(self,
amb_temp = np.array([-30, -20, -10, 0, 10, 20, 30])
pct_power_HVAC = np.array([.95, .54, .29, .13, .04, .08, .45])

# Heating power as long as ambient temperature
# Heating power as long as ambient temperature, in W
# is below the comfort indoor temperature

p_heating = np.where(t < indoor_temp, np.interp(t, amb_temp, pct_power_HVAC),
0).mean() * hvac_power
p_heating = (np.where(t < indoor_temp, np.interp(t, amb_temp, pct_power_HVAC), 0).mean() * hvac_power).values

# Cooling power as long as ambient temperature
# Cooling power as long as ambient temperature, in W
# is above the comfort indoor temperature
p_cooling = np.where(t > indoor_temp, np.interp(t, amb_temp, pct_power_HVAC),
0).mean() * hvac_power
p_cooling = (np.where(t > indoor_temp, np.interp(t, amb_temp, pct_power_HVAC), 0).mean() * hvac_power).values


# We want to add power draw for battery cooling
# and battery heating

# battery cooling occuring above 20C
p_battery_cooling = np.where(t > 20, battery_cooling_unit, 0)

# battery heating occuring below 5C
p_battery_heating = np.where(t < 5, battery_heating_unit, 0)
# battery cooling occuring above 20C, in W
p_battery_cooling = np.where(t > 20, battery_cooling_unit, 0).mean()

# battery heating occuring below 5C, in W
p_battery_heating = np.where(t < 5, battery_heating_unit, 0).mean()
return p_cooling, p_heating, p_battery_cooling, p_battery_heating


Expand Down Expand Up @@ -197,7 +192,7 @@ def motive_energy_per_km(
"""

# Convert to km; velocity is m/s, times 1 second
distance = self.velocity.sum(axis=0)[0][0] / 1000
distance = self.velocity.sum(axis=0) / 1000

ones = np.ones_like(self.velocity)

Expand Down
82 changes: 24 additions & 58 deletions carculator_bus/hot_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import xarray
import pandas as pd
from . import DATA_DIR
import pickle


def _(o):
Expand All @@ -16,13 +17,12 @@ def get_emission_factors():
""" Emissions factors extracted for trucks from HBEFA 4.1
deatiled by size, powertrain and EURO class for each substance.
"""
fp = DATA_DIR / "hbefa_factors_vs_fc.xls"
ef = pd.read_excel(fp)
return (
ef.groupby(["powertrain", "euro_class", "component"])
.sum()
.to_xarray()/1000
).to_array()
fp = DATA_DIR / "hot_buses.pickle"

with open(fp, 'rb') as f:
hot = pickle.load(f)

return hot


class HotEmissionsModel:
Expand All @@ -36,28 +36,12 @@ class HotEmissionsModel:
"""

def __init__(self, cycle_name, cycle):

self.cycle_name = cycle_name
def __init__(self, cycle):
self.cycle = cycle
# We determine which sections of the driving cycle correspond to an urban, suburban and rural environment
# This is to compartmentalize emissions
self.cycle_environment = {
"Urban delivery": {"urban start": 0, "urban stop": -1},
"Long haul": {"rural start": 0, "rural stop": -1},
"Regional delivery": {
"urban start": 0,
"urban stop": 250,
"suburban start": 251,
"suburban stop": 750,
"rural start": 751,
"rural stop": -1,
},
}
self.em = get_emission_factors()

def get_emissions_per_powertrain(
self, powertrain_type, euro_classes, energy_consumption, debug_mode=False
self, powertrain_type, euro_classes, energy_consumption, size, debug_mode=False
):
"""
Calculate hot pollutants emissions given a powertrain type (i.e., diesel, CNG) and a EURO pollution class,
Expand Down Expand Up @@ -85,7 +69,7 @@ def get_emissions_per_powertrain(
"HC",
"CO",
"NOx",
"PM",
"PM2.5",
"NO2",
"CH4",
"NMHC",
Expand All @@ -101,19 +85,18 @@ def get_emissions_per_powertrain(
distance = np.array(distance).reshape(1, 1)

# Emissions for each second of the driving cycle equal:
# a * energy consumption + b
# with a, b being a coefficient and an intercept respectively given by fitting HBEFA 4.1 data
# a * energy consumption
# with a being a coefficient given by fitting HBEFA 4.1 data
# the fitting of emissions function of energy consumption is described in the notebook
# `HBEFA trucks.ipynb` in the folder `dev`.
# `HBEFA buses.ipynb` in the folder `dev`.
a = arr.sel(variable="a").values[:, None, None, :, None, None] * energy_consumption.values
b = arr.sel(variable="b").values[:, None, None, :, None, None]

# The receiving array should contain 40 substances, not 10
arr_shape = list(a.shape)
arr_shape[0] = 40
em_arr = np.zeros(tuple(arr_shape))

em_arr[:10] = a + b
em_arr[:10] = a

# Ethane, Propane, Butane, Pentane, Hexane, Cyclohexane, Heptane
# Ethene, Propene, 1-Pentene, Toluene, m-Xylene, o-Xylene
Expand Down Expand Up @@ -177,36 +160,19 @@ def get_emissions_per_powertrain(
# If the driving cycle selected is instead specified by the user (passed directly as an array), we used
# speed levels to compartmentalize emissions.

if "urban start" in self.cycle_environment[self.cycle_name]:
start = self.cycle_environment[self.cycle_name]["urban start"]
stop = self.cycle_environment[self.cycle_name]["urban stop"]
urban = np.sum(em_arr[..., start:stop], axis=-1)
urban /= 1000 # going from grams to kg
urban /= distance[:, None, None, None]

else:
urban = np.zeros((40, self.cycle.shape[-1], em_arr.shape[2], em_arr.shape[3], em_arr.shape[4]))

if "suburban start" in self.cycle_environment[self.cycle_name]:
start = self.cycle_environment[self.cycle_name]["suburban start"]
stop = self.cycle_environment[self.cycle_name]["suburban stop"]
suburban = np.sum(em_arr[..., start:stop], axis=-1)
suburban /= 1000 # going from grams to kg
suburban /= distance[:, None, None, None]

else:
suburban = np.zeros((40, self.cycle.shape[-1], em_arr.shape[2], em_arr.shape[3], em_arr.shape[4]))
for s in size:
if s in ["9m", "13m-city", "13m-city-double"]:

if "rural start" in self.cycle_environment[self.cycle_name]:
start = self.cycle_environment[self.cycle_name]["rural start"]
stop = self.cycle_environment[self.cycle_name]["rural stop"]
rural = np.sum(em_arr[..., start:stop], axis=-1)
rural /= 1000 # going from grams to kg
rural /= distance[:, None, None, None]
urban = np.sum(em_arr, axis=-1) / 1000 / distance[:, None, None, None]
suburban = np.zeros((40, self.cycle.shape[-1], em_arr.shape[2], em_arr.shape[3], em_arr.shape[4]))
rural = np.zeros((40, self.cycle.shape[-1], em_arr.shape[2], em_arr.shape[3], em_arr.shape[4]))

else:
else:

rural = np.zeros((40, self.cycle.shape[-1], em_arr.shape[2], em_arr.shape[3], em_arr.shape[4]))
urban = np.zeros((40, self.cycle.shape[-1], em_arr.shape[2], em_arr.shape[3], em_arr.shape[4]))
suburban = np.sum(em_arr[..., 4000:12500], axis=-1) / 1000 / distance[:, None, None, None]
rural = np.sum(em_arr[..., 2000:4000], axis=-1) / 1000 / distance[:, None, None, None]
rural += np.sum(em_arr[..., 12500:], axis=-1) / 1000 / distance[:, None, None, None]

res = np.vstack((urban, suburban, rural))

Expand Down
Loading

0 comments on commit 6241a5d

Please sign in to comment.