Skip to content

Instantly share code, notes, and snippets.

@soxofaan
Last active December 12, 2019 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soxofaan/c896d032e581e5d86f45b772f653ace8 to your computer and use it in GitHub Desktop.
Save soxofaan/c896d032e581e5d86f45b772f653ace8 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import openeo"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# openeo_url = \"https://openeo.vito.be/openeo/0.4.2\"\n",
"openeo_url = \"http://localhost:8080/openeo/0.4.2\"\n",
"session = openeo.connect(openeo_url)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"bbox = {'west': 3.42, 'south': 51.00, 'east': 3.44, 'north': 51.05, 'crs': 'EPSG:4326'}\n",
"date = '2018-05-06'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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": [
"mask = (\n",
" session\n",
" .load_collection(\"S2_FAPAR_SCENECLASSIFICATION_V102_PYRAMID\")\n",
" .filter_bbox(**bbox)\n",
" .filter_temporal(date, date)\n",
" .band(\"classification\")\n",
")\n",
"mask = (mask != 4) & (mask !=5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check `mask` process graph: no nodes with `result=True` yet"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False filtertemporal1\n",
"False loadcollection1\n",
"False filterbbox1\n",
"False reduce1\n"
]
}
],
"source": [
"for name, process in mask.graph.items():\n",
" print(process.get(\"result\", False), name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use `mask` in a mask process on another cube."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"cube_masked = (\n",
" session\n",
" .load_collection(\"CGS_SENTINEL2_RADIOMETRY_V102_FILE\")\n",
" .filter_bbox(**bbox)\n",
" .filter_temporal(date, date)\n",
" .mask(rastermask=mask)\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`mask` process graph now suddenly has a result node `reduce1` with `result=True`"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False filtertemporal1\n",
"False loadcollection1\n",
"False filterbbox1\n",
"True reduce1\n"
]
}
],
"source": [
"for name, process in mask.graph.items():\n",
" print(process.get(\"result\", False), name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following fails because the download method adds (another) node with `result=True`: `save_result`"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[500] unknown: Multiple result nodes: saveresult3, reduce1\n"
]
}
],
"source": [
"try:\n",
" mask.download(\"mask.tiff\", format=\"GTIFF\")\n",
"except Exception as e:\n",
" print(e)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"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