Commits

Chris Mutel committed 8e29276

0.10.4

Comments (0)

Files changed (5)

bw2data/__init__.py

 # -*- coding: utf-8 -*
-__version__ = (0, 10, 3, 1)
+__version__ = (0, 10, 4)
 
 from _config import config
 from meta import databases, methods, mapping, reset_meta, geomapping, \

bw2data/io/import_ecospold2.py

 from ..units import normalize_units
 from lxml import objectify, etree
 from stats_arrays.distributions import *
+import hashlib
 import os
 import pprint
 import progressbar
             'location': stem.activityDescription.geography.shortname.text,
             'exchanges': [self.extract_exchange(exc) for exc in stem.flowData.iterchildren()],
             'filename': filename,
-            'id': stem.activityDescription.activity.get('id')
+            'activity': stem.activityDescription.activity.get('id')
         }
+
+        candidates = [exc for exc in data['exchanges'] if exc.get('product', False) and exc['amount']]
+        assert len(candidates) == 1
+        flow = candidates[0]['flow']
+
+        data['id'] = hashlib.md5(data['activity'] + flow).hexdigest()
+        data['id_from'] = {
+            'activity': data['activity'],
+            'flow': flow
+        }
+
         # Purge empties and exchanges with `amount` of zero
+        # Excludes parameters, by products (amount of zero),
+        # non-allocated reference products (amount of zero)
         data['exchanges'] = [x for x in data['exchanges'] if x and x['amount'] != 0]
         return data
 
             print exc.tag
             raise ValueError
 
-        is_product = hasattr(exc, "outputGroup") and not is_biosphere
+        # Output group 0 is reference product
+        # 2 is by-product
+        is_product = (not is_biosphere
+            and hasattr(exc, "outputGroup")
+            and exc.outputGroup.text == "0")
+        amount = float(exc.get('amount'))
+
+        if is_product and amount == 0.:
+            # This is system modeled multi-output dataset
+            # and a "fake" exchange. It represents a possible
+            # output which isn't actualized in this allocation
+            # and can therefore be ignored. This shouldn't exist
+            # at all, but the data format is not perfect.
+            return {}
 
         data = {
             'flow': exc.get(flow),
-            'amount': float(exc.get('amount')),
+            'amount': amount,
             'biosphere': is_biosphere,
             'product': is_product,
             'name': exc.name.text,
             # 'xml': etree.tostring(exc, pretty_print=True)
         }
-        if not is_biosphere and not is_product:
+        if not is_biosphere:
             data["activity"] = exc.get("activityLinkId")
         if hasattr(exc, "unitName"):
             data['unit'] = exc.unitName.text
                 elif exc['biosphere']:
                     exc['type'] = 'biosphere'
                     exc['input'] = ('biosphere3', exc['flow'])
-                else:
-                    exc['type'] = 'technosphere'
-                    exc['input'] = (self.name, exc['activity'])
-                if exc['input'][1] is None:
+                elif exc['activity'] is None:
                     # This exchange wasn't linked correctly by ecoinvent
                     # It is missing the "activityLinkId" attribute
                     # See http://www.ecoinvent.org/database/ecoinvent-version-3/reports-of-changes/known-data-issues/
                     exc['input'] = None
                     exc['activity filename'] = elem['filename']
                     exc['activity name'] = elem['name']
-                    continue
+                else:
+                    exc['type'] = 'technosphere'
+                    exc['input'] = (
+                        self.name,
+                        hashlib.md5(exc['activity'] + exc['flow']).hexdigest()
+                    )
 
         # Drop "missing" exchanges
         for elem in activities:
     return method
 
 
+def combine_databases(name, *dbs):
+    """Combine databases into new database called ``name``."""
+    pass
+
+
+def merge_databases(parent_db, *others):
+    """Merge ``others`` into ``parent_db``, including updating exchanges."""
+    pass
+
+
 def database_hash(data):
     """Hash a Database.
 
 # The short X.Y version.
 version = '0.10'
 # The full version, including alpha/beta/rc tags.
-release = '0.10.3'
+release = '0.10.4'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
 
 setup(
     name='bw2data',
-    version="0.10.3.1",
+    version="0.10.4",
     packages=packages,
     author="Chris Mutel",
     author_email="cmutel@gmail.com",
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.