Skip to content

Commit

Permalink
tackled comments + limited postprocessing options in notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jdegerickx committed Oct 15, 2024
1 parent 8c101c6 commit f450d28
Show file tree
Hide file tree
Showing 6 changed files with 926 additions and 105 deletions.
59 changes: 15 additions & 44 deletions notebooks/worldcereal_v1_demo_custom_cropland.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"\n",
"This notebook guides you through the process of training a custom cropland classification model using publicly available and harmonized in-situ reference data for your area of interest. Afterwards, the model can be applied to your area and season of interest to generate a cropland extent map.\n",
"\n",
"Please note that for the purpose of this demo, the processing area is currently limited to 250 km² per model run."
"Please note that for the purpose of this demo, the processing area is currently limited to 250 km² per model run. On average, one such run consumes xxx credits on the Copernicus Data Space Ecosystem."
]
},
{
Expand Down Expand Up @@ -53,7 +53,12 @@
"Click the Rectangle button on the left hand side of the map to start drawing your region of interest.\n",
"\n",
"Currently, there is a maximum size of 250 km² for your area within this demo. Upon exceeding this limit, an error will be shown.\n",
"The widget will automatically store the coordinates of the last rectangle you drew on the map.\n"
"You can bypass this limit by altering the code below to:<br>\n",
"*map = ui_map(area_limit=750)*<br>\n",
"\n",
"Processing areas beyond 750 km² are currently not supported.\n",
"\n",
"The widget will automatically store the coordinates of the last rectangle you drew on the map."
]
},
{
Expand Down Expand Up @@ -212,8 +217,9 @@
"source": [
"from worldcereal.utils.upload import deploy_model\n",
"from openeo_gfmap.backend import cdse_connection\n",
"from utils import get_input\n",
"\n",
"modelname = <your_model_name>\n",
"modelname = get_input(\"model\")\n",
"model_url = deploy_model(cdse_connection(), custom_model, pattern=modelname)"
]
},
Expand Down Expand Up @@ -276,25 +282,14 @@
"import os\n",
"from pathlib import Path\n",
"\n",
"# Choose whether or not you want to spatially clean the classification results (default = True)\n",
"# Choose whether or not you want to spatially clean the classification results\n",
"postprocess_result = True\n",
"# Choose the postprocessing method you want to use [\"smooth_probabilities\", \"majority_vote\"] (default = \"smooth_probabilities\")\n",
"postprocess_method = \"majority_vote\"\n",
"# Additiona parameters for the majority vote method:\n",
"kernel_size = 3 # default = 5\n",
"# Do you want to save the intermediate results (before applying the postprocessing)\n",
"save_intermediate = True #default is False\n",
"# Do you want to save all class probabilities in the final product? (default is False)\n",
"keep_class_probs = True\n",
"\n",
"postprocess_parameters = PostprocessParameters(enable=postprocess_result,\n",
" method=postprocess_method,\n",
" kernel_size=kernel_size,\n",
" save_intermediate=save_intermediate,\n",
" keep_class_probs=keep_class_probs)\n",
"\n",
"postprocess_parameters = PostprocessParameters(enable=postprocess_result)\n",
"\n",
"# Specify the local directory where the resulting maps should be downloaded to.\n",
"output_dir = Path(os.getcwd()) / 'CROPLAND_custom_test'\n",
"run = get_input(\"model run\")\n",
"output_dir = Path(os.getcwd()) / f'CROPLAND_{modelname}_{run}'\n",
"print(f\"Output directory: {output_dir}\")"
]
},
Expand Down Expand Up @@ -366,31 +361,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The resulting raster files can be visualized in QGIS.\n",
"\n",
"In case you are running this script on your local environment, you can alternatively use the following cells to visualize the outputs directly in this notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from utils import visualize_products\n",
"\n",
"visualize_products(rasters, port=8887)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from utils import show_color_legend\n",
"\n",
"show_color_legend(rasters, \"cropland\")"
"The resulting raster files can be visualized in QGIS."
]
}
],
Expand Down
Loading

0 comments on commit f450d28

Please sign in to comment.