GithubHelp home page GithubHelp logo

polca / wurst Goto Github PK

View Code? Open in Web Editor NEW
36.0 9.0 11.0 546 KB

Code and metadata for linking life cycle assessment databases to other models

License: Other

Python 97.14% Jupyter Notebook 2.86%

wurst's Introduction

Wurst

PyPi Version Conda Version Build Status Coverage Status Docs

Show how the sausage is made!

Wurst is a python package for linking and modifying industrial ecology models, with a focus on sparse matrices in life cycle assessment. It provides the following:

  • Helper functions to filter activities and exchanges
  • Helper functions to link exchanges
  • Transformation functions to change markets, change input efficiencies, and change emissions
  • Data IO with Brightway2
  • Logging framework and a log browser

See also the separate wurst examples repository.

Installation

Download and install miniconda, create and activate a new environment, and then install::

conda install -c conda-forge brightway2 jupyter wurst

License

BSD 2-clause license. Contributions are welcome!

Authors

  • Chris Mutel
  • Brian Cox

TODO

  • Review BW2 IO code to make sure all needed fields are present in newly-created and modified databases
  • Parameterized exchanges (e.g. electricity sector)
  • Check logging on all transformation functions
  • Log browser web app

wurst's People

Contributors

brianlcox avatar cmutel avatar kais-siala avatar m-rossi avatar pbaustert avatar romainsacchi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wurst's Issues

NoResults: No suitable production exchanges founds

Hello all,

I am trying to link and save an excel database, but I am getting an error (screenshot attached). Could you please let me know what might be the possibility for the error to occur?

Thank you!
image

Get region codes

REGIONS = [(row, ws.cell(row=row, column=2).value) for row in range(5, 47)]

Brian found an error, it is taking the data until line 45 (index 46) missing the last line of the data with RoW. So it should be 47 instead of 46 in the line of code.

Categories None in activity metadata

Hi.
Whenever I use wurst.extract_brightway2_databases() the resulting list incorporates a key categories: None in the activity description. This creates an issue whenever at the end you try to write_database not using wurst.
I know that it's not the expected function to use (should use wurst.write_brightway2_database() but because of reasons I have to use the brightway2 function write_database().
Anyways, while using the write_database() of brightway2, it tries to join categories (for elementary flows) but then also tries to do the same for activities (since wurst added categories) and because it is None, the .join of the _format_dataset() function of the IndexManager of brightway2 fails.
In any case I already resolved my issue but i still flag it instead it's somehow useful.

Inconsistency between `name` and `activity`

In the current schema, an activity has the field name in its metadata, but this same field is called activity in the exchange metadata. We can call it name in both cases - this decreases cognitive load and unpleasant surprises.

Reported by @brianlcox

ecoinvent filters for oil electricity have to exclude nuclear

the current oil electricity filters have to exclude nuclear, because 'boiling water reactor' is also selected here.

oil_open_cycle_electricity = [
contains('name', 'oil'),
contains('name', 'electricity'),
equals('unit', 'kilowatt hour'),
exclude(contains('name', 'combined cycle')),
]

oil_combined_cycle_electricity = [
contains('name', 'oil'),
contains('name', 'electricity'),
equals('unit', 'kilowatt hour'),
contains('name', 'combined cycle'),
]

oil_chp_electricity = [
contains('name', 'oil'),
contains('name', 'heat and power'),
equals('unit', 'kilowatt hour'),
]

Need parameters (efficiency) in database extract

Hi Chris,

We need the efficiency parameter extracted with the database!

I have found (so far) three different ways that the efficiency parameter could be labelled:

['parameters']['efficiency']['amount']
['parameters']['efficiency_oil_country']['amount']
['parameters']['efficiency_electrical']['amount']

Sometimes it's also hidden in the comments section, but there isn't much we can do about that...

Thanks,

Brian

Error "can only join an iterable" while writing database

Hi there,
I made some changes in the database and when i write database i get below error. Even just after reading the database in to wurst format when i directly try to write it to database it gives the same error.

TypeError Traceback (most recent call last)
d:\Python\Wurst\change_global_markets_location_to_rer.ipynb Cell 18 line 1
----> 1 w.write_brightway2_database(data,"cutoff_3.9.1_updated_22-10_test")

File c:\Users\M. Zeeshan\anaconda3\envs\bw\Lib\site-packages\wurst\brightway\write_database.py:53, in write_brightway2_database(data, name)
51 check_internal_linking(data)
52 check_duplicate_codes(data)
---> 53 WurstImporter(name, data).write_database()

File c:\Users\M. Zeeshan\anaconda3\envs\bw\Lib\site-packages\wurst\brightway\write_database.py:21, in WurstImporter.write_database(self)
19 assert not self.statistics()[2], "Not all exchanges are linked"
20 assert self.db_name not in databases, "This database already exists"
---> 21 super().write_database()

File c:\Users\M. Zeeshan\anaconda3\envs\bw\Lib\site-packages\bw2io\importers\base_lci.py:269, in LCIImporter.write_database(self, data, delete_existing, backend, activate_parameters, **kwargs)
266 self.write_database_parameters(activate_parameters, delete_existing)
268 existing.update(data)
--> 269 db.write(existing)
271 if activate_parameters:
272 self._write_activity_parameters(activity_parameters)

File c:\Users\M. Zeeshan\anaconda3\envs\bw\Lib\site-packages\bw2data\project.py:358, in writable_project(wrapped, instance, args, kwargs)
356 if projects.read_only:
357 raise ReadOnlyProject(READ_ONLY_PROJECT)
--> 358 return wrapped(*args, **kwargs)

