From c74fcadb0a4a24fb41dfe6d12d3319e64c446536 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 11 Feb 2024 12:46:46 +0100 Subject: [PATCH 1/9] Migration to ei39 --- carculator_truck/__init__.py | 2 +- requirements.txt | 2 +- setup.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/carculator_truck/__init__.py b/carculator_truck/__init__.py index 6122281..8ff0b04 100644 --- a/carculator_truck/__init__.py +++ b/carculator_truck/__init__.py @@ -18,7 +18,7 @@ ) # library version -__version__ = (0, 4, 0) +__version__ = (0, 5, 0, "dev0") from pathlib import Path diff --git a/requirements.txt b/requirements.txt index 864a3e4..d07f474 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -carculator-utils +carculator-utils>=1.2.0.dev5 prettytable \ No newline at end of file diff --git a/setup.py b/setup.py index acd880a..6cca697 100644 --- a/setup.py +++ b/setup.py @@ -33,14 +33,14 @@ def package_files(directory): setup( name="carculator_truck", - version="0.4.0", + version="0.5.0.dev0", packages=packages, author="Romain Sacchi ", license=open("LICENSE").read(), package_data={ "carculator_truck": package_files(os.path.join("carculator_truck", "data")) }, - install_requires=["carculator_utils", "prettytable"], + 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", From 18ae70920071884849ed6076a697a13fbc6e365c Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 11 Feb 2024 12:54:45 +0100 Subject: [PATCH 2/9] Fix github action recipe --- .github/workflows/main.yml | 8 ++++---- conda/conda_build_config.yaml | 2 +- setup.py | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f63e628..335ee99 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: | @@ -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 diff --git a/conda/conda_build_config.yaml b/conda/conda_build_config.yaml index 8d03891..30c7120 100644 --- a/conda/conda_build_config.yaml +++ b/conda/conda_build_config.yaml @@ -1,2 +1,2 @@ python: - - 3.9 \ No newline at end of file + - 3.10 \ No newline at end of file diff --git a/setup.py b/setup.py index 6cca697..9ceecc8 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ def package_files(directory): package_data={ "carculator_truck": package_files(os.path.join("carculator_truck", "data")) }, + 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" From 7a4c38981df9dbc3fedad2cef51445ab2283bd05 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 11 Feb 2024 11:55:10 +0000 Subject: [PATCH 3/9] Black reformating --- carculator_truck/model.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/carculator_truck/model.py b/carculator_truck/model.py index 044d460..ccc7d34 100644 --- a/carculator_truck/model.py +++ b/carculator_truck/model.py @@ -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. @@ -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): """ @@ -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"], @@ -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, "/", From 6415e0136bd7b1a532bbcc4ec9e4ab2469784859 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 11 Feb 2024 13:15:36 +0100 Subject: [PATCH 4/9] Fix test --- carculator_truck/inventory.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/carculator_truck/inventory.py b/carculator_truck/inventory.py index d546a94..0f0fe25 100644 --- a/carculator_truck/inventory.py +++ b/carculator_truck/inventory.py @@ -1,13 +1,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" From 48addac03a0f560c2d12bb2a1d6a159eb841cfd5 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 11 Feb 2024 12:16:10 +0000 Subject: [PATCH 5/9] Black reformating --- carculator_truck/inventory.py | 1 + 1 file changed, 1 insertion(+) diff --git a/carculator_truck/inventory.py b/carculator_truck/inventory.py index 0f0fe25..5ccaa86 100644 --- a/carculator_truck/inventory.py +++ b/carculator_truck/inventory.py @@ -1,6 +1,7 @@ """ inventory.py contains Inventory which provides all methods to solve inventories. """ + import warnings import numpy as np From f9a26a57f6f3997290d417441109b0ea42d02fbb Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 11 Feb 2024 13:49:02 +0100 Subject: [PATCH 6/9] Fix test --- tests/test_inventory.py | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/tests/test_inventory.py b/tests/test_inventory.py index c880ee8..cfd2707 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -94,31 +94,31 @@ def test_fuel_blend(): 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 = { @@ -163,12 +163,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(): From 494207832b920bfb2308353f2853b9ec9a8e878c Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 11 Feb 2024 12:49:35 +0000 Subject: [PATCH 7/9] Black reformating --- tests/test_inventory.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/test_inventory.py b/tests/test_inventory.py index cfd2707..1e32080 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -96,29 +96,29 @@ def test_fuel_blend(): for fuels in [ ("diesel", "hydrogen - electrolysis - PEM", "methane"), ( - "diesel - biodiesel - palm oil", - "hydrogen - smr - natural gas", - "methane - biomethane - sewage sludge", + "diesel - biodiesel - palm oil", + "hydrogen - smr - natural gas", + "methane - biomethane - sewage sludge", ), ( - "diesel - biodiesel - rapeseed oil", - "hydrogen - smr - natural gas with CCS", - "methane - synthetic - coal", + "diesel - biodiesel - rapeseed oil", + "hydrogen - smr - natural gas with CCS", + "methane - synthetic - coal", ), ( - "diesel - biodiesel - cooking oil", - "hydrogen - wood gasification", - "methane - synthetic - biological", + "diesel - biodiesel - cooking oil", + "hydrogen - wood gasification", + "methane - synthetic - biological", ), ( - "diesel - synthetic - FT - coal - economic allocation", - "hydrogen - atr - biogas", - "methane - synthetic - biological - MSWI", + "diesel - synthetic - FT - coal - economic allocation", + "hydrogen - atr - biogas", + "methane - synthetic - biological - MSWI", ), ( - "diesel - synthetic - methanol - cement - economic allocation", - "hydrogen - wood gasification with CCS", - "methane - synthetic - electrochemical - MSWI", + "diesel - synthetic - methanol - cement - economic allocation", + "hydrogen - wood gasification with CCS", + "methane - synthetic - electrochemical - MSWI", ), ]: fb = { From 509963085c8b34e3a7b1421344017bc4d07b4eb7 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 11 Feb 2024 14:00:06 +0100 Subject: [PATCH 8/9] Fix test --- tests/test_inventory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_inventory.py b/tests/test_inventory.py index cfd2707..1303c28 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -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": { "primary": { - "type": "biogas - sewage sludge", + "type": "methane - biomethane - sewage sludge", "share": [1, 1, 1, 1, 1, 1], } }, From 3ef076ca72998755605c3108e72070fdf318049c Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 11 Feb 2024 14:18:35 +0100 Subject: [PATCH 9/9] Fix test --- tests/test_inventory.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_inventory.py b/tests/test_inventory.py index 683ce6d..72f6428 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -67,7 +67,7 @@ def test_fuel_blend(): "share": [0.07, 0.07, 0.07, 0.07, 0.07, 0.07], }, }, - "cng": { + "methane": { "primary": { "type": "methane - biomethane - sewage sludge", "share": [1, 1, 1, 1, 1, 1], @@ -88,8 +88,7 @@ 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() @@ -126,7 +125,7 @@ def test_fuel_blend(): "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)