def main():
    file_name = "ExampleFile.dat"
    trigger_stream = clock_stream(period=0.1, num_periods=10, name="trigger_stream")
    s = stream_from_file(trigger_stream, file_name, step_size=1)
    s.set_name("s")
    print_stream_with_index(s)

    scheduler.run()
def main():
    file_name = 'ExampleFile.dat'
    trigger_stream = clock_stream(period=0.1,
                                  num_periods=10,
                                  name='trigger_stream')
    s = stream_from_file(trigger_stream, file_name, step_size=1)
    s.set_name('s')
    print_stream_with_index(s)

    scheduler.run()
def example_1():
    # FUNCTIONS FROM LIST TO LIST

    # This example uses the following list operators:
    # functions from a list to a list.
    # f, g, h, r

    # Example A: function using list comprehension
    def f(lst):
        return [w*w for w in lst]

    # Example B: function using filter
    threshold = 2
    def predicate(w):
        return w > threshold
    def g(lst):
        return filter(predicate, lst)

    # Example C: function using map
    # Raise each element of the list to the n-th power.   
    n = 3
    def power(w):
        return w**n
    def h(lst):
        return map(power, lst)

    # Example D: function using another list comprehension
    # Discard any element of x that is not a
    # multiple of a parameter n, and divide the
    # elements that are multiples of n by n.
    n = 3
    def r(lst):
        result = []
        for w in lst:
            if w%n == 0: result.append(w/n)
        return result

    # CREATE A CLOCK STREAM
    trigger_stream = clock_stream(period=0.01,
                                  num_periods=12, name='trigger_stream')

    list_of_values = [ 3, 7, 0, 11, 5, 4, 6, 2, -1, 3, 2, 0, 4, 6, -3, -9, 8]
    x = stream_from_list(trigger_stream, list_of_values)
    x.set_name('x')
    y = stream_from_file(trigger_stream, file_name='ExampleFile.dat', step_size=1)
    y.set_name('y')

    # EXAMPLES OF OPERATIONS ON STREAMS
    
    # The output streams a, b, c, d obtained by
    # applying the list operators f, g, h, r to
    # stream x.
    state = None
    call_streams = [trigger_stream]
    a = op(f, x, state, call_streams)
    b = op(g, x, state, call_streams)
    c = op(h, y, state, call_streams)
    d = op(r, x, state, call_streams)

    # Name the output streams to label the output
    # so that reading the output is easier.
    a.set_name('a')
    b.set_name('b')
    c.set_name('c')
    d.set_name('d')
    
    print_stream_with_index(x)
    print_stream_with_index(trigger_stream)
    print_stream_with_index(a)
    print_stream_with_index(b)
    print_stream_with_index(c)
    print_stream_with_index(d)
    print_stream_with_index(y)
Esempio n. 4
0
def example_1():
    # FUNCTIONS FROM LIST TO LIST

    # This example uses the following list operators:
    # functions from a list to a list.
    # f, g, h, r

    # Example A: function using list comprehension
    def f(lst):
        return [w * w for w in lst]

    # Example B: function using filter
    threshold = 2

    def predicate(w):
        return w > threshold

    def g(lst):
        return filter(predicate, lst)

    # Example C: function using map
    # Raise each element of the list to the n-th power.
    n = 3

    def power(w):
        return w**n

    def h(lst):
        return map(power, lst)

    # Example D: function using another list comprehension
    # Discard any element of x that is not a
    # multiple of a parameter n, and divide the
    # elements that are multiples of n by n.
    n = 3

    def r(lst):
        result = []
        for w in lst:
            if w % n == 0: result.append(w / n)
        return result

    # CREATE A CLOCK STREAM
    trigger_stream = clock_stream(period=0.01,
                                  num_periods=12,
                                  name='trigger_stream')

    list_of_values = [3, 7, 0, 11, 5, 4, 6, 2, -1, 3, 2, 0, 4, 6, -3, -9, 8]
    x = stream_from_list(trigger_stream, list_of_values)
    x.set_name('x')
    y = stream_from_file(trigger_stream,
                         file_name='ExampleFile.dat',
                         step_size=1)
    y.set_name('y')

    # EXAMPLES OF OPERATIONS ON STREAMS

    # The output streams a, b, c, d obtained by
    # applying the list operators f, g, h, r to
    # stream x.
    state = None
    call_streams = [trigger_stream]
    a = op(f, x, state, call_streams)
    b = op(g, x, state, call_streams)
    c = op(h, y, state, call_streams)
    d = op(r, x, state, call_streams)

    # Name the output streams to label the output
    # so that reading the output is easier.
    a.set_name('a')
    b.set_name('b')
    c.set_name('c')
    d.set_name('d')

    print_stream_with_index(x)
    print_stream_with_index(trigger_stream)
    print_stream_with_index(a)
    print_stream_with_index(b)
    print_stream_with_index(c)
    print_stream_with_index(d)
    print_stream_with_index(y)