File c:\Users\M. Zeeshan\anaconda3\envs\bw\Lib\site-packages\bw2data\backends\peewee\database.py:266, in SQLiteBackend.write(self, data, process)
263 self.delete(warn=False)
264 raise
--> 266 self.make_searchable(reset=True)
268 if process:
269 self.process()

File c:\Users\M. Zeeshan\anaconda3\envs\bw\Lib\site-packages\bw2data\project.py:358, in writable_project(wrapped, instance, args, kwargs)
356 if projects.read_only:
357 raise ReadOnlyProject(READ_ONLY_PROJECT)
--> 358 return wrapped(*args, **kwargs)

File c:\Users\M. Zeeshan\anaconda3\envs\bw\Lib\site-packages\bw2data\backends\peewee\database.py:311, in SQLiteBackend.make_searchable(self, reset)
309 databases.flush()
310 IndexManager(self.filename).delete_database()
--> 311 IndexManager(self.filename).add_datasets(self)

File c:\Users\M. Zeeshan\anaconda3\envs\bw\Lib\site-packages\bw2data\search\indices.py:47, in IndexManager.add_datasets(self, datasets)
45 writer = self.get().writer()
46 for ds in datasets:
---> 47 writer.add_document(**self._format_dataset(ds))
48 writer.commit()

File c:\Users\M. Zeeshan\anaconda3\envs\bw\Lib\site-packages\bw2data\search\indices.py:35, in IndexManager._format_dataset(self, ds)
29 def _format_dataset(self, ds):
30 fl = lambda o: o[1].lower() if isinstance(o, tuple) else o.lower()
31 return dict(
32 name=ds.get(u"name", u"").lower(),
33 comment=ds.get(u"comment", u"").lower(),
34 product=ds.get(u"reference product", u"").lower(),
---> 35 categories=u", ".join(ds.get(u"categories", [])).lower(),
36 location=fl(ds.get(u"location", u"")),
37 database=ds[u"database"],
38 code=ds['code']
39 )

TypeError: can only join an iterable

I am unable to grasp the error ,would appreciate any guidance.
Thanks in anticipation.

Attribute error

Hello, Iam trying to exclude the activity. want to read single activity so. Iam trying w.exclude code but iam getting attribute error.
also i have tried considering w. doesnt_contain_any but no result error occurs as shown in the attachetment.
can any one please help regrading my code
image.

image

function empty_high_voltage_markets needs to also remove imports

The function empty_high_voltage_markets should also delete all imports of electricity.

I have written my own function to delete all electricity inputs (except own consumption). it looks like this and seems to work:

def delete_electricity_inputs_from_market(ds):
    # This function reads through an electricity market dataset and deletes all electricity inputs that are not    
    # own consumption. 
    ds['exchanges'] = list(get_many(
        ds['exchanges'], 
        either(
            exclude(contains('unit', 'kilowatt hour')),
            contains('name', 'market for electricity, high voltage'),
            contains('name', 'market for electricity, medium voltage'),
            contains('name', 'market for electricity, low voltage'),
            contains('name', 'electricity voltage transformation')
        )
    ))
    return ds

keyerror with copy_to_new_location

I tried to test the copy_to_new_location function but I got a keyerror message. The code was the following

import wurst as w
boiler_ch=w.get_one(db,
                     w.searching.contains('name', 'light fuel oil'),
                     w.searching.contains('name', '10kW condensing'),
                     w.searching.equals('location', 'CH'),
                    )
boiler_qc=w.copy_to_new_location(boiler_ch,'CA-QC')

db is a version of ecoinvent 3.3 cutoff. get_one correctly identifies the activity , but I get a couple of messages (one an error) when executing copy_to_new_location

Successfully switched activity dataset to new code c9cc73b5becb4509804660ec8abf00e9
KeyError: 'exchanges'

I am using the following versions: wurst==0.1.dev2; brightway2==2.1.1

please let me know if you prefer that I post it as a question in stackoverflow instead opening an issue here.

keyerror_msg_copy to new location

parameter keys are different when exporting

here is the current code:
'parameters': {key: value['amount'] for key, value in proxy.data.get('parameters', {}).items()}

This means that in an unimported ecoinvent I would access the efficiency value with something like:

ds['parameters']['efficiency']['amount']

but if I export with wurst, I have to access the same parameter with:

ds['parameters']['efficiency']

empty file wurst/ecoinvent/__init___.py leads to error: "ImportError: cannot import name 'ECOINVENT_ORDERED_GEO' from 'wurst.ecoinvent'"

Trying to execute the marginal mixes wurst notebook example but got an error
ImportError: cannot import name 'ECOINVENT_ORDERED_GEO' from 'wurst.ecoinvent'

I see also that others have encountered the same issue. I contacted Laurant Vandepaer, who has no solution.

It seems that the wurst/ecoinvent/init_.py file is empty as per 28 sept 2017. I found the previuos file version in the commit history. copied the lines of code into my local init_.py file to resolve the issue.

I wanted to share this workaround in case others might be interested. I am new to github, and don't know how to contribute this? hence i made this post. Is it correct understood that I should make a "pull request" for the commit of 28 sept 2017, which deleted all lines of code from the init_.py file? I cant figure out how to do this :-)

Best regards, Simon

TRACE BACK ERROR

Hello iam trying to update the database by using the brightway2 and wurst while running the write database code iam getting this error can i know how to solve this
image
image

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.