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 Apr 24, 2023
2 parents eabb4ca + 8a4c99e commit 2bad203
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 157 deletions.
3 changes: 2 additions & 1 deletion carculator_bus/__init__.py
Expand Up @@ -24,6 +24,7 @@
DATA_DIR = Path(__file__).resolve().parent / "data"

from carculator_utils.array import fill_xarray_from_input_parameters

from .bus_input_parameters import BusInputParameters
from .inventory import InventoryBus
from .model import BusModel
from .model import BusModel
4 changes: 2 additions & 2 deletions carculator_bus/bus_input_parameters.py
Expand Up @@ -4,7 +4,6 @@

from carculator_utils.vehicle_input_parameters import VehicleInputParameters


DEFAULT = Path(__file__, "..").resolve() / "data" / "default_parameters.json"
EXTRA = Path(__file__, "..").resolve() / "data" / "extra_parameters.json"

Expand All @@ -17,6 +16,7 @@ def load_parameters(obj):
# Already in correct form, just return
return obj


class BusInputParameters(VehicleInputParameters):
""" """

Expand All @@ -29,4 +29,4 @@ def __init__(
extra: Union[str, Path, list] = None,
) -> None:
"""Create a `klausen <https://github.com/cmutel/klausen>`__ model with the car input parameters."""
super().__init__(None)
super().__init__(None)
85 changes: 47 additions & 38 deletions carculator_bus/inventory.py
Expand Up @@ -3,9 +3,10 @@
"""

import numpy as np
from . import DATA_DIR
from carculator_utils.inventory import Inventory

from . import DATA_DIR

np.warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning)

IAM_FILES_DIR = DATA_DIR / "IAM"
Expand All @@ -28,11 +29,11 @@ def fill_in_A_matrix(self):

# Assembly
self.A[
:,
self.find_input_indices(("assembly operation, for lorry",)),
self.find_input_indices(("Bus, ",)),
:,
self.find_input_indices(("assembly operation, for lorry",)),
self.find_input_indices(("Bus, ",)),
] = (
self.array[self.array_inputs["curb mass"]] * -1
self.array[self.array_inputs["curb mass"]] * -1
)

# Glider/Frame
Expand Down Expand Up @@ -121,7 +122,9 @@ def fill_in_A_matrix(self):
self.find_input_indices(
contains=("Bus, ",), excludes=("BEV", "FCEV", "PHEV")
),
] = (self.array[self.array_inputs["other components mass"], :, index] * -1)
] = (
self.array[self.array_inputs["other components mass"], :, index] * -1
)

# Other components, for electric trucks
index = self.get_index_vehicle_from_array(
Expand All @@ -131,10 +134,10 @@ def fill_in_A_matrix(self):
self.A[
:,
self.find_input_indices(("other components, for electric lorry",)),
self.find_input_indices(
contains=("Bus, ",), excludes=("ICEV", "HEV")
),
] = (self.array[self.array_inputs["other components mass"], :, index] * -1)
self.find_input_indices(contains=("Bus, ",), excludes=("ICEV", "HEV")),
] = (
self.array[self.array_inputs["other components mass"], :, index] * -1
)

self.A[
:,
Expand Down Expand Up @@ -221,19 +224,21 @@ def fill_in_A_matrix(self):
self.find_input_indices(("lead acid battery, for lorry",)),
self.find_input_indices(contains=("Bus, ", "ICEV")),
] = (
(
self.array[
[self.array_inputs[x] for x in ["battery BoP mass", "battery cell mass"]], :, index
].sum(dim="parameter")
* (
1
+ self.array[
self.array_inputs["battery lifetime replacements"], :, index
]
)
self.array[
[
self.array_inputs[x]
for x in ["battery BoP mass", "battery cell mass"]
],
:,
index,
].sum(dim="parameter")
* (
1
+ self.array[
self.array_inputs["battery lifetime replacements"], :, index
]
)
* -1
)
) * -1

# Fuel tank for diesel trucks
index = self.get_index_vehicle_from_array(["ICEV-d", "HEV-d"])
Expand All @@ -242,11 +247,12 @@ def fill_in_A_matrix(self):
:,
self.find_input_indices(("fuel tank, for diesel vehicle",)),
self.find_input_indices(contains=("Bus, ", "EV-d"), excludes=("battery",)),
] = (self.array[self.array_inputs["fuel tank mass"], :, index] * -1)
] = (
self.array[self.array_inputs["fuel tank mass"], :, index] * -1
)

self.add_cng_tank()


# End-of-life disposal and treatment
self.A[
:,
Expand Down Expand Up @@ -274,7 +280,9 @@ def fill_in_A_matrix(self):
np.ix_(
np.arange(self.iterations),
self.find_input_indices(
contains=("diesel, burned in diesel-electric generating set, 18.5kW",),
contains=(
"diesel, burned in diesel-electric generating set, 18.5kW",
),
excludes=("market for"),
),
self.find_input_indices(
Expand All @@ -290,15 +298,19 @@ def fill_in_A_matrix(self):
self.add_fuel_to_vehicles("cng", ["ICEV-g"], "EV-g")

for year in self.scope["year"]:

cng_idx = self.get_index_vehicle_from_array(["ICEV-g"], [year], method="and")
cng_idx = self.get_index_vehicle_from_array(
["ICEV-g"], [year], method="and"
)

self.A[
:,
self.find_input_indices(("fuel supply for cng vehicles", str(year))),
self.find_input_indices((f"transport, {self.vm.vehicle_type}, ", "ICEV-g", str(year))),
self.find_input_indices(
(f"transport, {self.vm.vehicle_type}, ", "ICEV-g", str(year))
),
] *= (
1 + self.array[self.array_inputs["CNG pump-to-tank leakage"], :, cng_idx]
1
+ self.array[self.array_inputs["CNG pump-to-tank leakage"], :, cng_idx]
)

# Gas leakage to air
Expand Down Expand Up @@ -346,9 +358,8 @@ def fill_in_A_matrix(self):
contains=("Bus, ", "battery"), excludes=("motion", "opp")
),
)
] = (
-1
/ (self.array[self.array_inputs["kilometers per year"], :, index] * 2 * 24)
] = -1 / (
self.array[self.array_inputs["kilometers per year"], :, index] * 2 * 24
)

# Opportunity charging BEV buses
Expand All @@ -368,9 +379,8 @@ def fill_in_A_matrix(self):
),
self.find_input_indices(contains=("Bus, ", "BEV-opp")),
)
] = (
-1
/ (self.array[self.array_inputs["kilometers per year"], :, index] * 10 * 24)
] = -1 / (
self.array[self.array_inputs["kilometers per year"], :, index] * 10 * 24
)

# In-motion charging BEV buses
Expand All @@ -388,9 +398,8 @@ def fill_in_A_matrix(self):
self.find_input_indices(("Overhead lines",)),
self.find_input_indices(contains=("Bus, ", "BEV-motion")),
)
] = (
-1
/ (self.array[self.array_inputs["lifetime kilometers"], :, index] * 60 * 40)
] = -1 / (
self.array[self.array_inputs["lifetime kilometers"], :, index] * 60 * 40
)

print("*********************************************************************")

0 comments on commit 2bad203

Please sign in to comment.