Skip to content

Commit

Permalink
add examples for NW results
Browse files Browse the repository at this point in the history
  • Loading branch information
msrocka committed Aug 30, 2024
1 parent 95187af commit c907f87
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/results/impacts/normalized.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
```
28 changes: 28 additions & 0 deletions src/results/impacts/normalized.py
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions src/results/impacts/weighted.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
```
28 changes: 28 additions & 0 deletions src/results/impacts/weighted.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit c907f87

Please sign in to comment.