REGISTER NOW: DdS Autumn School! 🇨🇭 Grosshöchstetten (Switzerland) 🗓️ 6.-11. October 2024

bw2io.extractors.ecospold2#

Module Contents#

Classes#

Ecospold2DataExtractor

Functions#

getattr2(obj, attr)

Get attribute of an object; return empty dict if AttributeError occurs.

Attributes#

ACTIVITY_TYPES

PM_MAPPING

TOO_HIGH

TOO_LOW

class bw2io.extractors.ecospold2.Ecospold2DataExtractor[source]#

Bases: object

classmethod abort_exchange(exc, comment=None)[source]#

Set the uncertainty type of the input exchange to UndefinedUncertainty.id. Remove the keys “scale”, “shape”, “minimum”, and “maximum” from the dictionary. Update the “loc” key to “amount”. Append “comment” to “exc[‘comment’]” if “comment” is not None, otherwise append “Invalid parameters - set to undefined uncertainty.” to “exc[‘comment’]”.

Args:

exc (dict): The input exchange. comment (str, optional): A string to append to “exc[‘comment’]”. Defaults to None.

Returns:

None

classmethod condense_multiline_comment(element)[source]#

Concatenate the text of all child elements with the tag “{http://www.EcoInvent.org/EcoSpold02}text” and the text of all child elements with the tag “{http://www.EcoInvent.org/EcoSpold02}imageUrl” in the given element XML element.

cls (type): The class object. element (lxml.etree.Element): The XML element.

Returns#

str: The concatenated text of all child elements with the tag “{http://www.EcoInvent.org/EcoSpold02}text” and the text of all child elements with the tag “{http://www.EcoInvent.org/EcoSpold02}imageUrl”. If an error occurs, an empty string is returned.

classmethod extract(dirpath, db_name, use_mp=True)[source]#

Extract data from all ecospold2 files in a directory.

Parameters#

dirpathstr

The path to the directory containing the ecospold2 files.

db_namestr

The name of the database to create.

use_mpbool, optional

Whether to use multiprocessing to extract the data (default is True).

Returns#

list

A list of the extracted data from the ecospold2 files.

Raises#

FileNotFoundError

If no .spold files are found in the directory.

classmethod extract_activity(dirpath, filename, db_name)[source]#

Extract and return the data of an activity from an XML file with the given filename in the directory with the path dirpath.

cls (type): The class object. dirpath (str): The path of the directory containing the XML file. filename (str): The name of the XML file. db_name (str): The name of the database.

Returns#

dict: The dictionary of data for the activity. The keys and values are as
follows:
  • “comment”: str. The condensed multiline comment.

  • “classifications”: list of tuples. The classification systems and values of the activity.

  • “activity type”: str. The type of the activity.

  • “activity”: str. The ID of the activity.

  • “database”: str. The name of the database.

  • “exchanges”: list of dicts. The exchanges of the activity.

  • “filename”: str. The name of the XML file.

  • “location”: str. The short name of the location of the activity.

  • “name”: str. The name of the activity.

  • “synonyms”: list of str. The synonyms of the activity.

  • “parameters”: dict. The parameters of the activity.

  • “authors”: dict of dicts. The authors of the activity. The keys and values of the inner dicts are as follows:

    • “name”: str. The name of the author.

    • “email”: str. The email of the author.

  • “type”: str. The type of the activity.

classmethod extract_exchange(exc)[source]#

Process exchange.

Input groups are:

  1. Materials/fuels

  2. Electricity/Heat

  3. Services

  4. From environment (elementary exchange only)

  5. FromTechnosphere

Output groups are:

0. ReferenceProduct 2. By-product 3. MaterialForTreatment 4. To environment (elementary exchange only) 5. Stock addition

classmethod extract_parameter(exc)[source]#

Extract parameter information from “exc” and return it as a tuple.

Args:

exc (dict): The input exchange.

Returns:

tuple: A tuple containing the parameter name and a dictionary containing the parameter information.

classmethod extract_properties(exc)[source]#

Extract the properties of an exchange.

Parameters#

exclxml.etree.Element

An XML element representing an exchange.

Returns#

dict

A dictionary of the properties of the exchange. Each key in the dictionary is a string representing the name of a property, and the corresponding value is a dictionary with the following keys:

  • “amount” (float): The numerical value of the property.

  • “comment” (str, optional): A comment describing the property, if available.

  • “unit” (str, optional): The unit of the property, if available.

  • “variable name” (str, optional): The name of the variable associated with

the property, if available.

classmethod extract_technosphere_metadata(dirpath)[source]#

Extract technosphere metadata from ecospold2 directory.

Parameters#

dirpathstr

The path to the ecospold2 directory.

Returns#

List of dict

List of names, units, and IDs

classmethod extract_uncertainty_dict(obj)[source]#

Extract uncertainty information from “obj” and return it as a dictionary.

Args:

obj: The input object.

Returns:

dict: The extracted uncertainty information.

bw2io.extractors.ecospold2.getattr2(obj, attr)[source]#

Get attribute of an object; return empty dict if AttributeError occurs.

Parameters#

objobject

The object to get attribute from.

attrstr

The name of the attribute to get.

Returns#

dict

The attribute value if it exists, else an empty dict.

bw2io.extractors.ecospold2.ACTIVITY_TYPES[source]#
bw2io.extractors.ecospold2.PM_MAPPING[source]#
bw2io.extractors.ecospold2.TOO_HIGH = Multiline-String[source]#
Show Value
"""Lognormal scale value impossibly high: {}.
Reverting to undefined uncertainty."""
bw2io.extractors.ecospold2.TOO_LOW = Multiline-String[source]#
Show Value
"""Lognormal scale value at or below zero: {}.
Reverting to undefined uncertainty."""