Giter Club home page Giter Club logo

bw_hestia_bridge's People

Contributors

cmutel avatar michaelweinold avatar renovate[bot] avatar tfardet avatar timodiepers avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bw_hestia_bridge's Issues

Proposed structure for to get data from hestia

_hestia_api/
    __init__.py
    query.py
        search_hestia(element: str)
        get_hestia_node(node_id: str)
    credentials.py
        login_to_hestia(email: str, pwd: str)
        set_token(token: str)
utils/
    __init__.py
    version.py
    appdirs.py

appdirs (MIT) is to get folders to store the token and cache requests

I'd propose to load everything from _hestia_api into the main __init__.py.

Make sure linking entries are unique

Currently, linking strategy for "znex7uqxsfqn" fails with

Applying strategy: link_iterable_by_fields
Couldn't apply strategy link_iterable_by_fields:
	Object in source database can't be uniquely linked to target database.
Problematic dataset is:
{'cycle_id': 'znex7uqxsfqn',
 'filename': '(missing)',
 'term_id': 'excretaBeefCattleExceptFeedlotFedKgN',
 'transformation_id': '3'}
Possible targets include (at least one not shown):
[{'cycle_id': 'znex7uqxsfqn',
  'filename': '(missing)',
  'term_id': 'excretaBeefCattleExceptFeedlotFedKgN',
  'transformation_id': '3'},
 {'cycle_id': 'znex7uqxsfqn',
  'filename': '(missing)',
  'term_id': 'excretaBeefCattleExceptFeedlotFedKgN',
  'transformation_id': '3'},
 {'cycle_id': 'znex7uqxsfqn',
  'filename': '(missing)',
  'term_id': 'excretaBeefCattleExceptFeedlotFedKgN',
  'transformation_id': '3'}]

Utility function to quickly find input nodes, if present

This cycle: https://www-staging.hestia.earth/cycle/s_iwp86ylxhd?dataState=recalculated#impactDriverChart

Consumes one of the outputs of this cycle: https://www-staging.hestia.earth/cycle/ribhbymfmmt3?dataState=recalculated#impactDriverChart

(though one is 2013, one is 2014, I am not sure if there could be another cycle which is more cleanly linked...)

It would be great, when turning the cycle into a process that Brightway can handle, to be able to find these kinds of links by calling the API.

Search the hestia cycles for a cycle that has a specific output

# all referring to staging-api
node = bhb.get_hestia_node({"@type": "cycle", "@id": "cx_dtpwud1iu"})
node_output = [i for i in node["products"] if i["term"]["@id"] == "bananaFruit"][0]

# TODO: Search the hestia cycles if a cycle has node_output as an input
# Perhaps in this style?:
bhb.search_hestia({"cycle.inputs.term.@id": node_output["term"]["@id"]})

# And probably in other contexts as well, like looking for cycles with a specific product
node_input = [i for i in node["inputs"] if i["term"]["@id"] == "saplings"][0]
# Perhaps in this style?
bhb.search_hestia({"cycle.products.term.@id": node_input["term"]["@id"]})

Remove token support

We're never going to upload and this is the only thing that requires a token so I'll remove the credentials unless someone has a good reason to keep them.

Searching for products.term.name for type of impactassessment seems not to work

While

bhb.search_hestia({"products.term.name": "Saplings", "@type": "cycle"})

yields perfect results,

bhb.search_hestia({"products.term.name": "Soybean, seed (whole)", "@type": "impactassessment"})

yields only an emtpy list. But there is actually at least one Impact Assessment who has "Soybean, seed (whole)" as a product name. See:
https://www-staging.hestia.earth/impactassessment/bv2ktx0jjkub?dataState=recalculated

Switch "hestia_api" to "use_staging" boolean

To avoid having to search for the API URL, it will be included in the source and switch between stable and staging will just be done via:

set_config("use_staging", True/False)
save_config()  # optional, to remember the config from one run to another

Create new dataset from `Transformations`

In the Hestia ontology, a Transformation is: "The Transformation of one Product to a new Product in the same Cycle."

This is complicated because transformations can branch (product A goes down one branch, product B down the other), and there can be allocation. Also, the branches can have multiple steps, so in theory one cycle can produce many products, all linked together in an arborescence.

This should be well tested...

Change behaviour if node is not present on server

When not setting use_staging to True the following occurs:

>>> import bw_hestia_bridge as bhb
>>> bhb.get_hestia_node("zcuqxv54gn2x")
Traceback (most recent call last):
  File "miniconda3\envs\hestia\lib\site-packages\IPython\core\interactiveshell.py", line 3442, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-16-a0f08a0feebb>", line 1, in <module>
    bhb.get_hestia_node("zcuqxv54gn2x")
  File "hestia\bw_hestia_bridge\bw_hestia_bridge\hestia_api\querying.py", line 154, in get_hestia_node
    node_type = node_type or get_node_type(node_id)
  File "hestia\bw_hestia_bridge\bw_hestia_bridge\hestia_api\querying.py", line 169, in get_node_type
    return search_hestia({"@id": node_id}, how="exact")[0]["@type"].lower()
IndexError: list index out of range
>>> bhb.get_cycle_graph("zcuqxv54gn2x")
Traceback (most recent call last):
  File "miniconda3\envs\hestia\lib\site-packages\IPython\core\interactiveshell.py", line 3442, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-17-cbfabe4f7c90>", line 1, in <module>
    bhb.get_cycle_graph("zcuqxv54gn2x")
  File "hestia\bw_hestia_bridge\bw_hestia_bridge\hestia_api\cycle_graph.py", line 48, in get_cycle_graph
    eid = elt["@id"]
TypeError: string indices must be integers

The node with id "zcuqxv54gn2x" only exists on the staging server. It would be helpful to get somehow the information as a return of the called function that the node is not present via the implicitly or explicitly chosen API.

Decide on config or function arguments for staging

Note: this is not urgent at all but I think we need to make a decision at some point.

At the moment, having the staging argument in the HestiaImporter together with the config is problematic as we have a class argument that permanently overrides the library's state (if you forget to set it, and were on staging, you're back on stable).

In my mind, if you're going to use staging, you can just use set_config("use_staging", True) at the beginning of your script.
You can also use save_config() to make this change permanent and not have to set it anymore or use a "use_staging" environment variable. This is documented here.
I do not believe that people are going to switch between stable and staging dynamically within a script.
If you think this is the assumption we should be working with, then probably we need to remove the config altogether.

As we've mostly been working on staging and this might be the case for quite some time, the config avoid having to provide a staging=True argument to all functions, which I personally appreciate, together with the fact that you only need one command to switch your whole script from one to the other, but maybe it's not what is actually needed, especially in the long run.

I just think we need to decide once and for all what to implement because the current mixed situation is not satisfactory.

Add tests

Would be good to set up tests for the various functions.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/python-package-deploy.yml
  • actions/setup-python v5
.github/workflows/python-test.yml
  • actions/checkout v4
  • actions/setup-python v5
pep621
pyproject.toml
  • setuptools >=61.0
pip_requirements
requirements.txt
  • bw2data >= 4.0.dev29
  • bw2io >= 0.9.DEV23

  • Check this box to trigger a request for Renovate to run again on this repository

Use the EcoInvent ids from Hestia

People in the Hackathon added the EcoInvent ids in the Hestia database so we should be able to use this directly to map to EcoInvent.

Traverse hestia graph of cycles

  • to find for a specific cycle all related hestia cycles ("activities")
  • in order to reach just dependencies with emissions ("elementary flows")

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.