Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to ei39 #5

Merged
merged 12 commits into from
Feb 11, 2024
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ jobs:
- uses: actions/checkout@v2

- name: Install python version
uses: gabrielfalcao/pyenv-action@v7
uses: gabrielfalcao/pyenv-action@v13
with:
default: 3.9.0
default: 3.10.6
command: pip install -U pip # upgrade pip after installing python

- name: create environment
run: pyenv local 3.9.0 && python -mvenv .venv390
run: pyenv local 3.10.6 && python -mvenv .venv390

- name: Install dependencies
run: |
Expand All @@ -88,7 +88,7 @@ jobs:
fail-fast: false
matrix:
os: [ "ubuntu-latest" ]
python-version: [ "3.9" ]
python-version: [ "3.10" ]
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
Expand Down
4 changes: 3 additions & 1 deletion carculator_truck/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
inventory.py contains Inventory which provides all methods to solve inventories.
"""

import warnings

import numpy as np
from carculator_utils.inventory import Inventory

from . import DATA_DIR

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

IAM_FILES_DIR = DATA_DIR / "IAM"

Expand Down
23 changes: 13 additions & 10 deletions carculator_truck/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def finite(array, mask_value=0):


class TruckModel(VehicleModel):

"""
This class represents the entirety of the vehicles considered, with useful attributes, such as an array that stores
all the vehicles parameters.
Expand Down Expand Up @@ -163,9 +162,9 @@ def set_cargo_mass_and_annual_mileage(self):

for s in self.array.coords["size"].values:
cycle = self.cycle if isinstance(self.cycle, str) else "Urban delivery"
self.array.loc[
dict(size=s, parameter="kilometers per year")
] = annual_mileage[cycle][s]
self.array.loc[dict(size=s, parameter="kilometers per year")] = (
annual_mileage[cycle][s]
)

def adjust_cost(self):
"""
Expand Down Expand Up @@ -958,9 +957,11 @@ def remove_energy_consumption_from_unavailable_vehicles(self):
# as a result of curb mass being too large
vals = np.asarray(
[
np.round(v[2][0], 1)
if (v[0][0] - v[1][0]) > 0
else f"-{np.round(v[2][0])}-"
(
np.round(v[2][0], 1)
if (v[0][0] - v[1][0]) > 0
else f"-{np.round(v[2][0])}-"
)
for v in (
self.array.sel(
parameter=["gross mass", "driving mass", "cargo mass"],
Expand All @@ -978,9 +979,11 @@ def remove_energy_consumption_from_unavailable_vehicles(self):
parameter="is_available",
powertrain=pt,
year=y,
value="reference"
if "reference" in self.array.coords["value"]
else 0,
value=(
"reference"
if "reference" in self.array.coords["value"]
else 0
),
).values,
vals,
"/",
Expand Down
2 changes: 1 addition & 1 deletion conda/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
python:
- 3.9
- 3.10
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
carculator-utils==1.2.0.dev0
carculator-utils>=1.2.0.dev5
prettytable
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def package_files(directory):
package_data={
"carculator_truck": package_files(os.path.join("carculator_truck", "data"))
},
install_requires=["carculator_utils==1.2.0.dev0", "prettytable"],
python_requires=">=3.10",
install_requires=["carculator_utils>=1.2.0.dev5", "prettytable"],
url="https://github.com/romainsacchi/carculator_truck",
description="Prospective environmental and economic life cycle assessment"
"of medium and heavy goods vehicles",
Expand Down
50 changes: 22 additions & 28 deletions tests/test_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ def test_fuel_blend():
"share": [0.93, 0.93, 0.93, 0.93, 0.93, 0.93],
},
"secondary": {
"type": "biodiesel - cooking oil",
"type": "diesel - biodiesel - cooking oil",
"share": [0.07, 0.07, 0.07, 0.07, 0.07, 0.07],
},
},
"cng": {
"methane": {
"primary": {
"type": "biogas - sewage sludge",
"type": "methane - biomethane - sewage sludge",
"share": [1, 1, 1, 1, 1, 1],
}
},
Expand All @@ -88,45 +88,44 @@ def test_fuel_blend():
tm.fuel_blend["diesel"]["secondary"]["share"],
[0.07, 0.07, 0.07, 0.07, 0.07, 0.07],
)
assert np.allclose(tm.fuel_blend["cng"]["primary"]["share"], [1, 1, 1, 1, 1, 1])
# assert np.sum(ic.fuel_blends["cng"]["secondary"]["share"]) == 0
assert np.allclose(tm.fuel_blend["methane"]["primary"]["share"], [1, 1, 1, 1, 1, 1])

ic.calculate_impacts()

for fuels in [
("diesel", "electrolysis", "cng"),
("diesel", "hydrogen - electrolysis - PEM", "methane"),
(
"biodiesel - palm oil",
"smr - natural gas",
"biogas - sewage sludge",
"diesel - biodiesel - palm oil",
"hydrogen - smr - natural gas",
"methane - biomethane - sewage sludge",
),
(
"biodiesel - rapeseed oil",
"smr - natural gas with CCS",
"biogas - biowaste",
"diesel - biodiesel - rapeseed oil",
"hydrogen - smr - natural gas with CCS",
"methane - synthetic - coal",
),
(
"biodiesel - cooking oil",
"wood gasification with EF with CCS",
"biogas - biowaste",
"diesel - biodiesel - cooking oil",
"hydrogen - wood gasification",
"methane - synthetic - biological",
),
(
"biodiesel - algae",
"atr - biogas",
"biogas - biowaste",
"diesel - synthetic - FT - coal - economic allocation",
"hydrogen - atr - biogas",
"methane - synthetic - biological - MSWI",
),
(
"synthetic diesel - energy allocation",
"wood gasification with EF with CCS",
"syngas",
"diesel - synthetic - methanol - cement - economic allocation",
"hydrogen - wood gasification with CCS",
"methane - synthetic - electrochemical - MSWI",
),
]:
fb = {
"diesel": {
"primary": {"type": fuels[0], "share": [1, 1, 1, 1, 1, 1]},
},
"hydrogen": {"primary": {"type": fuels[1], "share": [1, 1, 1, 1, 1, 1]}},
"cng": {"primary": {"type": fuels[2], "share": [1, 1, 1, 1, 1, 1]}},
"methane": {"primary": {"type": fuels[2], "share": [1, 1, 1, 1, 1, 1]}},
}

tm = TruckModel(array, cycle="Long haul", country="CH", fuel_blend=fb)
Expand Down Expand Up @@ -163,12 +162,7 @@ def test_endpoint():

def test_sulfur_concentration():
ic = InventoryTruck(tm, method="recipe", indicator="endpoint")
ic.get_sulfur_content("RER", "diesel", 2000)
ic.get_sulfur_content("foo", "diesel", 2000)

with pytest.raises(ValueError) as wrapped_error:
ic.get_sulfur_content("FR", "diesel", "jku")
assert wrapped_error.type == ValueError
ic.get_sulfur_content("RER", "diesel")


def test_custom_electricity_mix():
Expand Down
Loading