From c907f87a4b2432bc1f15009c7cd2f699357aa022 Mon Sep 17 00:00:00 2001 From: msrocka Date: Fri, 30 Aug 2024 19:18:42 +0200 Subject: [PATCH] add examples for NW results --- src/results/impacts/normalized.md | 8 ++++++++ src/results/impacts/normalized.py | 28 ++++++++++++++++++++++++++++ src/results/impacts/weighted.md | 9 +++++++++ src/results/impacts/weighted.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 src/results/impacts/normalized.py create mode 100644 src/results/impacts/weighted.py diff --git a/src/results/impacts/normalized.md b/src/results/impacts/normalized.md index b7d80ca..e5290c0 100644 --- a/src/results/impacts/normalized.md +++ b/src/results/impacts/normalized.md @@ -28,3 +28,11 @@ which is available in modern web-browsers or platforms like {{#include normalized.ts:body}} ``` +### olca-ipc.py + +The example below shows how to get normalized impact assessment results using +olca-ipc.py: + +```py +{{#include normalized.py}} +``` diff --git a/src/results/impacts/normalized.py b/src/results/impacts/normalized.py new file mode 100644 index 0000000..f82211d --- /dev/null +++ b/src/results/impacts/normalized.py @@ -0,0 +1,28 @@ +import olca_ipc as ipc +import olca_schema as o + +client = ipc.Client() + +# get the impact assessment method +method = client.get(o.ImpactMethod, "bf665139-3159-45ef-9b00-f439251d2b5b") + +# select the first normalisation & weighting set for the example; +# make sure the method has nw-sets +nwset = method.nw_sets[0] + +# run a calculation +result = client.calculate(o.CalculationSetup( + target=o.Ref( + id="7d1cbce0-b5b3-47ba-95b5-014ab3c7f569", + ref_type=o.RefType.ProductSystem, + ), + impact_method=method.to_ref(), + nw_set=nwset.to_ref(), +)) +result.wait_until_ready() + +# print the normalized results +for nr in result.get_normalized_impacts(): + print(f"{nr.impact_category.name} :: {nr.amount}") + +result.dispose() diff --git a/src/results/impacts/weighted.md b/src/results/impacts/weighted.md index 442bea8..65f0fb0 100644 --- a/src/results/impacts/weighted.md +++ b/src/results/impacts/weighted.md @@ -29,3 +29,12 @@ which is available in modern web-browsers or platforms like ```ts {{#include weighted.ts:body}} ``` + +### olca-ipc.py + +The example below shows how to get weighted impact assessment results using +olca-ipc.py: + +```py +{{#include weighted.py}} +``` diff --git a/src/results/impacts/weighted.py b/src/results/impacts/weighted.py new file mode 100644 index 0000000..4d6a115 --- /dev/null +++ b/src/results/impacts/weighted.py @@ -0,0 +1,28 @@ +import olca_ipc as ipc +import olca_schema as o + +client = ipc.Client() + +# get the impact assessment method +method = client.get(o.ImpactMethod, "bf665139-3159-45ef-9b00-f439251d2b5b") + +# select the first normalisation & weighting set for the example; +# make sure the method has nw-sets +nwset = method.nw_sets[0] + +# run a calculation +result = client.calculate(o.CalculationSetup( + target=o.Ref( + id="7d1cbce0-b5b3-47ba-95b5-014ab3c7f569", + ref_type=o.RefType.ProductSystem, + ), + impact_method=method.to_ref(), + nw_set=nwset.to_ref(), +)) +result.wait_until_ready() + +# print the weighted results +for wr in result.get_weighted_impacts(): + print(f"{wr.impact_category.name} :: {wr.amount} {nwset.weighted_score_unit}") + +result.dispose()