brightway-lca / brightway2-analyzer

BSD 3-Clause "New" or "Revised" License
7 stars 12 forks source link

Update tagged.py to handle traverse of multiple foreground databases #6

Closed ntropy-esa closed 2 years ago

ntropy-esa commented 3 years ago

Hello there, First attempt to contribute to code development in the bw2 community, after the encouraging brightcon'

In a previous project, I have used the traverse_tagged_database function to group my foreground results by tags, when I had only one foreground database. Now, I have a much larger project, and to keep things sorted in the Activity-Browser, I created several foreground databases (machinery, biomass, pyrolysis, use1, use2, use3, use4, use5) and I use ecoinvent as a background database.

So, I made a first attempt to edit the function, adding a parameter fg_databases. If the parameter fg_databases is set to a list of databases, they are all considered in the traverse. Otherwise, the function behaves as in previous version. I am also trying to make sure that fg_databases does not include all databases involved in a given activity, to avoid recursing through the background database (but we can't prevent a user from adding a large database like ecoinvent anyway to the fg_databases).

As far as I've tested this small change, it seems to work fine for my needs.

Maybe there are some improvements to do - or should the new functions have a new name (like for multi_traverse) instead of overriding the current functions?

cmutel commented 2 years ago

@ntropy-esa Sorry, I simply did not see this until now, thanks a lot! This will be in the upcoming 0.11.1 release, we need tests to make sure it works as expected.