Skip to content

Commit

Permalink
Latest work
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed May 9, 2021
1 parent 6514c21 commit a45c72f
Show file tree
Hide file tree
Showing 62 changed files with 10,834 additions and 12,683 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<a href="https://carculator_bus.readthedocs.io/en/latest/" target="_blank"><img src="https://readthedocs.org/projects/carculator_bus/badge/?version=latest"></a>
</p>

Prospective environmental and economic life cycle assessment of medium and heavy duty vehicles.
Prospective environmental and economic life cycle assessment of urban and coach buses.

A fully parameterized Python model developed by the [Technology Assessment group](https://www.psi.ch/en/ta) of the
[Paul Scherrer Institut](https://www.psi.ch/en) to perform life cycle assessments (LCA) of medium and heavy duty trucks.
[Paul Scherrer Institut](https://www.psi.ch/en) to perform life cycle assessments (LCA) of urban and coach buses.
Based on the Life Cycle Assessment tool for passenger vehicles [carculator](https://github.com/romainsacchi/carculator).

See [the documentation](https://carculator_bus.readthedocs.io/en/latest/index.html) for more detail, validation, etc.
Expand Down
4 changes: 1 addition & 3 deletions carculator_bus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"HotEmissionsModel",
"create_fleet_composition_from_IAM_file",
"extract_electricity_mix_from_IAM_file",
"extract_biofuel_shares_from_IAM"
)

# library version
Expand All @@ -41,8 +40,7 @@
from .model import BusModel
from .hot_emissions import HotEmissionsModel
from .inventory import InventoryCalculation
from .utils import (create_fleet_composition_from_IAM_file, extract_electricity_mix_from_IAM_file,
extract_biofuel_shares_from_IAM)
from .utils import (create_fleet_composition_from_IAM_file, extract_electricity_mix_from_IAM_file)



57 changes: 28 additions & 29 deletions carculator_bus/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pandas as pd
import stats_arrays as sa
import xarray as xr
import itertools


def fill_xarray_from_input_parameters(bip, sensitivity=False, scope=None):
Expand Down Expand Up @@ -50,13 +51,6 @@ def fill_xarray_from_input_parameters(bip, sensitivity=False, scope=None):
if "year" not in scope:
scope["year"] = bip.years

# Make sure to include PHEV-e and PHEV-c-d if
# PHEV-d is listed

if "PHEV-d" in scope["powertrain"]:
for pt in ["PHEV-e", "PHEV-c-d"]:
if pt not in scope["powertrain"]:
scope["powertrain"].append(pt)


if any(s for s in scope["size"] if s not in bip.sizes):
Expand Down Expand Up @@ -106,7 +100,8 @@ def fill_xarray_from_input_parameters(bip, sensitivity=False, scope=None):
],
dims=["size", "powertrain", "parameter", "year", "value"],
).astype("float32")
# if the purpose is ot do a sensitivity analysis

# if the purpose is to do a sensitivity analysis
# then the length of the dimensions `value` equals the number of parameters
else:
params = ["reference"]
Expand All @@ -121,7 +116,7 @@ def fill_xarray_from_input_parameters(bip, sensitivity=False, scope=None):
len(params),
)
),
coords=[bip.sizes, bip.powertrains, bip.parameters, bip.years, params, ],
coords=[scope["size"], scope["powertrain"], bip.parameters, scope["year"], params],
dims=["size", "powertrain", "parameter", "year", "value"],
).astype("float32")

Expand Down Expand Up @@ -161,33 +156,37 @@ def fill_xarray_from_input_parameters(bip, sensitivity=False, scope=None):
else:
# if `sensitivity` == True, the values of each parameter is
# incremented by 10% when `value` == `parameter`
for param in bip.input_parameters:
for x, param in enumerate(bip.input_parameters):
names = [n for n in bip.metadata if bip.metadata[n]['name'] == param]

pwt = set(bip.metadata[param]["powertrain"]) if isinstance(bip.metadata[param]["powertrain"], list) \
else set([bip.metadata[param]["powertrain"]])
pwt = list(set(itertools.chain.from_iterable([bip.metadata[name]["powertrain"] for name in names])))

size = set(bip.metadata[param]["sizes"]) if isinstance(bip.metadata[param]["sizes"], list) \
else set([bip.metadata[param]["sizes"]])
size = list(set(itertools.chain.from_iterable([bip.metadata[name]["sizes"] for name in names])))

year = set(bip.metadata[param]["year"]) if isinstance(bip.metadata[param]["year"], list) \
else set([bip.metadata[param]["year"]])
year = [str(bip.metadata[name]["year"]) for name in names]
year = list(set(year))
year = [int(y) for y in year]

for name in names:
vals = [bip.values[name] for _ in range(0, len(bip.input_parameters) + 1)]
vals[bip.input_parameters.index(param) + 1] *= 1.1

array.loc[
dict(
powertrain=[p for p in pwt
if p in scope["powertrain"]],
size=[s for s in size
if s in scope["size"]],
year=[y for y in year
if y in scope["year"]],
parameter=bip.metadata[name]["name"],
)
] = vals
if any(p for p in pwt if p in scope["powertrain"]) \
and any(s for s in size if s in scope["size"]) \
and any(y for y in year if y in scope["year"]):

vals = [bip.values[name] for _ in range(0, len(bip.input_parameters) + 1)]
vals[x + 1] *= 1.1

array.loc[
dict(
powertrain=[p for p in pwt
if p in scope["powertrain"]],
size=[s for s in size
if s in scope["size"]],
year=[y for y in year
if y in scope["year"]],
parameter=bip.metadata[name]["name"],
)
] = vals

return (size_dict, powertrain_dict, parameter_dict, year_dict), array

Expand Down
1,961 changes: 982 additions & 979 deletions carculator_bus/data/A_matrix.csv

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit a45c72f

Please sign in to comment.