Search code examples
brightway

Is it possible to use ecoinvent uncertanties in a foreground inventory?


I'm having trouble when importing an inventory, as a database. I have an excel inventory containing amounts, locations and ecoinvent flows. However I intend to run a MC simulation with background uncertainty. Is there a way to get the uncertainty parameters to my inventory or to link it with ecoinvent using the match database or apply_strategies methods? I haven't found much about it in the documentation. When I try:

    bd.projects.migrate_project_25
    fp = <'inventory_path'>
    enzymes = bi.ExcelImporter(fp)
    enzymes.match_database("ecoinvent 3.8 cutoff", fields=('name','unit','location','uncertainty type','scale'))
    enzymes.match_database("biosphere3", fields=('name','unit','uncertainty type','loc','scale'))
    enzymes.apply_strategies()
    enzymes.statistics()
    enzymes.write_database()

I get unlinked exchanges, and if I try without the uncertainty parameter in the match_database function, I get no unlinked exchanges.


Solution

  • thanks for your question!

    When you run the match_database function, you are trying to match specific parameters in two databases where you could have differences that you want to either ignore or keep. So, for example:

    a = {'foo': True, 'bar': False}
    b = {'foo': True, 'bar': True}
    

    If I wanted to treat a and b as the same thing, I could do:

    def match_objects(first: dict, second: dict, fields: [str]) -> bool:
        return all(first.get(field) == second.get(field) for field in fields)
    
    match_objects(a, b, ['foo'])
    >>> True
    

    However, if I wanted them to not match, I could run:

    match_objects(a, b, ['foo', 'bar'])
    >>> False
    

    This is exactly what match_database does. You only need to put in the fields you want to use for matching, not the fields you will eventually use for calculations or other purposes. Probably that is just name and unit in your example.

    Brightway will write all the fields when writing the database, and you will be able to use them later on.