Skip to content

Commit

Permalink
Merge pull request #46 from fkroeber/vis
Browse files Browse the repository at this point in the history
feat: blockly visualisation of models 🎁
  • Loading branch information
luukvdmeer authored Jul 2, 2024
2 parents 4b79cb8 + 3726c09 commit e55c180
Show file tree
Hide file tree
Showing 10 changed files with 3,578 additions and 10 deletions.
27 changes: 23 additions & 4 deletions demo/mapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,26 @@
"id": "98511bd7",
"metadata": {},
"source": [
"The flexible structure with the building blocks of semantique make many more structures possible. Now you have an idea of how to construct a mapping from scratch using the built-in Semantique configuration, we move on and construct a complete mapping in one go. However, we use simpler rules as above, since our demo EO data cube only contains a very limited set of resources."
"The flexible structure with the building blocks of semantique make many more structures possible. Note that you can visualise the structure of your defined mapping by calling `.visualise()`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a9ee5654",
"metadata": {},
"outputs": [],
"source": [
"mapping.visualise()"
]
},
{
"cell_type": "markdown",
"id": "21de8ad5",
"metadata": {},
"source": [
"\n",
"Now you have an idea of how to construct a mapping from scratch using the built-in Semantique configuration, we move on and construct a complete mapping in one go. However, we use simpler rules as above, since our demo EO data cube only contains a very limited set of resources."
]
},
{
Expand Down Expand Up @@ -1078,9 +1097,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:semantique]",
"display_name": "gsemantique",
"language": "python",
"name": "conda-env-semantique-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -1092,7 +1111,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
25 changes: 21 additions & 4 deletions demo/recipes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,24 @@
"id": "4dedbc77",
"metadata": {},
"source": [
"The recipe we just constructred looks like [this](https://github.com/ZGIS/semantique/blob/main/demo/files/recipe.json).\n",
"The recipe we just constructred looks like [this](https://github.com/ZGIS/semantique/blob/main/demo/files/recipe.json). It can be visualised by calling the corresponding method as shown below."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab0596d2",
"metadata": {},
"outputs": [],
"source": [
"recipe.visualise()"
]
},
{
"cell_type": "markdown",
"id": "6e47eb13",
"metadata": {},
"source": [
"\n",
"## Setting the context\n",
"\n",
Expand Down Expand Up @@ -1863,9 +1880,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:semantique]",
"display_name": "gsemantique",
"language": "python",
"name": "conda-env-semantique-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -1877,7 +1894,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
13 changes: 12 additions & 1 deletion semantique/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from semantique.processor.core import QueryProcessor, FakeProcessor
from semantique.processor.arrays import Collection
from semantique.processor import reducers
from semantique.visualiser.visualise import show

class Mapping(dict):
"""Base class for mapping configurations.
Expand Down Expand Up @@ -166,4 +167,14 @@ def translate(self, *reference, property = None, extent, datacube,
)
out = processor.call_handler(property)
out.name = reference[-1]
return out
return out

def visualise(self):
"""Visualise the mapping rules in a web browser.
This method visualises the mapping rules of the mapping instance in a web
browser. The visualisation is based on Blockly, a web-based visual programming
editor. The mapping rules are converted into Blockly XML format and served
to the browser.
"""
show(self)
13 changes: 12 additions & 1 deletion semantique/recipe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from semantique.processor.core import QueryProcessor, FakeProcessor
from semantique.visualiser.visualise import show

class QueryRecipe(dict):
"""Dict-like container to store instructions of a query recipe.
Expand Down Expand Up @@ -99,4 +100,14 @@ def execute(self, datacube, mapping, space, time, run_preview = False,
cache=cache,
**config
)
return qp.optimize().execute()
return qp.optimize().execute()

def visualise(self):
"""Visualise the recipe in a web browser.
This method visualises the recipe in a web browser.
The visualisation is based on Blockly, a web-based visual programming
editor. The recipe is converted into Blockly XML format and served
to the browser.
"""
show(self)
Empty file.
Loading

0 comments on commit e55c180

Please sign in to comment.