def pickMultiple_graph(): graph = Graph(name='graph') graph.add( PickN(name='cspad_pickN', N=9, inputs=['cspad', 'delta_t'], outputs=['ncspads'])) graph.compile(num_workers=4, num_local_collectors=2) return graph
def psana_graph(tmpdir_factory): graph = Graph(name='graph') graph.add( PickN(name='picker', inputs=['xppcspad:raw:image'], outputs=['picked'])) fname = tmpdir_factory.mktemp("psana_graph", False).join("psana_graph.dill") with open(fname, 'wb') as fd: dill.dump(graph, fd) return fname
def rollingBuffer_graph(request): N, nworkers, ncollectors, expected = request.param graph = Graph(name='graph') graph.add( RollingBuffer(name='cspad_rollingBuffer', N=N, inputs=['cspad'], outputs=['ncspads'])) graph.compile(num_workers=nworkers, num_local_collectors=ncollectors) return graph, expected
def test_rolling_buffer(): graph = Graph(name='graph') graph.add(RollingBuffer(name='ScatterPlot', inputs=['x', 'y'], outputs=['scatter'], N=8)) graph.add(Map(name='ScatterUnzip', inputs=['scatter'], outputs=['scatter_x', 'scatter_y'], func=lambda a: zip(*a))) graph.compile(num_workers=4, num_local_collectors=2) for node in graph.graph.nodes(): if type(node) is str: continue if node.name == 'ScatterPlot_worker': assert(node.N == 2) elif node.name == 'ScatterPlot_localCollector': assert(node.N == 4) elif node.name == 'ScatterPlot_globalCollector': assert(node.N == 8) worker1 = graph({'x': 0, 'y': 1}, color='worker') worker1 = graph({'x': 2, 'y': 3}, color='worker') assert(worker1 == {'scatter_worker': [(0, 1), (2, 3)]}) worker1 = graph({'x': 4, 'y': 5}, color='worker') assert(worker1 == {'scatter_worker': [(2, 3), (4, 5)]}) worker1 = {'scatter_worker': [(2, 3), (4, 5)]} worker2 = {'scatter_worker': [(3, 2), (5, 4)]} worker3 = {'scatter_worker': [(0, 1), (2, 3)]} worker4 = {'scatter_worker': [(1, 0), (3, 2)]} localCollector1 = graph(worker1, color='localCollector') localCollector1 = graph(worker2, color='localCollector') assert(localCollector1 == {'scatter_localCollector': [(2, 3), (4, 5), (3, 2), (5, 4)]}) localCollector1 = graph(worker3, color='localCollector') assert(localCollector1 == {'scatter_localCollector': [(3, 2), (5, 4), (0, 1), (2, 3)]}) localCollector1 = graph(worker4, color='localCollector') assert(localCollector1 == {'scatter_localCollector': [(0, 1), (2, 3), (1, 0), (3, 2)]}) localCollector1 = {'scatter_localCollector': [(0, 1), (2, 3), (4, 5), (6, 7)]} localCollector2 = {'scatter_localCollector': [(8, 9), (10, 11), (12, 13), (14, 15)]} globalCollector = graph(localCollector1, color='globalCollector') globalCollector = graph(localCollector2, color='globalCollector') assert(globalCollector == {'scatter_x': (0, 2, 4, 6, 8, 10, 12, 14), 'scatter_y': (1, 3, 5, 7, 9, 11, 13, 15)}) localCollector1 = {'scatter_localCollector': [(16, 17), (18, 19), (20, 21), (22, 23)]} globalCollector = graph(localCollector1, color='globalCollector') assert(globalCollector == {'scatter_x': (8, 10, 12, 14, 16, 18, 20, 22), 'scatter_y': (9, 11, 13, 15, 17, 19, 21, 23)})
from ami.graphkit_wrapper import Graph from ami.graph_nodes import Map, FilterOn, FilterOff, Binning import numpy as np graph = Graph(name='graph') graph.add( Map(name='Roi', inputs=['cspad'], outputs=['roi'], func=lambda cspad: cspad[:100, :100])) graph.add(Map(name='Sum', inputs=['roi'], outputs=['sum'], func=np.sum)) graph.add( FilterOn(name='FilterOn', condition_needs=['laser'], outputs=['laseron'])) graph.add( Binning(name='BinningOn', condition_needs=['laseron'], inputs=['delta_t', 'sum'], outputs=['signal'])) graph.add( FilterOff(name='FilterOff', condition_needs=['laser'], outputs=['laseroff'])) graph.add( Binning(name='BinningOff', condition_needs=['laseroff'], inputs=['delta_t', 'sum'], outputs=['reference'])) graph.compile(num_workers=4, num_local_collectors=2)
def complex_graph_file(tmpdir, qtbot): graph = Graph(name='graph') def roi(cspad): return cspad[:100, :100] graph.add(Map(name='Roi', inputs=['cspad'], outputs=['roi'], func=roi)) graph.add(Map(name='Sum', inputs=['roi'], outputs=['sum'], func=np.sum)) graph.add( FilterOn(name='FilterOn', condition_needs=['laser'], outputs=['laseron'])) binningOn = MeanVsScan('BinningOn') nodes = binningOn.to_operation({ "Bin": "delta_t", "Value": "sum" }, conditions={"Condition": 'laseron'}) graph.add(nodes) graph.add( FilterOff(name='FilterOff', condition_needs=['laser'], outputs=['laseroff'])) binningOff = MeanVsScan('BinningOff') nodes = binningOff.to_operation({ "Bin": "delta_t", "Value": "sum" }, conditions={"Condition": 'laseroff'}) graph.add(nodes) fname = tmpdir.mkdir("complex_graph").join("complex_graph.dill") with open(fname, 'wb') as fd: dill.dump(graph, fd) return fname
def complex_graph_file(tmpdir, qtbot): graph = Graph(name='graph') def roi(cspad): return cspad[:100, :100] graph.add(Map(name='Roi', inputs=['cspad'], outputs=['roi'], func=roi)) graph.add(Map(name='Sum', inputs=['roi'], outputs=['sum'], func=np.sum)) def filter_on(laser, sum0): if laser: return sum0 graph.add( Map(name='FilterOn', inputs=['laser', 'sum'], outputs=['laseron'], func=filter_on)) binningOn = MeanVsScan('BinningOn') nodes = binningOn.to_operation(inputs={ "Bin": "delta_t", "Value": "laseron" }, outputs=['laseron_bin', 'laseron_value']) graph.add(nodes) def filter_off(laser, sum0): if not laser: return sum0 graph.add( Map(name='FilterOff', inputs=['laser', 'sum'], outputs=['laseroff'], func=filter_off)) binningOff = MeanVsScan('BinningOff') nodes = binningOff.to_operation({ "Bin": "delta_t", "Value": "laseroff" }, outputs=['laseroff_bin', 'laseroff_value']) graph.add(nodes) fname = tmpdir.mkdir("complex_graph").join("complex_graph.dill") with open(fname, 'wb') as fd: dill.dump(graph, fd) return fname
def eb_graph(): graph = Graph(name='graph') graph.add( PickN(name='pick1_values', N=1, inputs=['values'], outputs=['value'])) return dill.dumps(graph)