Created
May 24, 2024 14:51
-
-
Save cmutel/b883fc8fe41a773478c2121d7c1ddb91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bw2data, bw2io | |
BIOSPHERE_FLOW_DATABASE_LABELS = ["ecoinvent-3.9.1-biosphere"] | |
class Purolator(bw2io.package.BW2Package): | |
@classmethod | |
def _create_obj(cls, data): | |
instance = data["class"](data["name"]) | |
if data["name"] not in instance._metadata: | |
instance.register(**data["metadata"]) | |
else: | |
instance.backup() | |
instance.metadata = data["metadata"] | |
flows = { | |
(obj['database'], obj['code']) | |
for label in BIOSPHERE_FLOW_DATABASE_LABELS | |
for obj in bw2data.Database(label) | |
} | |
if isinstance(instance, bw2data.Method): | |
data['data'] = [line for line in data['data'] if line[0] in flows] | |
instance.write(data["data"]) | |
return instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment