Code Monkey home page Code Monkey logo

Comments (6)

aleksandra-kim avatar aleksandra-kim commented on September 26, 2024

Original comment by Shubhankar Upasani (Bitbucket: Shubh1995, GitHub: Shubh1995).


I have the excel file that lists all the unlinked exchanges using

#!python

sp.write_excel(only_unlinked=True)

Can I perform a migration by reading from this excel file? Any suggestions how to?

from brightway2-io.

aleksandra-kim avatar aleksandra-kim commented on September 26, 2024

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


I assume you were linking to the US LCI notebook. As you read at the end: "For every unmatched exchange, there is a reason the computer couldn't match it exactly. The next step is to figure out the problem for each exchange, and then write a migration to fix the input data to match what is expected."

A migration is a set of structured data that changes attributes based on filters. For example, "carbon dioxide" could be changed into "carbon dioxide, fossil" if the associated activity was a combustion activity. You can see examples of migrations here and here.

To link the US LCI completely, you will need to write migrations to change the provided values into ones that can be matched exactly by other biosphere flows or activity names/units/whatever. In other words, you will have to find the existing values, find the "correct values", and write a migration from one to the other. The excel file can help, but you will also have to search for the "correct" values. The other importing notebooks have specific examples of how to build and use migrations.

Importing with missing biosphere flows just means you will miss out on some (potentially important) biosphere flows; importing with missing links in activities isn't possible unless you delete activities willy-nilly, which is almost certainly not what you want.

from brightway2-io.

aleksandra-kim avatar aleksandra-kim commented on September 26, 2024

Original comment by Shubhankar Upasani (Bitbucket: Shubh1995, GitHub: Shubh1995).


Hi Chris,

Thanks for replying. Finding the "correct values" seems too tedious. For each exchange, I need to find an associated process in ecoinvent?

Can I change my default biosphere3 (or biosphere4) to contain US LCI biosphere flows? Would that be possible and make things easier?

from brightway2-io.

aleksandra-kim avatar aleksandra-kim commented on September 26, 2024

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


It is tedious, that's why it hasn't been added to the default library so far. For each value which doesn't fit (could be activity name, but also unit, location, reference product), one needs to find the "correct" value.

You could use the biosphere flows from the US LCI, but then you wouldn't have any LCIA methods, and also would have the reverse problem linking e.g. ecoinvent activities to the US LCI biosphere flows.

So, there is no easy answer. This is the unfortunate state of LCA data exchange, and one of the reasons behind efforts like BONSAI.

from brightway2-io.

aleksandra-kim avatar aleksandra-kim commented on September 26, 2024

Original comment by Shubhankar Upasani (Bitbucket: Shubh1995, GitHub: Shubh1995).


Can you elaborate on how to apply

#!python

link_iterable_by_fields

after writing a migration? My question stands particularly for linking US LCI. I haven't imported ecoinvent 2.2 so I guess my code should be like

#!python

import functools
c = functools.partial(link_iterable_by_fields(unlinked = biosphere_flow_migration ,
    other=Database(config.biosphere)),
    kind='biosphere'
)
sp.apply_strategy(c)

where

#!python

biosphere_flow_migration

comes from the following migration definition

#!python

biosphere_flow_migration = Migration("US-LCI-biosphere").write(
    biosphere_migration_data, 
    description="unlinked biosphere exchanges in US LCI "
)

The error looks like this

#!python
TypeError                                 Traceback (most recent call last)
<ipython-input-93-e8a1bd027374> in <module>()
      1 import functools
      2 c = functools.partial(link_iterable_by_fields(unlinked = biosphere_flow_migration ,
----> 3     other=Database(config.biosphere)),
      4     kind='biosphere'
      5 )

~\AppData\Local\conda\conda\envs\tes\lib\site-packages\bw2io\strategies\generic.py in link_iterable_by_fields(unlinked, other, fields, kind, internal, relink)
     61                             "``database`` or ``code`` attributes")
     62 
---> 63     for container in unlinked:
     64         for obj in filter(filter_func, container.get('exchanges', [])):
     65             key = activity_hash(obj, fields)

TypeError: 'NoneType' object is not iterable



Any changes or suggestions? I don't think

#!python

sp.match_database

should work here.

from brightway2-io.

aleksandra-kim avatar aleksandra-kim commented on September 26, 2024

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


You should basically never be running link_iterable_by_fields yourself - it is normally wrapped by another call. In this case, you can call importer_object.migrate('name of migration'). See example, example.

from brightway2-io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.