Lets get it rolling
So we just created our first app. And ran it against the Arkitekt Server. But what did we just do ? And saying my name is not really useful. So lets dive a bit deeper and lets create a real app
Adapting our real App
Lets adapt our app to do something useful. We will create a simple app that will allow us to max project a microscopy image of our choice. So how do we do that ? Lets look at the code we created, before and deduce what we need to change.
from arkitekt import register
@register
def hello_world(name: str) -> str:
"""Hello World
This is a simple Hello World Node, that will greet you by your name.
and print it to the console.
Args:
name (str): Your name
Returns:
str: A greeting
"""
greeting = f"Hello {name}"
print(greeting)
return greeting
So what do we need to change ? First of all we need to change the name of the function. We will call it max_project
. Then we need to
change the documentation. We will call it Max Project
and we will change the description to Max Project a microscopy image
. Documentation
your functions is very important. It will help you and others to understand what your function does. And it will help you to find your function
in the UI.
But how do we tell Arkitekt that we are no longer working with strings but need "Images"? This is done through updating the type hint of our function. We will change it from str
to Representation
,
an import for the mikro
python package. When register a function the SDK will automatically detect the type hint and will create the correct input and output Port, for you.
This means you have to (almost) always use type hints to indicate the type of your input and output. But hey you should do that anyway.
from arkitekt import register
from mikro import Representation
@register
def max_project(image: Representation) -> Representation:
"""Max Project a microscopy image
This is a simple node that will max project a microscopy image.
Args:
image (Representation): The input image
Returns:
str: The output image
"""
print(f"Max Projecting {image}")
...
return image
And that is it.
The Representation
type from the mikro
is our first Structure. Structures represent more complex data types, then
simple types like String
or Int
. While most of the time you will find yourself working with sharable global structures (that live on a connected
service), you can also create your own structures (even non serializable), that are only available to your app. We will cover this in a later tutorial.