Esempio n. 1
0
 def _add_alloc_refs(self, arg, flow=None):
     col_idx = len(self._columns)
     for k in arg.references(flow=flow):
         rx = ExchangeValue(
             k.process, k.flow, k.direction,
             value=1.0)  # we do this to avoid calling RxRef.value
         # (and because table exchanges are normalized to this value, so 1.0 is the only correct value to report)
         rx.set_ref(k.process)
         row = k.direction, True, '; '.join(
             k.flow['Compartment']), k.flow['Name']
         self._add_rowitem(col_idx, rx, row=row)
     self._columns.append(arg)
Esempio n. 2
0
 def inventory(self, process, ref_flow=None, show=None):
     """
     Report the direct dependencies and exterior flows for the named product flow.  If the second argument is
     non-None, print the inventory instead of returning it.
     This should be identical to product_flow.process.inventory() so WHY DID I WRITE IT??????
     ans: because it exposes the allocated matrix model. so it's not the same for allocated processes.
     :param process:
     :param ref_flow: required for multi-product case
     :param show: [None] if present, show rather than return the inventory.
     :return: a list of exchanges.
     """
     product_flow = self._get_product_flow(process, ref_flow)
     ref_ex = ExchangeValue(product_flow.process, product_flow.flow, product_flow.direction, value=1.0)
     ref_ex.set_ref(product_flow.process)
     interior = [ref_ex]
     exterior = []
     if self._tstack.is_background(product_flow):
         # need to index into background matrix
         _af, _ad, _bf = self._be.make_foreground(product_flow)
         for i, row in enumerate(_ad.nonzero()[0]):
             dep = self._tstack.bg_node(row)
             dat = _ad.data[i]
             if dat < 0:
                 dirn = 'Output'
             else:
                 dirn = 'Input'
             interior.append(ExchangeValue(product_flow.process, dep.flow, dirn, value=abs(dat)))
         for i, row in enumerate(_bf.nonzero()[0]):
             ems = self._be.emissions[row]
             dat = _bf.data[i]
             exterior.append(ExchangeValue(product_flow.process, ems.emission.flow, ems.emission.direction,
                                           value=dat))
     else:
         # need to simply access the sparse matrix entries
         for fg in self._be.foreground_dependencies(product_flow):
             dat = fg.value
             if dat < 0:
                 dirn = 'Output'
             else:
                 dirn = 'Input'
             interior.append(ExchangeValue(product_flow.process, fg.term.flow, dirn, value=dat))
         for em in self._be.foreground_emissions(product_flow):
             exterior.append(ExchangeValue(product_flow.process, em.emission.flow, em.emission.direction,
                                           value=em.value))
     if show is None:
         return interior + exterior
     else:
         for x in interior:
             print('%s' % x)
         print('Exterior')
         for x in exterior:
             print('%s' % x)