brightway-lca / brightway2

Metapackage for brightway2 imports and documentation
https://brightway.dev/
BSD 3-Clause "New" or "Revised" License
100 stars 37 forks source link

Correct way to do activity-level LCIA #43

Closed MaxHalford closed 2 years ago

MaxHalford commented 2 years ago

Hey there @cmutel and co. I'm really enjoying your tool. Such a game-changer. Keep it up :)

In my case, I'm using Brightway2 to load Ecoinvent 3.8 data. I then want to run LCA to obtain scores for a subset of methods. I have 19565 activities. It's taking me roughly 24 hours to cover all the activities.

Am I doing something wrong? My usecase is very simple: I just need the score for one functional unit of each activity. So I'm wondering if I missed something. For instance maybe these activity-level LCIA values might be precomputed and available somewhere.

Here is the crux of my code:

import tqdm

lcias = {}

for activity in tqdm.tqdm(eidb):
    for method in [('CML 2001 (superseded)', 'climate change', 'GWP 20a')]:
        functional_unit = {activity: 1}
        lca = bw.LCA(functional_unit, method)
        lca.lci()
        lca.lcia()
        lcias[activity.key[1]] = {method: lca.score}

I noticed the switch and redo_* methods, but they don't save any computation time, on the contrary:

import tqdm

lcias = {}
lca = None

for activity in tqdm.tqdm(eidb):
    for method in [('CML 2001 (superseded)', 'climate change', 'GWP 20a')]:
        functional_unit = {activity: 1}
        if lca is None:
            lca = bw.LCA(functional_unit, method)
            lca.lci()
            lca.lcia()
        else:
            lca.switch_method(method)
            lca.redo_lci(functional_unit)
            lca.redo_lcia(functional_unit)

        lcias[activity.key[1]] = {method: lca.score}

Kind regards.

BenPortner commented 2 years ago

Hi @MaxHalford,

Most computation time is needed for the lci, consequently you should avoid it when you can. If you switch the method, there is no need to call redo_lci. You only need to redo_lci when you change the functional unit.

That being said, if your goal is to get the LCIA scores for all ecoinvent activities, it would be faster to simply download them. Check https://v38.ecoquery.ecoinvent.org/File/Files.

MaxHalford commented 2 years ago

Hey @BenPortner, thanks for the swift answer.

Most computation time is needed for the lci, consequently you should avoid it when you can. If you switch the method, there is no need to call redo_lci. You only need to redo_lci when you change the functional unit.

Duly noted, that's a good tip.

That being said, if your goal is to get the LCIA scores for all ecoinvent activities, it would be faster to simply download them. Check https://v38.ecoquery.ecoinvent.org/File/Files.

Ahah, silly me. And what's the recommended procedure for loading that data with Brightway2? Are there docs about that somewhere? Or should I just use the same procedure as I did for the activity SPOLD files?

Sorry for the possibly naive questions, I'm very new to this field :)

BenPortner commented 2 years ago

Hi @MaxHalford,

The files (ecoinvent 3.8_[system_model]_cumulative_lcia_xlsx.7z) are archives, which contain an Excel file that has activities for rows and methods for columns. The data points are the LCIA scores for the corresponding activity-method pair. Brightway offers no functionality to import these - but I am also not sure why you would need them in Brightway?

MaxHalford commented 2 years ago

I just found that the xlsx were a pain to work with. I liked that Brightway2 allows reading the spold files, and provides a common interface to different sources.

I'll have another go at the excel files, thanks :)