def transactions(evaler, senders=(), receivers=(), commodities=(), nucs=()): """ Shape the reduced transation Data Frame into a simple time serie. Applying nuclides selection when required. Parameters ---------- evaler : evaler senders : of the sending facility receivers : of the receiving facility commodities : of the commodity exchanged nucs : of nuclide to select. """ if len(nucs) != 0: nucs = tools.format_nucs(nucs) df = filters.transactions_nuc(evaler, senders, receivers, commodities, nucs) df = df[['Time', 'Mass']].groupby(['Time']).sum() df.reset_index(inplace=True) time = evaler.eval('TimeList') df = tools.add_missing_time_step(df, time) return df
def transactions(evaler, senders=(), receivers=(), commodities=(), nucs=()): """ Shape the reduced transation Data Frame into a simple time serie. Applying nuclides selection when required. Parameters ---------- evaler : evaler senders : of the sending facility receivers : of the receiving facility commodities : of the commodity exchanged nucs : of nuclide to select. """ if len(nucs) != 0: nucs = tools.format_nucs(nucs) df = filters.transactions_nuc( evaler, senders, receivers, commodities, nucs) df = df[['Time', 'Mass']].groupby(['Time']).sum() df.reset_index(inplace=True) time = evaler.eval('TimeList') df = tools.add_missing_time_step(df, time) return df
def flow_graph(evaler, senders=(), receivers=(), commodities=(), nucs=(), label='', start=None, stop=None): """ Generate the dot graph of the transation between facilitiese. Applying times nuclides selection when required. Parameters ---------- evaler : evaler senders : list of the sending facility to consider receivers : list of the receiving facility to consider commodities : list of the commodity exchanged to consider nucs : list of nuclide to consider label : label key, used to add label on the arrow connecting facilities (for commodity use 'com', for mass use 'mass', for both use com,mass) start : first timestep to consider, start included stop : last timestep to consider, stop included """ tools.raise_no_graphviz('Unable to generate flow graph!', HAVE_GRAPHVIZ) df = transactions_nuc(evaler, senders, receivers, commodities, nucs) if start != None: df = df.loc[(df['Time'] >= start)] if stop != None: df = df.loc[(df['Time'] <= stop)] group_end = ['ReceiverPrototype', 'SenderPrototype', 'Commodity'] group_start = group_end + ['Mass'] df = df[group_start].groupby(group_end).sum() df.reset_index(inplace=True) agents_ = evaler.eval('AgentEntry')['Prototype'].tolist() dot = Digraph('G') for agent in agents_: dot.node(agent) for index, row in df.iterrows(): lbl = '' if 'com' in label: lbl += str(row['Commodity']) + ' ' if 'mass' in label: lbl += str('{:.2e}'.format(row['Mass'])) + ' ' dot.edge(row['SenderPrototype'], row['ReceiverPrototype'], label=lbl) return dot
def flow_graph(evaler, senders=(), receivers=(), commodities=(), nucs=(), label='', start=None, stop=None): """ Generate the dot graph of the transation between facilitiese. Applying times nuclides selection when required. Parameters ---------- evaler : evaler senders : list of the sending facility to consider receivers : list of the receiving facility to consider commodities : list of the commodity exchanged to consider nucs : list of nuclide to consider label : label key, used to add label on the arrow connecting facilities (for commodity use 'com', for mass use 'mass', for both use com,mass) start : first timestep to consider, start included stop : last timestep to consider, stop included """ tools.raise_no_graphviz('Unable to generate flow graph!', HAVE_GRAPHVIZ) df = transactions_nuc( evaler, senders, receivers, commodities, nucs) if start != None: df = df.loc[(df['Time'] >= start)] if stop != None: df = df.loc[(df['Time'] <= stop)] group_end = ['ReceiverPrototype', 'SenderPrototype', 'Commodity'] group_start = group_end + ['Mass'] df = df[group_start].groupby(group_end).sum() df.reset_index(inplace=True) agents_ = evaler.eval('AgentEntry')['Prototype'].tolist() dot = Digraph('G') for agent in agents_: dot.node(agent) for index, row in df.iterrows(): lbl = '' if 'com' in label: lbl += str(row['Commodity']) + ' ' if 'mass' in label: lbl += str('{:.2e}'.format(row['Mass'])) + ' ' dot.edge(row['SenderPrototype'], row['ReceiverPrototype'], label= lbl) return dot
def test_transactions_nuc(db, fname, backend): evaler = cym.Evaluator(db) cal = filters.transactions_nuc(evaler) exp_head = [ 'SimId', 'ResourceId', 'NucId', 'Mass', 'ReceiverId', 'ReceiverPrototype', 'SenderId', 'SenderPrototype', 'TransactionId', 'Commodity', 'Time' ] assert_equal(list(cal), exp_head) # Check we have the correct headers if not HAVE_PYNE: raise SkipTest # test single nuclide selection cal = filters.transactions_nuc(evaler, nucs=['942390000']) cal = cal.drop('SimId', 1) # SimId change at each test need to drop it # SimId change at each test need to drop it cal = cal.drop('TransactionId', 1) # SimId change at each test need to drop it cal = cal.drop('ResourceId', 1) refs = pd.DataFrame( np.array([ (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 1), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 2), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 2), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 3), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 3), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 4), (942390000, 0.0444814879803, 17, 'Reactor3', 14, 'MOX_Source', 'mox', 4), ], dtype=ensure_dt_bytes([('NucId', '<i8'), ('Mass', '<f8'), ('ReceiverId', '<i8'), ('ReceiverPrototype', 'O'), ('SenderId', '<i8'), ('SenderPrototype', 'O'), ('Commodity', 'O'), ('Time', '<i8')]))) # refs.index = refs.index.astype('str') assert_frame_equal(cal, refs) # test multiple nuclide selection cal = filters.transactions_nuc(evaler, nucs=['942390000', '922380000']) cal = cal.drop('SimId', 1) # SimId change at each test need to drop it # SimId change at each test need to drop it cal = cal.drop('TransactionId', 1) # SimId change at each test need to drop it cal = cal.drop('ResourceId', 1) refs = pd.DataFrame( np.array([ (922380000, 0.7872433760310, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 1), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 1), (922380000, 0.7872433760310, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 2), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 2), (922380000, 0.7872433760310, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 2), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 2), (922380000, 0.7872433760310, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 3), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 3), (922380000, 0.7872433760310, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 3), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 3), (922380000, 0.7872433760310, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 4), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 4), (922380000, 0.7872433760310, 17, 'Reactor3', 14, 'MOX_Source', 'mox', 4), (942390000, 0.0444814879803, 17, 'Reactor3', 14, 'MOX_Source', 'mox', 4), (922380000, 0.9600000000000, 17, 'Reactor3', 13, 'UOX_Source', 'uox', 3), (922380000, 0.9600000000000, 15, 'Reactor1', 13, 'UOX_Source', 'uox', 4), ], dtype=ensure_dt_bytes([('NucId', '<i8'), ('Mass', '<f8'), ('ReceiverId', '<i8'), ('ReceiverPrototype', 'O'), ('SenderId', '<i8'), ('SenderPrototype', 'O'), ('Commodity', 'O'), ('Time', '<i8')]))) # refs.index = refs.index.astype('str') assert_frame_equal(cal, refs)
def test_transactions_nuc(db, fname, backend): evaler = cym.Evaluator(db) cal = filters.transactions_nuc(evaler) exp_head = ['SimId', 'ResourceId', 'NucId', 'Mass', 'ReceiverId', 'ReceiverPrototype', 'SenderId', 'SenderPrototype', 'TransactionId', 'Commodity', 'Time'] assert_equal(list(cal), exp_head) # Check we have the correct headers if not HAVE_PYNE: raise SkipTest # test single nuclide selection cal = filters.transactions_nuc(evaler, nucs=['942390000']) cal = cal.drop('SimId', 1) # SimId change at each test need to drop it # SimId change at each test need to drop it cal = cal.drop('TransactionId', 1) # SimId change at each test need to drop it cal = cal.drop('ResourceId', 1) refs = pd.DataFrame(np.array([ (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 1), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 2), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 2), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 3), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 3), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 4), (942390000, 0.0444814879803, 17, 'Reactor3', 14, 'MOX_Source', 'mox', 4), ], dtype=ensure_dt_bytes([ ('NucId', '<i8'), ('Mass', '<f8'), ('ReceiverId', '<i8'), ('ReceiverPrototype', 'O'), ('SenderId', '<i8'), ('SenderPrototype', 'O'), ('Commodity', 'O'), ('Time', '<i8') ])) ) # refs.index = refs.index.astype('str') assert_frame_equal(cal, refs) # test multiple nuclide selection cal = filters.transactions_nuc( evaler, nucs=['942390000', '922380000']) cal = cal.drop('SimId', 1) # SimId change at each test need to drop it # SimId change at each test need to drop it cal = cal.drop('TransactionId', 1) # SimId change at each test need to drop it cal = cal.drop('ResourceId', 1) refs = pd.DataFrame(np.array([ (922380000, 0.7872433760310, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 1), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 1), (922380000, 0.7872433760310, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 2), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 2), (922380000, 0.7872433760310, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 2), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 2), (922380000, 0.7872433760310, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 3), (942390000, 0.0444814879803, 15, 'Reactor1', 14, 'MOX_Source', 'mox', 3), (922380000, 0.7872433760310, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 3), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 3), (922380000, 0.7872433760310, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 4), (942390000, 0.0444814879803, 16, 'Reactor2', 14, 'MOX_Source', 'mox', 4), (922380000, 0.7872433760310, 17, 'Reactor3', 14, 'MOX_Source', 'mox', 4), (942390000, 0.0444814879803, 17, 'Reactor3', 14, 'MOX_Source', 'mox', 4), (922380000, 0.9600000000000, 17, 'Reactor3', 13, 'UOX_Source', 'uox', 3), (922380000, 0.9600000000000, 15, 'Reactor1', 13, 'UOX_Source', 'uox', 4), ], dtype=ensure_dt_bytes([ ('NucId', '<i8'), ('Mass', '<f8'), ('ReceiverId', '<i8'), ('ReceiverPrototype', 'O'), ('SenderId', '<i8'), ('SenderPrototype', 'O'), ('Commodity', 'O'), ('Time', '<i8') ])) ) # refs.index = refs.index.astype('str') assert_frame_equal(cal, refs)