def __init__(self, parent=None):
        super().__init__(parent=parent)

        # create pfgraph
        with pf.Graph() as graph:
            imageio = pf.import_('imageio')
            ndimage = pf.import_('scipy.ndimage')
            np = pf.import_('numpy')

            x = PFSlider(name="x")
            y = PFSlider(name="y")
            r = (x * y).set_name("r")

            frame = pf.placeholder("frame")
            readop(path=pf.placeholder('filepath'), frame=frame)
            # image = imageio.imread(filename).set_name('imread')

        self.setLayout(QHBoxLayout())

        self.model = PFGraphModel(
            graph, **{
                'x': 90,
                'y': 30,
                'frame': 0,
                'filepath': "C:/Users/andris/Videos/M2U00001.MPG"
            })
        self.graphview = GraphView()
        self.graphview.setModel(self.model)
        self.viewer = Viewer()
        self.layout().addWidget(self.graphview)
        self.layout().addWidget(self.viewer)

        self.renderer = GraphicsRenderer()
        self.viewer.addItem(self.renderer)
        self.viewer.body.centerOn(0, 0)

        def onSelectionChange():
            """show output results in viewer"""
            if len(self.model.nodeSelection()) > 0:
                for node in self.model.nodeSelection():
                    outputPorts = self.model.nodeOutputs(node)
                    port = outputPorts[0]
                    outputValue = self.model.portData((port, "value"),
                                                      Qt.EditRole)
                    self.renderer.setInput(outputValue)
                    self.renderer.update()
            else:
                self.renderer.setInput(None)
                self.renderer.update()

        def onDataChange(index):
            for node in self.model.nodeSelection():
                outputPorts = self.model.nodeOutputs(node)
                port = outputPorts[0]
                outputValue = self.model.portData((port, "value"), Qt.EditRole)
                self.renderer.setInput(outputValue)
                self.renderer.update()

        self.model.nodeSelectionChange.connect(onSelectionChange)
        self.model.portDataChange.connect(onDataChange)
Esempio n. 2
0
def test_profiling():
    with pf.Graph() as graph:
        duration = pf.placeholder('duration')
        # Use a conditional to make sure we also test the evaluation of conditionals with callbacks
        positive_duration = pf.conditional(duration < 0, 0, duration)
        sleep = pf.import_('time').sleep(positive_duration)

    callback = pf.Profiler()
    graph(sleep, callback=callback, duration=0.5)
    assert callback.times[sleep] > 0.5
    # We never evaluate duration because it is already provided in the context
    assert duration not in callback.times
    # Check that the slowest operation comes first
    callback_str = str(callback)
    assert callback_str.startswith(str(sleep))
    assert len(callback_str.split('\n')) == 5
Esempio n. 3
0
def test_import():
    with pf.Graph() as graph:
        os_ = pf.import_('os')
        isfile = os_.path.isfile(__file__)

    assert graph(isfile)
    # ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ #
    @slipform(debug=True)
    def graph():
        import string, math
        import os as os_
        import os.path as _path
        from os.path import join as _join
        # get stuff
        isfile = os_.path.isfile(__file__)
        a_is_ascii = 'a' in string.ascii_letters
        joined = _path.join('a', 'b')
        joined_fail = _join('a', 'b')

    assert graph('isfile')
    assert graph('a_is_ascii')
    assert graph('joined') == 'a/b'
    assert graph('joined_fail') == 'a/b'
Esempio n. 4
0
def test_import():
    with pf.Graph() as graph:
        os_ = pf.import_('os')
        isfile = os_.path.isfile(__file__)

    assert graph(isfile)
Esempio n. 5
0
import pythonflow as pf

with pf.Graph() as graph:
    # Only load the libraries when necessary
    imageio = pf.import_('imageio')
    ndimage = pf.import_('scipy.ndimage')
    np = pf.import_('numpy')

    filename = pf.placeholder('filename')
    image = (imageio.imread(filename).set_name('imread')[..., :3] /
             255.0).set_name('image')
    noise_scale = pf.constant(.25, name='noise_scale')
    noise = (1 -
             np.random.uniform(0, noise_scale, image.shape)).set_name('noise')
    noisy_image = (image * noise).set_name('noisy_image')
    angle = np.random.uniform(-45, 45)
    rotated_image = ndimage.rotate(noisy_image, angle,
                                   reshape=False).set_name('rotated_image')