{ "cells": [ { "cell_type": "markdown", "id": "f6b4fb29", "metadata": { "id": "f6b4fb29" }, "source": [ "# Land Cover Validation with LUCAS dataset" ] }, { "cell_type": "markdown", "id": "61c43ba2", "metadata": { "id": "61c43ba2" }, "source": [ "This is an example of a land cover product validation using LUCAS points. The process is using the class `Validator` to perform the main validation steps. " ] }, { "cell_type": "markdown", "id": "d11e86ef-51ce-4cd7-9746-b1f4275dc15b", "metadata": {}, "source": [ "## Install\n", "\n", "### Note for Google Colab" ] }, { "cell_type": "code", "execution_count": null, "id": "4a3aca7e-c155-4981-9b9a-fe5154c1251a", "metadata": {}, "outputs": [], "source": [ "!git clone https://gitlab.com/geoharmonizer_inea/st_lucas/st_lucas-python-package.git\n", "!(cd st_lucas-python-package/; git pull)\n", "import sys\n", "sys.path.insert(0, './st_lucas-python-package/docs/notebooks/')" ] }, { "cell_type": "markdown", "id": "b2e92dcd-ad5e-4763-8f29-fdce33d62865", "metadata": {}, "source": [ "### Install requirements" ] }, { "cell_type": "code", "execution_count": null, "id": "c5b6d920", "metadata": { "id": "c5b6d920" }, "outputs": [], "source": [ "!pip3 install geopandas pyyaml==6.0 ipyleaflet \n", "print(\"INSTALLATION COMPLETED\")" ] }, { "cell_type": "markdown", "id": "GkWH_uKh8sl8", "metadata": { "id": "GkWH_uKh8sl8" }, "source": [ "Now **we have to restart runtime**: `Runtime -> Restart runtime` (on Google Colab) or ``Kernel -> Restart`` (on JupyterLab)." ] }, { "cell_type": "code", "execution_count": 1, "id": "2tJuyMGs89M6", "metadata": { "id": "2tJuyMGs89M6" }, "outputs": [], "source": [ "import os\n", "import yaml \n", "\n", "from osgeo import gdal\n", "from osgeo import gdalconst\n", "import geopandas as gpd\n", "import numpy \n", "import urllib\n", "\n", "import matplotlib.pyplot as plt \n", "%matplotlib inline\n", "\n", "from validator import Validator" ] }, { "cell_type": "markdown", "id": "bd684782", "metadata": { "id": "bd684782" }, "source": [ "## Land Cover validation \n", "\n", "### Configure validation \n", "\n", "Check contents of the `config.yaml` file. " ] }, { "cell_type": "code", "execution_count": 2, "id": "69bef016", "metadata": { "id": "69bef016" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "project:\n", " name: 'Geoharmonizer Land Cover validation'\n", " abbrev: 'cz_lc_18'\n", " run_id: '20210907'\n", "\n", "# land cover & reference definitions \n", "input:\n", " # raster map \n", " path: ./sample_land_cover\n", " in_ras: cz_land_cover_osm_2018.tif\n", " ndv: 0\n", " legend: legend.yaml\n", " # vector reference \n", " in_vec: cz_lucas_points_l1_2018.shp\n", " ref_att: 'label_l1'\n", "\n", "# validation report settings\n", "report:\n", " path: ./sample_land_cover\n", " dir_name: 'lc_2018_validation'\n", "\n", "# validation points for GIS exploration \n", "validation_points: \n", " file_name: 'validation_points'\n", " ogr_format: 'ESRI Shapefile'\n", " epsg: 3035 \n", "\n", " \n", "\n" ] } ], "source": [ "# configuration with sample data \n", "config_file = \"sample_land_cover/config.yaml\" # On Google Colab: \"./st_lucas-python-package/docs/notebooks/sample_land_cover/config.yaml\"\n", "\n", "with open(config_file, 'r') as file: \n", " file_contents = file.read()\n", " \n", "print(file_contents)" ] }, { "cell_type": "markdown", "id": "2910653b", "metadata": { "id": "2910653b" }, "source": [ "### Initialize the validator " ] }, { "cell_type": "markdown", "id": "874f9348", "metadata": { "id": "874f9348" }, "source": [ "Initilize the validator by passing the config file or a Python dictionary with the same structure" ] }, { "cell_type": "code", "execution_count": 3, "id": "fbd60738", "metadata": { "id": "fbd60738" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "Validation project initialized!\n", "Inputs: \n", "cz_land_cover_osm_2018.tif\n", "cz_lucas_points_l1_2018.shp\n", "\n", "\n" ] } ], "source": [ "validation = Validator(config_file)" ] }, { "cell_type": "markdown", "id": "2c46e609", "metadata": { "id": "2c46e609" }, "source": [ "### Check validity of the inputs" ] }, { "cell_type": "code", "execution_count": 4, "id": "8f217242", "metadata": { "id": "8f217242" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Validation data ready: True\n" ] } ], "source": [ "# Check if you can read the geodata \n", "\n", "inputs_valid = validation.check_inputs()\n", "print('Validation data ready: {}'.format(inputs_valid))" ] }, { "cell_type": "code", "execution_count": 5, "id": "d20976e6", "metadata": { "id": "d20976e6" }, "outputs": [ { "data": { "text/html": [ "
| \n", " | point_id | \n", "survey_dat | \n", "gps_altitu | \n", "gps_lat | \n", "gps_long | \n", "nuts0 | \n", "obs_dist | \n", "obs_type | \n", "lc1 | \n", "lc1_perc | \n", "label_l1 | \n", "geometry | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "48262936 | \n", "2018-05-10 | \n", "309 | \n", "49.321800 | \n", "16.956880 | \n", "CZ | \n", "6.0 | \n", "1 | \n", "C33 | \n", "5 | \n", "NaN | \n", "POINT (4826005.575 2935998.024) | \n", "
| 1 | \n", "47162980 | \n", "2018-08-02 | \n", "409 | \n", "49.799533 | \n", "15.492019 | \n", "CZ | \n", "22.0 | \n", "1 | \n", "B75 | \n", "4 | \n", "3.0 | \n", "POINT (4716021.636 2979995.779) | \n", "
| 2 | \n", "46183058 | \n", "2018-07-19 | \n", "242 | \n", "50.557290 | \n", "14.193572 | \n", "CZ | \n", "0.0 | \n", "1 | \n", "B13 | \n", "3 | \n", "2.0 | \n", "POINT (4617999.865 3057999.905) | \n", "
| 3 | \n", "45262962 | \n", "2018-07-17 | \n", "545 | \n", "49.734924 | \n", "12.844097 | \n", "CZ | \n", "0.0 | \n", "1 | \n", "B35 | \n", "4 | \n", "2.0 | \n", "POINT (4526000.963 2961999.910) | \n", "
| 4 | \n", "47463004 | \n", "2018-07-24 | \n", "251 | \n", "49.993666 | \n", "15.933803 | \n", "CZ | \n", "0.0 | \n", "1 | \n", "B11 | \n", "4 | \n", "2.0 | \n", "POINT (4745999.810 3004000.403) | \n", "