Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OpenEO mask example
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import openeo\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"connection = openeo.connect(\"https://openeo.vito.be/openeo/0.4.2\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/lippenss/src/openeo/openeo-python-client/openeo/imagecollection.py:60: UserWarning: No band metadata under `properties/eo:bands` trying some fallback sources.\n",
" warnings.warn(\"No band metadata under `properties/eo:bands` trying some fallback sources.\")\n"
]
}
],
"source": [
"scene_classification = (\n",
" connection\n",
" .load_collection(\"S2_FAPAR_SCENECLASSIFICATION_V102_PYRAMID\")\n",
" .band('classification')\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"mask = (scene_classification != 4) & (scene_classification != 5)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"loadcollection1\": {\n",
" \"result\": false,\n",
" \"arguments\": {\n",
" \"temporal_extent\": null,\n",
" \"id\": \"S2_FAPAR_SCENECLASSIFICATION_V102_PYRAMID\",\n",
" \"spatial_extent\": null\n",
" },\n",
" \"process_id\": \"load_collection\"\n",
" },\n",
" \"reduce1\": {\n",
" \"result\": false,\n",
" \"arguments\": {\n",
" \"data\": {\n",
" \"from_node\": \"loadcollection1\"\n",
" },\n",
" \"dimension\": \"spectral_bands\",\n",
" \"reducer\": {\n",
" \"callback\": {\n",
" \"arrayelement3\": {\n",
" \"result\": false,\n",
" \"arguments\": {\n",
" \"index\": 0,\n",
" \"data\": {\n",
" \"from_argument\": \"data\"\n",
" }\n",
" },\n",
" \"process_id\": \"array_element\"\n",
" },\n",
" \"not3\": {\n",
" \"result\": false,\n",
" \"arguments\": {\n",
" \"expression\": {\n",
" \"from_node\": \"eq5\"\n",
" }\n",
" },\n",
" \"process_id\": \"not\"\n",
" },\n",
" \"arrayelement4\": {\n",
" \"result\": false,\n",
" \"arguments\": {\n",
" \"index\": 0,\n",
" \"data\": {\n",
" \"from_argument\": \"data\"\n",
" }\n",
" },\n",
" \"process_id\": \"array_element\"\n",
" },\n",
" \"eq6\": {\n",
" \"result\": false,\n",
" \"arguments\": {\n",
" \"y\": 5,\n",
" \"x\": {\n",
" \"from_node\": \"arrayelement4\"\n",
" }\n",
" },\n",
" \"process_id\": \"eq\"\n",
" },\n",
" \"eq5\": {\n",
" \"result\": false,\n",
" \"arguments\": {\n",
" \"y\": 4,\n",
" \"x\": {\n",
" \"from_node\": \"arrayelement3\"\n",
" }\n",
" },\n",
" \"process_id\": \"eq\"\n",
" },\n",
" \"not4\": {\n",
" \"result\": false,\n",
" \"arguments\": {\n",
" \"expression\": {\n",
" \"from_node\": \"eq6\"\n",
" }\n",
" },\n",
" \"process_id\": \"not\"\n",
" },\n",
" \"and1\": {\n",
" \"result\": true,\n",
" \"arguments\": {\n",
" \"expressions\": [\n",
" {\n",
" \"from_node\": \"not3\"\n",
" },\n",
" {\n",
" \"from_node\": \"not4\"\n",
" }\n",
" ]\n",
" },\n",
" \"process_id\": \"and\"\n",
" }\n",
" }\n",
" }\n",
" },\n",
" \"process_id\": \"reduce\"\n",
" }\n",
"}\n"
]
}
],
"source": [
"print(json.dumps(mask.graph, indent=4))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "OpenEO env",
"language": "python",
"name": "openeo"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment