예제 #1
0
 def create_fragment_from_process(self, process_ref, ref_flow=None, background=False, background_children=True):
     """
     The major entry into fragment building.  Given only a process ref, construct a fragment from the process,
     using the process's reference exchange as the reference fragment flow.
     :param process_ref:
     :param ref_flow:
     :param background: [False] add as a background fragment and do not traverse children
     :param background_children: [True] automatically terminate child flows with background references (ecoinvent).
     :return:
     """
     process = process_ref.fg()
     if ref_flow is None:
         if len(process.reference_entity) == 0:
             ref = pick_one([x for x in self.db.filter_exch(process_ref, elem=False) if x.direction == 'Output']
                            ).flow
         elif len(process.reference_entity) > 1:
             ref = pick_reference(process)
         else:
             ref = list(process.reference_entity)[0].flow
     else:
         try:
             ref = next(x.flow for x in process.reference_entity if x.flow.match(ref_flow))
         except StopIteration:
             print('Reference flow not found in target process.')
             return None
     ref_exch = next(x for x in process.exchange(ref))
     direction = comp_dir(ref_exch.direction)
     frag = self[0].create_fragment(ref, direction, Name='%s' % process_ref.entity(), background=background)
     frag.terminate(process_ref, flow=ref)
     if not background:
         self.build_child_flows(frag, background_children=background_children)
     return frag
예제 #2
0
    def _find_rf(p, ref_flow=None):
        if ref_flow is None:
            if len(p.reference_entity) > 1:
                print('This process has multiple allocations. Select reference flow:')
                ref_flow = pick_reference(p)
            else:
                ref_flow = list(p.reference_entity)[0].flow

        return [x.flow for x in p.reference_entity if x.flow.match(ref_flow)][0]
예제 #3
0
    def _find_rf(p, ref_flow=None):
        if ref_flow is None:
            if len(p.reference_entity) > 1:
                print('This process has multiple allocations. Select reference flow:')
                ref_flow = pick_reference(p)
            else:
                ref_flow = list(p.reference_entity)[0].flow

        return [x.flow for x in p.reference_entity if x.flow.match(ref_flow)][0]