├── .gitignore ├── LICENSE ├── README.md ├── img ├── bdc-article │ ├── land-trajectory.png │ └── study-area.png ├── bdc-workshop │ ├── SA_SOM_decision_making.png │ ├── SA_SOM_metrics.png │ ├── SA_SOM_properties.png │ └── samples_cerrado.png ├── image-time-series.png ├── lccs │ └── lccs_database.png ├── logo-bdc.png ├── sample │ └── db-schema.png ├── stac │ ├── ndvi.png │ ├── stac-asset.png │ ├── stac-catalog.png │ ├── stac-concept.png │ ├── stac-item.png │ ├── stac-model.png │ └── stac.png ├── wlts │ ├── example_wlts_area.png │ ├── mapa-ibge.png │ ├── mapbiomas-5v2.png │ ├── overview_example.png │ ├── traj1.png │ ├── traj2.png │ └── trajectory_def.png └── wtss │ ├── describe-coverage.png │ ├── list-coverages.png │ ├── sentinel-2-clouds.png │ ├── time-series.png │ ├── visualizing-timeseries.png │ ├── wtss-operations.png │ └── wtss.png ├── jupyter ├── Data │ ├── 2025-sbsr │ │ └── LEM_dataset_small.zip │ ├── wcpms │ │ └── LEM_dataset_small.gpkg │ └── wlts │ │ ├── amostras_wlts.zip │ │ └── sao-felix-do-xingu_utm_sqr_pts1km_subset80.zip ├── Python │ ├── lccs │ │ └── lccs-introduction.ipynb │ ├── metview │ │ ├── ASCII_Read_GRIB1_GRIB2.ipynb │ │ ├── BAM_Metview_PSNM_examples.ipynb │ │ ├── CPTEC_Model_RegModels.ipynb │ │ ├── Example_lib_Widgets.ipynb │ │ ├── GOES16_BAM_OBS_Metview.ipynb │ │ ├── MERGE_Daily_animation.ipynb │ │ ├── Sazonal_framework.ipynb │ │ ├── Subsazonal_plot_AMS.ipynb │ │ └── Surface_BAM_OBS_Metview.ipynb │ ├── sample │ │ └── sample-introduction.ipynb │ ├── stac │ │ ├── stac-aws-introduction.ipynb │ │ ├── stac-image-processing.ipynb │ │ └── stac-introduction.ipynb │ ├── tiler │ │ └── bdc-tiler_introduction.ipynb │ ├── wcpms │ │ ├── wcpms-introduction.ipynb │ │ └── wcpms-phenometrics-region.ipynb │ ├── wlts │ │ ├── wlts-example.ipynb │ │ └── wlts-introduction.ipynb │ └── wtss │ │ ├── wtss-examples.ipynb │ │ ├── wtss-introduction.ipynb │ │ └── wtss2.ipynb ├── R │ ├── bdc-article │ │ ├── 00_TableOfContents.ipynb │ │ ├── 01_ExtractTimeSeries.ipynb │ │ ├── 02_CB4_64_16D_STK-1_Classification.ipynb │ │ ├── 03_CB4_64_16D_STK-1_Validation.ipynb │ │ ├── 04_LC8_30_16D_STK-1_Classification.ipynb │ │ ├── 05_LC8_30_16D_STK-1_Validation.ipynb │ │ ├── 06_S2_10_16D_STK-1_Classification.ipynb │ │ └── 07_S2_10_16D_STK-1_Validation.ipynb │ ├── bdc-workshop │ │ └── 01_Samples_analysis.ipynb │ ├── stac │ │ └── stac-introduction.ipynb │ ├── wlts │ │ ├── intro-wlts-bkp │ │ │ ├── samples_trj.rds │ │ │ ├── tj1.rds │ │ │ ├── tj2.rds │ │ │ ├── trj_mult.rds │ │ │ ├── trj_tc_amazon1.rds │ │ │ ├── trj_tc_amazon2.rds │ │ │ └── trj_tc_map_amazon1.rds │ │ ├── sao-felix-do-xingu-samples │ │ │ ├── sao-felix-do-xingu-samples.cpg │ │ │ ├── sao-felix-do-xingu-samples.dbf │ │ │ ├── sao-felix-do-xingu-samples.prj │ │ │ ├── sao-felix-do-xingu-samples.shp │ │ │ └── sao-felix-do-xingu-samples.shx │ │ └── wlts-introduction.ipynb │ └── wtss │ │ ├── wtss-examples.ipynb │ │ └── wtss-introduction.ipynb └── events │ ├── 2024-big-bdc-queimadas │ ├── README,.md │ ├── bdc-big.ipynb │ ├── introduction-to-sits.ipynb │ ├── rstac-introducao-oficina-big-bdc-2024.ipynb │ ├── stac-goes-oficina-big-bdc-2024.ipynb │ ├── stac-introducao-oficina-big-bdc-2024.ipynb │ ├── wlts-example-big-bdc-2024.ipynb │ └── wlts-introducao-oficina-big-bdc-2024.ipynb │ ├── 2024-isprs │ └── 2024_ISPRS.ipynb │ ├── 2025-sbsr │ └── 2025_SBSR.ipynb │ └── big-techtalks │ ├── 02 │ ├── chuvas-rs-goes-big-techtalks.ipynb │ ├── intro-goes-big-techtalks.ipynb │ └── queimadas-sp-goes-big-techtalks.ipynb │ ├── 03 │ ├── techtalk03-01_stac.ipynb │ ├── techtalk03-02_wtss.ipynb │ └── techtalk03-03_tms.ipynb │ ├── 04 │ ├── Data │ │ ├── Billings.cpg │ │ ├── Billings.dbf │ │ ├── Billings.prj │ │ ├── Billings.shp │ │ ├── Billings.shx │ │ └── items.json │ ├── Parte01.ipynb │ ├── Parte02.ipynb │ ├── Parte03.ipynb │ ├── Parte04.ipynb │ ├── Parte04_ACOLITE.ipynb │ └── Parte05.ipynb │ └── 2025-love-data-day │ ├── assets │ ├── figura1_espetral.jpg │ ├── figura2_espetral.jpg │ ├── mapa_votuporanga.png │ └── noticias.png │ ├── data │ ├── area.zip │ ├── focos │ │ ├── focos_1908_2408_2024.cpg │ │ ├── focos_1908_2408_2024.dbf │ │ ├── focos_1908_2408_2024.prj │ │ ├── focos_1908_2408_2024.qmd │ │ ├── focos_1908_2408_2024.shp │ │ └── focos_1908_2408_2024.shx │ └── queimadas │ │ ├── area_interesse.cpg │ │ ├── area_interesse.dbf │ │ ├── area_interesse.prj │ │ ├── area_interesse.qmd │ │ ├── area_interesse.shp │ │ └── area_interesse.shx │ ├── img │ └── love-data-day.png │ ├── ldd_2025_00-big-techtalks.ipynb │ ├── ldd_2025_01-sentinel-2.ipynb │ ├── ldd_2025_02-goes-queimadas-sp.ipynb │ ├── ldd_2025_03-goes-chuvas-rs.ipynb │ ├── ldd_2025_04-fogo-merge.ipynb │ ├── ldd_2025_05-fogo-merge.ipynb │ ├── ldd_2025_06-fogo-samet.ipynb │ ├── ldd_2025_07-S2-agua-TSS-RS.ipynb │ └── ldd_2025_08-queimadas.ipynb ├── rmarkdown └── R │ └── bdc-article │ ├── 00_TableOfContents.Rmd │ ├── 01_ExtractTimeSeries.Rmd │ ├── 02_CB4_64_16D_STK-1_Classification.Rmd │ ├── 03_CB4_64_16D_STK-1_Validation.Rmd │ ├── 04_LC8_30_16D_STK-1_Classification.Rmd │ ├── 05_LC8_30_16D_STK-1_Validation.Rmd │ ├── 06_S2_10_16D_STK-1_Classification.Rmd │ └── 07_S2_10_16D_STK-1_Validation.Rmd ├── scripts └── R │ └── bdc-article │ ├── 01_ExtractTimeSeries.R │ ├── 02_CB4_64_16D_STK-1_Classification.R │ ├── 03_CB4_64_16D_STK-1_Validation.R │ ├── 04_LC8_30_16D_STK-1_Classification.R │ ├── 05_LC8_30_16D_STK-1_Validation.R │ ├── 06_S2_10_16D_STK-1_Classification.R │ └── 07_S2_10_16D_STK-1_Validation.R └── table-of-contents.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Brazil Data Cube STAC Service. 3 | # Copyright (C) 2019-2020 INPE. 4 | # 5 | # Brazil Data Cube STAC Service is free software; you can redistribute it and/or modify it 6 | # under the terms of the MIT License; see LICENSE file for more details. 7 | # 8 | 9 | # Byte-compiled / optimized / DLL files 10 | __pycache__/ 11 | *.py[cod] 12 | *$py.class 13 | 14 | # C extensions 15 | *.so 16 | 17 | # Distribution / packaging 18 | .Python 19 | build/ 20 | develop-eggs/ 21 | dist/ 22 | downloads/ 23 | eggs/ 24 | .eggs/ 25 | lib/ 26 | lib64/ 27 | parts/ 28 | sdist/ 29 | var/ 30 | wheels/ 31 | *.egg-info/ 32 | .installed.cfg 33 | *.egg 34 | MANIFEST 35 | 36 | # PyInstaller 37 | # Usually these files are written by a python script from a template 38 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 39 | *.manifest 40 | *.spec 41 | 42 | # Installer logs 43 | pip-log.txt 44 | pip-delete-this-directory.txt 45 | 46 | # Unit test / coverage reports 47 | htmlcov/ 48 | .tox/ 49 | .coverage 50 | .coverage.* 51 | .cache 52 | nosetests.xml 53 | coverage.xml 54 | *.cover 55 | .hypothesis/ 56 | .pytest_cache/ 57 | 58 | # Translations 59 | *.mo 60 | *.pot 61 | 62 | # Django stuff: 63 | *.log 64 | local_settings.py 65 | db.sqlite3 66 | 67 | # Flask stuff: 68 | instance/ 69 | .webassets-cache 70 | 71 | # Scrapy stuff: 72 | .scrapy 73 | 74 | # Sphinx documentation 75 | docs/sphinx/_build/ 76 | 77 | # PyBuilder 78 | target/ 79 | 80 | # Jupyter Notebook 81 | .ipynb_checkpoints 82 | 83 | # pyenv 84 | .python-version 85 | 86 | # celery beat schedule file 87 | celerybeat-schedule 88 | 89 | # SageMath parsed files 90 | *.sage.py 91 | 92 | # Environments 93 | .env 94 | .venv 95 | env/ 96 | venv/ 97 | ENV/ 98 | env.bak/ 99 | venv.bak/ 100 | 101 | # Spyder project settings 102 | .spyderproject 103 | .spyproject 104 | 105 | # Rope project settings 106 | .ropeproject 107 | 108 | # mkdocs documentation 109 | /site 110 | 111 | # mypy 112 | .mypy_cache/ 113 | 114 | #PyCharm 115 | .idea/ 116 | 117 | #vscode 118 | .vscode/ 119 | 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Brazil Data Cube Code Gallery 4 | 5 | 6 | 7 | 8 | [![Software License](https://img.shields.io/badge/license-MIT-green)](https://github.com/brazil-data-cube/code-gallery/blob/master/LICENSE) 9 | [![Software Life Cycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) 10 | [![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/brazil-data-cube/code-gallery/blob/master/table-of-contents.ipynb) 11 | [![Join us at Discord](https://img.shields.io/discord/689541907621085198?logo=discord&logoColor=ffffff&color=7389D8)](https://discord.com/channels/689541907621085198#) 12 | 13 | 14 | 15 | This repository contains a gallery of interesting Jupyter Notebooks, R Markdown and scripts based on Brazil Data Cube data and technologies. 16 | 17 | 18 | # Jupyter Notebooks 19 | 20 | 21 | ## Data Access through SpatioTemporal Asset Catalog API (STAC) 22 | 23 | - Introduction to the SpatioTemporal Asset Catalog. ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/stac/stac-introduction.ipynb), [R](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/R/stac/stac-introduction.ipynb)) 24 | 25 | - Image processing on images obtained through STAC. ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/stac/stac-image-processing.ipynb)). 26 | 27 | 28 | ## Web Time Series Service (WTSS) 29 | 30 | - Introduction to the Web Time Series Service (WTSS). ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/wtss/wtss-introduction.ipynb), [R](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/R/wtss/wtss-introduction.ipynb)). 31 | 32 | - Web Time Series Service (WTSS) examples. ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/wtss/wtss-examples.ipynb), [R](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/R/wtss/wtss-examples.ipynb)). 33 | 34 | - Web Time Series Service 2 - Time series from geometry. ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/wtss/wtss2.ipynb)). 35 | 36 | ## Web Land Trajectory Service (WLTS) 37 | 38 | - Introduction to the Web Land Trajectory Service (WLTS). ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/wlts/wlts-introduction.ipynb), [R](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/R/wlts/wlts-introduction.ipynb)) 39 | 40 | - Web Land Trajectory Service (WLTS) examples. ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/wlts/wlts-example.ipynb)). 41 | 42 | ## Web Crop Phenology Metrics Service (WCPMS) 43 | 44 | - Introduction to the Web Crop Phenology Metrics Service (WCPMS). ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/wcpms/wcpms-introduction.ipynb)). 45 | 46 | - Web Crop Phenology Metrics Service (WCPMS) Region. ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/wcpms/wcpms-phenometrics-region.ipynb)). 47 | 48 | 49 | ## Land Cover Classification System Service (LCCS) 50 | 51 | * Introduction to the Land Cover Classification System Service (LCCS). ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/lccs/lccs-introduction.ipynb)) 52 | 53 | ## Sample Database (SAMPLE-DB) 54 | 55 | * Introduction to the Sample Database (SAMPLE-DB). ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/sample/sample-introduction.ipynb)) 56 | 57 | ## Tile Map Service (BDC-Tiler) 58 | 59 | - Introduction to the Tile Map Service (BDC-Tiler). ([Python](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/tiler/bdc-tiler_introduction.ipynb)) 60 | 61 | ## Mapping LULC using BDC Data Cubes 62 | 63 | - Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. ([R](https://github.com/brazil-data-cube/code-gallery/tree/master/jupyter/R/bdc-article)) 64 | 65 | # R Markdown 66 | 67 | ## Mapping LULC using BDC Data Cubes 68 | 69 | - Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. ([R](https://github.com/brazil-data-cube/code-gallery/tree/master/rmarkdown/R/bdc-article)) 70 | 71 | # Scripts 72 | 73 | **R** 74 | 75 | - Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. ([R](https://github.com/brazil-data-cube/code-gallery/tree/master/scripts/R/bdc-article)) 76 | -------------------------------------------------------------------------------- /img/bdc-article/land-trajectory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/bdc-article/land-trajectory.png -------------------------------------------------------------------------------- /img/bdc-article/study-area.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/bdc-article/study-area.png -------------------------------------------------------------------------------- /img/bdc-workshop/SA_SOM_decision_making.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/bdc-workshop/SA_SOM_decision_making.png -------------------------------------------------------------------------------- /img/bdc-workshop/SA_SOM_metrics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/bdc-workshop/SA_SOM_metrics.png -------------------------------------------------------------------------------- /img/bdc-workshop/SA_SOM_properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/bdc-workshop/SA_SOM_properties.png -------------------------------------------------------------------------------- /img/bdc-workshop/samples_cerrado.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/bdc-workshop/samples_cerrado.png -------------------------------------------------------------------------------- /img/image-time-series.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/image-time-series.png -------------------------------------------------------------------------------- /img/lccs/lccs_database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/lccs/lccs_database.png -------------------------------------------------------------------------------- /img/logo-bdc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/logo-bdc.png -------------------------------------------------------------------------------- /img/sample/db-schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/sample/db-schema.png -------------------------------------------------------------------------------- /img/stac/ndvi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/stac/ndvi.png -------------------------------------------------------------------------------- /img/stac/stac-asset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/stac/stac-asset.png -------------------------------------------------------------------------------- /img/stac/stac-catalog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/stac/stac-catalog.png -------------------------------------------------------------------------------- /img/stac/stac-concept.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/stac/stac-concept.png -------------------------------------------------------------------------------- /img/stac/stac-item.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/stac/stac-item.png -------------------------------------------------------------------------------- /img/stac/stac-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/stac/stac-model.png -------------------------------------------------------------------------------- /img/stac/stac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/stac/stac.png -------------------------------------------------------------------------------- /img/wlts/example_wlts_area.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wlts/example_wlts_area.png -------------------------------------------------------------------------------- /img/wlts/mapa-ibge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wlts/mapa-ibge.png -------------------------------------------------------------------------------- /img/wlts/mapbiomas-5v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wlts/mapbiomas-5v2.png -------------------------------------------------------------------------------- /img/wlts/overview_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wlts/overview_example.png -------------------------------------------------------------------------------- /img/wlts/traj1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wlts/traj1.png -------------------------------------------------------------------------------- /img/wlts/traj2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wlts/traj2.png -------------------------------------------------------------------------------- /img/wlts/trajectory_def.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wlts/trajectory_def.png -------------------------------------------------------------------------------- /img/wtss/describe-coverage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wtss/describe-coverage.png -------------------------------------------------------------------------------- /img/wtss/list-coverages.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wtss/list-coverages.png -------------------------------------------------------------------------------- /img/wtss/sentinel-2-clouds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wtss/sentinel-2-clouds.png -------------------------------------------------------------------------------- /img/wtss/time-series.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wtss/time-series.png -------------------------------------------------------------------------------- /img/wtss/visualizing-timeseries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wtss/visualizing-timeseries.png -------------------------------------------------------------------------------- /img/wtss/wtss-operations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wtss/wtss-operations.png -------------------------------------------------------------------------------- /img/wtss/wtss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/img/wtss/wtss.png -------------------------------------------------------------------------------- /jupyter/Data/2025-sbsr/LEM_dataset_small.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/Data/2025-sbsr/LEM_dataset_small.zip -------------------------------------------------------------------------------- /jupyter/Data/wcpms/LEM_dataset_small.gpkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/Data/wcpms/LEM_dataset_small.gpkg -------------------------------------------------------------------------------- /jupyter/Data/wlts/amostras_wlts.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/Data/wlts/amostras_wlts.zip -------------------------------------------------------------------------------- /jupyter/Data/wlts/sao-felix-do-xingu_utm_sqr_pts1km_subset80.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/Data/wlts/sao-felix-do-xingu_utm_sqr_pts1km_subset80.zip -------------------------------------------------------------------------------- /jupyter/Python/metview/ASCII_Read_GRIB1_GRIB2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "8d1e5148-c630-4cd5-b049-60ca6aec73b3", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# Formatos GRIB e GRIB2\n", 15 | "\n", 16 | "**Meteorologia, Oceanografia e Climatologia**\n", 17 | "\n", 18 | "---\n", 19 | "\n", 20 | "## Objetivos\n", 21 | "- Entender o que são arquivos GRIB/GRIB2\n", 22 | "- Comparar GRIB1 vs. GRIB2\n", 23 | "- Aplicações práticas\n", 24 | "- Estrutura básica dos dados\n", 25 | "\n", 26 | "---\n", 27 | "\n", 28 | "## O que é GRIB?\n", 29 | "- **G**ridded **R**epresentation **I**n **B**inary\n", 30 | "- Formato binário otimizado para dados geoespaciais\n", 31 | "- Padrão **WMO** (Organização Meteorológica Mundial)\n", 32 | "- Foco em eficiência: compactação e organização\n", 33 | "\n", 34 | "---\n", 35 | "\n", 36 | "## Principais Usos\n", 37 | "- Previsão do tempo numérica (WRF, ECMWF, GFS)\n", 38 | "- Dados atmosféricos (pressão, temperatura, vento)\n", 39 | "- Oceanografia (temperatura da superfície do mar)\n", 40 | "- Satélites meteorológicos\n", 41 | "\n", 42 | "---\n", 43 | "\n", 44 | "## GRIB1 (Versão 1)\n", 45 | "- Lançado em **1994**\n", 46 | "- Estrutura simplificada:\n", 47 | " ```plaintext\n", 48 | " [Seção 0] - Indicador (GRIB)\n", 49 | " [Seção 1] - Definição do Produto (data, hora, variáveis)\n", 50 | " [Seção 2] - Definição da Grade (projeção, resolução)\n", 51 | " [Seção 3] - Dados Binários (compactados)\n", 52 | " [Seção 4] - Fim (7777)\n", 53 | " ```\n", 54 | "- Limitações: Suporte limitado a novos tipos de dados.\n", 55 | "\n", 56 | "---\n", 57 | "\n", 58 | "## GRIB2 (Versão 2)\n", 59 | "- Lançado em **2003**\n", 60 | "- Melhorias:\n", 61 | " - Mais flexível (novos tipos de grades e dados)\n", 62 | " - Compactação eficiente (JPEG2000, PNG)\n", 63 | " - Metadados detalhados\n", 64 | " - Suporte a dados probabilísticos e ensembles\n", 65 | "\n", 66 | "---\n", 67 | "\n", 68 | "## Estrutura GRIB2\n", 69 | "```plaintext\n", 70 | "[Seção 0] - Indicador (GRIB2)\n", 71 | "[Seção 1] - Identificação (origem do dado)\n", 72 | "[Seção 2] - Localização (geográfica/temporal)\n", 73 | "[Seção 3] - Definição da Grade\n", 74 | "[Seção 4] - Definição do Produto\n", 75 | "[Seção 5] - Representação dos Dados\n", 76 | "[Seção 6] - Dados Binários\n", 77 | "[Seção 7] - Fim (7777)\n", 78 | "```\n", 79 | "\n", 80 | "---\n", 81 | "\n", 82 | "## Vantagens do GRIB2\n", 83 | "- **Compactação**: Redução de até 40% vs. GRIB1\n", 84 | "- **Metadados**: Descrição detalhada de variáveis\n", 85 | "- **Flexibilidade**: Suporte a grades irregulares e satélites\n", 86 | "- **Templates**: Estruturas pré-definidas para cenários complexos\n", 87 | "\n", 88 | "---\n", 89 | "\n", 90 | "## Desafios\n", 91 | "- **Complexidade**: Mais difícil de decodificar\n", 92 | "- **Compatibilidade**: Não é retrocompatível com GRIB1\n", 93 | "- **Ferramentas**: Bibliotecas específicas necessárias (ex: `eccodes`, `wgrib2`)\n", 94 | "\n", 95 | "---\n", 96 | "\n", 97 | "## Exemplo de Uso\n", 98 | "```bash\n", 99 | "# Comando wgrib2 para extrair dados:\n", 100 | "wgrib2 arquivo.grib2 -match \"TMP:2 m\" -netcdf saida.nc\n", 101 | "\n", 102 | "# Python com cfgrib:\n", 103 | "import xarray as xr\n", 104 | "ds = xr.open_dataset(\"arquivo.grib2\", engine=\"cfgrib\")\n", 105 | "```\n", 106 | "\n", 107 | "---\n", 108 | "\n", 109 | "## Comparação GRIB1 vs. GRIB2\n", 110 | "| Característica | GRIB1 | GRIB2 |\n", 111 | "|----------------------|-----------------|-----------------|\n", 112 | "| Compactação | Simples | JPEG2000/PNG |\n", 113 | "| Metadados | Básicos | Detalhados |\n", 114 | "| Tipos de Grade | Limitados | Diversos |\n", 115 | "| Erros | Sem verificação | CRC32 |\n", 116 | "\n", 117 | "# Formatos GRIB e GRIB2\n", 118 | "**Exemplos Práticos com Metview, PyGRIB e GrADS**\n", 119 | "\n", 120 | "---\n", 121 | "\n", 122 | "## Exemplo 1: Metview\n", 123 | "**Visualização de dados GRIB2**\n", 124 | "```python\n", 125 | "# Carregar dados\n", 126 | "grib = read(source=\"temperatura.grib2\")\n", 127 | "\n", 128 | "# Configurar mapa\n", 129 | "coastlines = mv.mcoast(\n", 130 | " map_coastline_resolution=\"medium\",\n", 131 | " map_boundaries=\"on\"\n", 132 | ")\n", 133 | "\n", 134 | "# Plotar campo de temperatura\n", 135 | "mv.plot(grib, coastlines, style=\"contour\")\n", 136 | "```\n", 137 | "- **Saída**: Mapa com isotermas\n", 138 | "- **Vantagem**: Interface amigável para análise operacional\n", 139 | "\n", 140 | "---\n", 141 | "\n", 142 | "## Exemplo 2: PyGRIB (Python)\n", 143 | "**Extrair valores de temperatura**\n", 144 | "```python\n", 145 | "import pygrib\n", 146 | "\n", 147 | "# Abrir arquivo GRIB2\n", 148 | "grbs = pygrib.open('arquivo.grib2')\n", 149 | "\n", 150 | "# Selecionar primeiro registro de temperatura\n", 151 | "grb = grbs.select(name='2 metre temperature')[0]\n", 152 | "\n", 153 | "# Obter dados e coordenadas\n", 154 | "values, lats, lons = grb.data()\n", 155 | "print(f\"Temperatura máxima: {values.max()}°C\")\n", 156 | "```\n", 157 | "- **Uso típico**: Processamento automatizado de dados\n", 158 | "- **Dependência**: `pip install pygrib`\n", 159 | "\n", 160 | "---\n", 161 | "\n", 162 | "## Exemplo 3: GrADS\n", 163 | "**Script para plotagem rápida**\n", 164 | "```grads\n", 165 | "sdfopen precipitacao.grib2\n", 166 | "\n", 167 | "set gxout shaded\n", 168 | "set mpdset hires\n", 169 | "d pratesfc\n", 170 | "\n", 171 | "cbarn\n", 172 | "printim precipitacao.png white\n", 173 | "```\n", 174 | "- **Comandos-chave**:\n", 175 | " - `sdfopen`: Carrega arquivo\n", 176 | " - `gxout`: Define tipo de gráfico\n", 177 | " - `printim`: Exporta imagem\n", 178 | "\n", 179 | "---\n", 180 | "\n", 181 | "## Comparação de Ferramentas\n", 182 | "| | Metview | PyGRIB | GrADS |\n", 183 | "|---------------|------------------|------------------|------------------|\n", 184 | "| **Interface** | GUI/CLI | Biblioteca Python| Linguagem própria|\n", 185 | "| **Destaque** | Visualização | Extração de dados| Scripts rápidos |\n", 186 | "| **Curva de aprendizado** | Moderada | Baixa | Alta |\n", 187 | "\n", 188 | "---\n", 189 | "\n", 190 | "## Dicas para Uso Prático\n", 191 | "1. Sempre verifique a versão do GRIB:\n", 192 | " ```bash\n", 193 | " grib_dump -T arquivo.grib2 | grep edition\n", 194 | " ```\n", 195 | "2. Converta entre formatos quando necessário:\n", 196 | " ```bash\n", 197 | " grib_set -r -s edition=2 arquivo.grib1 arquivo.grib2\n", 198 | " ```\n", 199 | "3. Use **XArray** + **cfgrib** para análise em Python:\n", 200 | " ```python\n", 201 | " ds = xr.open_dataset('arquivo.grib2', engine='cfgrib')\n", 202 | " ```\n", 203 | "\n", 204 | "---\n", 205 | "\n", 206 | "## Recursos Adicionais\n", 207 | "- **Documentação Metview**: https://metview.readthedocs.io\n", 208 | "- **PyGRIB**: https://github.com/jswhit/pygrib\n", 209 | "- **GrADS Gallery**: http://cola.gmu.edu/grads/gallery\n", 210 | "---\n", 211 | "\n", 212 | "## Aplicações Práticas\n", 213 | "- Modelos climáticos (CMIP6)\n", 214 | "- Previsão de furacões\n", 215 | "- Energia renovável (previsão eólica/solar)\n", 216 | "- Visualização em softwares (GrADS, Panoply)\n", 217 | "\n", 218 | "---\n", 219 | "\n", 220 | "## Ferramentas Recomendadas\n", 221 | "- **Decodificação**: `wgrib2`, `eccodes`, `grib_api`\n", 222 | "- **Visualização**: ParaView, Panoply, Metview\n", 223 | "- **Linguagens**: Python (xarray, cfgrib), R (stars)\n", 224 | "\n", 225 | "---\n", 226 | "\n", 227 | "## Conclusão\n", 228 | "- **GRIB2** é o padrão atual para dados meteorológicos\n", 229 | "- Equilíbrio entre eficiência e complexidade\n", 230 | "- Essencial para análises profissionais em geociências\n", 231 | "\n", 232 | "**Perguntas?**" 233 | ] 234 | } 235 | ], 236 | "metadata": { 237 | "kernelspec": { 238 | "display_name": "Python (Geospatial)", 239 | "language": "python", 240 | "name": "geospatial" 241 | }, 242 | "language_info": { 243 | "codemirror_mode": { 244 | "name": "ipython", 245 | "version": 3 246 | }, 247 | "file_extension": ".py", 248 | "mimetype": "text/x-python", 249 | "name": "python", 250 | "nbconvert_exporter": "python", 251 | "pygments_lexer": "ipython3", 252 | "version": "3.11.6" 253 | } 254 | }, 255 | "nbformat": 4, 256 | "nbformat_minor": 5 257 | } 258 | -------------------------------------------------------------------------------- /jupyter/Python/metview/Example_lib_Widgets.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "d7f0a284", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "#conda create -n cptec python=3.10\n", 11 | "\n", 12 | "#conda activate cptec\n", 13 | "#conda install -c conda-forge xarray matplotlib pycurl cfgrib netcdf4 pynio xarray matplotlib pycurl cfgrib netcdf4 pynio dask\n", 14 | "#conda install -c anaconda ipykernel" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 6, 20 | "id": "3048d811", 21 | "metadata": { 22 | "execution": { 23 | "iopub.execute_input": "2025-02-21T13:49:39.343654Z", 24 | "iopub.status.busy": "2025-02-21T13:49:39.342971Z", 25 | "iopub.status.idle": "2025-02-21T13:49:39.351235Z", 26 | "shell.execute_reply": "2025-02-21T13:49:39.349623Z", 27 | "shell.execute_reply.started": "2025-02-21T13:49:39.343597Z" 28 | } 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "# Import para os modelos disponiveis\n", 33 | "# CPTEC_BAM, CPTEC_WRF, CPTEC_ETA, CPTEC_GFS\n", 34 | "\n", 35 | "import cptecmodel.CPTEC_WRF as WRF\n", 36 | "import cptecmodel.CPTEC_Widgets as WID" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 7, 42 | "id": "784331be", 43 | "metadata": { 44 | "execution": { 45 | "iopub.execute_input": "2025-02-21T13:49:40.454201Z", 46 | "iopub.status.busy": "2025-02-21T13:49:40.453558Z", 47 | "iopub.status.idle": "2025-02-21T13:49:40.465091Z", 48 | "shell.execute_reply": "2025-02-21T13:49:40.463594Z", 49 | "shell.execute_reply.started": "2025-02-21T13:49:40.454149Z" 50 | } 51 | }, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "\n", 58 | "#### US National Weather Service - NCEP (WMC) (ams_07km) #####\n", 59 | "\n", 60 | "Forecast data available for reading between 20250211 and 20250221.\n", 61 | "\n", 62 | "Surface variables: t2m, u10m, v10m, slp, psfc, precip\n", 63 | " terrain, sbcape, sbcin, pw.\n", 64 | "Level variables: t, u, v, rh, g, omega.\n", 65 | "\n", 66 | "levels (hPa): 1000 975 950 925 900 875 850 825 800 775 750 700 650\n", 67 | " 600 550 500 450 400 350 300 250 200 150 100 50.\n", 68 | "\n", 69 | "Frequency: hourly frequency [0,1,2,...,22,23].\n", 70 | "\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "# Durante a inicialização do construtor informações sobre os dados são exibidas\n", 76 | "# Entre elas informações de variaveis, niveis e frequência disponiveis para consulta\n", 77 | "\n", 78 | "wrf = WRF.model()" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 8, 84 | "id": "c38a9f18", 85 | "metadata": { 86 | "execution": { 87 | "iopub.execute_input": "2025-02-21T13:49:43.455258Z", 88 | "iopub.status.busy": "2025-02-21T13:49:43.454608Z", 89 | "iopub.status.idle": "2025-02-21T13:49:43.574847Z", 90 | "shell.execute_reply": "2025-02-21T13:49:43.573771Z", 91 | "shell.execute_reply.started": "2025-02-21T13:49:43.455207Z" 92 | } 93 | }, 94 | "outputs": [ 95 | { 96 | "data": { 97 | "application/vnd.jupyter.widget-view+json": { 98 | "model_id": "5ffd02dee35e4303a4e5cb4579ef6d68", 99 | "version_major": 2, 100 | "version_minor": 0 101 | }, 102 | "text/plain": [ 103 | "Tab(children=(HBox(children=(VBox(children=(RadioButtons(description='Datas', options=(Timestamp('2025-02-21 0…" 104 | ] 105 | }, 106 | "metadata": {}, 107 | "output_type": "display_data" 108 | }, 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "" 113 | ] 114 | }, 115 | "execution_count": 8, 116 | "metadata": {}, 117 | "output_type": "execute_result" 118 | } 119 | ], 120 | "source": [ 121 | "# Chamada da Interface Widget\n", 122 | "WID.show_menu(wrf)" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 10, 128 | "id": "b263b557", 129 | "metadata": { 130 | "execution": { 131 | "iopub.execute_input": "2025-02-21T13:55:42.820550Z", 132 | "iopub.status.busy": "2025-02-21T13:55:42.819834Z", 133 | "iopub.status.idle": "2025-02-21T13:55:43.417089Z", 134 | "shell.execute_reply": "2025-02-21T13:55:43.414685Z", 135 | "shell.execute_reply.started": "2025-02-21T13:55:42.820495Z" 136 | } 137 | }, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "-rw-r--r-- 1 jovyan users 285 Feb 21 13:55 output.csv\n", 144 | "latitude,longitude,level,2025-02-21 00:00:00,2025-02-21 01:00:00,2025-02-21 02:00:00,2025-02-21 03:00:00,2025-02-21 04:00:00,2025-02-21 05:00:00,2025-02-21 06:00:00,2025-02-21 07:00:00,2025-02-21 08:00:00\n", 145 | "-28.01136999999988,269.32605,875.0,90.0,91.0,89.0,91.0,90.0,92.0,91.0,91.0,91.0\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "!ls -ltr *csv\n", 151 | "!head -2 output.csv | tail -10" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "id": "0135a16a-6541-4ee8-9e35-653d05d78102", 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [] 161 | } 162 | ], 163 | "metadata": { 164 | "kernelspec": { 165 | "display_name": "Python 3 (ipykernel)", 166 | "language": "python", 167 | "name": "python3" 168 | }, 169 | "language_info": { 170 | "codemirror_mode": { 171 | "name": "ipython", 172 | "version": 3 173 | }, 174 | "file_extension": ".py", 175 | "mimetype": "text/x-python", 176 | "name": "python", 177 | "nbconvert_exporter": "python", 178 | "pygments_lexer": "ipython3", 179 | "version": "3.11.6" 180 | } 181 | }, 182 | "nbformat": 4, 183 | "nbformat_minor": 5 184 | } 185 | -------------------------------------------------------------------------------- /jupyter/Python/sample/sample-introduction.ipynb: -------------------------------------------------------------------------------- 1 | {"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"\n\n# Introduction to the Python Client Library for Sample Web Service (sample.py)\n
\n\n
\n \n
\n\n
\n Fabiana Zioti, Karine Reis Ferreira, Gilberto R. Queiroz\n

