Example #1
0
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
Example #2
0
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
Example #3
0
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)})
Example #4
0
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)