def new_flow(self, flow=None, name=None, cas=None, quantity=None, comment=None, compartment=None): if flow is None: name = name or input('Enter flow name: ') cas = cas or ifinput('Enter CAS number (or none): ', '') print('Choose reference quantity or none to create new: ') if quantity is None: q = pick_one(self.flow_properties) if q is None: q = self.new_quantity() quantity = q comment = comment or input('Enter flow comment: ') if compartment is None: print('Choose compartment:') compartment = pick_compartment(self.db.compartments).to_list() flow = LcFlow.new(name, quantity, CasNumber=cas, Compartment=compartment, Comment=comment) # flow.add_characterization(q, reference=True) else: quantity = flow.reference_entity self._catalog[0].add(flow) flow.profile() while ifinput('Add characterizations for this flow? y/n', 'n') != 'n': ch = cyoa('[n]ew or [e]xisting quantity? ', 'en', 'e') if ch == 'n': cq = self.new_quantity() else: cq = pick_one(self[0].quantities()) if cq is None: cq = self.new_quantity() val = parse_math(input('Value (1 %s = x %s): ' % (quantity.unit(), cq.unit()))) flow.add_characterization(cq, value=val) return flow
def create_fragment(self, parent=None, flow=None, direction=None, comment=None, value=None, balance=False, **kwargs): """ :param parent: :param flow: :param direction: :param comment: :param value: :param balance: :param kwargs: :return: """ if flow is None: ch = cyoa('(N)ew flow or (S)earch for flow? ', 'ns') if ch == 'n': flow = self.new_flow() elif ch == 's': index = self.current_archive or select_archive(self) elem = {'i': False, 'e': True, 'a': None}[cyoa('(I)ntermediate, (E)lementary, or (A)ll flows? ', 'aei', 'I').lower()] flow = self.find_flow(None, index=index, elementary=elem) if flow is None: return None flow = flow.entity() else: raise ValueError print('Creating fragment with flow %s' % flow) direction = direction or {'i': 'Input', 'o': 'Output'}[cyoa('flow is (I)nput or (O)utput?', 'IO').lower()] comment = comment or ifinput('Enter FragmentFlow comment: ', '') if parent is None: # direction reversed for UX! user inputs direction w.r.t. fragment, not w.r.t. parent if value is None: value = 1.0 frag = self.new_fragment(flow, comp_dir(direction), Comment=comment, exchange_value=value, **kwargs) else: if parent.term.is_null: self.terminate_to_foreground(parent) if value is None: val = ifinput('Exchange value (%s per %s): ' % (flow.unit(), parent.unit), '1.0') if val == '1.0': value = 1.0 else: value = parse_math(val) frag = self[0].add_child_fragment_flow(parent, flow, direction, Comment=comment, exchange_value=value, **kwargs) if balance: frag.set_balance_flow() self.traverse(parent) if self.db.is_elementary(frag.flow): self.terminate_to_foreground(frag) return frag
def _update_ev(frag, scenario): val = frag.exchange_value(scenario) cur = str(val) upd = ifinput('New value: ', cur) if upd != cur: new_val = parse_math(upd) if new_val != val: if scenario is None: frag.reset_cache() frag.cached_ev = new_val else: frag.set_exchange_value(scenario, new_val)