\n Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE)\n
\n Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil\n

\n Contact: brazildatacube@inpe.br\n

\n Last Update: November 10, 2023\n
\n\n
\n\n
\nAbstract. This Jupyter Notebook gives an overview on how to use sample.py to discover and access land use and cover classification samples.\n
\n","metadata":{}},{"cell_type":"markdown","source":"# Introduction\n
","metadata":{}},{"cell_type":"markdown","source":"Sample-DB provides a data model that represents the land use and cover samples collected by different projects and individuals. This model can be see in `Figure 1`.\n\n
\n
\n ,\n
\n Figure 1 - Sample-DB Model.\n
\n\n\nTo facilitate access to samples of land use and land cover stored in the database, a Python package called ``SAMPLE.py`` was developed. This package retrieves the land use and land cover samples that were made available via ``WFS`` by the GeoServer application.\n\nThis Jupyter Notebook shows how to use the [Python Client Library](https://github.com/brazil-data-cube/sample.py) for Sample Database Model.\n","metadata":{}},{"cell_type":"markdown","source":"# Python Client API\n
","metadata":{}},{"cell_type":"markdown","source":"For running the examples in this Jupyter Notebook you will need to install the [Sample client for Python](https://github.com/brazil-data-cube/sample.py).To install it from pip, use the following command:","metadata":{}},{"cell_type":"code","source":"!pip install git+https://github.com/brazil-data-cube/sample.py@v0.9.0","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In order to access the funcionalities of the client API, you should import the `sample` package, as follows:","metadata":{}},{"cell_type":"code","source":"import sample","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"After that, you can check the installed version of sample package:","metadata":{}},{"cell_type":"code","source":"sample.__version__","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Sample is a client-server service. In this tutorial, we will use the Python client to access the data. We need to define the URL where the SAMPLE server is operating.The code below defines the URL of the SAMPLE server of Brazil Data Cube that we are going to query: ","metadata":{}},{"cell_type":"code","source":"service = sample.SAMPLE(url='https://brazildatacube.dpi.inpe.br/sample/', access_token='change-me')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> To use the Brazil Data Cube services, you must have an `access token`. If you do not have a token, use Brazil [Brazil Data Cube Explorer](https://brazildatacube.dpi.inpe.br/portal/) to create one. Details and tips on how to generate the token are available in the [Data Cube Explorer documentation](https://brazil-data-cube.github.io/applications/dc_explorer/token-module.html).","metadata":{}},{"cell_type":"markdown","source":"The above cell will create an object named `service` that will allow us to comunicate to the given Sample service.","metadata":{}},{"cell_type":"markdown","source":"# Listing the Available Datasets\n
","metadata":{}},{"cell_type":"markdown","source":"In the Jupyter environment, the SAMPLE object will list the available datasets from the service:","metadata":{}},{"cell_type":"code","source":"service","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Or you can access the ``datasets`` property, which returns a list of available datasets:","metadata":{}},{"cell_type":"code","source":"service.datasets","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Retrieving the Metadata of a Dataset\n
","metadata":{}},{"cell_type":"markdown","source":"You can access the metadata of a specific dataset using the identifier (``id``) or using the datasets ``name`` and ``version``.","metadata":{}},{"cell_type":"code","source":"ds = service.dataset(dataset_name='bdc-all-test-area', dataset_version=1)\nds","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Retrieving the data\n
","metadata":{}},{"cell_type":"markdown","source":"In order to retrieve the data (observations) of a dataset, use the the function ``data()``. This will return the data in a ``GeoPandas``.","metadata":{}},{"cell_type":"code","source":"bdc_obs = ds.data()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This function returns the first n rows of bdc_obs\nbdc_obs.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing the data\n
","metadata":{}},{"cell_type":"markdown","source":"It is possible to plot the dataset data with the ``plot`` method:","metadata":{}},{"cell_type":"code","source":"bdc_obs.plot( marker='o', color='red', markersize=5, figsize=(20, 20));","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing the data with GeoPandas and others data\n
","metadata":{}},{"cell_type":"markdown","source":"After retrieving dataset data you can use any Python library to perform data processing. In this section we show how to use ``GeoPandas`` to load and use others data. With Pandas installed, import the library:","metadata":{}},{"cell_type":"code","source":"import geopandas as gpd\nfrom matplotlib import pyplot as plt","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"You can define a file to import. In this example we use the ``read_file()`` to open a shapefile. Those data can be found in [unidades_da_federacao](http://servicodados.ibge.gov.br/Download/Download.ashx?u=geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2017/Brasil/BR/br_unidades_da_federacao.zip) and [Biomas_250mil](ftp://geoftp.ibge.gov.br/informacoes_ambientais/estudos_ambientais/biomas/vetores/Biomas_250mil.zip)","metadata":{}},{"cell_type":"code","source":"file_biomas = \"https://geoftp.ibge.gov.br/informacoes_ambientais/estudos_ambientais/biomas/vetores/Biomas_250mil.zip\"\nfile_uf = \"https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2020/Brasil/BR/BR_UF_2020.zip\"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load the biomas data of IBGE\nbiomas = gpd.read_file(file_biomas)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"biomas","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"uf = gpd.read_file(file_uf)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"uf.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The code below plots ``biomes``, ``federative units`` and ``bdc-all-test-area`` samples on a single map:","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(20,15))\n\nbiomas.plot(ax=ax, cmap='Set2', column='Bioma',edgecolor='black', legend=True,legend_kwds={'title': \"Biomes\", 'fontsize': 15})\n\nuf.geometry.boundary.plot(ax=ax, color=None, edgecolor='black',linewidth = 0.2)\n\nbdc_obs.plot(ax=ax, marker='o', color='red', markersize=4, edgecolor='black', linewidth = 0.1);","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Save data to file\n
","metadata":{}},{"cell_type":"markdown","source":"You can save data from a dataset to a ``shapefile`` using the ``.to_file`` method. It is necessary to inform in the parameter path, the directory that you want to save the file and the data. In the example below the data ``bdc_obs`` from the ``bdc-ba-test-area-V1`` dataset is being saved in a shapefile with the name ``my_save_bdc_obs``","metadata":{}},{"cell_type":"code","source":"service.save_feature(filename=\"my_save_bdc_obs.shp\", gdf=bdc_obs)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]} -------------------------------------------------------------------------------- /jupyter/Python/tiler/bdc-tiler_introduction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "\n", 9 | "# Tile Map Service (BDC-Tiler)\n", 10 | "
\n", 11 | "\n", 12 | "BDC-Tiler is a Tile Map Service, created to serve the data products generated by the Brazil Data Cube project. This document presents an example of BDC-Tiler consumption using [ipyleaflet](https://ipyleaflet.readthedocs.io/en/latest/).\n", 13 | "\n", 14 | "> To make this tutorial it is necessary to have a BDC access key. More information is available at [How to create Personal Access Token](https://brazil-data-cube.github.io/applications/dc_explorer/token-module.html).\n", 15 | "\n", 16 | "To begin, first install the ipyleaflet package that will be used." 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "!pip install ipyleaflet > /dev/null" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "With the package installed, load the `Map` and `TileLayer`. These will be used to make the contents delivered by BDC-Tiler add to a map" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "from ipyleaflet import Map, TileLayer" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "Now the declaration of the variables used in this example is made. The variable `url_service` can vary according to the versions of the BDC-Tiler.\n", 49 | "\n", 50 | "> This document uses the latest version of the service URL.\n", 51 | "\n", 52 | "Note that `bdc_stac_token` must be exchanged for your access key." 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "bdc_stac_token = \"change-me\"\n", 62 | "url_service = \"https://brazildatacube.dpi.inpe.br/tiler/tms\"" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "Once this is done, make the `scene_id` statement and the color formula used for viewing.\n", 70 | "\n", 71 | "> If you wish, you can retrieve the `scene_id` that will be used for viewing through [stac-aws-introduction](https://github.com/brazil-data-cube/code-gallery/blob/master/jupyter/Python/stac/stac-aws-introduction.ipynb).\n" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "from urllib.parse import quote_plus\n", 81 | "\n", 82 | "# For Sentinel 2 use:\n", 83 | "collection = \"S2-16D-2\"\n", 84 | "scene_id = \"S2-16D_V2_030019_20220930\"\n", 85 | "bands = \"B04,B03,B02\"\n", 86 | "\n", 87 | "# For CBERS use the following values\n", 88 | "# collection = \"CB4-16D-2\"\n", 89 | "# scene_id = \"CB4-16D_V2_007004_20180930\"\n", 90 | "# bands = \"BAND15,BAND14,BAND13\"\n", 91 | "\n", 92 | "# quote as url encoded\n", 93 | "color_formula = quote_plus(\"Gamma RGB 2 Saturation 1.8 Sigmoidal RGB 5 0.35\")" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "There you go, now add the content to the screen through Map and TileLayer previously imported" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "# full_url\n", 110 | "center = (-12.50, -45.75)\n", 111 | "m = Map(center=center, zoom=9)\n", 112 | "\n", 113 | "layer = TileLayer(\n", 114 | " url=f\"{url_service}/{scene_id}/\" + \"{z}/{x}/{y}.png?\" + f\"collection={collection}&bands={bands}&color_formula={color_formula}&access_token={bdc_stac_token}\"\n", 115 | ")\n", 116 | "\n", 117 | "# add layer in the map\n", 118 | "m.add_layer(layer)\n", 119 | "display(m)" 120 | ] 121 | } 122 | ], 123 | "metadata": { 124 | "kernelspec": { 125 | "display_name": "Python 3 (ipykernel)", 126 | "language": "python", 127 | "name": "python3" 128 | }, 129 | "language_info": { 130 | "codemirror_mode": { 131 | "name": "ipython", 132 | "version": 3 133 | }, 134 | "file_extension": ".py", 135 | "mimetype": "text/x-python", 136 | "name": "python", 137 | "nbconvert_exporter": "python", 138 | "pygments_lexer": "ipython3", 139 | "version": "3.8.10" 140 | } 141 | }, 142 | "nbformat": 4, 143 | "nbformat_minor": 4 144 | } 145 | -------------------------------------------------------------------------------- /jupyter/Python/wtss/wtss2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# WTSS Python Client - Notebook example" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": { 14 | "editable": true, 15 | "slideshow": { 16 | "slide_type": "" 17 | }, 18 | "tags": [] 19 | }, 20 | "outputs": [], 21 | "source": [ 22 | "!pip install wtss==2.0.0a3" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "!pip install geopandas numpy matplotlib" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | "## Connect to WTSS server" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "from wtss import WTSS\n", 48 | "import os\n", 49 | "\n", 50 | "service = WTSS('https://data.inpe.br/bdc/wtss/v4/')\n", 51 | "service" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "import wtss\n", 61 | "wtss.__version__" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "## Select the data cube Sentinel-2 16 days" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "coverage = service['S2-16D-2']\n", 78 | "coverage" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "_______________________________________\n", 86 | "## 3) Timeseries: The user can retrieve all timeseries inside the geometry" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "import shapely.geometry\n", 96 | "\n", 97 | "timeseries = coverage.ts(attributes=('NDVI',),\n", 98 | " geom=shapely.geometry.box(-59.60, -5.69, -59.59, -5.68),\n", 99 | " start_datetime=\"2020-01-01\", end_datetime=\"2022-12-31\")\n", 100 | "\n", 101 | "timeseries" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "### 3.1) The query results are available as timeseries properties:" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "# Show total of locations matched\n", 118 | "total = timeseries.total_locations()\n", 119 | "total" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "### 3.2) The user can plot the time series for each pixel" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": null, 132 | "metadata": { 133 | "editable": true, 134 | "scrolled": true, 135 | "slideshow": { 136 | "slide_type": "" 137 | }, 138 | "tags": [] 139 | }, 140 | "outputs": [], 141 | "source": [ 142 | "timeseries.plot()" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "### 3.3) All values from each datetime and each attribute are available in a pandas dataframe format" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": null, 155 | "metadata": { 156 | "scrolled": true 157 | }, 158 | "outputs": [], 159 | "source": [ 160 | "timeseries_df = timeseries.df()\n", 161 | "timeseries_df" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "_______________________________________\n", 169 | "## 4) Summarize: The user can retrieve summarized timeseries from a geometry (e.g. mean, median, min, max, std)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "metadata": { 176 | "scrolled": true 177 | }, 178 | "outputs": [], 179 | "source": [ 180 | "summarize = timeseries.summarize()\n", 181 | "summarize" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "### 4.1) The query results are available as timeseries properties:" 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": null, 194 | "metadata": { 195 | "scrolled": true 196 | }, 197 | "outputs": [], 198 | "source": [ 199 | "print('\\n summarize attributes:', summarize.attributes)\n", 200 | "\n", 201 | "print('\\n summarize timeline:', summarize.timeline)\n", 202 | "\n", 203 | "print('\\n NDVI mean:', summarize.NDVI.mean)" 204 | ] 205 | }, 206 | { 207 | "cell_type": "markdown", 208 | "metadata": {}, 209 | "source": [ 210 | "### 4.2) The value of each aggregation on each datetime for each attribute is available in a pandas dataframe format" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "metadata": {}, 217 | "outputs": [], 218 | "source": [ 219 | "aggregation_df = summarize.df()\n", 220 | "aggregation_df" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": {}, 226 | "source": [ 227 | "### 4.3) The user can plot the summarized timeseries" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": null, 233 | "metadata": {}, 234 | "outputs": [], 235 | "source": [ 236 | "# Plot the selected aggregation chart for the selected attribute(s)\n", 237 | "summarize.plot(\n", 238 | " attributes = ['NDVI'],\n", 239 | " aggregation = 'mean'\n", 240 | ")" 241 | ] 242 | } 243 | ], 244 | "metadata": { 245 | "kernelspec": { 246 | "display_name": "remotesensing", 247 | "language": "python", 248 | "name": "python3" 249 | }, 250 | "language_info": { 251 | "codemirror_mode": { 252 | "name": "ipython", 253 | "version": 3 254 | }, 255 | "file_extension": ".py", 256 | "mimetype": "text/x-python", 257 | "name": "python", 258 | "nbconvert_exporter": "python", 259 | "pygments_lexer": "ipython3", 260 | "version": "3.11.10" 261 | } 262 | }, 263 | "nbformat": 4, 264 | "nbformat_minor": 4 265 | } 266 | -------------------------------------------------------------------------------- /jupyter/R/bdc-article/00_TableOfContents.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "junior-trading", 6 | "metadata": {}, 7 | "source": [ 8 | "\n", 9 | "\n", 10 | "# Land use and land cover classification in the Brazilian Cerrado biome using Brazil Data Cube\n", 11 | "
\n", 12 | "\n", 13 | "
\n", 14 | "\n", 15 | "
\n", 16 | " Rolf E. O. Simões , Alber H. Sanchez , Felipe M. Carlos , Leonardo S. Vieira ,
\n", 17 | " Karine R. Ferreira , Lubia Vinhas , Gilberto R. Queiroz* \n", 18 | "

\n", 19 | " Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE)\n", 20 | "
\n", 21 | " Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil\n", 22 | "

\n", 23 | " * Author to whom correspondence should be addressed.\n", 24 | "

\n", 25 | " February 24, 2021\n", 26 | "
\n", 27 | "\n", 28 | "
\n", 29 | "\n", 30 | "
\n", 31 | "Abstract. This Jupyter Notebook compendium contains useful information for the creation of land use and land cover (LULC) maps using Earth observations data cubes and machine learning (ML) techniques. The code is based on the research pipeline described in the paper Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. These notebooks access open data available in the Brazil Data Cube platform.\n", 32 | "
\n", 33 | "\n", 34 | "
\n", 35 | "
\n", 36 | " This Jupyter Notebook is supplement to the Section 5 of the following paper:\n", 37 | "
\n", 38 | " Ferreira, K.R.; Queiroz, G.R.; Vinhas, L.; Marujo, R.F.B.; Simoes, R.E.O.; Picoli, M.C.A.; Camara, G.; Cartaxo, R.; Gomes, V.C.F.; Santos, L.A.; Sanchez, A.H.; Arcanjo, J.S.; Fronza, J.G.; Noronha, C.A.; Costa, R.W.; Zaglia, M.C.; Zioti, F.; Korting, T.S.; Soares, A.R.; Chaves, M.E.D.; Fonseca, L.M.G. 2020. Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. Remote Sens. 12, no. 24: 4033. DOI: 10.3390/rs12244033.\n", 39 | "
\n", 40 | "
" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "id": "antique-equity", 46 | "metadata": {}, 47 | "source": [ 48 | "# Table of Contents\n", 49 | "
" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "id": "greater-durham", 55 | "metadata": {}, 56 | "source": [ 57 | "The Jupyter Notebooks are organized as follow:\n", 58 | "\n", 59 | "\n", 60 | "* [Extracting time series from sample locations](./01_ExtractTimeSeries.ipynb)\n", 61 | "\n", 62 | "* [Land Use and Cover Mapping from CBERS-4/AWFI Data Cubes](./02_CB4_64_16D_STK-1.ipynb)\n", 63 | "\n", 64 | "* [Validation results for CBERS-4/AWFI classification](./03_Validation_CB4_64_16D_STK-1.ipynb)\n", 65 | "\n", 66 | "* [Land Use and Cover Mapping from Landsat-8/OLI Data Cubes](./04_LC8_30_16D_STK-1.ipynb)\n", 67 | "\n", 68 | "* [Validation results for Landsat-8/OLI classification](./05_Validation_LC8_30_16D_STK-1.ipynb)\n", 69 | "\n", 70 | "* [Land Use and Cover Mapping from Sentinel-2/MSI Data Cubes](./06_S2_10_16D_STK-1.ipynb)\n", 71 | "\n", 72 | "* [Validation results for Sentinel-2/MSI classification](./07_Validation_S2_10_16D_STK-1.ipynb)\n", 73 | "\n", 74 | "\n", 75 | "Interest readers should try the notebooks in the proposed order as their contents are complementary." 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "id": "welcome-samoa", 81 | "metadata": {}, 82 | "source": [ 83 | "# Study Area\n", 84 | "
" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "id": "relative-affairs", 90 | "metadata": {}, 91 | "source": [ 92 | "The study area is located in the Bahia state, Brazil, between the Cerrado and Caatinga biomes as depicted in Figure 1.\n", 93 | "\n", 94 | "
\n", 95 | " \n", 96 | "
\n", 97 | "
Figure 1 - Study area in relation to Brazil and its biomes.
\n", 98 | "\n", 99 | "The code cell below shows the study area location in relation to Brazil:" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "id": "tracked-society", 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "library(leaflet)\n", 110 | "\n", 111 | "#\n", 112 | "# load sample and roi layers\n", 113 | "#\n", 114 | "region_of_interest <- sf::st_read(\"/vsicurl/https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/roi/shp/roi.shp\", quiet = TRUE)\n", 115 | "training_samples <- sf::st_read(\"/vsicurl/https://brazildatacube.dpi.inpe.br/public/bdc-article/training-samples/shp/bdc_paper_samples.shp\", quiet = TRUE)\n", 116 | "\n", 117 | "#\n", 118 | "# create a color map\n", 119 | "#\n", 120 | "factpal <- colorFactor(\n", 121 | " palette = c(\"#e18e18\", \"#4ad060\", \"#fcfe7b\"),\n", 122 | " domain = c(\"Crop\", \"Natural\", \"Pasture\")\n", 123 | ")\n", 124 | "\n", 125 | "#\n", 126 | "# create the map\n", 127 | "#\n", 128 | "leaflet::leaflet(width=\"100%\", height=\"600px\") %>%\n", 129 | " addProviderTiles(providers$Esri.WorldImagery) %>%\n", 130 | " setView(lng = -45.5, lat = -12.8, zoom = 9) %>%\n", 131 | " addPolygons(data = region_of_interest) %>%\n", 132 | " \n", 133 | " addCircleMarkers(data = training_samples, \n", 134 | " popup = ~label,\n", 135 | " color = ~factpal(label),\n", 136 | " radius = 4, \n", 137 | " stroke = FALSE, \n", 138 | " fillOpacity = 1) %>%\n", 139 | " \n", 140 | " addLegend(\"topright\", \n", 141 | " pal = factpal, \n", 142 | " values = training_samples$label,\n", 143 | " title = \"Training Samples\", \n", 144 | " opacity = 1)\n" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "id": "front-titanium", 150 | "metadata": {}, 151 | "source": [ 152 | "# Auxiliary Data\n", 153 | "
\n", 154 | "\n", 155 | "All the datasets used in this application along with the results are available from the web in the following URL:\n", 156 | "\n", 157 | "* https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/\n", 158 | "\n", 159 | "\n", 160 | "The folders are organized as follows:\n", 161 | "\n", 162 | "* `results`: This directory contains the set of thematic maps resulting from the classification process. For each satellite/sensor there is a subdirectory with two GeoTIFFs, one with the estimated probabilities of each LULC class, and the other with the final class.\n", 163 | "\n", 164 | "* `roi`: This directory contains the polygon representing the region of interest (the envelope of the validation samples in Figure 1).\n", 165 | "\n", 166 | "* `scripts`: R scripts with the application pipeline.\n", 167 | "\n", 168 | "* `training-samples`: This directory contains the sample set used for training the Multilayer Perceptron (MLP) model used in the application. The original sample points are available in CSV and ESRI Shapefile formats. The RDS files contain the time series for each sample point along with some spectral bands and vegetation indices.\n", 169 | "\n", 170 | "* `validation-samples`: This directory contains the sample set used to validate the classified maps.\n" 171 | ] 172 | } 173 | ], 174 | "metadata": { 175 | "kernelspec": { 176 | "display_name": "R", 177 | "language": "R", 178 | "name": "ir" 179 | }, 180 | "language_info": { 181 | "codemirror_mode": "r", 182 | "file_extension": ".r", 183 | "mimetype": "text/x-r-source", 184 | "name": "R", 185 | "pygments_lexer": "r", 186 | "version": "4.0.3" 187 | } 188 | }, 189 | "nbformat": 4, 190 | "nbformat_minor": 5 191 | } 192 | -------------------------------------------------------------------------------- /jupyter/R/bdc-workshop/01_Samples_analysis.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"metadata":{},"cell_type":"markdown","source":"\n\n\n# Samples Analysis - Clustering\n
\n\n
\n\n
\n Lorena Alves dos Santos\n

\n Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE)\n
\n Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil\n

\n Contact: brazildatacube@inpe.br\n

\n Last Update: March 31, 2021\n
\n\n
\n\n
\nAbstract. This document presents the steps to assess the samples' quality and reduce the noise in the land use and cover reference datasets. The main idea is to identify mislabeled samples, data with low discrimination when mixed with other classes, and explore the samples' spatiotemporal variability using satellite image time series. The method is based on unsupervised neural networks, the self-organizing map (SOM), and Bayesian Inference. It provides measures to identify mislabeled samples and assess the reliability of the samples\n.\n
\n"},{"metadata":{"_uuid":"051d70d956493feee0c6d64651c6a088724dca2a","_execution_state":"idle","trusted":true},"cell_type":"code","source":"#\n# install packages on-the-fly\n#\nsystem(\"cp -u -R ../input/sitspackages/sits-bundle/* /usr/local/lib/R/site-library/\")\n\n# remotes::install_github(\"e-sensing/sits\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"library(sits)\nlibrary(dplyr)\nlibrary(ggplot2)\nlibrary(sf)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Configure plot size \noptions(repr.plot.width = 15, repr.plot.height = 6)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Samples\n
\n\n\n\n\n
\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"# Loading noisy dataset\ninput_data.tb <- readRDS(\"../input/samples-dataset/samples_workshop_bdc.rds\")\n\n\nsits_labels_summary (input_data.tb)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sits_bands(input_data.tb)\nplot(sits_select(input_data.tb, bands = \"NDVI\"))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Clustering samples with self-organizing maps (SOM)\n
\n\n\n\n\n\n
\n\n\n\nThis function uses package Konhonen to find clusters in satellite image time series to cluster the samples. Besides that, this function evaluates the quality of each sample through SOM properties, such as evaluate each sample allocated in aneuron-cluster and its neighbourhood.\n\nThe main parameters for this functions are:\n\n(a) input_data.tb - A tibble with samples to be clustered.\n\n(b) Grid size (X,Y).\n\n(c) alpha - Learning rate.\n\n(d) rlen - Number of iterations to converge SOM method.\n\n(e) distance -The type of similarity measure (distance).\n\n(f) som_radius - Radius of SOM neighborhood\n\nThe function sits_som_map returns a list with two tibble and the SOM properties (provided by kohonen package). The first tibble contains the samples and the additional information about the neuron indentifier. The second tibble contains the information about each neuron, identifier,number of samples associate to it and their labels, and the metrics provided by each class assoaciate to a neuron.\n\n\n\n
\n\n\n\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"set.seed(777)\nclustering_CB4_workshop.lst <- sits::sits_som_map(\n input_data.tb,\n grid_xdim = 9,\n grid_ydim = 9,\n alpha = c(0.5, 0.01),\n distance = \"euclidean\",\n rlen = 100,\n som_radius = 1\n)\n\nclustering_CB4_workshop.lst","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"#List bands\nsits_bands(input_data.tb)\n\n#Plot the SOM grid - Using \"codes\" we can see the samples representad by the low dimension\nplot(clustering_CB4_workshop.lst, type = \"codes\", whatmap = 5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Where the samples are mapped?\nplot(clustering_CB4_workshop.lst, type = \"mapping\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"This function evaluate the clusters created by SOM. Each cluster is a neuron or a set of neuron categorized with same label. It produces a sits tibble indicating the percentage of mixture of classes in each cluster."},{"metadata":{"trusted":true},"cell_type":"code","source":"cluster_purity <- sits_som_evaluate_cluster(clustering_CB4_workshop.lst)\n\n#show the percentage of samples by class in each cluster\ncluster_purity\nplot(cluster_purity)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Output - Metrics \n
\n\n\n"},{"metadata":{},"cell_type":"markdown","source":"This function evaluate the quality of the samples based on the results of the SOM map. It produces a sits tibble with an evaluation column indicating if each sample is clean, should be analyzed or should be removed, and with a new column indicating the posterior probability of the sample\n\n\n
\n\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"samples_complete.tb <-\n sits::sits_som_clean_samples(\n clustering_CB4_workshop.lst,\n prior_threshold = 0.5,\n posterior_threshold = 0.5\n )\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# you can check the fields that sits_som_clean_samples() returns using colnames()\ncolnames(samples_complete.tb)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# output information\ndplyr::select(samples_complete.tb, id_sample, id_neuron, label, eval, post_prob)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Samples to remove\n
"},{"metadata":{"trusted":true},"cell_type":"code","source":"samples_to_remove.tb <- dplyr::filter(samples_complete.tb, eval == \"remove\")\n#dplyr::select(samples_to_remove.tb,id_sample, id_neuron, label)\n\n#plot samples to remove\nplot(sits_select(samples_to_remove.tb, bands = c(\"NDVI\")))\n\n\n#plot only samples labeled as \"Natural\"\n#plot(sits_select(dplyr::filter(samples_to_remove.tb, label == \"Natural\"), bands = c(\"NDVI\", \"EVI\")))\n\n#plot all bands\n#plot(dplyr::filter(samples_to_remove.tb, label == \"Natural\"))\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Neurons Analysis\n
\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"\nsamples_to_analyze <-\n dplyr::arrange(dplyr::filter(samples_complete.tb, eval == \"analyze\"), id_neuron)\n\ntable(samples_to_analyze$id_neuron, samples_to_analyze$label)\n\n#To check the complete table, print samples_to_analyze:\n#samples_to_analyze","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Get the outliers neuron identifier orderly \nneurons_to_analyze <- sort(unique(samples_to_analyze$id_neuron))\nprint('Neurons to analyze')\nneurons_to_analyze\n\n# Identify in the SOM grid the outlier neurons\nsom_clustering <- clustering_CB4_workshop.lst\n\n#paint the neuron identifed as outlier\nsom_clustering$som_properties$paint_map [neurons_to_analyze] = \"black\"\n\n#relabel the neurons identifed as outlier\nsom_clustering$som_properties$neuron_label [neurons_to_analyze] = \"analyze\"\n\n#plot SOM grid\npar(mfrow = c(1,2))\nplot(clustering_CB4_workshop.lst, type = \"codes\", whatmap = 6)\nplot(som_clustering, type = \"codes\", whatmap = 6)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Neuron 9 "},{"metadata":{"trusted":true},"cell_type":"code","source":"#We can analyze all samples assoaciated to these neurons using the dplyr\ndplyr::filter(dplyr::select(samples_to_analyze,id_sample, id_neuron, label, post_prob ), id_neuron == 9)\n\n#plot samples grouped in neuron 9\nplot(dplyr::filter(samples_complete.tb, id_neuron == 9 & eval == \"analyze\"))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Neuron 62 "},{"metadata":{"trusted":true},"cell_type":"code","source":"#We can analyze all samples assoaciated to these neurons using the dplyr\ndplyr::filter(dplyr::select(samples_to_analyze,id_sample, id_neuron, label, post_prob ), id_neuron == 62)\n\n#plot samples grouped in neuron 62\nplot(dplyr::filter(samples_complete.tb, id_neuron == 62 & eval == \"analyze\"))\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Neuron 74 "},{"metadata":{"trusted":true},"cell_type":"code","source":"#We can analyze all samples assoaciated to these neurons using the dplyr\ndplyr::filter(dplyr::select(samples_to_analyze,id_sample, id_neuron, label, post_prob ), id_neuron == 74)\n\n#plot samples grouped in neuron 74\nplot(dplyr::filter(samples_complete.tb, id_neuron == 74 & eval == \"analyze\"))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#select the point\npoints_to_plot.tb <- dplyr::filter(samples_complete.tb, eval == \"analyze\" & id_neuron %in% c(74, 9) )\n\n#load the shapefile\nbrasil.shp <- sf::st_read(\"../input/shapefilebrasil/br_biomes.shp\")\n\n#plot points\nggplot2::ggplot(data = st_transform(brasil.shp, 4326)) +\n ggplot2::geom_sf(fill = \"transparent\") +\n ggplot2::geom_point(data = points_to_plot.tb, aes(x = longitude, y = latitude, color = (label)))\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# New dataset "},{"metadata":{},"cell_type":"markdown","source":"During the samples analysis, we identified that the samples grouped in Nuron 74 and the sample 443 (grouped in Neuron 9) are mislabeled, for this reason they will be removed from the dataset."},{"metadata":{"trusted":true},"cell_type":"code","source":"#Samples after analaysis\n\n#Remove sample 443 and the all the samples grouped in neuron 74\n\nkeep_after_analysis.tb <- dplyr::filter(samples_to_analyze, !(id_sample %in% c(443)) & !(id_neuron %in% c(74)))\nkeep_after_analysis.tb\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#filter the \"clean\" samples\ncleaned_samples.tb <- dplyr::filter(samples_complete.tb, eval == \"clean\")\n\n#join the clean samples with the dataset that was analyaetz preioisly \nnew_dataset.tb <- rbind(cleaned_samples.tb, keep_after_analysis.tb)\nnew_dataset.tb","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"saveRDS(new_dataset.tb, file = \"new_dataset.rds\")","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"name":"ir","display_name":"R","language":"R"},"language_info":{"name":"R","codemirror_mode":"r","pygments_lexer":"r","mimetype":"text/x-r-source","file_extension":".r","version":"3.6.3"}},"nbformat":4,"nbformat_minor":4} -------------------------------------------------------------------------------- /jupyter/R/wlts/intro-wlts-bkp/samples_trj.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/intro-wlts-bkp/samples_trj.rds -------------------------------------------------------------------------------- /jupyter/R/wlts/intro-wlts-bkp/tj1.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/intro-wlts-bkp/tj1.rds -------------------------------------------------------------------------------- /jupyter/R/wlts/intro-wlts-bkp/tj2.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/intro-wlts-bkp/tj2.rds -------------------------------------------------------------------------------- /jupyter/R/wlts/intro-wlts-bkp/trj_mult.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/intro-wlts-bkp/trj_mult.rds -------------------------------------------------------------------------------- /jupyter/R/wlts/intro-wlts-bkp/trj_tc_amazon1.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/intro-wlts-bkp/trj_tc_amazon1.rds -------------------------------------------------------------------------------- /jupyter/R/wlts/intro-wlts-bkp/trj_tc_amazon2.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/intro-wlts-bkp/trj_tc_amazon2.rds -------------------------------------------------------------------------------- /jupyter/R/wlts/intro-wlts-bkp/trj_tc_map_amazon1.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/intro-wlts-bkp/trj_tc_map_amazon1.rds -------------------------------------------------------------------------------- /jupyter/R/wlts/sao-felix-do-xingu-samples/sao-felix-do-xingu-samples.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /jupyter/R/wlts/sao-felix-do-xingu-samples/sao-felix-do-xingu-samples.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/sao-felix-do-xingu-samples/sao-felix-do-xingu-samples.dbf -------------------------------------------------------------------------------- /jupyter/R/wlts/sao-felix-do-xingu-samples/sao-felix-do-xingu-samples.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] -------------------------------------------------------------------------------- /jupyter/R/wlts/sao-felix-do-xingu-samples/sao-felix-do-xingu-samples.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/sao-felix-do-xingu-samples/sao-felix-do-xingu-samples.shp -------------------------------------------------------------------------------- /jupyter/R/wlts/sao-felix-do-xingu-samples/sao-felix-do-xingu-samples.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/R/wlts/sao-felix-do-xingu-samples/sao-felix-do-xingu-samples.shx -------------------------------------------------------------------------------- /jupyter/events/2024-big-bdc-queimadas/README,.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/04/Data/Billings.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/04/Data/Billings.dbf: -------------------------------------------------------------------------------- 1 | }A 2 | Chla_NDCIN 1 -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/04/Data/Billings.prj: -------------------------------------------------------------------------------- 1 | PROJCS["WGS_1984_UTM_Zone_23S",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",10000000.0],PARAMETER["Central_Meridian",-45.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]] -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/04/Data/Billings.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/04/Data/Billings.shp -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/04/Data/Billings.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/04/Data/Billings.shx -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/04/Parte02.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "af6f36f9-a4df-49b8-a432-282e2ea580a7", 6 | "metadata": {}, 7 | "source": [ 8 | "## Parte 02 - Geração de modelo empírico para Clorofila-a\n", 9 | "
\n", 10 | "\n", 11 | "\n", 12 | "Agora que nós já fizemos as primeiras organizações nos dados, podemos começar a fazer um treinamento e validação de um algoritmo empírico com o NDCI. \n", 13 | "\n", 14 | "Este código irá utilizar os dados organizados anteriormente (NDCI e concentração de Chl-a) para gerar um algoritmo empírico para estimativa da concentração de Chl-a.\n", 15 | "\n", 16 | "Este código é apenas um exemplo. Idealmente, deveríamos validar o modelo aplicado na imagem em dados coletados ao mesmo tempo da passagem do satélite.\n", 17 | "\n", 18 | "Como estes dados não estão disponíveis, iremos treinar e validar utilizando apenas os dados de campo do GLORIA.\n", 19 | "\n", 20 | "\n", 21 | "
\n", 22 | "\n" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "id": "8342363a-dab8-443d-a354-4082093d102f", 29 | "metadata": { 30 | "execution": { 31 | "iopub.execute_input": "2025-05-21T12:16:08.836756Z", 32 | "iopub.status.busy": "2025-05-21T12:16:08.835838Z", 33 | "iopub.status.idle": "2025-05-21T12:21:20.773929Z", 34 | "shell.execute_reply": "2025-05-21T12:21:20.772711Z" 35 | }, 36 | "vscode": { 37 | "languageId": "r" 38 | } 39 | }, 40 | "outputs": [], 41 | "source": [ 42 | "zip('/home/jovyan/Desktop/Cursos/TechTalks', zipfile = 'Tech_talk.zip')" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "id": "ec4e266f-3445-4802-8c2b-861610a3c413", 49 | "metadata": { 50 | "execution": { 51 | "iopub.execute_input": "2025-05-20T10:42:13.102995Z", 52 | "iopub.status.busy": "2025-05-20T10:42:13.101796Z", 53 | "iopub.status.idle": "2025-05-20T10:42:13.115509Z", 54 | "shell.execute_reply": "2025-05-20T10:42:13.114242Z" 55 | }, 56 | "scrolled": true, 57 | "vscode": { 58 | "languageId": "r" 59 | } 60 | }, 61 | "outputs": [], 62 | "source": [ 63 | "## Model generation: Generate a empirical regression general model for Chl-a retrieval\n", 64 | "\n", 65 | "# loading require packages\n", 66 | "\n", 67 | "require(data.table)\n", 68 | "require(dplyr)\n", 69 | "require(Metrics)\n", 70 | "require(randomForest)\n", 71 | "\n", 72 | "options(warn = -1)\n", 73 | "\n", 74 | "\n" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "id": "f5900192-adb8-4924-97d7-6bc323cc696b", 81 | "metadata": { 82 | "execution": { 83 | "iopub.execute_input": "2025-05-20T10:42:30.082874Z", 84 | "iopub.status.busy": "2025-05-20T10:42:30.081904Z", 85 | "iopub.status.idle": "2025-05-20T10:42:30.195335Z", 86 | "shell.execute_reply": "2025-05-20T10:42:30.194442Z" 87 | }, 88 | "vscode": { 89 | "languageId": "r" 90 | } 91 | }, 92 | "outputs": [], 93 | "source": [ 94 | "data = fread(\"Outputs/sentinel2_simulated_filtered.csv\")\n", 95 | "\n", 96 | "set.seed(13) # To allow replicability\n", 97 | "\n", 98 | "\n", 99 | "## Random samples ; train / test\n", 100 | "\n", 101 | "samples = sample(x = 1:nrow(data),\n", 102 | " size = 0.7*nrow(data), \n", 103 | " replace = F)\n", 104 | "\n", 105 | "\n", 106 | "train = data[samples,]\n", 107 | "valid = data[-samples,]\n", 108 | "\n", 109 | "\n", 110 | "dim(train)\n", 111 | "dim(valid)\n", 112 | "\n", 113 | "\n", 114 | "## Creating an empirical (simple model) based on Normalized Difference Chlorophyll Index\n", 115 | "\n", 116 | "# Ajuste do modelo de potência: y = a * x^b\n", 117 | "\n", 118 | "\n", 119 | "train = filter(train, NDCI > 0 & NDCI < 2)\n", 120 | "\n", 121 | "matplot(x = train$Chla, y = train$NDCI)\n", 122 | "\n", 123 | "emp.chla <- nls(Chla ~ a * NDCI^b, start = list(a = 1, b = 1), data = train)\n", 124 | "\n", 125 | "\n", 126 | "summary(emp.chla)\n", 127 | "\n", 128 | "\n", 129 | "valid$NDCI_CHLA = predict(emp.chla, valid)\n", 130 | "\n" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": null, 136 | "id": "4b9a8f03-74e5-487c-badb-ccb9f2b6b3b4", 137 | "metadata": { 138 | "execution": { 139 | "iopub.execute_input": "2025-05-20T10:42:32.559502Z", 140 | "iopub.status.busy": "2025-05-20T10:42:32.558565Z", 141 | "iopub.status.idle": "2025-05-20T10:42:32.598753Z", 142 | "shell.execute_reply": "2025-05-20T10:42:32.597839Z" 143 | }, 144 | "vscode": { 145 | "languageId": "r" 146 | } 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "\n", 151 | "plot(valid$Chla, \n", 152 | " valid$NDCI_CHLA , pch = 20, xlab = \"Measured Chla\",\n", 153 | " ylab = \"Predicted Chla\", xlim = c(0,400), ylim = c(0,400))\n", 154 | "\n", 155 | "abline(0,1)" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": null, 161 | "id": "4c0557d9-8038-4000-99ad-1c63d5808150", 162 | "metadata": { 163 | "vscode": { 164 | "languageId": "r" 165 | } 166 | }, 167 | "outputs": [], 168 | "source": [ 169 | "## Modelo completo" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "id": "15589c60-b8ee-49a9-bfe1-2a8f07cee90e", 176 | "metadata": { 177 | "execution": { 178 | "iopub.execute_input": "2025-05-20T10:42:46.816598Z", 179 | "iopub.status.busy": "2025-05-20T10:42:46.815646Z", 180 | "iopub.status.idle": "2025-05-20T10:42:46.925599Z", 181 | "shell.execute_reply": "2025-05-20T10:42:46.924683Z" 182 | }, 183 | "vscode": { 184 | "languageId": "r" 185 | } 186 | }, 187 | "outputs": [], 188 | "source": [ 189 | "data = filter(data, NDCI > 0 & NDCI < 2)\n", 190 | "\n", 191 | "matplot(x = data$Chla, y = data$NDCI, pch = 20)\n", 192 | "]\n", 193 | "\n", 194 | "emp.chla <- nls(Chla ~ a * NDCI^b, start = list(a = 1, b = 1), data = data)\n", 195 | "\n", 196 | "\n", 197 | "saveRDS(emp.chla, file = 'Outputs/emp_chla.R')" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": null, 203 | "id": "64b79b17-528d-48af-863e-adcc286abcd5", 204 | "metadata": { 205 | "vscode": { 206 | "languageId": "r" 207 | } 208 | }, 209 | "outputs": [], 210 | "source": [] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": null, 215 | "id": "a3e19d75-18ec-44ba-b02d-b95b9e7fe10f", 216 | "metadata": { 217 | "vscode": { 218 | "languageId": "r" 219 | } 220 | }, 221 | "outputs": [], 222 | "source": [] 223 | } 224 | ], 225 | "metadata": { 226 | "kernelspec": { 227 | "display_name": "R (Geospatial)", 228 | "language": "R", 229 | "name": "ir" 230 | }, 231 | "language_info": { 232 | "codemirror_mode": "r", 233 | "file_extension": ".r", 234 | "mimetype": "text/x-r-source", 235 | "name": "R", 236 | "pygments_lexer": "r", 237 | "version": "4.4.3" 238 | } 239 | }, 240 | "nbformat": 4, 241 | "nbformat_minor": 5 242 | } 243 | -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/04/Parte03.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c709cbe5-7022-4e63-9a34-055e2ffa8e86", 6 | "metadata": {}, 7 | "source": [ 8 | "## Parte 03 - Aplicando o algoritmo em uma imagem Sentinel-2/A Nível 2\n", 9 | "
\n", 10 | "\n", 11 | "\n", 12 | "Agora, após a geração do nosso modelo nós iremos aplicar ele em uma imagem do Sentinel-2/MSI obtida através do STAC do BDC em Nível 2.\n", 13 | "\n", 14 | "As imagems em nível 2 já são corrigidas dos efeitos atmosféricos. Porém, o método adotado pela ESA para o produto pronto não é totalmente adequado para aplicações em ambientes aquáticos, tendo alguns problemas. Nesse sentido, iremos avaliar qual é a diferença depois usando os métodos L2A (Sen2Cor) e ACOLITE. \n", 15 | "
\n", 16 | "\n", 17 | "# \n" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "id": "09fa55d3-7569-4f89-b8ae-914e4ca409f6", 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "# Using RSTAC to get Sentinel-2 image and apply the algorithm developed\n", 28 | "\n", 29 | "require(data.table)\n", 30 | "require(dplyr)\n", 31 | "require(rstac)\n", 32 | "require(terra)\n", 33 | "require(mapview)\n", 34 | "require(httr)\n", 35 | "require(rstac)\n", 36 | "require(randomForest)\n", 37 | "library(rasterVis)\n", 38 | "require(RColorBrewer)\n", 39 | "require(terrainr)\n", 40 | "\n", 41 | "options(warn = -1)\n", 42 | "options(repr.plot.width = 15, repr.plot.height = 15) \n" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "id": "51344fc0-5dcf-4948-b259-91bfaf3a278e", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "\n", 53 | "# We gonna use the BDC STAC to get Sentinel-2 images\n", 54 | "\n", 55 | "stac_obj <- stac(\"https://data.inpe.br/bdc/stac/v1/\")\n" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "id": "117f056a-debc-47e8-8007-56db44d621e2", 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "\n", 66 | "#\n", 67 | "# query to the data catalog\n", 68 | "#\n", 69 | "catalog <- stac_obj %>% get_request()\n", 70 | "\n", 71 | "print(catalog)\n" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "id": "07f3e4ad-04a1-499b-a417-557857ee3d2f", 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "\n", 82 | "#\n", 83 | "# query the available product collections\n", 84 | "#\n", 85 | "collections <- stac_obj %>%\n", 86 | " collections() %>%\n", 87 | " get_request()\n", 88 | "\n", 89 | "print(collections, n = 100)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "id": "fa723a37-8acf-4669-b16d-2203c88d8ef9", 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "# Vamos usar sentinel-2 MSI Surface reflectance (inicialmente)\n", 100 | "\n", 101 | "\n", 102 | "collection_info <- stac_obj %>%\n", 103 | " collections(\"S2_L2A-1\") %>%\n", 104 | " get_request()\n", 105 | "\n", 106 | "print(collection_info)\n" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "id": "0adcce29-21ab-4b0c-8282-42e3eb8b47c5", 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "dates = c(\"2025-03-05/2025-03-07\")\n", 117 | "\n", 118 | "BBOX = c(-46.632525, -23.770232, -46.6369, -23.758501) #xmin, ymin, xmax, ymax\n", 119 | "\n", 120 | "it_obj <- stac_obj %>%\n", 121 | " stac_search(collections = \"S2_L2A-1\",\n", 122 | " bbox = BBOX,\n", 123 | " datetime = dates) %>%\n", 124 | " get_request() \n", 125 | "\n", 126 | "print(it_obj)\n", 127 | "\n" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": null, 133 | "id": "a3386320-c60c-4a76-ae64-d0a106e2d566", 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "## Filtrara para cloud-cover < 50 - se eu quiser...\n", 138 | "\n", 139 | "item_filtered <- items_filter(it_obj, properties$`eo:cloud_cover` < 50)\n", 140 | "\n", 141 | "print(item_filtered)\n", 142 | "\n" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": null, 148 | "id": "41ffe855-1a15-4984-b6c2-20534926d74b", 149 | "metadata": {}, 150 | "outputs": [], 151 | "source": [ 152 | "## Carregando as bandas para o NDCI e para cor verdadeira\n", 153 | "\n", 154 | "\n", 155 | "## Carregar os links dos assests (ou seja, os links para onde carregar as imagens)\n", 156 | "b2.url <- assets_url(item_filtered, asset_names = \"B02\", append_gdalvsi = TRUE) \n", 157 | "b3.url <- assets_url(item_filtered, asset_names = \"B03\", append_gdalvsi = TRUE) \n", 158 | "b4.url <- assets_url(item_filtered, asset_names = \"B04\", append_gdalvsi = TRUE) \n", 159 | "b5.url <- assets_url(item_filtered, asset_names = \"B05\", append_gdalvsi = TRUE) \n", 160 | "b12.url <- assets_url(item_filtered, asset_names = \"B12\", append_gdalvsi = TRUE) \n", 161 | "SCL.url <- assets_url(item_filtered, asset_names = \"SCL\", append_gdalvsi = TRUE) \n", 162 | "\n", 163 | "# Extensão do reservatório (poderia tmbém ser um shapefile, se quiser).\n", 164 | "\n", 165 | "shp_billings = vect(\"Data/Billings_shape/billings.shp\") %>% project(rast(b2.url))\n", 166 | "\n", 167 | "# Cropar para area do reservatório apenas\n", 168 | "\n", 169 | "b2 = rast(b2.url[1]) %>% crop(shp_billings)\n", 170 | "b3 = rast(b3.url[1]) %>% crop(shp_billings)\n", 171 | "b4 = rast(b4.url[1]) %>% crop(shp_billings)\n", 172 | "b5 = rast(b5.url[1]) %>% project(b4) %>% crop(shp_billings)\n", 173 | "\n", 174 | "# Banda de nuvem\n", 175 | "SCL = rast(SCL.url[1]) %>% project(b4) %>% crop(shp_billings)\n", 176 | "\n" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "id": "f02913fb-d6de-4d8d-897a-f9afcebd6385", 183 | "metadata": {}, 184 | "outputs": [], 185 | "source": [ 186 | "plot(b2)" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": null, 192 | "id": "e3fef0af-5624-466a-a415-6b41a56786be", 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "mosaico = c(b2, b3, b4, b5)\n", 197 | "\n", 198 | "names(mosaico) = c(\"B2\", \"B3\", \"B4\", \"B5\")\n", 199 | "\n", 200 | "# Remover as nuvens (Classes 7 8 e 9 são baixas, médias e altas probabilidades de nuvem)\n", 201 | "mosaico[SCL == 7] = NA\n", 202 | "mosaico[SCL == 8] = NA\n", 203 | "mosaico[SCL == 9] = NA\n", 204 | "\n", 205 | "\n", 206 | "plotRGB(mosaico, r = 3, g = 2, b = 1, stretch = 'lin')\n", 207 | "\n" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": null, 213 | "id": "6c81a2bf-be6a-441a-9bf4-cf76de835365", 214 | "metadata": {}, 215 | "outputs": [], 216 | "source": [ 217 | "## Carregar o modelo de NDCI\n", 218 | "\n", 219 | "modelo_NDCI = readRDS(\"Outputs/emp_chla.R\")\n", 220 | "\n", 221 | "\n", 222 | "## Criar a banda de NDCI no raster\n", 223 | "\n", 224 | "mosaico$NDCI = ((mosaico$B5-mosaico$B4)/(mosaico$B5+mosaico$B4))+1\n", 225 | "\n", 226 | "## aplicar a máscara de água do SCL\n", 227 | "\n", 228 | "mosaico[SCL != 6] = NA\n", 229 | "\n", 230 | "## Mosaico na água\n", 231 | "\n", 232 | "plotRGB(mosaico, r = 3, g = 2, b = 1, stretch = 'lin')\n", 233 | "\n" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": null, 239 | "id": "bccc8d34-10d3-4ba7-a498-a9cf345b32b4", 240 | "metadata": {}, 241 | "outputs": [], 242 | "source": [ 243 | "mosaico$Chla_NDCI = predict(mosaico, modelo_NDCI)" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": null, 249 | "id": "bb36a0f9-b4fd-4def-8827-fe087a3545ad", 250 | "metadata": {}, 251 | "outputs": [], 252 | "source": [ 253 | "colr <- colorRampPalette(rev(brewer.pal(11, 'RdBu')))\n", 254 | "\n", 255 | "levelplot(raster::stack(mosaico$Chla_NDCI),col.regions = colr, \n", 256 | " at = seq(0, 250, length = 100),\n", 257 | " maxpixels = 1e6, main = \"Chlorophyll-a Concentration (ug/L)\") " 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": null, 263 | "id": "b3c9523f-3eb6-4eac-97f3-b909bf45b739", 264 | "metadata": {}, 265 | "outputs": [], 266 | "source": [ 267 | "writeRaster(mosaico$Chla_NDCI, \"Outputs/chla_sen2cor.tif\", overwrite = T)" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": null, 273 | "id": "7d7b167b-d1dc-42fc-9a32-50dc7534e236", 274 | "metadata": {}, 275 | "outputs": [], 276 | "source": [] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": null, 281 | "id": "ecfd3061-378f-4196-a7cf-64f72327ff1b", 282 | "metadata": {}, 283 | "outputs": [], 284 | "source": [] 285 | } 286 | ], 287 | "metadata": { 288 | "kernelspec": { 289 | "display_name": "R (Geospatial)", 290 | "language": "R", 291 | "name": "ir" 292 | }, 293 | "language_info": { 294 | "codemirror_mode": "r", 295 | "file_extension": ".r", 296 | "mimetype": "text/x-r-source", 297 | "name": "R", 298 | "pygments_lexer": "r", 299 | "version": "4.4.3" 300 | } 301 | }, 302 | "nbformat": 4, 303 | "nbformat_minor": 5 304 | } 305 | -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/04/Parte04.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "7dbf7e5a-c50a-4c55-add0-424231fdbd0f", 6 | "metadata": { 7 | "execution": { 8 | "iopub.execute_input": "2025-05-16T15:43:55.278613Z", 9 | "iopub.status.busy": "2025-05-16T15:43:55.220426Z", 10 | "iopub.status.idle": "2025-05-16T15:43:55.296030Z", 11 | "shell.execute_reply": "2025-05-16T15:43:55.293571Z" 12 | } 13 | }, 14 | "source": [ 15 | "## Parte 04A - Download de imagens pelo BDC Lab / STAC BDC L1C\n", 16 | "
\n", 17 | "\n", 18 | "\n", 19 | "\n", 20 | "Para aplicar a correção do ACOLITE precisamos de duas coisas: Primeiro, precisamos baixar os bundles em nível 1 - sem correção atmosférica. Por sorte, o BDC fornece esses dados pra gente - o que facilita imensamente o acesso aos dados. \n", 21 | "\n", 22 | "Usaremos o RSTAC ainda para fazer as buscas nos dados - imagem Sentinel-2/MSI do dia 06 de março de 2025.\n", 23 | "\n", 24 | "\n", 25 | "
\n" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "id": "e6632887-1380-4b4a-a125-a8ceb57b987d", 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "require(data.table)\n", 36 | "require(dplyr)\n", 37 | "require(rstac)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "id": "bd8fc195-3651-4cf1-a9bb-bbfc14bc2533", 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "# Mesma busca anterior\n", 48 | "\n", 49 | "stac_obj <- stac(\"https://data.inpe.br/bdc/stac/v1/\")\n", 50 | "\n", 51 | "dates = c(\"2025-03-05/2025-03-07\")\n", 52 | "\n", 53 | "BBOX = c(-46.632525, -23.770232, -46.6369, -23.758501) #xmin, ymin, xmax, ymax\n", 54 | "\n", 55 | "it_obj <- stac_obj %>%\n", 56 | " stac_search(collections = \"S2_L1C_BUNDLE-1\", ### Veja que só a minha collection que mudou!\n", 57 | " bbox = BBOX,\n", 58 | " datetime = dates) %>%\n", 59 | " get_request() #%>% items_filter(properties$`eo:cloud_cover` <= 50) \n", 60 | "\n", 61 | "\n", 62 | "print(it_obj)\n", 63 | "\n" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "id": "f4a7768f-b2ce-4634-a74c-02520e557964", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "\n", 74 | "for(i in 1:length(it_obj$features)) {\n", 75 | " \n", 76 | " \n", 77 | " assets_download(items = it_obj, asset_names = NULL, output_dir = 'Outputs', overwrite = T)\n", 78 | " \n", 79 | " \n", 80 | "}" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "id": "e2321b31-a45f-46a2-916d-f93274330523", 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "getwd()" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "id": "0c8dfe1e-c80b-4972-b56d-7ba39594d1ea", 97 | "metadata": {}, 98 | "outputs": [], 99 | "source": [ 100 | "unlink('/home/jovyan/Desktop/Cursos/TechTalks/Desktop/', recursive = T, expand = T)" 101 | ] 102 | } 103 | ], 104 | "metadata": { 105 | "kernelspec": { 106 | "display_name": "R (Geospatial)", 107 | "language": "R", 108 | "name": "ir" 109 | }, 110 | "language_info": { 111 | "codemirror_mode": "r", 112 | "file_extension": ".r", 113 | "mimetype": "text/x-r-source", 114 | "name": "R", 115 | "pygments_lexer": "r", 116 | "version": "4.4.3" 117 | } 118 | }, 119 | "nbformat": 4, 120 | "nbformat_minor": 5 121 | } 122 | -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/04/Parte05.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "fd2f53a6-1acf-4eb2-8451-bcdabb314db5", 6 | "metadata": { 7 | "execution": { 8 | "iopub.execute_input": "2025-05-16T18:01:29.389492Z", 9 | "iopub.status.busy": "2025-05-16T18:01:29.387960Z", 10 | "iopub.status.idle": "2025-05-16T18:01:29.401437Z", 11 | "shell.execute_reply": "2025-05-16T18:01:29.399942Z" 12 | } 13 | }, 14 | "source": [ 15 | "## Parte 05 - Comparações e plots usando o ACOLITE e o Sen2COR \n", 16 | "
\n", 17 | "\n", 18 | "\n", 19 | "Agora que conseguimos baixar e rodar a correção atmosférica com o ACOLITE, podemos aplicar o modelo de Chl-a na imagem e avaliar os resultados com ela também.\n", 20 | "\n", 21 | "\n", 22 | "
\n", 23 | "\n" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "id": "c8c7fd9d-f1bf-4afc-96c6-b7580bcb93a3", 30 | "metadata": {}, 31 | "outputs": [], 32 | "source": [ 33 | "require(data.table)\n", 34 | "require(dplyr)\n", 35 | "require(rstac)\n", 36 | "require(terra)\n", 37 | "require(httr)\n", 38 | "library(rasterVis)\n", 39 | "require(RColorBrewer)\n", 40 | "\n", 41 | "options(warn = -1)\n", 42 | "options(repr.plot.width = 20, repr.plot.height = 10) \n" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "id": "5bd1614c-ac5d-4809-bf2a-bbdf7c53653f", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "# Carregando o modelo de NDCI\n", 53 | "modelo_ndci = readRDS('Outputs/emp_chla.R')" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": null, 59 | "id": "00cc396c-842c-4c4f-a66e-5e6a60373329", 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "# Carregando os resultados do Sen2Cor\n", 64 | "\n", 65 | "chla_sen2cor = rast(\"Outputs/chla_sen2cor.tif\")\n", 66 | "\n", 67 | "names(chla_sen2cor) = \"Chla Sen2Cor\"" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "id": "39675ed4-4339-4f3d-bbf4-0f5ee69f6c85", 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "## Carregando o ACOLITE\n", 78 | "\n", 79 | "b5_acolite = rast(\"Outputs/ACOLITE/S2B_MSIL1C_20250306T131249_N0511_R138_T23KLP_20250306T144532.SAFE//S2B_MSI_2025_03_06_13_18_59_T23KLP_L2W_Rrs_704.tif\")\n", 80 | "b4_acolite = rast(\"Outputs/ACOLITE/S2B_MSIL1C_20250306T131249_N0511_R138_T23KLP_20250306T144532.SAFE//S2B_MSI_2025_03_06_13_18_59_T23KLP_L2W_Rrs_665.tif\")\n", 81 | "b3_acolite = rast(\"Outputs/ACOLITE/S2B_MSIL1C_20250306T131249_N0511_R138_T23KLP_20250306T144532.SAFE//S2B_MSI_2025_03_06_13_18_59_T23KLP_L2W_Rrs_559.tif\")\n", 82 | "b2_acolite = rast(\"Outputs/ACOLITE/S2B_MSIL1C_20250306T131249_N0511_R138_T23KLP_20250306T144532.SAFE//S2B_MSI_2025_03_06_13_18_59_T23KLP_L2W_Rrs_492.tif\")\n", 83 | "\n", 84 | "\n", 85 | "# Mosaico\n", 86 | "mosaico = c(b2_acolite, b3_acolite, b4_acolite, b5_acolite)\n", 87 | "\n", 88 | "# Cálculo do NDCI\n", 89 | "ndci_acolite = ((b5_acolite-b4_acolite)/(b5_acolite+b4_acolite))+1\n", 90 | "names(ndci_acolite)[1] = \"NDCI\"\n", 91 | "\n", 92 | "# Cálculo da concentração de clorofila-a\n", 93 | "\n", 94 | "chla_acolite = predict(ndci_acolite, modelo_ndci, na.rm = T)\n", 95 | "\n", 96 | "names(chla_acolite) = \"Chla ACOLITE\"\n" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "id": "3671b5b6-3346-46c1-9b79-0056d1c0ca9d", 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "\n", 107 | "plotRGB(mosaico, r = 3, g = 2, b = 1, stretch = 'lin')\n", 108 | "\n" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "id": "63307d88-3fe5-40d9-886c-2e05a3b920c9", 115 | "metadata": {}, 116 | "outputs": [], 117 | "source": [ 118 | "# Escala de cores\n", 119 | "colr <- colorRampPalette(rev(brewer.pal(11, 'RdBu')))\n", 120 | "\n", 121 | "# Reprojetando para a mesma escala do ACOLITE\n", 122 | "sen2cor = project(x = chla_sen2cor, y = chla_acolite)\n", 123 | "\n", 124 | "# Colocndo no mesmo arquivo\n", 125 | "rasters = c(chla_acolite, sen2cor)\n", 126 | "\n", 127 | "#plot \n", 128 | "levelplot(raster::stack(rasters),col.regions = colr, layout = c(2, 1),\n", 129 | " at = seq(0, 250, length = 100),\n", 130 | " maxpixels = 1e9,\n", 131 | " main = \"Chlorophyll-a Concentration (ug/L)\") " 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "id": "108d1004-db50-42a7-8f08-5234397e42ed", 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "df = data.frame(acolite = values(chla_acolite), sen2cor = values(sen2cor)) %>% na.omit()" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "id": "193833f1-d4c5-4d79-9fb5-482c5cb6c3c9", 148 | "metadata": {}, 149 | "outputs": [], 150 | "source": [ 151 | "require(ggplot2)\n", 152 | "ggplot(df, aes(x = Chla.ACOLITE, y = Chla.Sen2Cor)) + \n", 153 | " geom_point() + \n", 154 | " theme_bw() +\n", 155 | " scale_x_continuous(limits = c(0,600)) + \n", 156 | " scale_y_continuous(limits = c(0,600)) + geom_abline(slope = 1, intercept = 0)" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "id": "e02a2be9-48af-49cf-b1de-cc01ca836087", 162 | "metadata": {}, 163 | "source": [ 164 | "\n", 165 | "## E agora o que fazer?????? \n", 166 | "
\n", 167 | "\n", 168 | "\n", 169 | "\n", 170 | "\n", 171 | "Como comentado - o ideal é sempre aplicar correções atmosféricas específicas para água. Nesse caso abordado - essa imagem - os resultados são muito diferentes. Assim, precisamos ter consciência de qual dado é melhor para nossa aplicação. Observamos que houve um resídual de correção atmosférica nos dados do Sen2Cor - que é resolvido com a subtração da banda do SWIR (Não mostrado aqui no curso). Porém, temos que ter claro que estamos comparando coisas iguais - ou seja, dados no mesmo formato - os dados do ACOLITE não possuem a correção resídual ou correção de glint. \n", 172 | "\n", 173 | "Assim, recomendamos novamente fortemente o uso de métodos específios para água para aplicação de correção atmosférica. \n", 174 | "\n", 175 | "
\n", 176 | "\n", 177 | "\n", 178 | "\n" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": null, 184 | "id": "fb223e4e-d3bd-4316-8822-c583a71edad0", 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": null, 192 | "id": "ee0e98aa-1e81-48af-b2b6-2fbc240bd028", 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [] 196 | } 197 | ], 198 | "metadata": { 199 | "kernelspec": { 200 | "display_name": "R (Geospatial)", 201 | "language": "R", 202 | "name": "ir" 203 | }, 204 | "language_info": { 205 | "codemirror_mode": "r", 206 | "file_extension": ".r", 207 | "mimetype": "text/x-r-source", 208 | "name": "R", 209 | "pygments_lexer": "r", 210 | "version": "4.4.3" 211 | } 212 | }, 213 | "nbformat": 4, 214 | "nbformat_minor": 5 215 | } 216 | -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/assets/figura1_espetral.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/assets/figura1_espetral.jpg -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/assets/figura2_espetral.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/assets/figura2_espetral.jpg -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/assets/mapa_votuporanga.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/assets/mapa_votuporanga.png -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/assets/noticias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/assets/noticias.png -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/area.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/data/area.zip -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/focos/focos_1908_2408_2024.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/focos/focos_1908_2408_2024.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/data/focos/focos_1908_2408_2024.dbf -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/focos/focos_1908_2408_2024.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/focos/focos_1908_2408_2024.qmd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 0 17 | 0 18 | 19 | 20 | 21 | 22 | false 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/focos/focos_1908_2408_2024.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/data/focos/focos_1908_2408_2024.shp -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/focos/focos_1908_2408_2024.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/data/focos/focos_1908_2408_2024.shx -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/queimadas/area_interesse.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/queimadas/area_interesse.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/data/queimadas/area_interesse.dbf -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/queimadas/area_interesse.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/queimadas/area_interesse.qmd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 0 17 | 0 18 | 19 | 20 | 21 | 22 | false 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/queimadas/area_interesse.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/data/queimadas/area_interesse.shp -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/data/queimadas/area_interesse.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/data/queimadas/area_interesse.shx -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/img/love-data-day.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brazil-data-cube/code-gallery/a9fe99d822f73b69db663f3c2fd60f8f2a4afd09/jupyter/events/big-techtalks/2025-love-data-day/img/love-data-day.png -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/ldd_2025_00-big-techtalks.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "g1IGOwiFeIHP" 7 | }, 8 | "source": [ 9 | "\n", 10 | "# BIG TechTalks - Edição Especial\n", 11 | "
\n", 12 | "\n", 13 | "
\n", 14 | " \n", 15 | "
\n", 16 | "\n", 17 | "
\n", 18 | " Programa BIG - Base de Informações Georreferenciadas\n", 19 | "
\n", 20 | " CGCT - Coordenação-Geral de Ciências da Terra\n", 21 | "
\n", 22 | " INPE - Instituto Nacional de Pesquisas Espaciais, Brasil\n", 23 | "
\n", 24 | " Contato: data.support@inpe.br\n", 25 | "

\n", 26 | "\n", 27 | "
\n", 28 | "
\n", 29 | "
\n", 30 | "\n", 31 | "
\n", 32 | "\n", 33 | "
\n", 34 | "Resumo Edição especial do BIG TechTalks/INPE em celebração ao evento Love Data Day Brasil, promovido pela Sociedade Brasileira de Computação (SBC). Evento totalmente online e aberto ao público, reforçando a importância da disseminação, do acesso aberto e da valorização dos dados científicos, fundamentais para o avanço da ciência e sociedade. Na ocasião, apresentam-se dados e aplicações da plataforma Brazil Data Cube, estudos de caso com acesso e uso de imagens das coleções GOES, Sentinel-2, dados de precipitação e temperatura, uso de imagens de satélites para análise espaço-temporal de mudanças na cobertura da paisagem devido a ciclos agrícolas e ocorrência de queimadas ou incêndios.
" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": { 40 | "jp-MarkdownHeadingCollapsed": true 41 | }, 42 | "source": [ 43 | "# Programação\n", 44 | "\n", 45 | "| Horário | Tópico | Responsável |\n", 46 | "| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |\n", 47 | "| 09:00 - 09:10 | ✨ Abertura | Gilberto Queiroz
Rafael Santos |\n", 48 | "| 09:10 - 09:30 | [🌎 Plataforma Brazil Data Cube](https://data.inpe.br/bdc/web/) | Karine Reis Ferreira |\n", 49 | "| 09:30 - 09:45 | [🌎 Data Cube Explorer](https://data.inpe.br/bdc/explorer/) - Catálogo Integrado de Dados Geoespaciais | Gilberto Queiroz
Gabriel Sansigolo |\n", 50 | "| 09:45 - 10:00 | [🌎 BDC-Lab](https://data.inpe.br/bdc/lab/) - Ambiente de Ciência de Dados Geoespaciais | Luana Luz |\n", 51 | "| 10:00 - 10:45 | [🛰️ Acesso, Visualização e Processamento de Imagens Sentinel-2 utilizando Python](https://github.com/uba/code-gallery/blob/master/jupyter/events/big-techtalks/2025-love-data-day/ldd_2025_01-sentinel-2.ipynb) | Rennan Marujo |\n", 52 | "| 10:45 - 11:00 | ☕ **Pausa para o Café** | |\n", 53 | "| 11:00 - 11:10 | [🛰️ DSAT](https://www.cptec.inpe.br/dsat/) - Visualização de imagens GOES com a aplicação Web | Douglas Uba |\n", 54 | "| 11:10 - 11:45 | Acesso e Processamento de Imagens GOES utilizando STAC e Python
[🔥 Análise de Focos de Calor no Estado de SP](https://github.com/uba/code-gallery/blob/master/jupyter/events/big-techtalks/2025-love-data-day/ldd_2025_02-goes-queimadas-sp.ipynb)
[🌧️ Análise de Topos de Nuvens Associadas à Precipitação no Estado do RS](https://github.com/uba/code-gallery/blob/master/jupyter/events/big-techtalks/2025-love-data-day/ldd_2025_03-goes-chuvas-rs.ipynb) | Douglas Uba |\n", 55 | "| 11:45 - 12:00 | 🗨️ Discussão e encerramento da primeira etapa | |\n", 56 | "| 12:00 - 13:30 | 🍴 **Almoço** | |\n", 57 | "| 14:00 - 14:45 | 🌧️ Acesso a dados de Precipitação e Temperatura utilizando STAC e Python | Alex de Almeida Fernandes |\n", 58 | "| 14:45 - 15:45 | 💧 Mapeamento de parâmetros de qualidade de água com Sentinel-2
utilizando STAC, Python e R | Rogério Flores Júnior |\n", 59 | "| 15:45 - 16:45 | 🔥 Uso de imagens de satélites para análise espaço-temporal
de mudanças na cobertura da paisagem devido a ciclos agrícolas
e ocorrência de queimadas ou incêndios | Fabiano Morelli
Paulo Cunha |\n", 60 | "| 16:45 - 17:00 | 🗨️ Discussões e Encerramento | |\n", 61 | "\n", 62 | "O evento reflete os princípios celebrados no **Love Data Day**, reforçando a importância da disseminação, do acesso aberto e da valorização dos dados científicos, fundamentais para o avanço da ciência e sociedade geral.\n", 63 | "\n", 64 | "👉 **Observação:** Caso queira receber comunicados de novos eventos do BIG TechTalks, cadastre-se [aqui](https://forms.gle/FZ9vENQsUdREJk7L9).\n", 65 | "\n", 66 | "## Sobre as atividades práticas\n", 67 | "\n", 68 | "* Descoberta e acesso aos dados via catálogo integrado [🌎 STAC](https://data.inpe.br/stac/browser/), utilizando `Python` para consulta, recuperação, processamento e visualização de imagens e produtos ambientais.\n", 69 | "\n", 70 | "* Integração de diferentes sensores de satélites:\n", 71 | "\n", 72 | " - `Sentinel-2`que oferece **alta resolução espacial**, permitindo visualizar com grande detalhe a superfície da Terra.\n", 73 | "\n", 74 | " - `GOES-16`, que fornece **alta resolução temporal**, com imagens a cada 10 minutos, possibilitando acompanhar a evolução de eventos atmosféricos e na superfície em tempo quase real.\n", 75 | "\n", 76 | "* Análise de dados de temperatura estimada de superfície - `SAMeT` e estimativas de precipitação - `MERGE`.\n", 77 | "\n", 78 | "O propósito principal é demonstrar como é possível realizar de modo eficiente e rápido análises ambientais integradas a partir de um ponto único de acesso aos dados.\n", 79 | "\n", 80 | "Além disso, os processamentos são realizados diretamente no ambiente de computação interativa em nuvem do **INPE**, o [`BDC-Lab`](https://data.inpe.br/bdc/lab/). Este ambiente oferece infraestrutura de processamento sobre grandes volumes de dados, eliminando a necessidade de download de arquivos para máquinas locais. É um aspecto fundamental, pois permite ao usuário trabalhar diretamente com os dados no sistema em que estão armazenados, aproveitando ainda o poder computacional do Instituto." 81 | ] 82 | } 83 | ], 84 | "metadata": { 85 | "colab": { 86 | "provenance": [], 87 | "toc_visible": true 88 | }, 89 | "kernelspec": { 90 | "display_name": "Python (Geospatial)", 91 | "language": "python", 92 | "name": "geospatial" 93 | }, 94 | "language_info": { 95 | "codemirror_mode": { 96 | "name": "ipython", 97 | "version": 3 98 | }, 99 | "file_extension": ".py", 100 | "mimetype": "text/x-python", 101 | "name": "python", 102 | "nbconvert_exporter": "python", 103 | "pygments_lexer": "ipython3", 104 | "version": "3.11.6" 105 | } 106 | }, 107 | "nbformat": 4, 108 | "nbformat_minor": 4 109 | } 110 | -------------------------------------------------------------------------------- /jupyter/events/big-techtalks/2025-love-data-day/ldd_2025_05-fogo-merge.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "73163a6a-1070-43e4-bc21-cdd2338b9b93", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "#%pip install xarray cfgrib\n", 11 | "#%pip install cartopy\n", 12 | "#%pip install geopandas\n", 13 | "#%pip install regionmask\n", 14 | "\n", 15 | "#%pip show cartopy\n", 16 | "#%pip show cfgrib\n", 17 | "\n", 18 | "#%reset -f\n" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "id": "60219ead-b4d4-4f12-b13b-6479d8299ab7", 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "import xarray as xr\n", 29 | "import numpy as np\n", 30 | "import pandas as pd\n", 31 | "import pystac_client\n", 32 | "import pystac\n", 33 | "import itertools\n", 34 | "import requests\n", 35 | "import time\n", 36 | "import numpy as np\n", 37 | "import matplotlib.pyplot as plt\n", 38 | "import cartopy.crs as ccrs\n", 39 | "import cartopy.feature as cfeature\n", 40 | "from pathlib import Path\n", 41 | "from dateutil.parser import parse\n", 42 | "from datetime import datetime, timedelta\n", 43 | "import warnings\n", 44 | "\n", 45 | "\n", 46 | "import os\n", 47 | "os.environ['PROJ_LIB'] = \"/opt/conda/envs/geospatial/share/proj\"\n", 48 | "os.environ['decode_timedelta'] = \"True\"\n", 49 | "\n", 50 | "warnings.filterwarnings('ignore', category=DeprecationWarning)\n", 51 | "warnings.filterwarnings('ignore', category=UserWarning)\n" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "id": "cace998d-a738-428a-a1b8-0700119a7723", 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "#PySTAC\n", 62 | "service = pystac_client.Client.open('https://data.inpe.br/bdc/stac/v1/')\n", 63 | "service" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "id": "f73650df-74a1-4584-8a2b-80dd548b8964", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "collection = service.get_collection('prec_merge_hourly-1')\n", 74 | "collection" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "id": "a07eb7a8-f370-44e0-a79e-efd80811b152", 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "def download_and_read_merge_stac(\n", 85 | " stac_service: str,\n", 86 | " start_date: str,\n", 87 | " end_date: str,\n", 88 | " output_dir: str = \"merge_data\"\n", 89 | "):\n", 90 | " \"\"\"\n", 91 | " Busca, baixa e lê dados MERGE em formato GRIB2 de um catálogo STAC,\n", 92 | " filtrando por um período de datas.\n", 93 | "\n", 94 | " Args:\n", 95 | " stac_catalog_url (str): URL do catálogo/item STAC.\n", 96 | " start_date (str): Data inicial (formato ISO ou legível, ex: '2024-01-01').\n", 97 | " end_date (str): Data final (formato ISO ou legível, ex: '2024-01-31').\n", 98 | " output_dir (str): Pasta onde salvar os arquivos baixados.\n", 99 | "\n", 100 | " Returns:\n", 101 | " ds (xarray.Dataset): Dataset contendo os dados lidos.\n", 102 | " \"\"\"\n", 103 | " # Converte datas para objetos datetime\n", 104 | " start_dt = parse(start_date)\n", 105 | " end_dt = parse(end_date)\n", 106 | "\n", 107 | " # Cria diretório de saída se não existir\n", 108 | " output_path = Path(output_dir)\n", 109 | " output_path.mkdir(exist_ok=True, parents=True)\n", 110 | "\n", 111 | " downloaded_files = []\n", 112 | " time = []\n", 113 | "\n", 114 | " if isinstance(service, pystac.Catalog) and stac_service.id == 'INPE':\n", 115 | " item_search = service.search(datetime=start_date+'/'+end_date,\n", 116 | " collections=['prec_merge_hourly-1'])\n", 117 | " for asset in item_search.items():\n", 118 | " if asset.assets['merge_hourly'].href.endswith(\".grib2\"):\n", 119 | " file_url = asset.assets['merge_hourly'].href\n", 120 | " filename = Path(file_url).name\n", 121 | " file_path = output_path / filename\n", 122 | " grib_date = (asset.datetime + timedelta(hours=1)).strftime(\"%Y%m%d %H:00\")\n", 123 | " #print (grib_date)\n", 124 | "\n", 125 | " print(f\"Baixando: {file_url}\")\n", 126 | " response = requests.get(file_url, stream=True)\n", 127 | " response.raise_for_status()\n", 128 | "\n", 129 | " with open(file_path, \"wb\") as f:\n", 130 | " for chunk in response.iter_content(chunk_size=1024 * 1024):\n", 131 | " if chunk:\n", 132 | " f.write(chunk)\n", 133 | "\n", 134 | " #print(f\"Arquivo salvo: {file_path}\")\n", 135 | " downloaded_files.append(file_path)\n", 136 | " time.append(grib_date)\n", 137 | " else:\n", 138 | " raise ValueError(\"STAC URL deve apontar para um Catálogo ou Item.\")\n", 139 | "\n", 140 | " # Verifica se algum arquivo foi baixado\n", 141 | " if not downloaded_files:\n", 142 | " raise FileNotFoundError(\"Nenhum arquivo .grib2 foi encontrado no período especificado.\")\n", 143 | "\n", 144 | " # Lê os arquivos com xarray\n", 145 | " print(\"Lendo arquivos com xarray...\")\n", 146 | " \n", 147 | " # Lê múltiplos arquivos com open_mfdataset, aplicando a função preprocess\n", 148 | " ds = xr.open_mfdataset(\n", 149 | " downloaded_files,\n", 150 | " engine='cfgrib',\n", 151 | " combine='nested',\n", 152 | " concat_dim='time',\n", 153 | " decode_timedelta=True)\n", 154 | " return ds\n", 155 | "\n", 156 | "ds = download_and_read_merge_stac(service, '2024-08-09', '2024-08-10', './data/tmp')\n", 157 | "ds = ds.sortby('time')\n", 158 | "ds" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "id": "e5fb3df2-179d-4b4f-81e6-bfb74c32cfb4", 165 | "metadata": {}, 166 | "outputs": [], 167 | "source": [ 168 | "ds['rdp'].max(dim=['latitude', 'longitude']).plot()\n" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": null, 174 | "id": "bbe2a80b-d9dc-4a61-af74-2fbed8dc9c77", 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "import matplotlib.pyplot as plt\n", 179 | "import matplotlib.animation as animation\n", 180 | "import cartopy.crs as ccrs\n", 181 | "import cartopy.feature as cfeature\n", 182 | "import numpy as np\n", 183 | "\n", 184 | "def animate_precipitacao_merge(\n", 185 | " ds,\n", 186 | " var='rdp',\n", 187 | " title='Precipitação Total (MERGE)',\n", 188 | " cmap='YlGnBu',\n", 189 | " levels=np.linspace(0, 50, 51),\n", 190 | " extent=[-85, -34, -60, 15], # Extent da América do Sul\n", 191 | " interval=300, # milissegundos entre frames\n", 192 | " save_as=None # opcional: nome do arquivo para salvar (ex: 'animacao.mp4')\n", 193 | "):\n", 194 | " \"\"\"\n", 195 | " Cria uma animação da variável de precipitação do dataset MERGE para a América do Sul.\n", 196 | "\n", 197 | " Args:\n", 198 | " ds (xarray.Dataset): Dataset com os dados lidos.\n", 199 | " var (str): Nome da variável de precipitação. Padrão: 'prec'.\n", 200 | " title (str): Título do gráfico.\n", 201 | " cmap (str): Colormap usado.\n", 202 | " levels (array): Níveis do contorno para o plot.\n", 203 | " extent (list): [min_lon, max_lon, min_lat, max_lat] da região a ser plotada.\n", 204 | " interval (int): Milissegundos entre cada frame da animação.\n", 205 | " save_as (str): Nome do arquivo para salvar (opcional). Ex: 'animacao.mp4' ou 'animacao.gif'.\n", 206 | " \"\"\"\n", 207 | " # Definir projeção\n", 208 | " proj = ccrs.PlateCarree()\n", 209 | "\n", 210 | " # Criar figura e eixo com projeção geográfica\n", 211 | " fig, ax = plt.subplots(figsize=(12, 8), subplot_kw={'projection': proj})\n", 212 | "\n", 213 | " # Primeiro frame (para inicializar)\n", 214 | " pcm = ds[var][0].plot.pcolormesh(\n", 215 | " ax=ax,\n", 216 | " transform=proj,\n", 217 | " cmap=cmap,\n", 218 | " levels=levels,\n", 219 | " extend='max',\n", 220 | " add_colorbar=True,\n", 221 | " cbar_kwargs={'shrink': 0.7, 'label': 'Precipitação (mm/h)'}\n", 222 | " )\n", 223 | "\n", 224 | " # Configurações do mapa\n", 225 | " ax.set_title(title, fontsize=14)\n", 226 | " ax.set_extent(extent, crs=proj)\n", 227 | "\n", 228 | " # Adicionar limites continentais e países\n", 229 | " ax.add_feature(cfeature.LAND, facecolor='lightgray')\n", 230 | " ax.add_feature(cfeature.OCEAN, facecolor='white')\n", 231 | " ax.add_feature(cfeature.COASTLINE, linewidth=0.8)\n", 232 | " ax.add_feature(cfeature.BORDERS, linewidth=0.5, linestyle=':')\n", 233 | " ax.add_feature(cfeature.STATES, linewidth=0.3, alpha=0.5)\n", 234 | "\n", 235 | " # Grid e rótulos\n", 236 | " gl = ax.gridlines(draw_labels=True, linewidth=0.5, color='gray', alpha=0.7, linestyle='--')\n", 237 | " gl.top_labels = False\n", 238 | " gl.right_labels = False\n", 239 | "\n", 240 | " # Função de atualização de cada frame\n", 241 | " def update(frame):\n", 242 | " pcm.set_array(ds[var][frame].values.ravel())\n", 243 | " time_str = ds['time'][frame].dt.strftime(\"%Y-%m-%d %H:%M\").item()\n", 244 | " ax.set_title(f\"{title} - {time_str}\")\n", 245 | " return pcm,\n", 246 | "\n", 247 | " # Criar a animação\n", 248 | " ani = animation.FuncAnimation(\n", 249 | " fig,\n", 250 | " update,\n", 251 | " frames=ds.dims['time'],\n", 252 | " interval=interval,\n", 253 | " blit=False\n", 254 | " )\n", 255 | "\n", 256 | " plt.tight_layout()\n", 257 | "\n", 258 | " # Salvar, se necessário\n", 259 | " if save_as:\n", 260 | " if save_as.endswith('.mp4'):\n", 261 | " writer = animation.FFMpegWriter(fps=2, metadata=dict(artist='FernandesAA'), bitrate=1800)\n", 262 | " ani.save(save_as, writer=writer)\n", 263 | " elif save_as.endswith('.gif'):\n", 264 | " ani.save(save_as, writer='pillow', fps=2)\n", 265 | " else:\n", 266 | " raise ValueError(\"Formato não suportado. Use .mp4 ou .gif\")\n", 267 | "\n", 268 | " plt.close() # Evita mostrar o plot estático\n", 269 | " return ani # Retorna a animação para exibição no Jupyter" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": null, 275 | "id": "a50d7af8-c93c-4c53-9e90-64f9af1cc84a", 276 | "metadata": {}, 277 | "outputs": [], 278 | "source": [ 279 | "# Chamar a função de animação\n", 280 | "ani = animate_precipitacao_merge(ds.sortby('time'), extent=[-52.9518,-44.1291,-25.7323,-19.2479], levels=np.linspace(0, 10, 11), var='rdp')\n", 281 | "\n", 282 | "# Para exibir no notebook:\n", 283 | "from IPython.display import HTML\n", 284 | "HTML(ani.to_jshtml())" 285 | ] 286 | } 287 | ], 288 | "metadata": { 289 | "kernelspec": { 290 | "display_name": "Python 3 (ipykernel)", 291 | "language": "python", 292 | "name": "python3" 293 | }, 294 | "language_info": { 295 | "codemirror_mode": { 296 | "name": "ipython", 297 | "version": 3 298 | }, 299 | "file_extension": ".py", 300 | "mimetype": "text/x-python", 301 | "name": "python", 302 | "nbconvert_exporter": "python", 303 | "pygments_lexer": "ipython3", 304 | "version": "3.11.9" 305 | } 306 | }, 307 | "nbformat": 4, 308 | "nbformat_minor": 5 309 | } 310 | -------------------------------------------------------------------------------- /rmarkdown/R/bdc-article/00_TableOfContents.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "." 3 | 4 | knit: (function(input, ...) { 5 | rmarkdown::render( 6 | input, 7 | output_file = paste0( 8 | '~/', basename(input), '.html' 9 | ), 10 | intermediates_dir = '~/', 11 | envir = globalenv(), 12 | output_format = rmarkdown::html_document(css = c("https://pro.fontawesome.com/releases/v5.11.0/css/all.css")) 13 | ) 14 | }) 15 | --- 16 | 17 | 18 | 19 | # Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products 20 |
21 | 22 |
23 | 24 |
25 | 26 | Rolf E. O. Simões , Alber H. Sanchez , Felipe M. Carlos , Leonardo S. Vieira ,
27 | 28 | Karine R. Ferreira , Lubia Vinhas , Gilberto R. Queiroz* 29 |

30 | Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE) 31 |
32 | Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil 33 |

34 | * Author to whom correspondence should be addressed. 35 |

36 | February 24, 2021 37 |
38 | 39 |
40 | 41 |
42 | Abstract. This RMarkdown compendium contains useful information for the creation of land use and land cover (LULC) maps using Earth observations data cubes and machine learning (ML) techniques. The code is based on the research pipeline described in the paper Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. These notebooks access open data available in the Brazil Data Cube platform. 43 |
44 | 45 |
46 |
47 | This RMarkdown page is supplement to the Section 5 of the following paper: 48 |
49 | Ferreira, K.R.; Queiroz, G.R.; Vinhas, L.; Marujo, R.F.B.; Simoes, R.E.O.; Picoli, M.C.A.; Camara, G.; Cartaxo, R.; Gomes, V.C.F.; Santos, L.A.; Sanchez, A.H.; Arcanjo, J.S.; Fronza, J.G.; Noronha, C.A.; Costa, R.W.; Zaglia, M.C.; Zioti, F.; Korting, T.S.; Soares, A.R.; Chaves, M.E.D.; Fonseca, L.M.G. 2020. Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. Remote Sens. 12, no. 24: 4033. DOI: 10.3390/rs12244033. 50 |
51 |
52 | 53 | # Table of Contents 54 |
55 | 56 | The Jupyter Notebooks are organized as follow: 57 | 58 | 59 | 60 | 61 | * [Extracting time series from sample locations](./01_ExtractTimeSeries.html) 62 | 63 | * [Land Use and Cover Mapping from CBERS-4/AWFI Data Cubes](./02_CB4_64_16D_STK-1.html) 64 | 65 | * [Validation results for CBERS-4/AWFI classification](./03_Validation_CB4_64_16D_STK-1.html) 66 | 67 | * [Land Use and Cover Mapping from Landsat-8/OLI Data Cubes](./04_LC8_30_16D_STK-1.html) 68 | 69 | * [Validation results for Landsat-8/OLI classification](./05_Validation_LC8_30_16D_STK-1.html) 70 | 71 | * [Land Use and Cover Mapping from Sentinel-2/MSI Data Cubes](./06_S2_10_16D_STK-1.html) 72 | 73 | * [Validation results for Sentinel-2/MSI classification](./07_Validation_S2_10_16D_STK-1.html) 74 | 75 | 76 | Interest readers should try the notebooks in the proposed order as their contents are complementary. 77 | 78 | # Study Area 79 |
80 | 81 | The study area is located in the Bahia state, Brazil, between the Cerrado and Caatinga biomes as depicted in Figure 1. 82 | 83 |
84 | 85 |
86 |
Figure 1 - Study area in relation to Brazil and its biomes.
87 | 88 | The code cell below shows the study area location in relation to Brazil: 89 | 90 | ```{r} 91 | library(leaflet) 92 | 93 | # 94 | # load sample and roi layers 95 | # 96 | region_of_interest <- sf::st_read("/vsicurl/https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/roi/shp/roi.shp", quiet = TRUE) 97 | training_samples <- sf::st_read("/vsicurl/https://brazildatacube.dpi.inpe.br/public/bdc-article/training-samples/shp/bdc_paper_samples.shp", quiet = TRUE) 98 | 99 | # 100 | # create a color map 101 | # 102 | factpal <- colorFactor( 103 | palette = c("#e18e18", "#4ad060", "#fcfe7b"), 104 | domain = c("Crop", "Natural", "Pasture") 105 | ) 106 | 107 | # 108 | # create the map 109 | # 110 | leaflet::leaflet(width="100%", height="600px") %>% 111 | addProviderTiles(providers$Esri.WorldImagery) %>% 112 | setView(lng = -45.5, lat = -12.8, zoom = 9) %>% 113 | addPolygons(data = region_of_interest) %>% 114 | 115 | addCircleMarkers(data = training_samples, 116 | popup = ~label, 117 | color = ~factpal(label), 118 | radius = 4, 119 | stroke = FALSE, 120 | fillOpacity = 1) %>% 121 | 122 | addLegend("topright", 123 | pal = factpal, 124 | values = training_samples$label, 125 | title = "Training Samples", 126 | opacity = 1) 127 | ``` 128 | 129 | # Auxiliary Data 130 |
131 | 132 | All the datasets used in this application along with the results are available from the web in the following URL: 133 | 134 | * https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/ 135 | 136 | The folders are organized as follows: 137 | 138 | * `results`: This directory contains the set of thematic maps resulting from the classification process. For each satellite/sensor there is a subdirectory with two GeoTIFFs, one with the estimated probabilities of each LULC class, and the other with the final class. 139 | 140 | * `roi`: This directory contains the polygon representing the region of interest (the envelope of the validation samples in Figure 1). 141 | 142 | * `scripts`: R scripts with the application pipeline. 143 | 144 | * `training-samples`: This directory contains the sample set used for training the Multilayer Perceptron (MLP) model used in the application. The original sample points are available in CSV and ESRI Shapefile formats. The RDS files contain the time series for each sample point along with some spectral bands and vegetation indices. 145 | 146 | * `validation-samples`: This directory contains the sample set used to validate the classified maps. 147 | 148 | -------------------------------------------------------------------------------- /rmarkdown/R/bdc-article/01_ExtractTimeSeries.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "." 3 | 4 | knit: (function(input, ...) { 5 | rmarkdown::render( 6 | input, 7 | output_file = paste0( 8 | '~/', basename(input), '.html' 9 | ), 10 | intermediates_dir = '~/', 11 | envir = globalenv(), 12 | output_format = rmarkdown::html_document(css = c("https://pro.fontawesome.com/releases/v5.11.0/css/all.css")) 13 | ) 14 | }) 15 | --- 16 | 17 | 18 | 19 | # Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products 20 |
21 | 22 |
23 | 24 |
25 | 26 | Rolf E. O. Simões , Alber H. Sanchez , Felipe M. Carlos , Leonardo S. Vieira ,
27 | 28 | Karine R. Ferreira , Lubia Vinhas , Gilberto R. Queiroz* 29 |

30 | Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE) 31 |
32 | Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil 33 |

34 | * Author to whom correspondence should be addressed. 35 |

36 | February 24, 2021 37 |
38 | 39 |
40 | 41 |
42 | Abstract. This RMarkdown compendium contains useful information for the creation of land use and land cover (LULC) maps using Earth observations data cubes and machine learning (ML) techniques. The code is based on the research pipeline described in the paper Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. These notebooks access open data available in the Brazil Data Cube platform. 43 |
44 | 45 |
46 |
47 | This RMarkdown page is supplement to the Section 5 of the following paper: 48 |
49 | Ferreira, K.R.; Queiroz, G.R.; Vinhas, L.; Marujo, R.F.B.; Simoes, R.E.O.; Picoli, M.C.A.; Camara, G.; Cartaxo, R.; Gomes, V.C.F.; Santos, L.A.; Sanchez, A.H.; Arcanjo, J.S.; Fronza, J.G.; Noronha, C.A.; Costa, R.W.; Zaglia, M.C.; Zioti, F.; Korting, T.S.; Soares, A.R.; Chaves, M.E.D.; Fonseca, L.M.G. 2020. Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. Remote Sens. 12, no. 24: 4033. DOI: 10.3390/rs12244033. 50 |
51 |
52 | 53 | # Extracting time series from sample locations 54 |
55 | 56 | This document describes the process of extracting time series from EO data cubes associated with LULC samples. This information is required during the creation and training of the model based on a MultiLayer Perceptron neural network described later in the notebooks related to the classification process. 57 | 58 | In general, at this stage, as shown in the Figure 1, for each sample, a temporal spectral signature is associated considering different bands and vegetation indices. This allows each sample's labels to be linked to a specific temporal variation pattern, which is used by the algorithms for classification. 59 | 60 |
61 | 62 |
63 |
64 |
Figure 1 - Temporal patterns based on spectral signature.
Source: Victor Maus
65 | 66 | # The SITS R package 67 |
68 | 69 | 70 | For the time series extraction process we use the [SITS R package](https://github.com/e-sensing/sits).It can be loaded with the `library` command: 71 | 72 | ```{r} 73 | library(sits) 74 | ``` 75 | 76 | The access to the Brazil Data Cube (BDC) data products requires an **access key**. If you have an account for the Brazil Data Cube services, [sign in](https://brazildatacube.dpi.inpe.br/auth-app) and replace the key value in the code cell below. If you do not have an account, [sign up](https://brazildatacube.dpi.inpe.br/auth-app) to create an account and get the access key. 77 | 78 | ```{r} 79 | MY_ACCESS_KEY <- "change-me" 80 | 81 | Sys.setenv(BDC_ACCESS_KEY = MY_ACCESS_KEY) 82 | ``` 83 | 84 | ## Crop Calendar 85 |
86 | 87 | We use the region's agricultural calendar year that ranges from September 2018 to August 2019: 88 | 89 | ```{r} 90 | start_date <- "2018-09-01" 91 | end_date <- "2019-08-31" 92 | ``` 93 | 94 | ## Sample Data Points 95 |
96 | 97 | The sample set that will be used to train the MLP model described in the manuscript contains 922 data points organized into three classes: 98 | 99 | * Crop (242) 100 | * Natural Vegetation (422) 101 | * Pasture (258) 102 | 103 | The file `training-samples.csv` in the folder `training-samples` contains the labeled data points. 104 | 105 | ```{r} 106 | sample_file <- "https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/training-samples/training-samples.csv" 107 | ``` 108 | 109 | As one can see, this file contains the location (`latitude`/`longitude`), a timestamp (`start_date`/`end_date`) and a label: 110 | 111 | ```{r} 112 | head( read.csv(sample_file) ) 113 | ``` 114 | 115 | The SITS package contains some facilities to read the location of these samples and to extract the time series from data cubes. This process will result in a dataframe where each sample point is associated to time series from spectral bands and vegetation indices. 116 | 117 | ## Creating the Output Directory 118 |
119 | 120 | Let's create an output folder for the datasets generated by this notebook. We are going to choose a folder named `training-samples`: 121 | 122 | ```{r} 123 | output_dir <- "training-samples" 124 | 125 | dir.create( 126 | path = output_dir, 127 | showWarnings = FALSE, 128 | recursive = TRUE 129 | ) 130 | ``` 131 | 132 | ## Time Series Extraction 133 |
134 | 135 | ### CBERS-4/AWFI (16 days 'stack') 136 | 137 | The `sits_cube` function can be used to define the working data cube and the interest spectral bands and vegetation indices: 138 | 139 | ```{r} 140 | cb4_cube <- sits_cube( 141 | type = "BDC", 142 | url = "https://brazildatacube.dpi.inpe.br/stac/", 143 | collection = "CB4_64_16D_STK-1", 144 | start_date = start_date, 145 | end_date = end_date, 146 | bands = c("BAND15", "BAND14", "BAND13", "BAND16", "NDVI", "EVI") 147 | ) 148 | ``` 149 | 150 | In the above cell we provided the following arguments 151 | 152 | * `type`: Inform that the data cube will be based on the Brazil Data Cube definitions. 153 | 154 | * `url`: The SpatioTemporal Asset Catalog address for BDC data cubes. In this sandbox you can use the following address: https://brazildatacube.dpi.inpe.br/stac/ 155 | 156 | * `collection`: Defines the use of CBERS-4/AWFI data cube. 157 | 158 | * `start_date` and `end_date`: The temporal interval of interest. 159 | 160 | * `bands`: The list of spectral bands and spectral indices that will be accessed. 161 | 162 | The `sits_get_data` retries the time series from the defined data cube `cb4_cube` using the locations in the sample file: 163 | 164 | ```{r} 165 | cb4_samples_with_ts <- sits_get_data(cube = cb4_cube, file = sample_file) 166 | ``` 167 | 168 | The structure of the returned dataframe can be seen below: 169 | 170 | ```{r} 171 | head(cb4_samples_with_ts, 2) 172 | ``` 173 | 174 | If you want to plot the NDVI time series for all the LULC classes, use the following `plot` function: 175 | 176 | ```{r} 177 | plot(sits_select(cb4_samples_with_ts, bands = c("NDVI"))) 178 | ``` 179 | 180 | If you are interested only in a single class: 181 | 182 | ```{r} 183 | plot(sits_select(cb4_samples_with_ts[cb4_samples_with_ts$label == "Pasture",], bands = c("NDVI"))) 184 | ``` 185 | 186 | Finally, let's save the dataframe with the samples and time series in a file named `CB4_64_16D_STK_1.rds`. We are going to use it later on the classification notebook. 187 | 188 | ```{r} 189 | saveRDS(cb4_samples_with_ts, paste0(output_dir, "/CB4_64_16D_STK_1.rds")) 190 | ``` 191 | 192 | ### Landsat-8/OLI (16 days 'stack') 193 | 194 | The following code cells repeat the process described on the previous section to the Landsat-8 data cube. 195 | 196 | ```{r} 197 | l8_cube <- sits_cube( 198 | type = "BDC", 199 | name = "bdc-l8", 200 | url = "https://brazildatacube.dpi.inpe.br/stac/", 201 | collection = "LC8_30_16D_STK-1", 202 | start_date = start_date, 203 | end_date = end_date, 204 | bands = c("band4", "band3", "band2", "band5", "NDVI", "EVI") 205 | ) 206 | ``` 207 | 208 | ```{r} 209 | l8_samples_with_ts <- sits_get_data(cube = l8_cube, file = sample_file) 210 | 211 | saveRDS(l8_samples_with_ts, paste0(output_dir, "/LC8_30_16D_STK_1.rds")) 212 | ``` 213 | 214 | ### Sentinel-2/MSI (16 days 'stack') 215 | 216 | The following code cells repeat the process described on the CBERS-4/AWFI data cube section to the Sentinel-2 data cube. 217 | 218 | ```{r} 219 | s2_cube <- sits_cube( 220 | type = "BDC", 221 | name = "bdc-s2", 222 | url = "https://brazildatacube.dpi.inpe.br/stac/", 223 | collection = "S2_10_16D_STK-1", 224 | start_date = start_date, 225 | end_date = end_date, 226 | bands = c("band4", "band3", "band2", "band8", "NDVI", "EVI") 227 | ) 228 | ``` 229 | 230 | ```{r} 231 | s2_samples_with_ts <- sits_get_data(cube = s2_cube, file = sample_file) 232 | 233 | saveRDS(s2_samples_with_ts, paste0(output_dir, "/S2_10_16D_STK_1.rds")) 234 | ``` 235 | 236 | # Final Remarks 237 |
238 | 239 | * A copy of the training samples with the time series for each satellite/sensor data cube can be found in the folder `training-samples/rds`. 240 | 241 | * If you want to download and run this notebook in a workflow as a script, you can perform its parameterization through the [papermill library](https://github.com/nteract/papermill). 242 | 243 | * The data cubes used to extract the time series are also available on [BDC-STAC](https://brazildatacube.dpi.inpe.br/stac/). 244 | -------------------------------------------------------------------------------- /rmarkdown/R/bdc-article/02_CB4_64_16D_STK-1_Classification.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "." 3 | 4 | knit: (function(input, ...) { 5 | rmarkdown::render( 6 | input, 7 | output_file = paste0( 8 | '~/', basename(input), '.html' 9 | ), 10 | intermediates_dir = '~/', 11 | envir = globalenv(), 12 | output_format = rmarkdown::html_document(css = c("https://pro.fontawesome.com/releases/v5.11.0/css/all.css")) 13 | ) 14 | }) 15 | --- 16 | 17 | 18 | 19 | # Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products 20 |
21 | 22 |
23 | 24 |
25 | 26 | Rolf E. O. Simões , Alber H. Sanchez , Felipe M. Carlos , Leonardo S. Vieira ,
27 | 28 | Karine R. Ferreira , Lubia Vinhas , Gilberto R. Queiroz* 29 |

30 | Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE) 31 |
32 | Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil 33 |

34 | * Author to whom correspondence should be addressed. 35 |

36 | February 24, 2021 37 |
38 | 39 |
40 | 41 |
42 | Abstract. This RMarkdown compendium contains useful information for the creation of land use and land cover (LULC) maps using Earth observations data cubes and machine learning (ML) techniques. The code is based on the research pipeline described in the paper Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. These notebooks access open data available in the Brazil Data Cube platform. 43 |
44 | 45 |
46 |
47 | This RMarkdown page is supplement to the Section 5 of the following paper: 48 |
49 | Ferreira, K.R.; Queiroz, G.R.; Vinhas, L.; Marujo, R.F.B.; Simoes, R.E.O.; Picoli, M.C.A.; Camara, G.; Cartaxo, R.; Gomes, V.C.F.; Santos, L.A.; Sanchez, A.H.; Arcanjo, J.S.; Fronza, J.G.; Noronha, C.A.; Costa, R.W.; Zaglia, M.C.; Zioti, F.; Korting, T.S.; Soares, A.R.; Chaves, M.E.D.; Fonseca, L.M.G. 2020. Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. Remote Sens. 12, no. 24: 4033. DOI: 10.3390/rs12244033. 50 |
51 |
52 | 53 | # Land Use and Cover Mapping from CBERS-4/AWFI Data Cubes 54 |
55 | 56 | This document will present the steps to create a LULC map based on CBERS-4/AWFI data cube, training samples and a MultiLayer Perceptron neural network. This code relies on the [SITS R package](https://github.com/e-sensing/sits). 57 | 58 | ## Study Area and samples 59 |
60 | 61 | In this application we use the same region of interest and samples described in [Ferreira et al. (2020)](https://doi.org/10.3390/rs12244033). As depicted in Figure 1, the region is located in the Bahia state (Brazil), between the Cerrado and Caatinga biomes. 62 | 63 |
64 | 65 |
66 |
67 |
Figure 1 - Study area in relation to Brazil and its biomes.
68 | 69 | ## Set a pseudo-randomic seed 70 |
71 | 72 | We will fix a pseudo-randomic seed in order to run the code: 73 | 74 | ```{r} 75 | set.seed(777) 76 | ``` 77 | 78 | ## Loading the software packages 79 |
80 | 81 | ```{r} 82 | library(sits) 83 | ``` 84 | 85 | The user should also provides his access key to the Brazil Data Cube platform: 86 | 87 | ```{r} 88 | MY_ACCESS_KEY <- "change-me" 89 | Sys.setenv(BDC_ACCESS_KEY = MY_ACCESS_KEY) 90 | ``` 91 | 92 | ## Defining the Data Cube 93 |
94 | 95 | Let's start by defining the region of interest (ROI) as a sub-space of the red rectangle shown in Figure 1. 96 | 97 | The ROI is available in a file name `roi.rds` under the directory `roi`: 98 | 99 | ```{r} 100 | roi <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/roi/roi.rds")) 101 | ``` 102 | 103 | > The `roi` is a list with two components: 104 | > * `classification_roi`: contains the geometry boundary for the classification. 105 | > * `search_roi`: a smaller rectangle than the `classification_roi`, that intersects only the data cube tiles we are interested to use in the classification. 106 | 107 | Next we define a time interval based on the crop calendar to define the working period: 108 | 109 | ```{r} 110 | start_date <- "2018-09-01" 111 | end_date <- "2019-08-31" 112 | ``` 113 | 114 | In this Jupyter Notebook we focus the classification based on a CBERS-4/AWFI data cube named `CB4_64_16D_STK-1`: 115 | 116 | ```{r} 117 | collection <- "CB4_64_16D_STK-1" 118 | ``` 119 | 120 | Finally, let's define the data cube. 121 | 122 | The `sits` package will access the CBERS-4/AWFI data cube available in the Brazil Data Cube platform through the STAC web service: 123 | 124 | ```{r} 125 | cube <- sits_cube( 126 | type = "BDC", 127 | name = "cube_to_classify", 128 | url = "https://brazildatacube.dpi.inpe.br/stac/", 129 | collection = collection, 130 | start_date = start_date, 131 | end_date = end_date, 132 | roi = roi$search_roi 133 | ) 134 | ``` 135 | 136 | > The definition above includes the spectral bands `Red`, `Green`, `Blue`, `Near-Infrared (NIR)` and the vegetation indices `EVI` and `NDVI` already available in the cube. 137 | 138 | > It also limits the temporal extension to `2018-09` to `2019-08`. 139 | 140 | ## Loading the Training Samples 141 |
142 | 143 | Now, let's load the samples from a prepared file named `CB4_64_16D_STK_1.rds`: 144 | 145 | ```{r} 146 | samples <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/training-samples/rds/CB4_64_16D_STK_1.rds")) 147 | ``` 148 | 149 | > The Jupyter Notebook entitled [Extracting time series from sample locations](./01_ExtractTimeSeries.ipynb) describes in detail how to prepare this file. 150 | 151 | ## MultiLayer Perceptron model definition 152 |
153 | 154 | For the classification of data cubes, the article presents the use of an MLP network with five hidden layers with 512 neurons, trained with the backpropagation algorithm, using the Adam optimizer. The model uses the ReLu activation function. 155 | 156 | Below is the definition of this model using the [SITS package](https://github.com/e-sensing/sits). 157 | 158 | ```{r} 159 | mlp_model <- sits_deeplearning(layers = c(512, 512, 512, 512, 512), 160 | activation = "relu", 161 | optimizer = keras::optimizer_adam(lr = 0.001), 162 | epochs = 200) 163 | ``` 164 | 165 | Below, the defined model is trained using the same samples used in the article. 166 | 167 | ```{r} 168 | dl_model <- sits_train(samples, mlp_model) 169 | ``` 170 | 171 | ## Output Directory 172 |
173 | 174 | All the results generated in this document will be saved in your user's home directory, inside `results/CB4_64_16D_STK_1` directory: 175 | 176 | ```{r} 177 | output_dir <- "results/CB4_64_16D_STK_1" 178 | 179 | dir.create( 180 | path = output_dir, 181 | showWarnings = FALSE, 182 | recursive = TRUE 183 | ) 184 | ``` 185 | 186 | ## Classifying the tiles from the data cube 187 |
188 | 189 | Before running the classification step, you should define the hardware resources that `sits` will be allowed to use during the classification: 190 | 191 | ```{r} 192 | classification_memsize <- 8 # GB 193 | classification_multicores <- 3 # CPU logical cores 194 | ``` 195 | 196 | The next cell uses the trainned MLP model (`dl_model`) to perform a classification based on the temporal data from the data cube: 197 | 198 | 199 | > This is a time-consuming process. 200 | 201 | ```{r} 202 | probs <- sits_classify(data = cube, 203 | ml_model = dl_model, 204 | memsize = classification_memsize, 205 | multicores = classification_multicores, 206 | roi = roi$classification_roi, 207 | output_dir = output_dir) 208 | ``` 209 | 210 | > The generated data will be stored under the directory indicated by `output_dir`. 211 | 212 | > Note that here we use a geometry boundary from `roi$classification_roi` that is smaller than the region defined by the samples. 213 | 214 | The classification output of the Multilayer Perceptron (MLP) model is a raster with three layers (one for each land use class) containing the probabilities of each pixel belonging to each of the classes. 215 | 216 | The raster file named `cube_to_classify_022024_probs_2018_8_2019_7_v1.tif` has 3 layers containing scaled probabilities (`x 10,000`) corresponding to the classes `Crop` (layer 1), `Natural Vegetation` (layer 2), and `Pasture` (layer 3). 217 | 218 | ## Generating the Thematic Map 219 |
220 | 221 | We are going to apply a probability Bayesian smoother method over the output of the MLP. This procedure uses the information of a pixel’s neighborhood to update its probabilities by taking the maximum likelihood estimator. The smoothing procedure removes isolated pixel class values and produces more homogeneous spatial areas. 222 | 223 | The next cell perform this operation: 224 | 225 | ```{r} 226 | probs_smoothed <- sits_smooth(probs, type = "bayes", output_dir = output_dir) 227 | ``` 228 | 229 | > The above cell will create a file name `cube_to_classify_022024_probs_2018_8_2019_7_bayes_v1.tif`. 230 | 231 | After that, to generate the thematic maps the most probable class is taken as the pixel class. Each class is represented by the codes 1 (Crop), 2 (Natural Vegetation), and 3 (Pasture). The next cell show how to perform this step: 232 | 233 | ```{r} 234 | labels <- sits_label_classification(probs_smoothed, output_dir = output_dir) 235 | ``` 236 | 237 | > The final map is named `cube_to_classify_022024_probs_class_2018_8_2019_7_v1.tif`. 238 | 239 | ## Visualizing the Thematic Map 240 |
241 | 242 | Finally, let's use the `rgdal` library to plot the resulted map: 243 | 244 | ```{r} 245 | library(rgdal) 246 | ``` 247 | 248 | ```{r} 249 | rst <- raster::raster( 250 | paste0(output_dir, "/cube_to_classify_022024_probs_class_2018_8_2019_7_v1.tif") 251 | ) 252 | ``` 253 | 254 | ```{r} 255 | plot(rst) 256 | ``` 257 | -------------------------------------------------------------------------------- /rmarkdown/R/bdc-article/03_CB4_64_16D_STK-1_Validation.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "." 3 | 4 | knit: (function(input, ...) { 5 | rmarkdown::render( 6 | input, 7 | output_file = paste0( 8 | '~/', basename(input), '.html' 9 | ), 10 | intermediates_dir = '~/', 11 | envir = globalenv(), 12 | output_format = rmarkdown::html_document(css = c("https://pro.fontawesome.com/releases/v5.11.0/css/all.css")) 13 | ) 14 | }) 15 | --- 16 | 17 | 18 | 19 | # Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products 20 |
21 | 22 |
23 | 24 |
25 | 26 | Rolf E. O. Simões , Alber H. Sanchez , Felipe M. Carlos , Leonardo S. Vieira ,
27 | 28 | Karine R. Ferreira , Lubia Vinhas , Gilberto R. Queiroz* 29 |

30 | Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE) 31 |
32 | Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil 33 |

34 | * Author to whom correspondence should be addressed. 35 |

36 | February 24, 2021 37 |
38 | 39 |
40 | 41 |
42 | Abstract. This RMarkdown compendium contains useful information for the creation of land use and land cover (LULC) maps using Earth observations data cubes and machine learning (ML) techniques. The code is based on the research pipeline described in the paper Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. These notebooks access open data available in the Brazil Data Cube platform. 43 |
44 | 45 |
46 |
47 | This RMarkdown page is supplement to the Section 5 of the following paper: 48 |
49 | Ferreira, K.R.; Queiroz, G.R.; Vinhas, L.; Marujo, R.F.B.; Simoes, R.E.O.; Picoli, M.C.A.; Camara, G.; Cartaxo, R.; Gomes, V.C.F.; Santos, L.A.; Sanchez, A.H.; Arcanjo, J.S.; Fronza, J.G.; Noronha, C.A.; Costa, R.W.; Zaglia, M.C.; Zioti, F.; Korting, T.S.; Soares, A.R.; Chaves, M.E.D.; Fonseca, L.M.G. 2020. Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. Remote Sens. 12, no. 24: 4033. DOI: 10.3390/rs12244033. 50 |
51 |
52 | 53 | # Validation results for CBERS-4/AWFI classification 54 |
55 | 56 | This document presents the process for the validation of the results generated in the classification made using the CBERS-4/AWFI data cube. 57 | 58 | The validation procedure of the land use and land cover thematic followed the good practice guidelines for accuracy assessment based on reference data proposed by [Olofsson et al. (2014)](https://doi.org/10.1016/j.rse.2014.02.015). 59 | 60 | > The Jupyter Notebook entitled [Land Use and Cover Mapping from CBERS-4/AWFI Data Cubes](./02_CB4_64_16D_STK-1.ipynb) describes in detail how to create the thematic map used here. 61 | 62 | ## Loading the software packages 63 |
64 | 65 | In this example, the validation process uses the [SITS R package](https://github.com/e-sensing/sits): 66 | 67 | ```{r} 68 | library(sits) 69 | ``` 70 | 71 | We are going to use functionalities from the `sf` package as well: 72 | 73 | ```{r} 74 | library(sf) 75 | ``` 76 | 77 | ## Load data 78 |
79 | 80 | To perform the validation, it is initially necessary to load the classification results and the samples used as a reference. 81 | 82 | ```{r} 83 | classification_results <- raster::raster(paste0("/vsicurl/https://brazildatacube.dpi.inpe.br/", 84 | "geo-knowledge-hub/bdc-article/results/CB4_64_16D_STK_1/", 85 | "cube_to_classify_022024_probs_class_2018_8_2019_7_v1.tif")) 86 | 87 | validation_samples <- readRDS(url(paste0("https://brazildatacube.dpi.inpe.br/", 88 | "geo-knowledge-hub/bdc-article/validation-samples/", 89 | "validation-samples.rds"))) 90 | ``` 91 | 92 | > If you want to use the output generated in the previous Jupyter Notebook, entitled [Land Use and Cover Mapping from CBERS-4/AWFI Data Cubes](./02_CB4_64_16D_STK-1.ipynb), you can replace the url by the path `results/CB4_64_16D_STK_1` in the first line of the above cell. 93 | 94 | The cell code below shows the region of the validation samples: 95 | 96 | ```{r} 97 | library(leaflet) 98 | 99 | # 100 | # extract reference 101 | # 102 | reference_val <- validation_samples$geom$reference 103 | region_of_interest <- sf::st_read("/vsicurl/https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/roi/shp/roi.shp", quiet = TRUE) 104 | 105 | # 106 | # rename values 107 | # 108 | reference_val[reference_val == 1] <- 'Natural' 109 | reference_val[reference_val == 2] <- 'Anthropic' 110 | 111 | # 112 | # create a color function 113 | # 114 | factpal <- colorFactor( 115 | palette = c("#ea18d2", "#44ea57"), 116 | domain = c( "Anthropic", "Natural") 117 | ) 118 | 119 | # 120 | # generate the map! 121 | # 122 | leaflet::leaflet(validation_samples$geom, width="100%", height="600px") %>% 123 | addProviderTiles(providers$Esri.WorldImagery) %>% 124 | setView(lng = -45.5, lat = -12.8, zoom = 9) %>% 125 | 126 | addPolygons(data = region_of_interest) %>% 127 | addCircleMarkers(popup = reference_val, color = factpal(reference_val), 128 | radius = 4, stroke = FALSE, fillOpacity = 1) %>% 129 | 130 | addLegend("topright", 131 | pal = factpal, 132 | values = reference_val, 133 | title = "Validation Samples", 134 | opacity = 1) 135 | ``` 136 | 137 | ## Extract predicted values 138 |
139 | 140 | With the rasters and reference samples loaded, it will now be necessary to extract the values corresponding to each of the validation samples' locations from the classified raster. This extraction allows the comparison of the predicted and reference values. 141 | 142 | > For extraction at each location, the `extract` function of the [raster package](https://cran.r-project.org/web/packages/raster/raster.pdf) is used. 143 | 144 | In the next cell $x$ corresponds to the classified raster and $y$ to the location of the validation samples: 145 | 146 | ```{r} 147 | predicted_values <- raster::extract( 148 | x = classification_results, 149 | y = validation_samples$geom 150 | ) 151 | ``` 152 | 153 | The `predicted_values` is a vector with the same length as `validation_samples`, whose values correspond to classes from the input classified raster. 154 | 155 | ## Transform extracted values 156 |
157 | 158 | We base the validation on two classes, the `Natural Vegetation` class and on a new broader class named `Anthropic`. 159 | 160 | To obtain the `Anthropic` class we have to merge the `Crop` and `Pasture` classes. So, in the `predicted_values` vector we will temporarily relabel the cells `Natural Vegetation` from code `2` to `5`: 161 | 162 | ```{r} 163 | predicted_values[predicted_values == 2] <- 5 164 | ``` 165 | 166 | Then, we can relabel `Pasture` (1) and `Agriculture` (3) to the equivalent PRODES `Anthropic` class (2): 167 | 168 | ```{r} 169 | predicted_values[predicted_values == 1] <- 2 170 | predicted_values[predicted_values == 3] <- 2 171 | ``` 172 | 173 | Finally, we can set the `Natural Vegetation` cells to value `1` again: 174 | 175 | ```{r} 176 | predicted_values[predicted_values == 5] <- 1 177 | ``` 178 | 179 | > When the classification process is carried out, there is no way to specify the values assigned to each of the classes being identified. Thus, it may be necessary to check the classification values and their corresponding elements so that the values are used for comparison. 180 | 181 | ## Evaluating 182 |
183 | 184 | ```{r} 185 | sits_conf_matrix(list( 186 | predicted = predicted_values, 187 | reference = validation_samples$reference 188 | )) 189 | ``` 190 | 191 | -------------------------------------------------------------------------------- /rmarkdown/R/bdc-article/05_LC8_30_16D_STK-1_Validation.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "." 3 | 4 | knit: (function(input, ...) { 5 | rmarkdown::render( 6 | input, 7 | output_file = paste0( 8 | '~/', basename(input), '.html' 9 | ), 10 | intermediates_dir = '~/', 11 | envir = globalenv(), 12 | output_format = rmarkdown::html_document(css = c("https://pro.fontawesome.com/releases/v5.11.0/css/all.css")) 13 | ) 14 | }) 15 | --- 16 | 17 | 18 | 19 | # Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products 20 |
21 | 22 |
23 | 24 |
25 | 26 | Rolf E. O. Simões , Alber H. Sanchez , Felipe M. Carlos , Leonardo S. Vieira ,
27 | 28 | Karine R. Ferreira , Lubia Vinhas , Gilberto R. Queiroz* 29 |

30 | Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE) 31 |
32 | Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil 33 |

34 | * Author to whom correspondence should be addressed. 35 |

36 | February 24, 2021 37 |
38 | 39 |
40 | 41 |
42 | Abstract. This RMarkdown compendium contains useful information for the creation of land use and land cover (LULC) maps using Earth observations data cubes and machine learning (ML) techniques. The code is based on the research pipeline described in the paper Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. These notebooks access open data available in the Brazil Data Cube platform. 43 |
44 | 45 |
46 |
47 | This RMarkdown page is supplement to the Section 5 of the following paper: 48 |
49 | Ferreira, K.R.; Queiroz, G.R.; Vinhas, L.; Marujo, R.F.B.; Simoes, R.E.O.; Picoli, M.C.A.; Camara, G.; Cartaxo, R.; Gomes, V.C.F.; Santos, L.A.; Sanchez, A.H.; Arcanjo, J.S.; Fronza, J.G.; Noronha, C.A.; Costa, R.W.; Zaglia, M.C.; Zioti, F.; Korting, T.S.; Soares, A.R.; Chaves, M.E.D.; Fonseca, L.M.G. 2020. Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. Remote Sens. 12, no. 24: 4033. DOI: 10.3390/rs12244033. 50 |
51 |
52 | 53 | # Validation results for Landsat-8/OLI classification 54 |
55 | 56 | This document presents the process for the validation of the results generated in the classification made using the Landsat-8/OLI data cube. 57 | 58 | The validation procedure of the land use and land cover thematic followed the good practice guidelines for accuracy assessment based on reference data proposed by [Olofsson et al. (2014)](https://doi.org/10.1016/j.rse.2014.02.015). 59 | 60 | > The Jupyter Notebook entitled [Land Use and Cover Mapping from Landsat-8/OLI Data Cubes](./04_LC8_30_16D_STK-1.ipynb) describes in detail how to create the thematic map used here. 61 | 62 | ## Loading the software packages 63 |
64 | 65 | In this example, the validation process uses the [SITS R package](https://github.com/e-sensing/sits): 66 | 67 | ```{r} 68 | library(sits) 69 | ``` 70 | 71 | We are going to use functionalities from the `sf` package as well: 72 | 73 | ```{r} 74 | library(sf) 75 | ``` 76 | 77 | ## Load data 78 |
79 | 80 | To perform the validation, it is initially necessary to load the classification results and the samples used as a reference. 81 | 82 | ```{r} 83 | classification_results <- raster::raster(paste0("/vsicurl/https://brazildatacube.dpi.inpe.br/", 84 | "geo-knowledge-hub/bdc-article/results/LC8_30_16D_STK_1/", 85 | "cube_to_classify_merged_probs_class_2018_8_2019_7_v1.tif")) 86 | 87 | validation_samples <- readRDS(url(paste0("https://brazildatacube.dpi.inpe.br/", 88 | "geo-knowledge-hub/bdc-article/validation-samples/", 89 | "validation-samples.rds"))) 90 | ``` 91 | 92 | > If you want to use the output generated in the previous Jupyter Notebook, entitled [Land Use and Cover Mapping from Landsat-8/OLI Data Cubes](./04_LC8_30_16D_STK-1.ipynb), you can replace the url by the path `results/LC8_30_16D_STK_1` in the first line of the above cell. 93 | 94 | The cell below shows the region of the validation samples: 95 | 96 | ```{r} 97 | library(leaflet) 98 | 99 | # 100 | # extract reference 101 | # 102 | reference_val <- validation_samples$geom$reference 103 | region_of_interest <- sf::st_read("/vsicurl/https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/roi/shp/roi.shp", quiet = TRUE) 104 | 105 | # 106 | # rename values 107 | # 108 | reference_val[reference_val == 1] <- 'Natural' 109 | reference_val[reference_val == 2] <- 'Anthropic' 110 | 111 | # 112 | # create a color function 113 | # 114 | factpal <- colorFactor( 115 | palette = c("#ea18d2", "#44ea57"), 116 | domain = c( "Anthropic", "Natural") 117 | ) 118 | 119 | # 120 | # generate the map! 121 | # 122 | leaflet::leaflet(validation_samples$geom, width="100%", height="600px") %>% 123 | addProviderTiles(providers$Esri.WorldImagery) %>% 124 | setView(lng = -45.5, lat = -12.8, zoom = 9) %>% 125 | 126 | addPolygons(data = region_of_interest) %>% 127 | addCircleMarkers(popup = reference_val, color = factpal(reference_val), 128 | radius = 4, stroke = FALSE, fillOpacity = 1) %>% 129 | 130 | addLegend("topright", 131 | pal = factpal, 132 | values = reference_val, 133 | title = "Validation Samples", 134 | opacity = 1) 135 | ``` 136 | 137 | ## Extract predicted values 138 |
139 | 140 | With the rasters and reference samples loaded, it will now be necessary to extract the values corresponding to each of the validation samples' locations from the classified raster. This extraction allows the comparison of the predicted and reference values. 141 | 142 | > For extraction at each location, the `extract` function of the [raster package](https://cran.r-project.org/web/packages/raster/raster.pdf) is used. 143 | 144 | In the next cell $x$ corresponds to the classified raster and $y$ to the location of the validation samples: 145 | 146 | ```{r} 147 | predicted_values <- raster::extract( 148 | x = classification_results, 149 | y = validation_samples$geom 150 | ) 151 | ``` 152 | 153 | The `predicted_values` is a vector with the same length as `validation_samples`, whose values correspond to classes from the input classified raster. 154 | 155 | ## Transform extracted values 156 |
157 | 158 | We base the validation on two classes, the `Natural Vegetation` class and on a new broader class named `Anthropic`. 159 | 160 | To obtain the `Anthropic` class we have to merge the `Crop` and `Pasture` classes. So, in the `predicted_values` vector we will temporarily relabel the cells `Natural Vegetation` from code `2` to `5`: 161 | 162 | ```{r} 163 | predicted_values[predicted_values == 2] <- 5 164 | ``` 165 | 166 | Then, we can relabel `Pasture` (1) and `Agriculture` (3) to the equivalent PRODES `Anthropic` class (2): 167 | 168 | ```{r} 169 | predicted_values[predicted_values == 1] <- 2 170 | predicted_values[predicted_values == 3] <- 2 171 | ``` 172 | 173 | Finally, we can set the `Natural Vegetation` cells to value `1` again: 174 | 175 | ```{r} 176 | predicted_values[predicted_values == 5] <- 1 177 | ``` 178 | 179 | > When the classification process is carried out, there is no way to specify the values assigned to each of the classes being identified. Thus, it may be necessary to check the classification values and their corresponding elements so that the values are used for comparison. 180 | 181 | ## Evaluating 182 |
183 | 184 | ```{r} 185 | sits_conf_matrix(list( 186 | predicted = predicted_values, 187 | reference = validation_samples$reference 188 | )) 189 | ``` 190 | 191 | -------------------------------------------------------------------------------- /rmarkdown/R/bdc-article/07_S2_10_16D_STK-1_Validation.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "." 3 | 4 | knit: (function(input, ...) { 5 | rmarkdown::render( 6 | input, 7 | output_file = paste0( 8 | '~/', basename(input), '.html' 9 | ), 10 | intermediates_dir = '~/', 11 | envir = globalenv(), 12 | output_format = rmarkdown::html_document(css = c("https://pro.fontawesome.com/releases/v5.11.0/css/all.css")) 13 | ) 14 | }) 15 | --- 16 | 17 | 18 | 19 | # Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products 20 |
21 | 22 |
23 | 24 |
25 | 26 | Rolf E. O. Simões , Alber H. Sanchez , Felipe M. Carlos , Leonardo S. Vieira ,
27 | 28 | Karine R. Ferreira , Lubia Vinhas , Gilberto R. Queiroz* 29 |

30 | Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE) 31 |
32 | Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil 33 |

34 | * Author to whom correspondence should be addressed. 35 |

36 | February 24, 2021 37 |
38 | 39 |
40 | 41 |
42 | Abstract. This RMarkdown compendium contains useful information for the creation of land use and land cover (LULC) maps using Earth observations data cubes and machine learning (ML) techniques. The code is based on the research pipeline described in the paper Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. These notebooks access open data available in the Brazil Data Cube platform. 43 |
44 | 45 |
46 |
47 | This RMarkdown page is supplement to the Section 5 of the following paper: 48 |
49 | Ferreira, K.R.; Queiroz, G.R.; Vinhas, L.; Marujo, R.F.B.; Simoes, R.E.O.; Picoli, M.C.A.; Camara, G.; Cartaxo, R.; Gomes, V.C.F.; Santos, L.A.; Sanchez, A.H.; Arcanjo, J.S.; Fronza, J.G.; Noronha, C.A.; Costa, R.W.; Zaglia, M.C.; Zioti, F.; Korting, T.S.; Soares, A.R.; Chaves, M.E.D.; Fonseca, L.M.G. 2020. Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. Remote Sens. 12, no. 24: 4033. DOI: 10.3390/rs12244033. 50 |
51 |
52 | 53 | # Validation results for Sentinel-2/MSI classification 54 |
55 | 56 | This document presents the process for the validation of the results generated in the classification made using the Sentinel-2/MSI data cube. 57 | 58 | The validation procedure of the land use and land cover thematic followed the good practice guidelines for accuracy assessment based on reference data proposed by [Olofsson et al. (2014)](https://doi.org/10.1016/j.rse.2014.02.015). 59 | 60 | > The Jupyter Notebook entitled [Land Use and Cover Mapping from Sentinel-2/MSI Data Cubes](./06_S2_10_16D_STK-1.ipynb) describes in detail how to create the thematic map used here. 61 | 62 | ## Loading the software packages 63 |
64 | 65 | In this example, the validation process uses the [SITS R package](https://github.com/e-sensing/sits): 66 | 67 | ```{r} 68 | library(sits) 69 | ``` 70 | 71 | We are going to use functionalities from the `sf` package as well: 72 | 73 | ```{r} 74 | library(sf) 75 | ``` 76 | 77 | ## Load data 78 |
79 | 80 | To perform the validation, it is initially necessary to load the classification results and the samples used as a reference. 81 | 82 | ```{r} 83 | classification_results <- raster::raster(paste0("/vsicurl/https://brazildatacube.dpi.inpe.br/", 84 | "geo-knowledge-hub/bdc-article/results/S2_10_16D_STK_1/", 85 | "cube_to_classify_merged_probs_class_2018_8_2019_7_v1.tif")) 86 | 87 | validation_samples <- readRDS(url(paste0("https://brazildatacube.dpi.inpe.br/", 88 | "geo-knowledge-hub/bdc-article/validation-samples/", 89 | "validation-samples.rds"))) 90 | ``` 91 | 92 | > If you want to use the output generated in the previous Jupyter Notebook, entitled [Land Use and Cover Mapping from Sentinel-2/MSI Data Cubes](./06_S2_10_16D_STK-1.ipynb), you can replace the directory path by the path `results/S2_10_16D_STK_1` in the first line of the above cell. 93 | 94 | The cell code below shows the region of the validation samples: 95 | 96 | ```{r} 97 | library(leaflet) 98 | 99 | # 100 | # extract reference 101 | # 102 | reference_val <- validation_samples$geom$reference 103 | region_of_interest <- sf::st_read("/vsicurl/https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/roi/shp/roi.shp", quiet = TRUE) 104 | 105 | # 106 | # rename values 107 | # 108 | reference_val[reference_val == 1] <- 'Natural' 109 | reference_val[reference_val == 2] <- 'Anthropic' 110 | 111 | # 112 | # create a color function 113 | # 114 | factpal <- colorFactor( 115 | palette = c("#ea18d2", "#44ea57"), 116 | domain = c( "Anthropic", "Natural") 117 | ) 118 | 119 | # 120 | # generate the map! 121 | # 122 | leaflet::leaflet(validation_samples$geom, width="100%", height="600px") %>% 123 | addProviderTiles(providers$Esri.WorldImagery) %>% 124 | setView(lng = -45.5, lat = -12.8, zoom = 9) %>% 125 | 126 | addPolygons(data = region_of_interest) %>% 127 | addCircleMarkers(popup = reference_val, color = factpal(reference_val), 128 | radius = 4, stroke = FALSE, fillOpacity = 1) %>% 129 | 130 | addLegend("topright", 131 | pal = factpal, 132 | values = reference_val, 133 | title = "Validation Samples", 134 | opacity = 1) 135 | ``` 136 | 137 | ## Extract predicted values 138 |
139 | 140 | With the rasters and reference samples loaded, it will now be necessary to extract the values corresponding to each of the validation samples' locations from the classified raster. This extraction allows the comparison of the predicted and reference values. 141 | 142 | > For extraction at each location, the `extract` function of the [raster package](https://cran.r-project.org/web/packages/raster/raster.pdf) is used. 143 | 144 | In the next cell $x$ corresponds to the classified raster and $y$ to the location of the validation samples: 145 | 146 | ```{r} 147 | predicted_values <- raster::extract( 148 | x = classification_results, 149 | y = validation_samples$geom 150 | ) 151 | ``` 152 | 153 | The `predicted_values` is a vector with the same length as `validation_samples`, whose values correspond to classes from the input classified raster. 154 | 155 | ## Transform extracted values 156 |
157 | 158 | 159 | We base the validation on two classes, the `Natural Vegetation` class and on a new broader class named `Anthropic`. 160 | 161 | To obtain the `Anthropic` class we have to merge the `Crop` and `Pasture` classes. So, in the `predicted_values` vector we will temporarily relabel the cells `Natural Vegetation` from code `2` to `5`: 162 | 163 | ```{r} 164 | predicted_values[predicted_values == 2] <- 5 165 | ``` 166 | 167 | Then, we can relabel `Pasture` (1) and `Agriculture` (3) to the equivalent PRODES `Anthropic` class (2): 168 | 169 | ```{r} 170 | predicted_values[predicted_values == 1] <- 2 171 | predicted_values[predicted_values == 3] <- 2 172 | ``` 173 | 174 | Finally, we can set the `Natural Vegetation` cells to value `1` again: 175 | 176 | ```{r} 177 | predicted_values[predicted_values == 5] <- 1 178 | ``` 179 | 180 | > When the classification process is carried out, there is no way to specify the values assigned to each of the classes being identified. Thus, it may be necessary to check the classification values and their corresponding elements so that the values are used for comparison. 181 | 182 | ## Evaluating 183 |
184 | 185 | ```{r} 186 | sits_conf_matrix(list( 187 | predicted = predicted_values, 188 | reference = validation_samples$reference 189 | )) 190 | ``` 191 | 192 | -------------------------------------------------------------------------------- /scripts/R/bdc-article/01_ExtractTimeSeries.R: -------------------------------------------------------------------------------- 1 | set.seed(777) 2 | library(sits) 3 | 4 | # 5 | # BDC Access definition 6 | # 7 | Sys.setenv( 8 | BDC_ACCESS_KEY = "My-Token" 9 | ) 10 | 11 | # 12 | # Auxiliary function 13 | # 14 | extract_ts_by_sample_location <- function(collection, start_date, end_date, bands, sample_file) { 15 | cube <- sits_cube( 16 | type = "BDC", 17 | name = "cube_to_extract_sample", 18 | url = "https://brazildatacube.dpi.inpe.br/stac/", 19 | collection = collection, 20 | start_date = start_date, 21 | end_date = end_date, 22 | bands = bands 23 | ) 24 | 25 | samples <- sits_get_data(cube = cube, file = sample_file) 26 | samples 27 | } 28 | 29 | # 30 | # General definitions 31 | # 32 | start_date <- "2018-09-01" 33 | end_date <- "2019-08-31" 34 | sample_file <- "https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/training-samples/training-samples.csv" 35 | 36 | # 37 | # Output directory 38 | # 39 | output_dir <- paste0(path.expand('~/work'), "/bdc-article", "/training-samples") 40 | dir.create( 41 | path = output_dir, 42 | showWarnings = FALSE, 43 | recursive = TRUE 44 | ) 45 | 46 | # 47 | # CBERS-4/AWFI (16 days 'stack') 48 | # 49 | cb4_samples_with_ts <- extract_ts_by_sample_location( 50 | collection = "CB4_64_16D_STK-1", 51 | start_date = start_date, 52 | end_date = end_date, 53 | bands = c("BAND15", "BAND14", "BAND13", "BAND16", "NDVI", "EVI"), 54 | sample_file = sample_file 55 | ) 56 | saveRDS(cb4_samples_with_ts, paste0(output_dir, "/CB4_64_16D_STK_1.rds")) 57 | 58 | # 59 | # Landsat-8/OLI (16 days 'stack') 60 | # 61 | l8_samples_with_ts <- extract_ts_by_sample_location( 62 | collection = "LC8_30_16D_STK-1", 63 | start_date = start_date, 64 | end_date = end_date, 65 | bands = c("band4", "band3", "band2", "band5", "NDVI", "EVI"), 66 | sample_file = sample_file 67 | ) 68 | saveRDS(l8_samples_with_ts, paste0(output_dir, "/LC8_30_16D_STK_1.rds")) 69 | 70 | # 71 | # Sentinel-2/MSI (16 days 'stack') 72 | # 73 | s2_samples_with_ts <- extract_ts_by_sample_location( 74 | collection = "S2_10_16D_STK-1", 75 | start_date = start_date, 76 | end_date = end_date, 77 | bands = c("band4", "band3", "band2", "band8", "NDVI", "EVI"), 78 | sample_file = sample_file 79 | ) 80 | saveRDS(s2_samples_with_ts, paste0(output_dir, "/S2_10_16D_STK_1.rds")) 81 | -------------------------------------------------------------------------------- /scripts/R/bdc-article/02_CB4_64_16D_STK-1_Classification.R: -------------------------------------------------------------------------------- 1 | set.seed(777) 2 | library(sits) 3 | 4 | # 5 | # BDC Access definition 6 | # 7 | Sys.setenv( 8 | BDC_ACCESS_KEY = "My-Token" 9 | ) 10 | 11 | # 12 | # General definitions 13 | # 14 | classification_memsize <- 20 # in GB 15 | classification_multicores <- 20 16 | 17 | start_date <- "2018-09-01" 18 | end_date <- "2019-08-31" 19 | 20 | # sample and ROI definition 21 | collection <- "CB4_64_16D_STK-1" 22 | 23 | # define the roi and load samples file 24 | roi <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/roi/roi.rds")) 25 | samples <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/training-samples/rds/CB4_64_16D_STK_1.rds")) 26 | 27 | # 28 | # Output directory 29 | # 30 | output_dir <- paste0(path.expand('~/work'), "/bdc-article", "/results", "/CB4_64_16D_STK_1") 31 | 32 | dir.create( 33 | path = output_dir, 34 | showWarnings = FALSE, 35 | recursive = TRUE 36 | ) 37 | 38 | # 39 | # Load data cube from BDC-STAC 40 | # 41 | cube <- sits_cube( 42 | type = "BDC", 43 | name = "cube_to_classify", 44 | url = "https://brazildatacube.dpi.inpe.br/stac/", 45 | collection = collection, 46 | start_date = start_date, 47 | end_date = end_date, 48 | roi = roi$search_roi 49 | ) 50 | 51 | # 52 | # Defining MLP Model 53 | # 54 | mlp_model <- sits_deeplearning(layers = c(512, 512, 512, 512, 512), 55 | activation = "relu", 56 | optimizer = keras::optimizer_adam(lr = 0.001), 57 | epochs = 200) 58 | 59 | # 60 | # Training model 61 | # 62 | dl_model <- sits_train(samples, mlp_model) 63 | 64 | # 65 | # Classify using the data cubes 66 | # 67 | probs <- sits_classify(data = cube, 68 | ml_model = dl_model, 69 | memsize = classification_memsize, 70 | multicores = classification_multicores, 71 | roi = roi$classification_roi, 72 | output_dir = output_dir) 73 | 74 | # 75 | # Post-processing 76 | # 77 | probs_smoothed <- sits_smooth(probs, type = "bayes", output_dir = output_dir) 78 | labels <- sits_label_classification(probs_smoothed, output_dir = output_dir) 79 | 80 | # 81 | # Saving results 82 | # 83 | 84 | # labels 85 | saveRDS( 86 | labels, file = paste0(output_dir, "/labels.rds") 87 | ) 88 | 89 | # probs 90 | saveRDS( 91 | probs, file = paste0(output_dir, "/probs_cube.rds") 92 | ) 93 | 94 | # smoothed probs 95 | saveRDS( 96 | probs_smoothed, file = paste0(output_dir, "/probs_smoothed_cube.rds") 97 | ) 98 | -------------------------------------------------------------------------------- /scripts/R/bdc-article/03_CB4_64_16D_STK-1_Validation.R: -------------------------------------------------------------------------------- 1 | library(sf) 2 | library(sits) 3 | library(raster) 4 | 5 | # 6 | # Load classification results 7 | # 8 | output_dir <- paste0(path.expand('~/work'), "/bdc-article", "/results", "/CB4_64_16D_STK_1") 9 | 10 | classification_results <- raster::raster( 11 | paste0(output_dir, "/cube_to_classify_022024_probs_2018_8_2019_7_v1.tif") 12 | ) 13 | 14 | # 15 | # Load validation samples 16 | # 17 | validation_samples <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/validation-samples/validation-samples.rds")) 18 | 19 | # 20 | # Extract predicted values from raster (Using validation samples locations) 21 | # 22 | predicted_values <- raster::extract( 23 | x = classification_results, 24 | y = validation_samples$geom 25 | ) 26 | 27 | # 28 | # Transform values to PRODES Anthropic and Natural vegetation 29 | # 30 | 31 | # Natural Vegetation (2) 32 | predicted_values[predicted_values == 2] <- 5 33 | 34 | # Pasture (2) and Agriculture (3) to PRODES Anthropic class 35 | predicted_values[predicted_values == 1] <- 2 36 | predicted_values[predicted_values == 3] <- 2 37 | 38 | # Natural Vegetation (1) 39 | predicted_values[predicted_values == 5] <- 1 40 | 41 | # 42 | # Generate confusion matrix and user/producer accuracy 43 | # 44 | sits_conf_matrix(list( 45 | predicted = predicted_values, 46 | reference = validation_samples$reference 47 | )) 48 | -------------------------------------------------------------------------------- /scripts/R/bdc-article/04_LC8_30_16D_STK-1_Classification.R: -------------------------------------------------------------------------------- 1 | set.seed(777) 2 | library(sits) 3 | 4 | # 5 | # BDC Access definition 6 | # 7 | Sys.setenv( 8 | BDC_ACCESS_KEY = "My-Token" 9 | ) 10 | 11 | # 12 | # General definitions 13 | # 14 | classification_memsize <- 20 # in GB 15 | classification_multicores <- 20 16 | 17 | start_date <- "2018-09-01" 18 | end_date <- "2019-08-31" 19 | 20 | # fixed parameters 21 | collection <- "LC8_30_16D_STK-1" 22 | 23 | # define the roi and load samples file 24 | roi <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/roi/roi.rds")) 25 | samples <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/training-samples/rds/LC8_30_16D_STK_1.rds")) 26 | 27 | # 28 | # Output directory 29 | # 30 | output_dir <- paste0(path.expand('~/work'), "/bdc-article", "/results", "/LC8_30_16D_STK_1") 31 | 32 | dir.create( 33 | path = output_dir, 34 | showWarnings = FALSE, 35 | recursive = TRUE 36 | ) 37 | 38 | # 39 | # Load data cube from BDC-STAC 40 | # 41 | cube <- sits_cube( 42 | type = "BDC", 43 | name = "cube_to_classify", 44 | url = "https://brazildatacube.dpi.inpe.br/stac/", 45 | collection = collection, 46 | start_date = start_date, 47 | end_date = end_date, 48 | roi = roi$search_roi 49 | ) 50 | 51 | # 52 | # Defining MLP Model 53 | # 54 | mlp_model <- sits_deeplearning(layers = c(512, 512, 512, 512, 512), 55 | activation = "relu", 56 | optimizer = keras::optimizer_adam(lr = 0.001), 57 | epochs = 200) 58 | 59 | # 60 | # Training model 61 | # 62 | dl_model <- sits_train(samples, mlp_model) 63 | 64 | # 65 | # Classify using the data cubes 66 | # 67 | probs <- sits_classify(data = cube, 68 | ml_model = dl_model, 69 | memsize = classification_memsize, 70 | multicores = classification_multicores, 71 | roi = roi$classification_roi, 72 | output_dir = output_dir) 73 | 74 | # 75 | # Post-processing 76 | # 77 | probs_smoothed <- sits_smooth(probs, type = "bayes", output_dir = output_dir) 78 | labels <- sits_label_classification(probs_smoothed, output_dir = output_dir) 79 | 80 | # 81 | # Saving results 82 | # 83 | 84 | # classification mosaic 85 | gdalUtils::mosaic_rasters(c( 86 | paste0(output_dir, "/cube_to_classify_044048_probs_class_2018_8_2019_7_v1.tif"), 87 | paste0(output_dir, "/cube_to_classify_044049_probs_class_2018_8_2019_7_v1.tif") 88 | ), paste0(output_dir, "/cube_to_classify_merged_probs_class_2018_8_2019_7_v1.tif")) 89 | 90 | # labels 91 | saveRDS( 92 | labels, file = paste0(output_dir, "/labels.rds") 93 | ) 94 | 95 | # probs 96 | saveRDS( 97 | probs, file = paste0(output_dir, "/probs_cube.rds") 98 | ) 99 | 100 | # smoothed probs 101 | saveRDS( 102 | probs_smoothed, file = paste0(output_dir, "/probs_smoothed_cube.rds") 103 | ) 104 | -------------------------------------------------------------------------------- /scripts/R/bdc-article/05_LC8_30_16D_STK-1_Validation.R: -------------------------------------------------------------------------------- 1 | library(sf) 2 | library(sits) 3 | library(raster) 4 | 5 | # 6 | # Load classification results 7 | # 8 | output_dir <- paste0(path.expand('~/work'), "/bdc-article", "/results", "/LC8_30_16D_STK_1") 9 | 10 | classification_results <- raster::raster( 11 | paste0(output_dir, "/cube_to_classify_merged_probs_class_2018_8_2019_7_v1.tif") 12 | ) 13 | 14 | # Load classification reference 15 | validation_samples <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/validation-samples/validation-samples.rds")) 16 | 17 | # 18 | # Extract predicted values from raster (Using validation samples locations) 19 | # 20 | predicted_values <- raster::extract( 21 | x = classification_results, 22 | y = validation_samples$geom 23 | ) 24 | 25 | # 26 | # Transform values to PRODES Anthropic and Natural vegetation 27 | # 28 | 29 | # Natural Vegetation (2) 30 | predicted_values[predicted_values == 2] <- 5 31 | 32 | # Pasture (2) and Agriculture (3) to PRODES Anthropic class 33 | predicted_values[predicted_values == 1] <- 2 34 | predicted_values[predicted_values == 3] <- 2 35 | 36 | # Natural Vegetation (1) 37 | predicted_values[predicted_values == 5] <- 1 38 | 39 | # 40 | # Generate confusion matrix and user/producer accuracy 41 | # 42 | sits_conf_matrix(list( 43 | predicted = predicted_values, 44 | reference = validation_samples$reference 45 | )) 46 | -------------------------------------------------------------------------------- /scripts/R/bdc-article/06_S2_10_16D_STK-1_Classification.R: -------------------------------------------------------------------------------- 1 | set.seed(777) 2 | library(sits) 3 | 4 | # 5 | # BDC Access definition 6 | # 7 | Sys.setenv( 8 | BDC_ACCESS_KEY = "My-Token" 9 | ) 10 | 11 | # 12 | # General definitions 13 | # 14 | classification_memsize <- 20 # in GB 15 | classification_multicores <- 20 16 | 17 | start_date <- "2018-09-01" 18 | end_date <- "2019-08-31" 19 | collection <- "S2_10_16D_STK-1" 20 | 21 | # fixed parameters 22 | collection <- "S2_10_16D_STK-1" 23 | 24 | # define the roi and load samples file 25 | roi <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/roi/roi.rds")) 26 | samples <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/training-samples/rds/S2_10_16D_STK_1.rds")) 27 | 28 | # 29 | # Output directory 30 | # 31 | output_dir <- paste0(path.expand('~/work'), "/bdc-article", "/results", "/S2_10_16D_STK_1") 32 | 33 | dir.create( 34 | path = output_dir, 35 | showWarnings = FALSE, 36 | recursive = TRUE 37 | ) 38 | 39 | # 40 | # Load data cube from BDC-STAC 41 | # 42 | cube <- sits_cube( 43 | type = "BDC", 44 | name = "cube_to_classify", 45 | url = "https://brazildatacube.dpi.inpe.br/stac/", 46 | collection = collection, 47 | start_date = start_date, 48 | end_date = end_date, 49 | roi = roi$search_roi 50 | ) 51 | 52 | # 53 | # Defining MLP Model 54 | # 55 | mlp_model <- sits_deeplearning(layers = c(512, 512, 512, 512, 512), 56 | activation = "relu", 57 | optimizer = keras::optimizer_adam(lr = 0.001), 58 | epochs = 200) 59 | 60 | # 61 | # Training model 62 | # 63 | dl_model <- sits_train(samples, mlp_model) 64 | 65 | # 66 | # Classify using the data cubes 67 | # 68 | probs <- sits_classify(data = cube, 69 | ml_model = dl_model, 70 | memsize = classification_memsize, 71 | multicores = classification_multicores, 72 | roi = roi$classification_roi, 73 | output_dir = output_dir) 74 | 75 | # 76 | # Post-processing 77 | # 78 | probs_smoothed <- sits_smooth(probs, type = "bayes", output_dir = output_dir) 79 | labels <- sits_label_classification(probs_smoothed, output_dir = output_dir) 80 | 81 | # 82 | # Saving results 83 | # 84 | 85 | # classification mosaic 86 | gdalUtils::mosaic_rasters(c( 87 | paste0(output_dir, "/cube_to_classify_088097_probs_class_2018_8_2019_7_v1.tif"), 88 | paste0(output_dir, "/cube_to_classify_089097_probs_class_2018_8_2019_7_v1.tif"), 89 | paste0(output_dir, "/cube_to_classify_089098_probs_class_2018_8_2019_7_v1.tif") 90 | ), paste0(output_dir, "/cube_to_classify_merged_probs_class_2018_8_2019_7_v1.tif")) 91 | 92 | # labels 93 | saveRDS( 94 | labels, file = paste0(output_dir, "/labels.rds") 95 | ) 96 | 97 | # probs 98 | saveRDS( 99 | probs, file = paste0(output_dir, "/probs_cube.rds") 100 | ) 101 | 102 | # smoothed probs 103 | saveRDS( 104 | probs_smoothed, file = paste0(output_dir, "/probs_smoothed_cube.rds") 105 | ) 106 | -------------------------------------------------------------------------------- /scripts/R/bdc-article/07_S2_10_16D_STK-1_Validation.R: -------------------------------------------------------------------------------- 1 | library(sf) 2 | library(sits) 3 | library(raster) 4 | 5 | # 6 | # Load classification results 7 | # 8 | output_dir <- paste0(path.expand('~/work'), "/bdc-article", "/results", "/S2_10_16D_STK_1") 9 | classification_results <- raster::raster( 10 | paste0(output_dir, "/cube_to_classify_merged_probs_class_2018_8_2019_7_v1.tif") 11 | ) 12 | 13 | # Load classification reference 14 | validation_samples <- readRDS(url("https://brazildatacube.dpi.inpe.br/geo-knowledge-hub/bdc-article/validation-samples/validation-samples.rds")) 15 | 16 | # 17 | # Extract predicted values from raster (Using validation samples locations) 18 | # 19 | predicted_values <- raster::extract( 20 | x = classification_results, 21 | y = validation_samples$geom 22 | ) 23 | 24 | # 25 | # Transform values to PRODES Anthropic and Natural vegetation 26 | # 27 | 28 | # Natural Vegetation (2) 29 | predicted_values[predicted_values == 2] <- 5 30 | 31 | # Pasture (2) and Agriculture (3) to PRODES Anthropic class 32 | predicted_values[predicted_values == 1] <- 2 33 | predicted_values[predicted_values == 3] <- 2 34 | 35 | # Natural Vegetation (1) 36 | predicted_values[predicted_values == 5] <- 1 37 | 38 | # 39 | # Generate confusion matrix and user/producer accuracy 40 | # 41 | sits_conf_matrix(list( 42 | predicted = predicted_values, 43 | reference = validation_samples$reference 44 | )) 45 | -------------------------------------------------------------------------------- /table-of-contents.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "legitimate-suite", 6 | "metadata": {}, 7 | "source": [ 8 | "# Brazil Data Cube Jupyter Notebook Gallery\n", 9 | "
\n", 10 | "\n", 11 | "
\n", 12 | "\n", 13 | "
\n", 14 | " \n", 15 | "
\n", 16 | " Brazil Data Cube Team\n", 17 | "

\n", 18 | " Earth Observation and Geoinformatics Division, National Institute for Space Research (INPE)\n", 19 | "
\n", 20 | " Avenida dos Astronautas, 1758, Jardim da Granja, São José dos Campos, SP 12227-010, Brazil\n", 21 | "

\n", 22 | " Last Update: February 22, 2021\n", 23 | "
\n", 24 | "\n", 25 | "
\n", 26 | "\n", 27 | "
\n", 28 | "Abstract. This repository contains a gallery of interesting Jupyter Notebooks, R Markdown and scripts based on Brazil Data Cube data and its technologies. This document contains the table of contents for the available Jupyter Notebooks.\n", 29 | "
\n", 30 | "\n", 31 | "
\n", 32 | "\n", 33 | "
\n", 34 | " \n", 35 | "
" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "id": "laughing-patent", 41 | "metadata": {}, 42 | "source": [ 43 | "# Table of Contents\n", 44 | "
\n", 45 | "\n", 46 | "\n", 47 | "## Data Access through SpatioTemporal Asset Catalog API (STAC)\n", 48 | "\n", 49 | "* Introduction to the SpatioTemporal Asset Catalog. ([Python](./jupyter/Python/stac/stac-introduction.ipynb), [R](./jupyter/R/stac/stac-introduction.ipynb))\n", 50 | "\n", 51 | "* [Image processing on images obtained through STAC](./jupyter/Python/stac/stac-image-processing.ipynb).\n", 52 | "\n", 53 | "\n", 54 | "## Web Time Series Service (WTSS)\n", 55 | "\n", 56 | "* Introduction to the Web Time Series Service (WTSS). ([Python](./jupyter/Python/wtss/wtss-introduction.ipynb), [R](./jupyter/R/wtss/wtss-introduction.ipynb)).\n", 57 | "\n", 58 | "* Web Time Series Service (WTSS) examples. ([Python](./jupyter/Python/wtss/wtss-examples.ipynb), [R](./jupyter/R/wtss/wtss-examples.ipynb)).\n", 59 | "\n", 60 | "\n", 61 | "## Web Land Trajectory Service (WLTS)\n", 62 | "\n", 63 | "* Introduction to the Web Land Trajectory Service (WLTS). ([Python](./jupyter/Python/wlts/wlts-introduction.ipynb), [R](./jupyter/R/wlts/wlts-introduction.ipynb))\n", 64 | "\n", 65 | "* Web Land Trajectory Service (WLTS) examples. ([Python](./jupyter/Python/wlts/wlts-example.ipynb)).\n", 66 | "\n", 67 | "\n", 68 | "## Land Cover Classification System Service (LCCS)\n", 69 | "\n", 70 | "* Introduction to the Land Cover Classification System Service (LCCS). ([Python](./jupyter/Python/lccs/lccs-introduction.ipynb))\n", 71 | "\n", 72 | "\n", 73 | "## Sample Web Service (SAMPLE-WS)\n", 74 | "\n", 75 | "* Introduction to the Sample Web Service (SAMPLE-WS). ([Python](./jupyter/Python/sample/sample-introduction.ipynb))\n", 76 | "\n", 77 | "\n", 78 | "## Tile Map Service (BDC-Tiler)\n", 79 | "\n", 80 | "- Introduction to the Tile Map Service (BDC-Tiler). ([Python](./jupyter/Python/tiler/bdc-tiler_introduction.ipynb))\n", 81 | "\n", 82 | "\n", 83 | "## Mapping LULC using BDC Data Cubes\n", 84 | "\n", 85 | "- Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products. ([R](./jupyter/R/bdc-article/00_TableOfContents.ipynb))" 86 | ] 87 | } 88 | ], 89 | "metadata": { 90 | "kernelspec": { 91 | "display_name": "Python 3 (ipykernel)", 92 | "language": "python", 93 | "name": "python3" 94 | }, 95 | "language_info": { 96 | "codemirror_mode": { 97 | "name": "ipython", 98 | "version": 3 99 | }, 100 | "file_extension": ".py", 101 | "mimetype": "text/x-python", 102 | "name": "python", 103 | "nbconvert_exporter": "python", 104 | "pygments_lexer": "ipython3", 105 | "version": "3.7.11" 106 | } 107 | }, 108 | "nbformat": 4, 109 | "nbformat_minor": 5 110 | } 111 | --------------------------------------------------------------------------------