예제 #1
0
    def update_sankey(self, demand, method, cut_off=0.05, max_calc=100):
        """Calculate LCA, do graph traversal, get JSON graph data for this, and send to javascript."""
        print("Demand / Method:", demand, method)
        start = time.time()
        try:
            data = bw.GraphTraversal().calculate(demand, method, cutoff=cut_off, max_calc=max_calc)
        except ValueError as e:
            QtWidgets.QMessageBox.information(None, "Not possible.", str(e))
        print("Completed graph traversal ({:.2g} seconds, {} iterations)".format(time.time() - start, data["counter"]))

        self.graph.new_graph(data)
        # print("emitting graph ready signal")
        self.send_json()
예제 #2
0
def filter_technosphere_exchanges(fu, method, cutoff=0.05, max_calc=1e4):
    """Use brightway's GraphTraversal to identify the relevant
    technosphere exchanges in a non-stochastic LCA."""
    start = time()
    res = bw.GraphTraversal().calculate(fu, method, cutoff=cutoff, max_calc=max_calc)

    # get all edges
    technosphere_exchange_indices = []
    for e in res['edges']:
        if e['to'] != -1:  # filter out head introduced in graph traversal
            technosphere_exchange_indices.append((e['from'], e['to']))
    print('TECHNOSPHERE {} filtering resulted in {} of {} exchanges and took {} iterations in {} seconds.'.format(
        res['lca'].technosphere_matrix.shape,
        len(technosphere_exchange_indices),
        res['lca'].technosphere_matrix.getnnz(),
        res['counter'],
        np.round(time() - start, 2),
    ))
    return technosphere_exchange_indices
예제 #3
0
 def run(self):
     res = bw.GraphTraversal().calculate(self.demand, self.method,
                                         self.cutoff, self.max_calc)
     sankeysignals.gt_ready.emit(res)