Beispiel #1
0
    def compare_allocation(self, p_ref):
        def _key(exc):
            return '%s' % exc.flow, exc.direction

        ints = dict()
        elems = dict()
        int_set = set()
        elem_set = set()
        cols = []
        for p in p_ref.entity().reference_entity:
            cols.append(p)
            ints[p] = self.db.filter_exch(p_ref, elem=False, ref_flow=p.flow)
            int_set = int_set.union(_key(x) for x in ints[p])
            elems[p] = self.db.filter_exch(p_ref, elem=True, ref_flow=p.flow)
            elem_set = elem_set.union(_key(x) for x in elems[p])

        int_rows = sorted(int_set, key=lambda x: x[1])

        dynamic_grid(cols, int_rows,
                     lambda x, y: {t for t in ints[y] if _key(t) == x},
                     ('Direction', lambda x: x[1]),
                     ('Flow', lambda x: x[0]), returns_sets=True, suppress_col_list=True)
        ele_rows = sorted(elem_set, key=lambda x: x[1])

        dynamic_grid(cols, ele_rows, lambda x, y: {t for t in elems[y] if _key(t) == x},
                     ('Direction', lambda x: x[1]),
                     ('Flow', lambda x: x[0]), returns_sets=True)
Beispiel #2
0
    def compare_inventory(self, p_refs, elementary=False, **kwargs):
        def _key(exc):
            return ('%s [%s]' % (exc.flow['Name'], exc.flow.reference_entity.reference_entity.unitstring()),
                    exc.direction, exc.flow)
        ints = dict()
        int_set = set()
        elems = dict()
        elem_set = set()

        for p in p_refs:
            ints[p] = self.db.filter_exch(p, elem=False, **kwargs)
            int_set = int_set.union(_key(x) for x in ints[p])
            if elementary:
                elems[p] = self.db.filter_exch(p, elem=True, **kwargs)
                elem_set = elem_set.union(_key(x) for x in elems[p])

        int_rows = sorted(int_set, key=lambda x: x[1])
        int_flows = [x[2] for x in int_rows]

        dynamic_grid(p_refs, int_rows,
                     lambda x, y: {t for t in ints[y] if _key(t) == x},
                     ('Direction', lambda x: x[1]),
                     ('Flow', lambda x: x[0]),
                     returns_sets=True, suppress_col_list=elementary)

        if elementary:
            ele_rows = sorted(elem_set, key=lambda x: x[1])
            ele_flows = [x[2] for x in ele_rows]

            dynamic_grid(p_refs, ele_rows, lambda x, y: {t for t in elems[y] if _key(t) == x},
                         ('Direction', lambda x: x[1]),
                         ('Flow', lambda x: x[0]), returns_sets=True)
            return int_flows, ele_flows
        return int_flows
Beispiel #3
0
    def cfs_for_flowable(self, flowable, **kwargs):

        rows = [cf for cf in self.all_cfs(flowable, **kwargs)]
        cols = [self._q_id[k] for k, v in self._q_dict.items() if flowable in v]

        print('%s [%s]' % (self.flowables.name(flowable), self.flowables.cas(flowable)))
        print('Characterization Factors\n ')

        dynamic_grid(cols, rows, lambda x, y: x if y == x.quantity else None,
                     ('Locations', lambda x: x.list_locations()),
                     ('Compartment', lambda x: x.flow['Compartment']))
Beispiel #4
0
    def factors_for_quantity(self, quantity):
        """
        Finally, my text mode chart expertise pays off!
        :param quantity:
        :return:
        """
        q = get_entity_uuid(quantity)

        rows = sorted(self._q_dict[q], key=lambda x: self.flowables.name(x))
        cols = self.compartments_for(rows, quantity)

        print('%s' % quantity)
        print('Characterization Factors\n ')
        dynamic_grid(cols, rows, lambda x, y: self._f_dict[(x, q)][y],
                     ('CAS Number ', lambda x: self.flowables.cas(x)),
                     ('Flowable', lambda x: self.flowables.name(x)),
                     returns_sets=True)
Beispiel #5
0
    def compare_lcia_results(self, p_refs, quantities=None, background=False, **kwargs):
        """
        p_refs should be an array of catalog_refs
        :param p_refs:
        :param quantities: list of qs
        :param background: whether to use bg_lcia instead of fg_lcia
        :return:
        """
        results = dict()
        qs = self._prep_quantities(quantities)
        for p in p_refs:
            if background:
                results[p] = self.bg_lcia(p, quantities=quantities, **kwargs)
            else:
                results[p] = self.fg_lcia(p, quantities=quantities, **kwargs)

        dynamic_grid(p_refs, qs, lambda x, y: results[y][x.get_uuid()],
                     ('Ref Units', lambda x: x.reference_entity),
                     ('LCIA Method', lambda x: x['Name']))