.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_examples_imaging_syntax_intro.py:
Syntax Intro
============
How to leverage the syntax of ImagePypelines effectively!
Let's try blockifying vs using a FuncBlock vs using a Block subclass
.. code-block:: default
# NOTE: can't blockify built-ins or c-functions *directly* (they don't have a signature!!!)
import imagepypelines as ip
def print_msg(msg):
print(msg)
print_msg1 = ip.FuncBlock(print_msg, void=True)
@ip.blockify(void=True)
def print_msg2(msg):
print(msg)
class PrintMsg(ip.Block):
def __init__(self, **block_kwargs):
super().__init__(name="PrintMsg", **block_kwargs)
def process(self, msg):
print_msg(msg)
print_msg3 = PrintMsg()
print_msg("Blah blah")
print_msg1("Blah1 blah1!")
print_msg2("Blah2 blah2!!")
print_msg3.process("Blah3 blah3!!!")
print_msg3("Blah4 blah4!!!!")
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
Blah blah
Blah1 blah1!
Blah2 blah2!!
Blah3 blah3!!!
Blah4 blah4!!!!
tasks = {'msg':ip.Input(),
'null':(print_msg, 'msg')}
msg_printer = ip.Pipeline(tasks)
processed = msg_printer.process(["Hello World!"])
We can pass in any data we want! In this example, we call this function
once for every datum passed in
processed = msg_printer.process(['we','can','print','anything','individually!'])
We can also print everything at once with the `batch_type` variable
-------------------------------------------------------------------
@ip.blockify(batch_type="all", void=True)
def print_all(msg):
print(msg)
tasks = {'msg':ip.Input(),
'null':(print_all, 'msg')}
print_all_pipeline = ip.Pipeline(tasks)
processed = print_all_pipeline.process(['we','can','print','everything','at','once!'])
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.002 seconds)
.. _sphx_glr_download_examples_imaging_syntax_intro.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: syntax_intro.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: syntax_intro.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_