Commits

Chris Mutel committed ea3a16c

0.9.3.3: Add keyword Gephi exporter

Comments (0)

Files changed (4)

bw2data/__init__.py

 import validate
 import io
 
-__version__ = (0, 9, 3, 2)
+__version__ = (0, 9, 3, 3)

bw2data/io/export_gexf.py

             for exc in value["exchanges"]:
                 if exc["input"] not in self.id_mapping:
                     continue
+                elif exc["input"] == key:
+                    # Don't need production process in graph
+                    continue
                 else:
                     edges.append(E.edge(
                         id=str(count.next()),
         pbar.finish()
 
         return E.nodes(*nodes), E.edges(*edges)
+
+
+class DatabaseSelectionToGEXF(DatabaseToGEXF):
+    def __init__(self, database, keys):
+        self.database = database
+        self.filepath = os.path.join(config.request_dir("output"),
+            database + "selection.gexf")
+        unfiltered_data = Database(self.database).load()
+        self.data = {key: value for key, value in unfiltered_data.iteritems() if key in keys}
+        self.id_mapping = dict([(key, str(i)) for i, key in enumerate(
+            self.data)])
         pbar.update(index)
     pbar.finish()
     print "Conversion finished"
+
+
+def keyword_to_gephi_graph(database, keyword):
+    """Export a Gephi graph from a keyword in activity names"""
+    from . import Database, Filter
+    from bw2data.io.export_gexf import DatabaseSelectionToGEXF
+    query = Database(database).query(Filter("name", "in", keyword))
+    return DatabaseSelectionToGEXF(database, set(query.keys())).export()
 
 setup(
     name='bw2data',
-    version="0.9.3.2",
+    version="0.9.3.3",
     packages=packages,
     author="Chris Mutel",
     author_email="cmutel@gmail.com",