├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ └── feature_request.md ├── ee_token.py └── workflows │ └── docs.yml ├── .gitignore ├── Analysis ├── zonal_statistics.ipynb └── zonal_stats_by_group.ipynb ├── AssetManagement ├── export_data.ipynb └── extract_values.ipynb ├── FeatureCollection └── vector_styling.ipynb ├── Image ├── conditional_operations.ipynb ├── image_colorbar.ipynb ├── image_metadata.ipynb ├── image_overview.ipynb ├── image_visualization.ipynb └── math_operations.ipynb ├── ImageCollection ├── cloud_free_composite.ipynb ├── image_collection_overview.ipynb ├── mapping_over_image_collection.ipynb ├── reducing_image_collection.ipynb └── visualizing_time_series.ipynb ├── LICENSE ├── README.md ├── docs ├── Analysis │ ├── zonal_statistics.ipynb │ └── zonal_stats_by_group.ipynb ├── AssetManagement │ ├── export_data.ipynb │ └── extract_values.ipynb ├── CNAME ├── FeatureCollection │ └── vector_styling.ipynb ├── Image │ ├── conditional_operations.ipynb │ ├── image_colorbar.ipynb │ ├── image_metadata.ipynb │ ├── image_overview.ipynb │ ├── image_visualization.ipynb │ └── math_operations.ipynb ├── ImageCollection │ ├── cloud_free_composite.ipynb │ ├── image_collection_overview.ipynb │ ├── mapping_over_image_collection.ipynb │ ├── reducing_image_collection.ipynb │ └── visualizing_time_series.ipynb ├── index.md └── overrides │ └── main.html ├── mkdocs.yml └── requirements.txt /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Create a bug report to help us improve 4 | labels: bug 5 | --- 6 | 7 | 8 | 9 | ### Environment Information 10 | 11 | - geemap version: 12 | - Python version: 13 | - Operating System: 14 | 15 | ### Description 16 | 17 | Describe what you were trying to get done. 18 | Tell us what happened, what went wrong, and what you expected to happen. 19 | 20 | ### What I Did 21 | 22 | ``` 23 | Paste the command(s) you ran and the output. 24 | If there was a crash, please include the traceback here. 25 | ``` 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: Ask questions 3 | url: https://github.com/giswqs/gee-tutorials/discussions/categories/q-a 4 | about: Please ask and answer questions here. 5 | - name: Ideas 6 | url: https://github.com/giswqs/gee-tutorials/discussions/categories/ideas 7 | about: Please share your ideas here. 8 | - name: Ask questions from the GEE community 9 | url: https://gis.stackexchange.com/questions/tagged/google-earth-engine 10 | about: To get answers from questions in the GEE commminuty, please ask and answer questions here. 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Submit a feature request to help us improve 4 | labels: Feature Request 5 | --- 6 | 7 | 8 | 9 | ### Description 10 | 11 | Describe the feature (e.g., new functions/tutorials) you would like to propose. 12 | Tell us what can be achieved with this new feature and what's the expected outcome. 13 | 14 | ### Source code 15 | 16 | ``` 17 | Paste your source code here if have sample code to share. 18 | ``` 19 | -------------------------------------------------------------------------------- /.github/ee_token.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | ee_token = os.environ["EARTHENGINE_TOKEN"] 4 | credential = '{"refresh_token":"%s"}' % ee_token 5 | credential_file_path = os.path.expanduser("~/.config/earthengine/") 6 | os.makedirs(credential_file_path, exist_ok=True) 7 | with open(credential_file_path + "credentials", "w") as file: 8 | file.write(credential) 9 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: docs 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | deploy: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions/setup-python@v2 12 | with: 13 | python-version: 3.8 14 | - name: Install dependencies 15 | run: | 16 | python -m pip install --upgrade pip 17 | pip install --user --no-cache-dir Cython 18 | pip install --user -r requirements.txt 19 | - name: LOAD EE CREDENTIALS 20 | run: python ./.github/ee_token.py 21 | env: 22 | EARTHENGINE_TOKEN: ${{ secrets.EARTHENGINE_TOKEN }} 23 | # - name: GEEMAP-TEST 24 | # run: | 25 | # python -m unittest discover tests/ 26 | - name: Install dependencies 27 | run: pip install mkdocs-material mkdocstrings mkdocs-git-revision-date-plugin mkdocs-jupyter mkdocs-pdf-export-plugin ipykernel 28 | - name: depoly 29 | run: mkdocs gh-deploy --force 30 | env: 31 | RUN_GITHUB_ACTION: ${{ secrets.RUN_GITHUB_ACTION }} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | testing/ 6 | labs/ 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | pip-wheel-metadata/ 26 | share/python-wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | MANIFEST 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .nox/ 46 | .coverage 47 | .coverage.* 48 | .cache 49 | nosetests.xml 50 | coverage.xml 51 | *.cover 52 | *.py,cover 53 | .hypothesis/ 54 | .pytest_cache/ 55 | 56 | # Translations 57 | *.mo 58 | *.pot 59 | 60 | # Django stuff: 61 | *.log 62 | local_settings.py 63 | db.sqlite3 64 | db.sqlite3-journal 65 | 66 | # Flask stuff: 67 | instance/ 68 | .webassets-cache 69 | 70 | # Scrapy stuff: 71 | .scrapy 72 | 73 | # Sphinx documentation 74 | docs/_build/ 75 | 76 | # PyBuilder 77 | target/ 78 | 79 | # Jupyter Notebook 80 | .ipynb_checkpoints 81 | 82 | # IPython 83 | profile_default/ 84 | ipython_config.py 85 | 86 | # pyenv 87 | .python-version 88 | 89 | # pipenv 90 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 91 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 92 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 93 | # install all needed dependencies. 94 | #Pipfile.lock 95 | 96 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 97 | __pypackages__/ 98 | 99 | # Celery stuff 100 | celerybeat-schedule 101 | celerybeat.pid 102 | 103 | # SageMath parsed files 104 | *.sage.py 105 | 106 | # Environments 107 | .env 108 | .venv 109 | env/ 110 | venv/ 111 | ENV/ 112 | env.bak/ 113 | venv.bak/ 114 | 115 | # Spyder project settings 116 | .spyderproject 117 | .spyproject 118 | 119 | # Rope project settings 120 | .ropeproject 121 | 122 | # mkdocs documentation 123 | /site 124 | 125 | # mypy 126 | .mypy_cache/ 127 | .dmypy.json 128 | dmypy.json 129 | 130 | # Pyre type checker 131 | .pyre/ 132 | -------------------------------------------------------------------------------- /Analysis/zonal_statistics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"Open\n", 8 | "\n", 9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed." 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "# !pip install geemap" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "import ee\n", 28 | "import geemap\n", 29 | "import os" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "## Create an interactive map" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "Map = geemap.Map()\n", 46 | "Map" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "## Add Earth Engine data" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": null, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "# Add Earth Engine dataset\n", 63 | "dem = ee.Image('USGS/SRTMGL1_003')\n", 64 | "\n", 65 | "# Set visualization parameters.\n", 66 | "dem_vis = {\n", 67 | " 'min': 0,\n", 68 | " 'max': 4000,\n", 69 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n", 70 | "\n", 71 | "# Add Earth Engine DEM to map\n", 72 | "Map.addLayer(dem, dem_vis, 'SRTM DEM')\n", 73 | "\n", 74 | "# Add Landsat data to map\n", 75 | "landsat = ee.Image('LE7_TOA_5YEAR/1999_2003')\n", 76 | "\n", 77 | "landsat_vis = {\n", 78 | " 'bands': ['B4', 'B3', 'B2'], \n", 79 | " 'gamma': 1.4\n", 80 | "}\n", 81 | "Map.addLayer(landsat, landsat_vis, \"Landsat\", False)\n", 82 | "\n", 83 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 84 | "Map.addLayer(states, {}, 'US States')" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "## Compute zonal statistics for one image" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": null, 97 | "metadata": {}, 98 | "outputs": [], 99 | "source": [ 100 | "out_dir = os.path.expanduser('~/Downloads')\n", 101 | "if not os.path.exists(out_dir):\n", 102 | " os.makedirs(out_dir)" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": {}, 109 | "outputs": [], 110 | "source": [ 111 | "out_dem_stats = os.path.join(out_dir, 'dem_stats.csv') \n", 112 | "\n", 113 | "# Allowed output formats: csv, shp, json, kml, kmz\n", 114 | "# Allowed statistics type: MEAN, MAXIMUM, MINIMUM, MEDIAN, STD, MIN_MAX, VARIANCE, SUM\n", 115 | "geemap.zonal_statistics(dem, states, out_dem_stats, statistics_type='MEAN', scale=1000)" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": { 122 | "scrolled": false 123 | }, 124 | "outputs": [], 125 | "source": [ 126 | "out_landsat_stats = os.path.join(out_dir, 'landsat_stats.csv') \n", 127 | "geemap.zonal_statistics(landsat, states, out_landsat_stats, statistics_type='SUM', scale=1000)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "## Compute zonal statistics for time-series images" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "Map = geemap.Map()\n", 144 | "\n", 145 | "collection = ee.ImageCollection('MODIS/MCD43A4_006_NDVI') \\\n", 146 | " .filter(ee.Filter.date('2018-04-01', '2018-05-01')) \\\n", 147 | " .select(\"NDVI\")\\\n", 148 | "\n", 149 | "vis_params = {\n", 150 | " 'min': 0.0,\n", 151 | " 'max': 1.0,\n", 152 | " 'palette': [\n", 153 | " 'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',\n", 154 | " '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',\n", 155 | " '012E01', '011D01', '011301'\n", 156 | " ],\n", 157 | "}\n", 158 | "\n", 159 | "first_image = collection.first()\n", 160 | "\n", 161 | "Map.addLayer(first_image, vis_params, \"First image\")\n", 162 | "Map.setCenter(-7.03125, 31.0529339857, 2)\n", 163 | "Map" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "modis = collection.toBands()\n", 173 | "Map.addLayer(modis, {}, \"MODIS Time series\", False)" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": null, 179 | "metadata": {}, 180 | "outputs": [], 181 | "source": [ 182 | "out_landsat_stats = os.path.join(out_dir, 'ndvi.csv') \n", 183 | "geemap.zonal_statistics(modis, states, out_landsat_stats, statistics_type='MEAN', scale=1000)" 184 | ] 185 | } 186 | ], 187 | "metadata": { 188 | "hide_input": false, 189 | "kernelspec": { 190 | "display_name": "Python 3", 191 | "language": "python", 192 | "name": "python3" 193 | }, 194 | "language_info": { 195 | "codemirror_mode": { 196 | "name": "ipython", 197 | "version": 3 198 | }, 199 | "file_extension": ".py", 200 | "mimetype": "text/x-python", 201 | "name": "python", 202 | "nbconvert_exporter": "python", 203 | "pygments_lexer": "ipython3", 204 | "version": "3.8.5" 205 | }, 206 | "toc": { 207 | "base_numbering": 1, 208 | "nav_menu": {}, 209 | "number_sections": true, 210 | "sideBar": true, 211 | "skip_h1_title": true, 212 | "title_cell": "Table of Contents", 213 | "title_sidebar": "Table of Contents", 214 | "toc_cell": false, 215 | "toc_position": {}, 216 | "toc_section_display": true, 217 | "toc_window_display": true 218 | }, 219 | "varInspector": { 220 | "cols": { 221 | "lenName": 16, 222 | "lenType": 16, 223 | "lenVar": 40 224 | }, 225 | "kernels_config": { 226 | "python": { 227 | "delete_cmd_postfix": "", 228 | "delete_cmd_prefix": "del ", 229 | "library": "var_list.py", 230 | "varRefreshCmd": "print(var_dic_list())" 231 | }, 232 | "r": { 233 | "delete_cmd_postfix": ") ", 234 | "delete_cmd_prefix": "rm(", 235 | "library": "var_list.r", 236 | "varRefreshCmd": "cat(var_dic_list()) " 237 | } 238 | }, 239 | "types_to_exclude": [ 240 | "module", 241 | "function", 242 | "builtin_function_or_method", 243 | "instance", 244 | "_Feature" 245 | ], 246 | "window_display": false 247 | } 248 | }, 249 | "nbformat": 4, 250 | "nbformat_minor": 4 251 | } 252 | -------------------------------------------------------------------------------- /Analysis/zonal_stats_by_group.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"Open\n", 8 | "\n", 9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed." 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "# !pip install geemap" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "import os\n", 28 | "import ee\n", 29 | "import geemap" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "## Analyzing U.S. Land Cover" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "Map = geemap.Map()\n", 46 | "Map" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "### Add NLCD data\n", 54 | "\n", 55 | "NLCD: USGS National Land Cover Database\n", 56 | "\n", 57 | "https://developers.google.com/earth-engine/datasets/catalog/USGS_NLCD_RELEASES_2016_REL" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "dataset = ee.Image('USGS/NLCD/NLCD2016')\n", 67 | "landcover = ee.Image(dataset.select('landcover'))\n", 68 | "Map.addLayer(landcover, {}, 'NLCD 2016')\n", 69 | "\n", 70 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 71 | "Map.addLayer(states, {}, 'US States')" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "Map.add_legend(builtin_legend='NLCD')" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "### Calculate land cover compostion of each US state" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": null, 93 | "metadata": {}, 94 | "outputs": [], 95 | "source": [ 96 | "out_dir = os.path.expanduser('~/Downloads')\n", 97 | "if not os.path.exists(out_dir):\n", 98 | " os.makedirs(out_dir)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "nlcd_stats = os.path.join(out_dir, 'nlcd_stats_sum.csv') \n", 108 | " \n", 109 | "# statistics_type can be either 'SUM' or 'PERCENTAGE'\n", 110 | "# denominator can be used to convert square meters to other areal units, such as square kilimeters\n", 111 | "geemap.zonal_statistics_by_group(landcover, states, nlcd_stats, statistics_type='SUM', denominator=1000000, decimal_places=2)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": null, 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [ 120 | "nlcd_stats = os.path.join(out_dir, 'nlcd_stats_pct.csv') \n", 121 | "geemap.zonal_statistics_by_group(landcover, states, nlcd_stats, statistics_type='PERCENTAGE')" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "## Analyzing Global Land Cover" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "### Add MODIS global land cover data\n", 136 | "\n", 137 | "MCD12Q1.006 MODIS Land Cover Type Yearly Global 500m\n", 138 | "\n", 139 | "https://developers.google.com/earth-engine/datasets/catalog/MODIS_006_MCD12Q1" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "Map = geemap.Map()\n", 149 | "\n", 150 | "landcover = ee.Image('MODIS/006/MCD12Q1/2019_01_01') \\\n", 151 | " .select('LC_Type1')\n", 152 | "\n", 153 | "igbpLandCoverVis = {\n", 154 | " 'min': 1.0,\n", 155 | " 'max': 17.0,\n", 156 | " 'palette': [\n", 157 | " '05450a', '086a10', '54a708', '78d203', '009900', 'c6b044', 'dcd159',\n", 158 | " 'dade48', 'fbff13', 'b6ff05', '27ff87', 'c24f44', 'a5a5a5', 'ff6d4c',\n", 159 | " '69fff8', 'f9ffa4', '1c0dff'\n", 160 | " ],\n", 161 | "}\n", 162 | "\n", 163 | "Map.setCenter(6.746, 46.529, 2)\n", 164 | "Map.addLayer(landcover, igbpLandCoverVis, 'MODIS Land Cover')\n", 165 | "\n", 166 | "countries = ee.FeatureCollection('users/giswqs/public/countries')\n", 167 | "Map.addLayer(countries, {}, \"Countries\")\n", 168 | "\n", 169 | "Map" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "Map.add_legend(builtin_legend='MODIS/051/MCD12Q1')" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": null, 184 | "metadata": {}, 185 | "outputs": [], 186 | "source": [ 187 | "out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')\n", 188 | "global_stats = os.path.join(out_dir, 'global_stats_sum.csv') \n", 189 | "\n", 190 | "# statistics_type can be either 'SUM' or 'PERCENTAGE'\n", 191 | "# denominator can be used to convert square meters to other areal units, such as square kilimeters\n", 192 | "geemap.zonal_statistics_by_group(landcover, countries, global_stats, statistics_type='SUM', denominator=1000000, decimal_places=2)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "global_stats = os.path.join(out_dir, 'global_stats_pct.csv') \n", 202 | "geemap.zonal_statistics_by_group(landcover, countries, global_stats, statistics_type='PERCENTAGE')" 203 | ] 204 | } 205 | ], 206 | "metadata": { 207 | "hide_input": false, 208 | "kernelspec": { 209 | "display_name": "Python 3", 210 | "language": "python", 211 | "name": "python3" 212 | }, 213 | "language_info": { 214 | "codemirror_mode": { 215 | "name": "ipython", 216 | "version": 3 217 | }, 218 | "file_extension": ".py", 219 | "mimetype": "text/x-python", 220 | "name": "python", 221 | "nbconvert_exporter": "python", 222 | "pygments_lexer": "ipython3", 223 | "version": "3.8.5" 224 | }, 225 | "toc": { 226 | "base_numbering": 1, 227 | "nav_menu": {}, 228 | "number_sections": true, 229 | "sideBar": true, 230 | "skip_h1_title": true, 231 | "title_cell": "Table of Contents", 232 | "title_sidebar": "Table of Contents", 233 | "toc_cell": false, 234 | "toc_position": {}, 235 | "toc_section_display": true, 236 | "toc_window_display": false 237 | }, 238 | "varInspector": { 239 | "cols": { 240 | "lenName": 16, 241 | "lenType": 16, 242 | "lenVar": 40 243 | }, 244 | "kernels_config": { 245 | "python": { 246 | "delete_cmd_postfix": "", 247 | "delete_cmd_prefix": "del ", 248 | "library": "var_list.py", 249 | "varRefreshCmd": "print(var_dic_list())" 250 | }, 251 | "r": { 252 | "delete_cmd_postfix": ") ", 253 | "delete_cmd_prefix": "rm(", 254 | "library": "var_list.r", 255 | "varRefreshCmd": "cat(var_dic_list()) " 256 | } 257 | }, 258 | "types_to_exclude": [ 259 | "module", 260 | "function", 261 | "builtin_function_or_method", 262 | "instance", 263 | "_Feature" 264 | ], 265 | "window_display": false 266 | } 267 | }, 268 | "nbformat": 4, 269 | "nbformat_minor": 4 270 | } 271 | -------------------------------------------------------------------------------- /AssetManagement/extract_values.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"Open\n", 8 | "\n", 9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed." 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "# !pip install geemap" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "# import geemap\n", 28 | "# geemap.update_package()" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "# Interactive extraction of pixel values and interactive region reduction" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Interactive extraction of pixel values" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "### Import libraries" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "import os\n", 59 | "import ee\n", 60 | "import geemap" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "### Create an interactive map" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "Map = geemap.Map()\n", 77 | "Map" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "### Add data to the map" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003') \\\n", 94 | " .select([0, 1, 2, 3, 4, 6])\n", 95 | "landsat_vis = {\n", 96 | " 'bands': ['B4', 'B3', 'B2'], \n", 97 | " 'gamma': 1.7\n", 98 | "}\n", 99 | "Map.addLayer(landsat7, landsat_vis, \"LE7_TOA_5YEAR/1999_2003\")\n", 100 | "\n", 101 | "Map.set_plot_options(add_marker_cluster=True)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "### Activate the plotting tool\n", 109 | "\n", 110 | "Tick the `Plotting` checkbox and click the mouse on the map to start displaying charts." 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "### Export pixel values to shapefile/csv" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "out_dir = os.path.expanduser('~/Downloads')\n", 127 | "# out_csv = os.path.join(out_dir, 'points.csv')\n", 128 | "out_shp = os.path.join(out_dir, 'points.shp')" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": null, 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "Map.extract_values_to_points(out_shp)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "## Interactive Region Reduction" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "### Import libraries" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "metadata": {}, 158 | "outputs": [], 159 | "source": [ 160 | "import geemap.colormaps as cm" 161 | ] 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "metadata": {}, 166 | "source": [ 167 | "### Create an interactive map" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [ 176 | "m = geemap.Map()" 177 | ] 178 | }, 179 | { 180 | "cell_type": "markdown", 181 | "metadata": {}, 182 | "source": [ 183 | "### Add add to the map" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "collection = ee.ImageCollection('MODIS/006/MOD13A2') \\\n", 193 | " .filterDate('2015-01-01', '2019-12-31') \\\n", 194 | " .select('NDVI')\n", 195 | "\n", 196 | "# Convert the image collection to an image.\n", 197 | "image = collection.toBands()\n", 198 | "\n", 199 | "palette = cm.palettes.ndvi\n", 200 | "\n", 201 | "ndvi_vis = {\n", 202 | " 'min': 0.0,\n", 203 | " 'max': 9000.0,\n", 204 | " 'palette': palette\n", 205 | "}\n", 206 | "\n", 207 | "m.addLayer(image, {}, 'MODIS NDVI Time-series')\n", 208 | "m.addLayer(image.select(0), ndvi_vis, 'MODIS NDVI VIS')\n", 209 | "\n", 210 | "m" 211 | ] 212 | }, 213 | { 214 | "cell_type": "markdown", 215 | "metadata": {}, 216 | "source": [ 217 | "### Set reducer" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": null, 223 | "metadata": {}, 224 | "outputs": [], 225 | "source": [ 226 | "m.set_plot_options(add_marker_cluster=True, marker=None)\n", 227 | "m.roi_reducer = ee.Reducer.mean()" 228 | ] 229 | }, 230 | { 231 | "cell_type": "markdown", 232 | "metadata": {}, 233 | "source": [ 234 | "### Export data" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": null, 240 | "metadata": {}, 241 | "outputs": [], 242 | "source": [ 243 | "out_dir = os.path.expanduser('~/Downloads')\n", 244 | "# out_csv = os.path.join(out_dir, 'points.csv')\n", 245 | "out_shp = os.path.join(out_dir, 'ndvi.shp')\n", 246 | "m.extract_values_to_points(out_shp)" 247 | ] 248 | }, 249 | { 250 | "cell_type": "markdown", 251 | "metadata": {}, 252 | "source": [ 253 | "## Creating training samples" 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": null, 259 | "metadata": {}, 260 | "outputs": [], 261 | "source": [ 262 | "import geemap" 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": null, 268 | "metadata": {}, 269 | "outputs": [], 270 | "source": [ 271 | "geemap.show_youtube(\"https://youtu.be/VWh5PxXPZw0\")" 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": null, 277 | "metadata": {}, 278 | "outputs": [], 279 | "source": [ 280 | "Map = geemap.Map()\n", 281 | "Map" 282 | ] 283 | } 284 | ], 285 | "metadata": { 286 | "_draft": { 287 | "nbviewer_url": "https://gist.github.com/3ebde541f34a1757035a67dee34939d0" 288 | }, 289 | "gist": { 290 | "data": { 291 | "description": "extract values to points", 292 | "public": true 293 | }, 294 | "id": "3ebde541f34a1757035a67dee34939d0" 295 | }, 296 | "hide_input": false, 297 | "kernelspec": { 298 | "display_name": "Python 3", 299 | "language": "python", 300 | "name": "python3" 301 | }, 302 | "language_info": { 303 | "codemirror_mode": { 304 | "name": "ipython", 305 | "version": 3 306 | }, 307 | "file_extension": ".py", 308 | "mimetype": "text/x-python", 309 | "name": "python", 310 | "nbconvert_exporter": "python", 311 | "pygments_lexer": "ipython3", 312 | "version": "3.8.5" 313 | }, 314 | "toc": { 315 | "base_numbering": 1, 316 | "nav_menu": {}, 317 | "number_sections": true, 318 | "sideBar": true, 319 | "skip_h1_title": true, 320 | "title_cell": "Table of Contents", 321 | "title_sidebar": "Table of Contents", 322 | "toc_cell": false, 323 | "toc_position": {}, 324 | "toc_section_display": true, 325 | "toc_window_display": false 326 | }, 327 | "varInspector": { 328 | "cols": { 329 | "lenName": 16, 330 | "lenType": 16, 331 | "lenVar": 40 332 | }, 333 | "kernels_config": { 334 | "python": { 335 | "delete_cmd_postfix": "", 336 | "delete_cmd_prefix": "del ", 337 | "library": "var_list.py", 338 | "varRefreshCmd": "print(var_dic_list())" 339 | }, 340 | "r": { 341 | "delete_cmd_postfix": ") ", 342 | "delete_cmd_prefix": "rm(", 343 | "library": "var_list.r", 344 | "varRefreshCmd": "cat(var_dic_list()) " 345 | } 346 | }, 347 | "types_to_exclude": [ 348 | "module", 349 | "function", 350 | "builtin_function_or_method", 351 | "instance", 352 | "_Feature" 353 | ], 354 | "window_display": false 355 | } 356 | }, 357 | "nbformat": 4, 358 | "nbformat_minor": 4 359 | } 360 | -------------------------------------------------------------------------------- /FeatureCollection/vector_styling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"Open" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Uncomment the following line to install [geemap](https://geemap.org) if needed." 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "# !pip install geemap" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "**Styling Earth Engine vector data**" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "import ee\n", 40 | "import geemap" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "# geemap.update_package()" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "## Use the default style" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "Map = geemap.Map()\n", 66 | "\n", 67 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 68 | "\n", 69 | "Map.addLayer(states, {}, \"US States\")\n", 70 | "Map" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "## Use Image.paint()" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "Map = geemap.Map()\n", 87 | "\n", 88 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 89 | "image = ee.Image().paint(states, 0, 3)\n", 90 | "\n", 91 | "Map.addLayer(image, {'palette': 'red'}, \"US States\")\n", 92 | "Map" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "## Use FeatureCollection.style()" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [ 108 | "Map = geemap.Map()\n", 109 | "\n", 110 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 111 | "style = {'color': '0000ffff', 'width': 2, 'lineType': 'solid', 'fillColor': '00000080'}\n", 112 | "\n", 113 | "Map.addLayer(states.style(**style), {}, \"US States\")\n", 114 | "Map" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "## Use add_styled_vector()" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "Map = geemap.Map()\n", 131 | "\n", 132 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 133 | "\n", 134 | "vis_params = {\n", 135 | " 'color': '000000', \n", 136 | " 'colorOpacity': 1,\n", 137 | " 'pointSize': 3,\n", 138 | " 'pointShape': 'circle',\n", 139 | " 'width': 2,\n", 140 | " 'lineType': 'solid', \n", 141 | " 'fillColorOpacity': 0.66 \n", 142 | "}\n", 143 | "\n", 144 | "palette = ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']\n", 145 | "\n", 146 | "Map.add_styled_vector(states, column=\"NAME\", palette=palette, layer_name=\"Styled vector\", **vis_params)\n", 147 | "Map" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "import geemap.colormaps as cm" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "Map = geemap.Map()\n", 166 | "\n", 167 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 168 | "\n", 169 | "vis_params = {\n", 170 | " 'color': '000000', \n", 171 | " 'colorOpacity': 1,\n", 172 | " 'pointSize': 3,\n", 173 | " 'pointShape': 'circle',\n", 174 | " 'width': 2,\n", 175 | " 'lineType': 'solid', \n", 176 | " 'fillColorOpacity': 0.66 \n", 177 | "}\n", 178 | "\n", 179 | "palette = list(cm.palettes.gist_earth.n12)\n", 180 | "\n", 181 | "Map.add_styled_vector(states, column=\"NAME\", palette=palette, layer_name=\"Styled vector\", **vis_params)\n", 182 | "Map" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": {}, 188 | "source": [ 189 | "## Use interactive GUI" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "Map = geemap.Map()\n", 199 | "\n", 200 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 201 | "\n", 202 | "Map.addLayer(states, {}, \"US States\")\n", 203 | "Map" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": null, 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [] 212 | } 213 | ], 214 | "metadata": { 215 | "hide_input": false, 216 | "kernelspec": { 217 | "display_name": "Python 3", 218 | "language": "python", 219 | "name": "python3" 220 | }, 221 | "language_info": { 222 | "codemirror_mode": { 223 | "name": "ipython", 224 | "version": 3 225 | }, 226 | "file_extension": ".py", 227 | "mimetype": "text/x-python", 228 | "name": "python", 229 | "nbconvert_exporter": "python", 230 | "pygments_lexer": "ipython3", 231 | "version": "3.8.5" 232 | }, 233 | "toc": { 234 | "base_numbering": 1, 235 | "nav_menu": {}, 236 | "number_sections": true, 237 | "sideBar": true, 238 | "skip_h1_title": true, 239 | "title_cell": "Table of Contents", 240 | "title_sidebar": "Table of Contents", 241 | "toc_cell": false, 242 | "toc_position": { 243 | "height": "calc(100% - 180px)", 244 | "left": "10px", 245 | "top": "150px", 246 | "width": "262px" 247 | }, 248 | "toc_section_display": true, 249 | "toc_window_display": true 250 | }, 251 | "varInspector": { 252 | "cols": { 253 | "lenName": 16, 254 | "lenType": 16, 255 | "lenVar": 40 256 | }, 257 | "kernels_config": { 258 | "python": { 259 | "delete_cmd_postfix": "", 260 | "delete_cmd_prefix": "del ", 261 | "library": "var_list.py", 262 | "varRefreshCmd": "print(var_dic_list())" 263 | }, 264 | "r": { 265 | "delete_cmd_postfix": ") ", 266 | "delete_cmd_prefix": "rm(", 267 | "library": "var_list.r", 268 | "varRefreshCmd": "cat(var_dic_list()) " 269 | } 270 | }, 271 | "types_to_exclude": [ 272 | "module", 273 | "function", 274 | "builtin_function_or_method", 275 | "instance", 276 | "_Feature" 277 | ], 278 | "window_display": false 279 | } 280 | }, 281 | "nbformat": 4, 282 | "nbformat_minor": 4 283 | } 284 | -------------------------------------------------------------------------------- /Image/conditional_operations.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/Image/conditional_operations.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Relational, conditional and Boolean operations**\n", 15 | "\n", 16 | "Reference: " 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "import ee\n", 26 | "import geemap" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "Map = geemap.Map(basemap=\"HYBRID\")" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "To perform per-pixel comparisons between images, use relational operators. To extract urbanized areas in an image, this example uses relational operators to threshold spectral indices, combining the thresholds with `And()`:" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "metadata": { 49 | "scrolled": false 50 | }, 51 | "outputs": [], 52 | "source": [ 53 | "# Load a Landsat 8 image.\n", 54 | "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n", 55 | "\n", 56 | "# Create NDVI and NDWI spectral indices.\n", 57 | "ndvi = image.normalizedDifference(['B5', 'B4'])\n", 58 | "ndwi = image.normalizedDifference(['B3', 'B5'])\n", 59 | "\n", 60 | "# Create a binary layer using logical operations.\n", 61 | "bare = ndvi.lt(0.2).And(ndwi.lt(0))\n", 62 | "\n", 63 | "# Mask and display the binary layer.\n", 64 | "Map.setCenter(-122.3578, 37.7726, 12)\n", 65 | "Map.addLayer(bare.selfMask(), {}, 'bare')\n", 66 | "\n", 67 | "Map" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "As illustrated by this example, the output of relational and boolean operators is either True (1) or False (0). To mask the 0's, you can mask the resultant binary image with itself. \n", 75 | "\n", 76 | "The binary images that are returned by relational and boolean operators can be used with mathematical operators. This example creates zones of urbanization in a nighttime lights image using relational operators and `image.add()`:" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 86 | "\n", 87 | "# Load a 2012 nightlights image.\n", 88 | "nl2012 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182012')\n", 89 | "lights = nl2012.select('stable_lights')\n", 90 | "Map.addLayer(lights, {}, 'Nighttime lights')\n", 91 | "\n", 92 | "# Define arbitrary thresholds on the 6-bit stable lights band.\n", 93 | "zones = lights.gt(30).add(lights.gt(55)).add(lights.gt(62))\n", 94 | "\n", 95 | "# Display the thresholded image as three distinct zones near Paris.\n", 96 | "palette = ['000000', '0000FF', '00FF00', 'FF0000']\n", 97 | "Map.setCenter(2.373, 48.8683, 8)\n", 98 | "Map.addLayer(zones, {'min': 0, 'max': 3, 'palette': palette}, 'development zones')\n", 99 | "\n", 100 | "Map" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "Note that the code in the previous example is equivalent to using a [ternary operator](http://en.wikipedia.org/wiki/%3F:) implemented by `expression()`:" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": { 114 | "scrolled": true 115 | }, 116 | "outputs": [], 117 | "source": [ 118 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 119 | "\n", 120 | "# Create zones using an expression, display.\n", 121 | "zonesExp = nl2012.expression(\n", 122 | " \"(b('stable_lights') > 62) ? 3\" +\n", 123 | " \": (b('stable_lights') > 55) ? 2\" +\n", 124 | " \": (b('stable_lights') > 30) ? 1\" +\n", 125 | " \": 0\"\n", 126 | ")\n", 127 | "Map.addLayer(zonesExp, {'min': 0, 'max': 3, 'palette': palette}, 'development zones (ternary)')\n", 128 | "Map.setCenter(2.373, 48.8683, 8)\n", 129 | "\n", 130 | "Map" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "Observe that in the previous expression example, the band of interest is referenced using the`b()` function, rather than a dictionary of variable names. (Learn more about image expressions on [this page](https://developers.google.com/earth-engine/image_math#expressions). Using either mathematical operators or an expression, the output is the same and should look something like Figure 2.\n", 138 | "\n", 139 | "Another way to implement conditional operations on images is with the `image.where()` operator. Consider the need to replace masked pixels with some other data. In the following example, cloudy pixels are replaced by pixels from a cloud-free image using `where()`:" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 149 | "\n", 150 | "# Load a cloudy Landsat 8 image.\n", 151 | "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20130603')\n", 152 | "Map.addLayer(image,\n", 153 | " {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5},\n", 154 | " 'original image')\n", 155 | "\n", 156 | "# Load another image to replace the cloudy pixels.\n", 157 | "replacement = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20130416')\n", 158 | "\n", 159 | "# Compute a cloud score band.\n", 160 | "cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud')\n", 161 | "Map.addLayer(cloud, {}, 'Cloud score')\n", 162 | "\n", 163 | "# Set cloudy pixels to the other image.\n", 164 | "replaced = image.where(cloud.gt(10), replacement)\n", 165 | "\n", 166 | "# Display the result.\n", 167 | "Map.centerObject(image, 9)\n", 168 | "Map.addLayer(replaced,\n", 169 | " {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5},\n", 170 | " 'clouds replaced')\n", 171 | "Map" 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": {}, 177 | "source": [ 178 | "In this example, observe the use of the `simpleCloudScore()` algorithm. This algorithm ranks pixels by cloudiness on a scale of 0-100, with 100 most cloudy. Learn more about `simpleCloudScore()` on the [Landsat Algorithms page](https://developers.google.com/earth-engine/landsat#simple-cloud-score)." 179 | ] 180 | } 181 | ], 182 | "metadata": { 183 | "anaconda-cloud": {}, 184 | "hide_input": false, 185 | "kernelspec": { 186 | "display_name": "Python 3", 187 | "language": "python", 188 | "name": "python3" 189 | }, 190 | "language_info": { 191 | "codemirror_mode": { 192 | "name": "ipython", 193 | "version": 3 194 | }, 195 | "file_extension": ".py", 196 | "mimetype": "text/x-python", 197 | "name": "python", 198 | "nbconvert_exporter": "python", 199 | "pygments_lexer": "ipython3", 200 | "version": "3.8.5" 201 | }, 202 | "toc": { 203 | "base_numbering": 1, 204 | "nav_menu": {}, 205 | "number_sections": true, 206 | "sideBar": true, 207 | "skip_h1_title": false, 208 | "title_cell": "Table of Contents", 209 | "title_sidebar": "Contents", 210 | "toc_cell": false, 211 | "toc_position": {}, 212 | "toc_section_display": true, 213 | "toc_window_display": false 214 | }, 215 | "varInspector": { 216 | "cols": { 217 | "lenName": 16, 218 | "lenType": 16, 219 | "lenVar": 40 220 | }, 221 | "kernels_config": { 222 | "python": { 223 | "delete_cmd_postfix": "", 224 | "delete_cmd_prefix": "del ", 225 | "library": "var_list.py", 226 | "varRefreshCmd": "print(var_dic_list())" 227 | }, 228 | "r": { 229 | "delete_cmd_postfix": ") ", 230 | "delete_cmd_prefix": "rm(", 231 | "library": "var_list.r", 232 | "varRefreshCmd": "cat(var_dic_list()) " 233 | } 234 | }, 235 | "types_to_exclude": [ 236 | "module", 237 | "function", 238 | "builtin_function_or_method", 239 | "instance", 240 | "_Feature" 241 | ], 242 | "window_display": false 243 | } 244 | }, 245 | "nbformat": 4, 246 | "nbformat_minor": 1 247 | } 248 | -------------------------------------------------------------------------------- /Image/image_colorbar.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/Image/image_colorbar.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "# !pip install geemap" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "import ee\n", 26 | "import geemap\n", 27 | "import geemap.colormaps as cm" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "## Colormap" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "# geemap.update_package()" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "cm.palettes.dem" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "cm.palettes.ndvi" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "cm.palettes.ndwi" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "cm.get_palette('terrain', n_class=8)" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "cm.plot_colormap('terrain', width=8.0, height=0.4, orientation='horizontal')" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": { 95 | "scrolled": false 96 | }, 97 | "outputs": [], 98 | "source": [ 99 | "cm.list_colormaps()" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "metadata": { 106 | "scrolled": false 107 | }, 108 | "outputs": [], 109 | "source": [ 110 | "cm.plot_colormaps(width=12, height=0.4)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "## Colorbar" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "Map = geemap.Map()\n", 127 | "\n", 128 | "palette = cm.palettes.dem\n", 129 | "# palette = cm.palettes.terrain\n", 130 | "\n", 131 | "dem = ee.Image('USGS/SRTMGL1_003')\n", 132 | "vis_params = {\n", 133 | " 'min': 0,\n", 134 | " 'max': 4000,\n", 135 | " 'palette': palette}\n", 136 | "\n", 137 | "Map.addLayer(dem, vis_params, 'SRTM DEM')\n", 138 | "Map.add_colorbar(vis_params, label=\"Elevation (m)\", layer_name=\"SRTM DEM\")\n", 139 | "Map" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "Map.add_colorbar(vis_params, label=\"Elevation (m)\", orientation=\"vertical\", layer_name=\"SRTM DEM\")" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": null, 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "Map.add_colorbar(vis_params, label=\"Elevation (m)\", orientation=\"vertical\", layer_name=\"SRTM DEM\", transparent_bg=True)" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "Map.add_colorbar(vis_params, discrete=True, label=\"Elevation (m)\", orientation=\"vertical\", layer_name=\"SRTM DEM\")" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "## Legend" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": null, 179 | "metadata": {}, 180 | "outputs": [], 181 | "source": [ 182 | "legends = geemap.builtin_legends\n", 183 | "for legend in legends:\n", 184 | " print(legend)" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": null, 190 | "metadata": {}, 191 | "outputs": [], 192 | "source": [ 193 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 194 | "\n", 195 | "Map.add_basemap(\"FWS NWI Wetlands Raster\")\n", 196 | "Map.add_legend(builtin_legend=\"NWI\")\n", 197 | "\n", 198 | "Map" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": null, 204 | "metadata": {}, 205 | "outputs": [], 206 | "source": [ 207 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 208 | "\n", 209 | "Map.add_basemap(\"NLCD 2016 CONUS Land Cover\")\n", 210 | "Map.add_legend(builtin_legend=\"NLCD\")\n", 211 | "\n", 212 | "Map" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [ 221 | "Map = geemap.Map()\n", 222 | "\n", 223 | "legend_dict = {\n", 224 | " '11 Open Water': '466b9f',\n", 225 | " '12 Perennial Ice/Snow': 'd1def8',\n", 226 | " '21 Developed, Open Space': 'dec5c5',\n", 227 | " '22 Developed, Low Intensity': 'd99282',\n", 228 | " '23 Developed, Medium Intensity': 'eb0000',\n", 229 | " '24 Developed High Intensity': 'ab0000',\n", 230 | " '31 Barren Land (Rock/Sand/Clay)': 'b3ac9f',\n", 231 | " '41 Deciduous Forest': '68ab5f',\n", 232 | " '42 Evergreen Forest': '1c5f2c',\n", 233 | " '43 Mixed Forest': 'b5c58f',\n", 234 | " '51 Dwarf Scrub': 'af963c',\n", 235 | " '52 Shrub/Scrub': 'ccb879',\n", 236 | " '71 Grassland/Herbaceous': 'dfdfc2',\n", 237 | " '72 Sedge/Herbaceous': 'd1d182',\n", 238 | " '73 Lichens': 'a3cc51',\n", 239 | " '74 Moss': '82ba9e',\n", 240 | " '81 Pasture/Hay': 'dcd939',\n", 241 | " '82 Cultivated Crops': 'ab6c28',\n", 242 | " '90 Woody Wetlands': 'b8d9eb',\n", 243 | " '95 Emergent Herbaceous Wetlands': '6c9fb8'\n", 244 | "}\n", 245 | "\n", 246 | "landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')\n", 247 | "Map.addLayer(landcover, {}, 'NLCD Land Cover')\n", 248 | "\n", 249 | "Map.add_legend(title=\"NLCD Land Cover Classification\", legend_dict=legend_dict, layer_name='NLCD Land Cover')\n", 250 | "\n", 251 | "Map" 252 | ] 253 | } 254 | ], 255 | "metadata": { 256 | "hide_input": false, 257 | "kernelspec": { 258 | "display_name": "Python 3", 259 | "language": "python", 260 | "name": "python3" 261 | }, 262 | "language_info": { 263 | "codemirror_mode": { 264 | "name": "ipython", 265 | "version": 3 266 | }, 267 | "file_extension": ".py", 268 | "mimetype": "text/x-python", 269 | "name": "python", 270 | "nbconvert_exporter": "python", 271 | "pygments_lexer": "ipython3", 272 | "version": "3.8.5" 273 | }, 274 | "toc": { 275 | "base_numbering": 1, 276 | "nav_menu": {}, 277 | "number_sections": true, 278 | "sideBar": true, 279 | "skip_h1_title": false, 280 | "title_cell": "Table of Contents", 281 | "title_sidebar": "Contents", 282 | "toc_cell": false, 283 | "toc_position": {}, 284 | "toc_section_display": true, 285 | "toc_window_display": false 286 | }, 287 | "varInspector": { 288 | "cols": { 289 | "lenName": 16, 290 | "lenType": 16, 291 | "lenVar": 40 292 | }, 293 | "kernels_config": { 294 | "python": { 295 | "delete_cmd_postfix": "", 296 | "delete_cmd_prefix": "del ", 297 | "library": "var_list.py", 298 | "varRefreshCmd": "print(var_dic_list())" 299 | }, 300 | "r": { 301 | "delete_cmd_postfix": ") ", 302 | "delete_cmd_prefix": "rm(", 303 | "library": "var_list.r", 304 | "varRefreshCmd": "cat(var_dic_list()) " 305 | } 306 | }, 307 | "types_to_exclude": [ 308 | "module", 309 | "function", 310 | "builtin_function_or_method", 311 | "instance", 312 | "_Feature" 313 | ], 314 | "window_display": false 315 | } 316 | }, 317 | "nbformat": 4, 318 | "nbformat_minor": 4 319 | } 320 | -------------------------------------------------------------------------------- /Image/image_metadata.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/Image/image_metadata.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Image information and metadata**\n", 15 | "\n", 16 | "To explore image bands and properties in Python, `print()` the image with the `getInfo()` function. This information can also be accessed programmatically. For example, the following demonstrates how to access information about bands, projections and other metadata:" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "## Import libraries" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "import ee\n", 33 | "import geemap" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Create an interactive map " 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "Map = geemap.Map()\n", 50 | "Map" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "## Display data on the map" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "# Load an image.\n", 67 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 68 | "vis_params = {'bands': ['B5', 'B4', 'B3'], 'min': 0.0, 'max': 3000, 'opacity': 1.0, 'gamma': 1.2}\n", 69 | "\n", 70 | "# Center the map and display the image.\n", 71 | "Map.centerObject(image, zoom=8)\n", 72 | "Map.addLayer(image, vis_params, 'Landsat')" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "## Get image metadata" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | "Get information about the bands as a list." 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "bandNames = image.bandNames()\n", 96 | "print('Band names: ', bandNames.getInfo())" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "Get projection information from band 1. https://epsg.io/32610" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [ 112 | "b1proj = image.select('B1').projection()\n", 113 | "print('Band 1 projection: ', b1proj.getInfo()) " 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "Get scale (in meters) information from band 1." 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "b1scale = image.select('B1').projection().nominalScale()\n", 130 | "print('Band 1 scale: ', b1scale.getInfo()) " 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "Note that different bands can have different projections and scale." 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": null, 143 | "metadata": {}, 144 | "outputs": [], 145 | "source": [ 146 | "b10scale = image.select('B10').projection().nominalScale()\n", 147 | "print('Band 10 scale: ', b10scale.getInfo())" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "Get a list of all metadata properties." 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "properties = image.propertyNames()\n", 164 | "print('Metadata properties: ', properties.getInfo())" 165 | ] 166 | }, 167 | { 168 | "cell_type": "markdown", 169 | "metadata": {}, 170 | "source": [ 171 | "Get a specific metadata property." 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": null, 177 | "metadata": {}, 178 | "outputs": [], 179 | "source": [ 180 | "cloudiness = image.get('CLOUD_COVER')\n", 181 | "print('CLOUD_COVER: ', cloudiness.getInfo())" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "Get the timestamp and convert it to a date." 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": null, 194 | "metadata": {}, 195 | "outputs": [], 196 | "source": [ 197 | "date = ee.Date(image.get('system:time_start'))\n", 198 | "print('Timestamp: ', date.getInfo())" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": null, 204 | "metadata": {}, 205 | "outputs": [], 206 | "source": [ 207 | "date2 = date.format('YYYY-MM-dd')\n", 208 | "print('Timestamp: ', date2.getInfo())" 209 | ] 210 | }, 211 | { 212 | "cell_type": "markdown", 213 | "metadata": {}, 214 | "source": [ 215 | "## Use geemap to get image metadata" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": null, 221 | "metadata": {}, 222 | "outputs": [], 223 | "source": [ 224 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 225 | "image_props = geemap.image_props(image)" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": null, 231 | "metadata": {}, 232 | "outputs": [], 233 | "source": [ 234 | "image_props.getInfo()" 235 | ] 236 | } 237 | ], 238 | "metadata": { 239 | "anaconda-cloud": {}, 240 | "hide_input": false, 241 | "kernelspec": { 242 | "display_name": "Python 3", 243 | "language": "python", 244 | "name": "python3" 245 | }, 246 | "language_info": { 247 | "codemirror_mode": { 248 | "name": "ipython", 249 | "version": 3 250 | }, 251 | "file_extension": ".py", 252 | "mimetype": "text/x-python", 253 | "name": "python", 254 | "nbconvert_exporter": "python", 255 | "pygments_lexer": "ipython3", 256 | "version": "3.8.5" 257 | }, 258 | "toc": { 259 | "base_numbering": 1, 260 | "nav_menu": {}, 261 | "number_sections": true, 262 | "sideBar": true, 263 | "skip_h1_title": false, 264 | "title_cell": "Table of Contents", 265 | "title_sidebar": "Contents", 266 | "toc_cell": false, 267 | "toc_position": {}, 268 | "toc_section_display": true, 269 | "toc_window_display": false 270 | }, 271 | "varInspector": { 272 | "cols": { 273 | "lenName": 16, 274 | "lenType": 16, 275 | "lenVar": 40 276 | }, 277 | "kernels_config": { 278 | "python": { 279 | "delete_cmd_postfix": "", 280 | "delete_cmd_prefix": "del ", 281 | "library": "var_list.py", 282 | "varRefreshCmd": "print(var_dic_list())" 283 | }, 284 | "r": { 285 | "delete_cmd_postfix": ") ", 286 | "delete_cmd_prefix": "rm(", 287 | "library": "var_list.r", 288 | "varRefreshCmd": "cat(var_dic_list()) " 289 | } 290 | }, 291 | "types_to_exclude": [ 292 | "module", 293 | "function", 294 | "builtin_function_or_method", 295 | "instance", 296 | "_Feature" 297 | ], 298 | "window_display": false 299 | } 300 | }, 301 | "nbformat": 4, 302 | "nbformat_minor": 1 303 | } 304 | -------------------------------------------------------------------------------- /Image/image_overview.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/Image/image_overview.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Image Overview**\n", 15 | "\n", 16 | "Raster data are represented as `Image` objects in Earth Engine. Images are composed of one or more bands and each band has its own name, data type, scale, mask and projection. Each image has metadata stored as a set of properties.\n", 17 | "\n", 18 | "In addition to loading images from the archive by an image ID, you can also create images from constants, lists or other suitable Earth Engine objects. The following illustrates methods for creating images, getting band subsets, and manipulating bands.\n", 19 | "\n", 20 | "More information about ee.Image can be found in the [Earth Engine Documentation](https://developers.google.com/earth-engine/guides/image_overview)." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "# !pip isntall geemap" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": null, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "import ee\n", 39 | "import geemap" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "## Loading a single-band image\n", 47 | "\n", 48 | "Images can be loaded by pasting an Earth Engine asset ID into the ee.Image constructor. You can find image IDs in the [data catalog](https://developers.google.com/earth-engine/datasets). For example, to load SRTM Digital Elevation Data:" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "Map = geemap.Map(center=(40, -100), zoom=4)\n", 58 | "Map" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "dem = ee.Image('CGIAR/SRTM90_V4')\n", 68 | "Map.addLayer(dem, {}, \"DEM\")" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "# Set visualization parameters.\n", 78 | "vis_params = {\n", 79 | " 'min': 0,\n", 80 | " 'max': 4000,\n", 81 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n", 82 | "Map.addLayer(dem, vis_params, \"DEM Vis\")" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "## Loading a multi-band image" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "Map = geemap.Map()\n", 99 | "# Load an image.\n", 100 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 101 | "\n", 102 | "# Center the map and display the image.\n", 103 | "Map.centerObject(image, zoom=8)\n", 104 | "Map.addLayer(image, {}, 'Landsat')\n", 105 | "\n", 106 | "Map" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "vis_params = {'bands': ['B5', 'B4', 'B3'], 'min': 0.0, 'max': 3000, 'opacity': 1.0, 'gamma': 1.2}\n", 116 | "Map.addLayer(image, vis_params, \"Landsat Vis\")" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "## Getting image properties" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 133 | "props = geemap.image_props(image)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "props.getInfo()" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "## Selecting image bands" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": null, 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 159 | "bands = image.select(['B5', 'B4', 'B3'])" 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": null, 165 | "metadata": {}, 166 | "outputs": [], 167 | "source": [ 168 | "Map.addLayer(bands, vis_params, 'Landsat B543')\n", 169 | "Map" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "## Renaming band names" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 186 | "new_image = image.select(['B5', 'B4', 'B3'], ['NIR', 'Red', 'Green'])\n", 187 | "band_names = new_image.bandNames()" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "band_names.getInfo()" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": {}, 202 | "source": [ 203 | "## Adding a legend" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": null, 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [ 212 | "Map = geemap.Map()\n", 213 | "Map.add_basemap('HYBRID')\n", 214 | "Map" 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": null, 220 | "metadata": {}, 221 | "outputs": [], 222 | "source": [ 223 | "landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')\n", 224 | "Map.addLayer(landcover, {}, 'Land Cover')\n", 225 | "Map.add_legend(builtin_legend='NLCD', layer_name='Land Cover')" 226 | ] 227 | } 228 | ], 229 | "metadata": { 230 | "anaconda-cloud": {}, 231 | "hide_input": false, 232 | "kernelspec": { 233 | "display_name": "Python 3", 234 | "language": "python", 235 | "name": "python3" 236 | }, 237 | "language_info": { 238 | "codemirror_mode": { 239 | "name": "ipython", 240 | "version": 3 241 | }, 242 | "file_extension": ".py", 243 | "mimetype": "text/x-python", 244 | "name": "python", 245 | "nbconvert_exporter": "python", 246 | "pygments_lexer": "ipython3", 247 | "version": "3.8.5" 248 | }, 249 | "toc": { 250 | "base_numbering": 1, 251 | "nav_menu": {}, 252 | "number_sections": true, 253 | "sideBar": true, 254 | "skip_h1_title": false, 255 | "title_cell": "Table of Contents", 256 | "title_sidebar": "Contents", 257 | "toc_cell": false, 258 | "toc_position": { 259 | "height": "calc(100% - 180px)", 260 | "left": "10px", 261 | "top": "150px", 262 | "width": "384px" 263 | }, 264 | "toc_section_display": true, 265 | "toc_window_display": true 266 | }, 267 | "varInspector": { 268 | "cols": { 269 | "lenName": 16, 270 | "lenType": 16, 271 | "lenVar": 40 272 | }, 273 | "kernels_config": { 274 | "python": { 275 | "delete_cmd_postfix": "", 276 | "delete_cmd_prefix": "del ", 277 | "library": "var_list.py", 278 | "varRefreshCmd": "print(var_dic_list())" 279 | }, 280 | "r": { 281 | "delete_cmd_postfix": ") ", 282 | "delete_cmd_prefix": "rm(", 283 | "library": "var_list.r", 284 | "varRefreshCmd": "cat(var_dic_list()) " 285 | } 286 | }, 287 | "types_to_exclude": [ 288 | "module", 289 | "function", 290 | "builtin_function_or_method", 291 | "instance", 292 | "_Feature" 293 | ], 294 | "window_display": false 295 | } 296 | }, 297 | "nbformat": 4, 298 | "nbformat_minor": 1 299 | } 300 | -------------------------------------------------------------------------------- /Image/math_operations.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/Image/math_operations.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Mathematical operations**\n", 15 | "\n", 16 | "Reference: \n", 17 | "\n", 18 | "Earth Engine supports many basic mathematical operators. They share some common features. Earth Engine performs math operations per pixel. When an operator is applied to an image, it's applied to each unmasked pixel of each band. In the case of operations on two images, the operation is only applied at the locations where pixels in both images are unmasked. Earth Engine automatically matches bands between images. When an operator is applied to two images, the images are expected to have the same number of bands so they can be matched pairwise. However, if one of the images has only a single band, it is matched with all of the bands in the other image, essentially replicating that band enough times to match the other image." 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "import ee\n", 28 | "import geemap" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "Map = geemap.Map()" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Operators" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "Math operators perform basic arithmetic operations on image bands. They take two inputs: either two images or one image and a constant term, which is interpreted as a single-band constant image with no masked pixels. Operations are performed per pixel for each band.\n", 52 | "\n", 53 | "As a simple example, consider the task of calculating the Normalized Difference Vegetation Index (NDVI) using Landsat imagery, where `add()`, `subtract()`, and `divide()` operators are used:\n", 54 | "\n", 55 | "![](https://wikimedia.org/api/rest_v1/media/math/render/svg/6e8f5257f485c39659111ddc8b81452984e6278f)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "# Load a 5-year Landsat 7 composite 1999-2003.\n", 65 | "landsat1999 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003')\n", 66 | "\n", 67 | "# Compute NDVI.\n", 68 | "\n", 69 | "NIR = landsat1999.select('B4')\n", 70 | "Red = landsat1999.select('B3')\n", 71 | "\n", 72 | "ndvi1999 = NIR.subtract(Red).divide(NIR.add(Red))\n", 73 | "# ndvi1999 = landsat1999.normalizedDifference(['B4', 'B3'])\n", 74 | "\n", 75 | "palette = [\n", 76 | " 'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',\n", 77 | " '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',\n", 78 | " '012E01', '011D01', '011301']\n", 79 | "\n", 80 | "Map.addLayer(ndvi1999, {'palette': palette}, \"NDVI 1999\")\n", 81 | "Map" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "Only the intersection of unmasked pixels between the two inputs are considered and returned as unmasked, all else are masked. In general, if either input has only one band, then it is used against all the bands in the other input. If the inputs have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in the first input's order. The type of the output pixels is the union of the input types.\n", 89 | "\n", 90 | "The following example of multi-band image subtraction demonstrates how bands are matched automatically, resulting in a “change vector” for each pixel for each co-occurring band." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "# Load a 5-year Landsat 7 composite 2008-2012.\n", 100 | "landsat2008 = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012')\n", 101 | "\n", 102 | "# Compute multi-band difference between the 2008-2012 composite and the\n", 103 | "# previously loaded 1999-2003 composite.\n", 104 | "diff = landsat2008.subtract(landsat1999)\n", 105 | "Map.addLayer(diff, {'bands': ['B4', 'B3', 'B2'], 'min': -32, 'max': 32}, 'difference')\n", 106 | "\n", 107 | "# Compute the squared difference in each band.\n", 108 | "squaredDifference = diff.pow(2)\n", 109 | "Map.addLayer(squaredDifference, {'bands': ['B4', 'B3', 'B2'], 'max': 1000}, 'squared diff.')\n", 110 | "Map" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "In the second part of this example, the squared difference is computed using `image.pow(2)`. For the complete list of mathematical operators handling basic arithmetic, trigonometry, exponentiation, rounding, casting, bitwise operations and more, see the API documentation (in the Docs tab of the [Earth Engine Code Editor](https://code.earthengine.google.com/))." 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "## Expressions\n", 125 | "To implement more complex mathematical expressions, it may be more convenient to use `image.expression()`, which parses a text representation of a math operation. The following example uses `expression()` to compute the Enhanced Vegetation Index (EVI):" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": null, 131 | "metadata": {}, 132 | "outputs": [], 133 | "source": [ 134 | "Map = geemap.Map()" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "# Load a Landsat 8 image.\n", 144 | "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n", 145 | "\n", 146 | "# Compute the EVI using an expression.\n", 147 | "evi = image.expression(\n", 148 | " '2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {\n", 149 | " 'NIR': image.select('B5'),\n", 150 | " 'RED': image.select('B4'),\n", 151 | " 'BLUE': image.select('B2')\n", 152 | "})\n", 153 | "\n", 154 | "Map.centerObject(image, 9)\n", 155 | "Map.addLayer(image, {'bands': ['B5', 'B4', 'B3']}, 'Landsat 8')\n", 156 | "Map.addLayer(evi, {'min': -1, 'max': 1, 'palette': ['FF0000', '00FF00']}, 'EVI')\n", 157 | "Map" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "Observe that the first argument to expression is the textual representation of the math operation, the second argument is a dictionary where the keys are variable names used in the expression and the values are the image bands to which the variables should be mapped. Bands in the image may be referred to as `b(\"band name\")` or `b(index)`, for example `b(0)`, instead of providing the dictionary. Note that division functions as it does in Python: dividing two integers results in an integer. For example `10 / 20 = 0`. To change this behavior, multiply one of the operands by `1.0: 10 * 1.0 / 20 = 0.5`. Supported expression operators are listed in the following table.\n", 165 | "\n", 166 | "![](https://i.imgur.com/TyXM4s9.png)" 167 | ] 168 | } 169 | ], 170 | "metadata": { 171 | "anaconda-cloud": {}, 172 | "hide_input": false, 173 | "kernelspec": { 174 | "display_name": "Python 3", 175 | "language": "python", 176 | "name": "python3" 177 | }, 178 | "language_info": { 179 | "codemirror_mode": { 180 | "name": "ipython", 181 | "version": 3 182 | }, 183 | "file_extension": ".py", 184 | "mimetype": "text/x-python", 185 | "name": "python", 186 | "nbconvert_exporter": "python", 187 | "pygments_lexer": "ipython3", 188 | "version": "3.8.5" 189 | }, 190 | "toc": { 191 | "base_numbering": 1, 192 | "nav_menu": {}, 193 | "number_sections": true, 194 | "sideBar": true, 195 | "skip_h1_title": false, 196 | "title_cell": "Table of Contents", 197 | "title_sidebar": "Contents", 198 | "toc_cell": false, 199 | "toc_position": {}, 200 | "toc_section_display": true, 201 | "toc_window_display": false 202 | }, 203 | "varInspector": { 204 | "cols": { 205 | "lenName": 16, 206 | "lenType": 16, 207 | "lenVar": 40 208 | }, 209 | "kernels_config": { 210 | "python": { 211 | "delete_cmd_postfix": "", 212 | "delete_cmd_prefix": "del ", 213 | "library": "var_list.py", 214 | "varRefreshCmd": "print(var_dic_list())" 215 | }, 216 | "r": { 217 | "delete_cmd_postfix": ") ", 218 | "delete_cmd_prefix": "rm(", 219 | "library": "var_list.r", 220 | "varRefreshCmd": "cat(var_dic_list()) " 221 | } 222 | }, 223 | "types_to_exclude": [ 224 | "module", 225 | "function", 226 | "builtin_function_or_method", 227 | "instance", 228 | "_Feature" 229 | ], 230 | "window_display": false 231 | } 232 | }, 233 | "nbformat": 4, 234 | "nbformat_minor": 1 235 | } 236 | -------------------------------------------------------------------------------- /ImageCollection/cloud_free_composite.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/ImageCollection/cloud_free_composite.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import ee\n", 17 | "import geemap" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "Map = geemap.Map()\n", 27 | "Map" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "states = ee.FeatureCollection('TIGER/2018/States')\n", 37 | "TN = states.filter(ee.Filter.eq(\"NAME\", \"Tennessee\"))\n", 38 | "Map.addLayer(TN, {}, \"Tennessee\")" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "years = ee.List.sequence(2013, 2020)\n", 48 | "years.getInfo()" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "def yearly_image(year):\n", 58 | " \n", 59 | " start_date = ee.Date.fromYMD(year, 1, 1) \n", 60 | " end_date = start_date.advance(1, \"year\")\n", 61 | " \n", 62 | " collection = ee.ImageCollection('LANDSAT/LC08/C01/T1') \\\n", 63 | " .filterDate(start_date, end_date) \\\n", 64 | " .filterBounds(TN) \n", 65 | " \n", 66 | " image = ee.Algorithms.Landsat.simpleComposite(collection).clipToCollection(TN)\n", 67 | "\n", 68 | " return image" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "images = years.map(yearly_image)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "vis_params = {'bands': ['B5', 'B4', 'B3'], 'max': 128}" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "for index in range(0, 8):\n", 96 | " image = ee.Image(images.get(index))\n", 97 | " layer_name = \"Image \" + str(index + 2013)\n", 98 | " Map.addLayer(image, vis_params, layer_name)" 99 | ] 100 | } 101 | ], 102 | "metadata": { 103 | "hide_input": false, 104 | "kernelspec": { 105 | "display_name": "Python 3", 106 | "language": "python", 107 | "name": "python3" 108 | }, 109 | "language_info": { 110 | "codemirror_mode": { 111 | "name": "ipython", 112 | "version": 3 113 | }, 114 | "file_extension": ".py", 115 | "mimetype": "text/x-python", 116 | "name": "python", 117 | "nbconvert_exporter": "python", 118 | "pygments_lexer": "ipython3", 119 | "version": "3.8.5" 120 | }, 121 | "toc": { 122 | "base_numbering": 1, 123 | "nav_menu": {}, 124 | "number_sections": true, 125 | "sideBar": true, 126 | "skip_h1_title": false, 127 | "title_cell": "Table of Contents", 128 | "title_sidebar": "Contents", 129 | "toc_cell": false, 130 | "toc_position": {}, 131 | "toc_section_display": true, 132 | "toc_window_display": false 133 | }, 134 | "varInspector": { 135 | "cols": { 136 | "lenName": 16, 137 | "lenType": 16, 138 | "lenVar": 40 139 | }, 140 | "kernels_config": { 141 | "python": { 142 | "delete_cmd_postfix": "", 143 | "delete_cmd_prefix": "del ", 144 | "library": "var_list.py", 145 | "varRefreshCmd": "print(var_dic_list())" 146 | }, 147 | "r": { 148 | "delete_cmd_postfix": ") ", 149 | "delete_cmd_prefix": "rm(", 150 | "library": "var_list.r", 151 | "varRefreshCmd": "cat(var_dic_list()) " 152 | } 153 | }, 154 | "types_to_exclude": [ 155 | "module", 156 | "function", 157 | "builtin_function_or_method", 158 | "instance", 159 | "_Feature" 160 | ], 161 | "window_display": false 162 | } 163 | }, 164 | "nbformat": 4, 165 | "nbformat_minor": 5 166 | } 167 | -------------------------------------------------------------------------------- /ImageCollection/image_collection_overview.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/ImageCollection/image_collection_overview.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Getting Started with Earth Engine ImageCollection**\n", 15 | "\n", 16 | "As illustrated in the [Get Started section](https://developers.google.com/earth-engine/guides/getstarted) and the [ImageCollection Information section](https://developers.google.com/earth-engine/guides/ic_info), Earth Engine provides a variety of convenience methods for filtering image collections. Specifically, many common use cases are handled by `imageCollection.filterDate()`, and `imageCollection.filterBounds()`. For general purpose filtering, use `imageCollection.filter()` with an ee.Filter as an argument. The following example demonstrates both convenience methods and `filter()` to identify and remove images with bad registration from an `ImageCollection`:" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "import ee\n", 26 | "import geemap" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "Map = geemap.Map()\n", 36 | "Map" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "## Get collection size" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "print(collection.size().getInfo())" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "## Get the first image" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "image = collection.first()\n", 78 | "geemap.image_props(image).getInfo()" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "Map.addLayer(image, {}, \"First image\")\n", 88 | "Map.centerObject(image, 6)\n", 89 | "Map" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "## Filter by dates\n", 97 | "\n", 98 | "https://developers.google.com/earth-engine/apidocs/ee-imagecollection-filterdate" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 108 | " .filterDate('2020-01-01', '2020-12-31')" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "print(collection.size().getInfo())" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "image2 = collection.first()\n", 127 | "Map.addLayer(image2, {}, \"Another image\")\n", 128 | "Map.centerObject(image2, 6)\n", 129 | "Map" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "## Filter by location\n", 137 | "\n", 138 | "https://developers.google.com/earth-engine/apidocs/ee-imagecollection-filterbounds" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": null, 144 | "metadata": {}, 145 | "outputs": [], 146 | "source": [ 147 | "roi = ee.Geometry.Point(-122.4488, 37.7589)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 157 | " .filterDate('2020-01-01', '2020-12-31') \\\n", 158 | " .filterBounds(roi)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [ 167 | "print(collection.size().getInfo())" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [ 176 | "Map = geemap.Map()\n", 177 | "image = collection.first()\n", 178 | "\n", 179 | "vis_param = {'min': 0, \n", 180 | " 'max': 2000, \n", 181 | " 'bands': ['B5', 'B4', 'B3'], \n", 182 | " 'gamma': 1.5}\n", 183 | "\n", 184 | "Map.addLayer(image, vis_param, \"First mage\")\n", 185 | "Map.centerObject(image, 8)\n", 186 | "\n", 187 | "Map" 188 | ] 189 | }, 190 | { 191 | "cell_type": "markdown", 192 | "metadata": {}, 193 | "source": [ 194 | "## Filter by metadata\n", 195 | "\n", 196 | "https://developers.google.com/earth-engine/apidocs/ee-imagecollection-filtermetadata" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [ 205 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 206 | " .filterDate('2020-01-01', '2020-12-31') \\\n", 207 | " .filterBounds(ee.Geometry.Point(-122.4488, 37.7589)) \\\n", 208 | " .filterMetadata('CLOUD_COVER', 'less_than', 10) \\\n", 209 | " .sort(\"CLOUD_COVER\")" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": null, 215 | "metadata": {}, 216 | "outputs": [], 217 | "source": [ 218 | "Map = geemap.Map()\n", 219 | "image = collection.first()\n", 220 | "\n", 221 | "vis_param = {'min': 0, \n", 222 | " 'max': 2000, \n", 223 | " 'bands': ['B5', 'B4', 'B3'], \n", 224 | " 'gamma': 1.5}\n", 225 | "\n", 226 | "Map.addLayer(image, vis_param, \"First mage\")\n", 227 | "Map.centerObject(image, 8)\n", 228 | "\n", 229 | "Map" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": null, 235 | "metadata": {}, 236 | "outputs": [], 237 | "source": [ 238 | "geemap.image_props(image).getInfo()" 239 | ] 240 | }, 241 | { 242 | "cell_type": "markdown", 243 | "metadata": {}, 244 | "source": [ 245 | "## Get image collection properties" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": null, 251 | "metadata": {}, 252 | "outputs": [], 253 | "source": [ 254 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 255 | " .filterDate('2020-01-01', '2020-12-31') \\\n", 256 | " .filterBounds(ee.Geometry.Point(-122.4488, 37.7589)) \\\n", 257 | " .filterMetadata('CLOUD_COVER', 'less_than', 10)" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": null, 263 | "metadata": {}, 264 | "outputs": [], 265 | "source": [ 266 | "collection.aggregate_array('CLOUD_COVER').getInfo()" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": null, 272 | "metadata": {}, 273 | "outputs": [], 274 | "source": [ 275 | "collection.aggregate_array('system:id').getInfo()" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": null, 281 | "metadata": {}, 282 | "outputs": [], 283 | "source": [ 284 | "collection.aggregate_mean('CLOUD_COVER').getInfo()" 285 | ] 286 | } 287 | ], 288 | "metadata": { 289 | "anaconda-cloud": {}, 290 | "hide_input": false, 291 | "kernelspec": { 292 | "display_name": "Python 3", 293 | "language": "python", 294 | "name": "python3" 295 | }, 296 | "language_info": { 297 | "codemirror_mode": { 298 | "name": "ipython", 299 | "version": 3 300 | }, 301 | "file_extension": ".py", 302 | "mimetype": "text/x-python", 303 | "name": "python", 304 | "nbconvert_exporter": "python", 305 | "pygments_lexer": "ipython3", 306 | "version": "3.8.5" 307 | }, 308 | "toc": { 309 | "base_numbering": 1, 310 | "nav_menu": {}, 311 | "number_sections": true, 312 | "sideBar": true, 313 | "skip_h1_title": false, 314 | "title_cell": "Table of Contents", 315 | "title_sidebar": "Contents", 316 | "toc_cell": false, 317 | "toc_position": {}, 318 | "toc_section_display": true, 319 | "toc_window_display": false 320 | }, 321 | "varInspector": { 322 | "cols": { 323 | "lenName": 16, 324 | "lenType": 16, 325 | "lenVar": 40 326 | }, 327 | "kernels_config": { 328 | "python": { 329 | "delete_cmd_postfix": "", 330 | "delete_cmd_prefix": "del ", 331 | "library": "var_list.py", 332 | "varRefreshCmd": "print(var_dic_list())" 333 | }, 334 | "r": { 335 | "delete_cmd_postfix": ") ", 336 | "delete_cmd_prefix": "rm(", 337 | "library": "var_list.r", 338 | "varRefreshCmd": "cat(var_dic_list()) " 339 | } 340 | }, 341 | "types_to_exclude": [ 342 | "module", 343 | "function", 344 | "builtin_function_or_method", 345 | "instance", 346 | "_Feature" 347 | ], 348 | "window_display": false 349 | } 350 | }, 351 | "nbformat": 4, 352 | "nbformat_minor": 1 353 | } 354 | -------------------------------------------------------------------------------- /ImageCollection/mapping_over_image_collection.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/ImageCollection/mapping_over_image_collection.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Mapping over an ImageCollection**\n", 15 | "\n", 16 | "Reference: https://developers.google.com/earth-engine/guides/ic_mapping\n", 17 | "\n", 18 | "To apply a function to every `Image` in an `ImageCollection` use `imageCollection.map()`. The only argument to `map()` is a function which takes one parameter: an `ee.Image`. " 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "import ee\n", 28 | "import geemap" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "Map = geemap.Map()" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Define a function" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "def minus1000(num):\n", 54 | " result = ee.Number(num).subtract(1000)\n", 55 | " return result" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "result = minus1000(2000)\n", 65 | "print(result.getInfo())" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "## Apply the map function" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "years = ee.List.sequence(2000, 2010)\n", 82 | "print(years.getInfo())" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": {}, 89 | "outputs": [], 90 | "source": [ 91 | "results = years.map(minus1000)\n", 92 | "print(results.getInfo())" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "## Use anonymous/lambda function" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [ 108 | "years = ee.List.sequence(2000, 2010)\n", 109 | "\n", 110 | "results = years.map(lambda x: ee.Number(x).subtract(1000))\n", 111 | "print(results.getInfo())" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "## Filter an ImageCollection" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "roi = ee.Geometry.Point(-83.92, 35.96) # Knoxville, Tennessee\n", 128 | "\n", 129 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 130 | " .filterBounds(roi) \\\n", 131 | " .filterDate(\"2019-01-01\", \"2020-01-01\") \\\n", 132 | " .sort(\"CLOUD_COVER\")\n", 133 | "\n", 134 | "print(collection.size().getInfo())" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "image = collection.first()" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": null, 149 | "metadata": { 150 | "scrolled": false 151 | }, 152 | "outputs": [], 153 | "source": [ 154 | "# image.getInfo()" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "geemap.image_props(image).getInfo()" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "collection.aggregate_array(\"CLOUD_COVER\").getInfo()" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "vis_params = {\n", 182 | " 'bands': ['B5', 'B4', 'B3'],\n", 183 | " 'min': 0, \n", 184 | " 'max': 3000,\n", 185 | " 'gamma': 1.0\n", 186 | "}\n", 187 | "\n", 188 | "Map.addLayer(image, vis_params, \"First image\")\n", 189 | "Map.centerObject(image)\n", 190 | "Map" 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "metadata": {}, 196 | "source": [ 197 | "## Select the best image each year" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": null, 203 | "metadata": {}, 204 | "outputs": [], 205 | "source": [ 206 | "roi = ee.Geometry.Point(-83.92, 35.96) # Knoxville, Tennessee\n", 207 | "\n", 208 | "\n", 209 | "def best_image(year):\n", 210 | " start_date = ee.Date.fromYMD(year, 1, 1)\n", 211 | " end_date = start_date.advance(1, 'year')\n", 212 | " \n", 213 | " image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 214 | " .filterBounds(roi) \\\n", 215 | " .filterDate(start_date, end_date) \\\n", 216 | " .sort(\"CLOUD_COVER\") \\\n", 217 | " .first()\n", 218 | " \n", 219 | " return image" 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": null, 225 | "metadata": {}, 226 | "outputs": [], 227 | "source": [ 228 | "start_year = 2013\n", 229 | "end_year = 2020\n", 230 | "years = ee.List.sequence(start_year, end_year)\n", 231 | "year_list = years.getInfo()\n", 232 | "print(year_list)" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": null, 238 | "metadata": {}, 239 | "outputs": [], 240 | "source": [ 241 | "images = years.map(best_image)" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": null, 247 | "metadata": {}, 248 | "outputs": [], 249 | "source": [ 250 | "count = images.size().getInfo()\n", 251 | "print(count)" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": null, 257 | "metadata": {}, 258 | "outputs": [], 259 | "source": [ 260 | "ee.ImageCollection(images).aggregate_array(\"CLOUD_COVER\").getInfo()" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "metadata": {}, 267 | "outputs": [], 268 | "source": [ 269 | "for index in range(0, count):\n", 270 | " image = ee.Image(images.get(index))\n", 271 | " layer_name = \"Image \" + str(year_list[index])\n", 272 | " Map.addLayer(image, vis_params, layer_name, False)" 273 | ] 274 | }, 275 | { 276 | "cell_type": "code", 277 | "execution_count": null, 278 | "metadata": {}, 279 | "outputs": [], 280 | "source": [ 281 | "Map" 282 | ] 283 | }, 284 | { 285 | "cell_type": "markdown", 286 | "metadata": {}, 287 | "source": [ 288 | "## Set image properties" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": null, 294 | "metadata": {}, 295 | "outputs": [], 296 | "source": [ 297 | "collection = ee.ImageCollection(images)" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": null, 303 | "metadata": {}, 304 | "outputs": [], 305 | "source": [ 306 | "collection.aggregate_array(\"system:time_start\").getInfo()" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": null, 312 | "metadata": {}, 313 | "outputs": [], 314 | "source": [ 315 | "collection = collection.map(lambda img: img.set({\"DATE\": ee.Date(img.get(\"system:time_start\")).format(\"YYYY-MM-dd\")}))" 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": null, 321 | "metadata": {}, 322 | "outputs": [], 323 | "source": [ 324 | "collection.aggregate_array(\"DATE\").getInfo()" 325 | ] 326 | } 327 | ], 328 | "metadata": { 329 | "anaconda-cloud": {}, 330 | "hide_input": false, 331 | "kernelspec": { 332 | "display_name": "Python 3", 333 | "language": "python", 334 | "name": "python3" 335 | }, 336 | "language_info": { 337 | "codemirror_mode": { 338 | "name": "ipython", 339 | "version": 3 340 | }, 341 | "file_extension": ".py", 342 | "mimetype": "text/x-python", 343 | "name": "python", 344 | "nbconvert_exporter": "python", 345 | "pygments_lexer": "ipython3", 346 | "version": "3.8.5" 347 | }, 348 | "toc": { 349 | "base_numbering": 1, 350 | "nav_menu": {}, 351 | "number_sections": true, 352 | "sideBar": true, 353 | "skip_h1_title": false, 354 | "title_cell": "Table of Contents", 355 | "title_sidebar": "Contents", 356 | "toc_cell": false, 357 | "toc_position": {}, 358 | "toc_section_display": true, 359 | "toc_window_display": false 360 | }, 361 | "varInspector": { 362 | "cols": { 363 | "lenName": 16, 364 | "lenType": 16, 365 | "lenVar": 40 366 | }, 367 | "kernels_config": { 368 | "python": { 369 | "delete_cmd_postfix": "", 370 | "delete_cmd_prefix": "del ", 371 | "library": "var_list.py", 372 | "varRefreshCmd": "print(var_dic_list())" 373 | }, 374 | "r": { 375 | "delete_cmd_postfix": ") ", 376 | "delete_cmd_prefix": "rm(", 377 | "library": "var_list.r", 378 | "varRefreshCmd": "cat(var_dic_list()) " 379 | } 380 | }, 381 | "types_to_exclude": [ 382 | "module", 383 | "function", 384 | "builtin_function_or_method", 385 | "instance", 386 | "_Feature" 387 | ], 388 | "window_display": false 389 | } 390 | }, 391 | "nbformat": 4, 392 | "nbformat_minor": 1 393 | } 394 | -------------------------------------------------------------------------------- /ImageCollection/reducing_image_collection.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/ImageCollection/reducing_image_collection.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Reducing an ImageCollection**\n", 15 | "\n", 16 | "To composite images in an `ImageCollection`, use `imageCollection.reduce()`. This will composite all the images in the collection to a single image representing, for example, the min, max, mean or standard deviation of the images. (See the Reducers section for more information about reducers). For example, to create a median value image from a collection:" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "## Create an interactive map" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "import ee\n", 33 | "import geemap" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [ 42 | "Map = geemap.Map()\n", 43 | "Map" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Compute a median image" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "# Load a Landsat 8 collection for a single path-row.\n", 60 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \\\n", 61 | " .filter(ee.Filter.eq('WRS_PATH', 44)) \\\n", 62 | " .filter(ee.Filter.eq('WRS_ROW', 34)) \\\n", 63 | " .filterDate('2014-01-01', '2015-01-01')\n", 64 | "\n", 65 | "# Compute a median image and display.\n", 66 | "median = collection.median()\n", 67 | "Map.setCenter(-122.3578, 37.7726, 12)\n", 68 | "Map.addLayer(median, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3}, 'median')" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "collection.size().getInfo()" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "collection.aggregate_array(\"system:id\").getInfo()" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": {}, 92 | "source": [ 93 | "## Use median reducer" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "At each location in the output image, in each band, the pixel value is the median of all unmasked pixels in the input imagery (the images in the collection). In the previous example, `median()` is a convenience method for the following call:" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "# Reduce the collection with a median reducer.\n", 110 | "median = collection.reduce(ee.Reducer.median())\n", 111 | "\n", 112 | "# Display the median image.\n", 113 | "Map.addLayer(median,\n", 114 | " {'bands': ['B4_median', 'B3_median', 'B2_median'], 'max': 0.3},\n", 115 | " 'also median')\n", 116 | "Map" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "## Create an image composite" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "states = ee.FeatureCollection('TIGER/2018/States')\n", 133 | "Map.addLayer(states, {}, \"US States\")" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "ca = states.filter(ee.Filter.eq(\"NAME\", \"California\"))\n", 143 | "Map.addLayer(ca, {}, \"California\")" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": null, 149 | "metadata": {}, 150 | "outputs": [], 151 | "source": [ 152 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \\\n", 153 | " .filterBounds(ca) \\\n", 154 | " .filterDate('2020-01-01', '2021-01-01')" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "collection.size().getInfo()" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "image = collection.median().clip(ca)\n", 173 | "Map.addLayer(image, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3}, 'Landsat 2020')" 174 | ] 175 | } 176 | ], 177 | "metadata": { 178 | "hide_input": false, 179 | "kernelspec": { 180 | "display_name": "Python 3", 181 | "language": "python", 182 | "name": "python3" 183 | }, 184 | "language_info": { 185 | "codemirror_mode": { 186 | "name": "ipython", 187 | "version": 3 188 | }, 189 | "file_extension": ".py", 190 | "mimetype": "text/x-python", 191 | "name": "python", 192 | "nbconvert_exporter": "python", 193 | "pygments_lexer": "ipython3", 194 | "version": "3.8.5" 195 | }, 196 | "toc": { 197 | "base_numbering": 1, 198 | "nav_menu": {}, 199 | "number_sections": true, 200 | "sideBar": true, 201 | "skip_h1_title": false, 202 | "title_cell": "Table of Contents", 203 | "title_sidebar": "Contents", 204 | "toc_cell": false, 205 | "toc_position": {}, 206 | "toc_section_display": true, 207 | "toc_window_display": false 208 | }, 209 | "varInspector": { 210 | "cols": { 211 | "lenName": 16, 212 | "lenType": 16, 213 | "lenVar": 40 214 | }, 215 | "kernels_config": { 216 | "python": { 217 | "delete_cmd_postfix": "", 218 | "delete_cmd_prefix": "del ", 219 | "library": "var_list.py", 220 | "varRefreshCmd": "print(var_dic_list())" 221 | }, 222 | "r": { 223 | "delete_cmd_postfix": ") ", 224 | "delete_cmd_prefix": "rm(", 225 | "library": "var_list.r", 226 | "varRefreshCmd": "cat(var_dic_list()) " 227 | } 228 | }, 229 | "types_to_exclude": [ 230 | "module", 231 | "function", 232 | "builtin_function_or_method", 233 | "instance", 234 | "_Feature" 235 | ], 236 | "window_display": false 237 | } 238 | }, 239 | "nbformat": 4, 240 | "nbformat_minor": 4 241 | } 242 | -------------------------------------------------------------------------------- /ImageCollection/visualizing_time_series.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/ImageCollection/visualizing_time_series.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import ee\n", 17 | "import geemap" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "# geemap.update_package()" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Visualizing weather data" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": { 40 | "scrolled": false 41 | }, 42 | "outputs": [], 43 | "source": [ 44 | "Map = geemap.Map()\n", 45 | "\n", 46 | "collection = ee.ImageCollection('NOAA/GFS0P25') \\\n", 47 | " .filterDate('2018-12-22', '2018-12-23') \\\n", 48 | " .limit(24) \\\n", 49 | " .select('temperature_2m_above_ground')\n", 50 | "\n", 51 | "vis_params = {\n", 52 | " 'min': -40.0,\n", 53 | " 'max': 35.0,\n", 54 | " 'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red']\n", 55 | "}\n", 56 | "\n", 57 | "first_image = collection.first()\n", 58 | "\n", 59 | "Map.addLayer(first_image, vis_params, \"First image\")\n", 60 | "Map.setCenter(-0.3490, 25.7900, 2)\n", 61 | "Map" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "image = collection.toBands()\n", 71 | "Map.addLayer(image, {}, \"Time series\", False)" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "labels = [str(n).zfill(2) + \":00\" for n in range(0, 24)]\n", 81 | "labels" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "Map.add_time_slider(collection, vis_params, labels=labels, time_interval=1)\n", 91 | "Map" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "## Visualizing vegetation data" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": { 105 | "scrolled": false 106 | }, 107 | "outputs": [], 108 | "source": [ 109 | "Map = geemap.Map()\n", 110 | "\n", 111 | "collection = ee.ImageCollection('MODIS/MCD43A4_006_NDVI') \\\n", 112 | " .filter(ee.Filter.date('2018-04-01', '2018-05-01')) \\\n", 113 | " .select(\"NDVI\")\\\n", 114 | "\n", 115 | "vis_params = {\n", 116 | " 'min': 0.0,\n", 117 | " 'max': 1.0,\n", 118 | " 'palette': [\n", 119 | " 'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',\n", 120 | " '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',\n", 121 | " '012E01', '011D01', '011301'\n", 122 | " ],\n", 123 | "}\n", 124 | "\n", 125 | "first_image = collection.first()\n", 126 | "\n", 127 | "Map.addLayer(first_image, vis_params, \"First image\")\n", 128 | "Map.setCenter(-7.03125, 31.0529339857, 2)\n", 129 | "Map" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "image = collection.toBands()\n", 139 | "Map.addLayer(image, {}, \"Time series\", False)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "labels = collection.aggregate_array(\"system:index\").getInfo()\n", 149 | "Map.add_time_slider(collection, vis_params, labels=labels, time_interval=1)" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "## Visualizing Landsat imagery" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "Map = geemap.Map()\n", 166 | "\n", 167 | "bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']\n", 168 | "image = ee.Image('LE7_TOA_5YEAR/1999_2003').select(bands)\n", 169 | "vis_params = {'min': 20, 'max': 200, 'gamma': 2.0}\n", 170 | "\n", 171 | "Map.add_time_slider(image, vis_params, labels=bands, time_interval=1)\n", 172 | "\n", 173 | "Map" 174 | ] 175 | } 176 | ], 177 | "metadata": { 178 | "hide_input": false, 179 | "kernelspec": { 180 | "display_name": "Python 3", 181 | "language": "python", 182 | "name": "python3" 183 | }, 184 | "language_info": { 185 | "codemirror_mode": { 186 | "name": "ipython", 187 | "version": 3 188 | }, 189 | "file_extension": ".py", 190 | "mimetype": "text/x-python", 191 | "name": "python", 192 | "nbconvert_exporter": "python", 193 | "pygments_lexer": "ipython3", 194 | "version": "3.8.5" 195 | }, 196 | "toc": { 197 | "base_numbering": 1, 198 | "nav_menu": {}, 199 | "number_sections": true, 200 | "sideBar": true, 201 | "skip_h1_title": false, 202 | "title_cell": "Table of Contents", 203 | "title_sidebar": "Contents", 204 | "toc_cell": false, 205 | "toc_position": {}, 206 | "toc_section_display": true, 207 | "toc_window_display": false 208 | }, 209 | "varInspector": { 210 | "cols": { 211 | "lenName": 16, 212 | "lenType": 16, 213 | "lenVar": 40 214 | }, 215 | "kernels_config": { 216 | "python": { 217 | "delete_cmd_postfix": "", 218 | "delete_cmd_prefix": "del ", 219 | "library": "var_list.py", 220 | "varRefreshCmd": "print(var_dic_list())" 221 | }, 222 | "r": { 223 | "delete_cmd_postfix": ") ", 224 | "delete_cmd_prefix": "rm(", 225 | "library": "var_list.r", 226 | "varRefreshCmd": "cat(var_dic_list()) " 227 | } 228 | }, 229 | "types_to_exclude": [ 230 | "module", 231 | "function", 232 | "builtin_function_or_method", 233 | "instance", 234 | "_Feature" 235 | ], 236 | "window_display": false 237 | } 238 | }, 239 | "nbformat": 4, 240 | "nbformat_minor": 4 241 | } 242 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Qiusheng Wu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gee-tutorials 2 | Google Earth Engine tutorials 3 | -------------------------------------------------------------------------------- /docs/Analysis/zonal_statistics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"Open\n", 8 | "\n", 9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed." 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "# !pip install geemap" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "import ee\n", 28 | "import geemap\n", 29 | "import os" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "## Create an interactive map" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "Map = geemap.Map()\n", 46 | "Map" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "## Add Earth Engine data" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": null, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "# Add Earth Engine dataset\n", 63 | "dem = ee.Image('USGS/SRTMGL1_003')\n", 64 | "\n", 65 | "# Set visualization parameters.\n", 66 | "dem_vis = {\n", 67 | " 'min': 0,\n", 68 | " 'max': 4000,\n", 69 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n", 70 | "\n", 71 | "# Add Earth Engine DEM to map\n", 72 | "Map.addLayer(dem, dem_vis, 'SRTM DEM')\n", 73 | "\n", 74 | "# Add Landsat data to map\n", 75 | "landsat = ee.Image('LE7_TOA_5YEAR/1999_2003')\n", 76 | "\n", 77 | "landsat_vis = {\n", 78 | " 'bands': ['B4', 'B3', 'B2'], \n", 79 | " 'gamma': 1.4\n", 80 | "}\n", 81 | "Map.addLayer(landsat, landsat_vis, \"Landsat\", False)\n", 82 | "\n", 83 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 84 | "Map.addLayer(states, {}, 'US States')" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "## Compute zonal statistics for one image" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": null, 97 | "metadata": {}, 98 | "outputs": [], 99 | "source": [ 100 | "out_dir = os.path.expanduser('~/Downloads')\n", 101 | "if not os.path.exists(out_dir):\n", 102 | " os.makedirs(out_dir)" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": {}, 109 | "outputs": [], 110 | "source": [ 111 | "out_dem_stats = os.path.join(out_dir, 'dem_stats.csv') \n", 112 | "\n", 113 | "# Allowed output formats: csv, shp, json, kml, kmz\n", 114 | "# Allowed statistics type: MEAN, MAXIMUM, MINIMUM, MEDIAN, STD, MIN_MAX, VARIANCE, SUM\n", 115 | "geemap.zonal_statistics(dem, states, out_dem_stats, statistics_type='MEAN', scale=1000)" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": { 122 | "scrolled": false 123 | }, 124 | "outputs": [], 125 | "source": [ 126 | "out_landsat_stats = os.path.join(out_dir, 'landsat_stats.csv') \n", 127 | "geemap.zonal_statistics(landsat, states, out_landsat_stats, statistics_type='SUM', scale=1000)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "## Compute zonal statistics for time-series images" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "Map = geemap.Map()\n", 144 | "\n", 145 | "collection = ee.ImageCollection('MODIS/MCD43A4_006_NDVI') \\\n", 146 | " .filter(ee.Filter.date('2018-04-01', '2018-05-01')) \\\n", 147 | " .select(\"NDVI\")\\\n", 148 | "\n", 149 | "vis_params = {\n", 150 | " 'min': 0.0,\n", 151 | " 'max': 1.0,\n", 152 | " 'palette': [\n", 153 | " 'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',\n", 154 | " '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',\n", 155 | " '012E01', '011D01', '011301'\n", 156 | " ],\n", 157 | "}\n", 158 | "\n", 159 | "first_image = collection.first()\n", 160 | "\n", 161 | "Map.addLayer(first_image, vis_params, \"First image\")\n", 162 | "Map.setCenter(-7.03125, 31.0529339857, 2)\n", 163 | "Map" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "modis = collection.toBands()\n", 173 | "Map.addLayer(modis, {}, \"MODIS Time series\", False)" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": null, 179 | "metadata": {}, 180 | "outputs": [], 181 | "source": [ 182 | "out_landsat_stats = os.path.join(out_dir, 'ndvi.csv') \n", 183 | "geemap.zonal_statistics(modis, states, out_landsat_stats, statistics_type='MEAN', scale=1000)" 184 | ] 185 | } 186 | ], 187 | "metadata": { 188 | "hide_input": false, 189 | "kernelspec": { 190 | "display_name": "Python 3", 191 | "language": "python", 192 | "name": "python3" 193 | }, 194 | "language_info": { 195 | "codemirror_mode": { 196 | "name": "ipython", 197 | "version": 3 198 | }, 199 | "file_extension": ".py", 200 | "mimetype": "text/x-python", 201 | "name": "python", 202 | "nbconvert_exporter": "python", 203 | "pygments_lexer": "ipython3", 204 | "version": "3.8.5" 205 | }, 206 | "toc": { 207 | "base_numbering": 1, 208 | "nav_menu": {}, 209 | "number_sections": true, 210 | "sideBar": true, 211 | "skip_h1_title": true, 212 | "title_cell": "Table of Contents", 213 | "title_sidebar": "Table of Contents", 214 | "toc_cell": false, 215 | "toc_position": {}, 216 | "toc_section_display": true, 217 | "toc_window_display": true 218 | }, 219 | "varInspector": { 220 | "cols": { 221 | "lenName": 16, 222 | "lenType": 16, 223 | "lenVar": 40 224 | }, 225 | "kernels_config": { 226 | "python": { 227 | "delete_cmd_postfix": "", 228 | "delete_cmd_prefix": "del ", 229 | "library": "var_list.py", 230 | "varRefreshCmd": "print(var_dic_list())" 231 | }, 232 | "r": { 233 | "delete_cmd_postfix": ") ", 234 | "delete_cmd_prefix": "rm(", 235 | "library": "var_list.r", 236 | "varRefreshCmd": "cat(var_dic_list()) " 237 | } 238 | }, 239 | "types_to_exclude": [ 240 | "module", 241 | "function", 242 | "builtin_function_or_method", 243 | "instance", 244 | "_Feature" 245 | ], 246 | "window_display": false 247 | } 248 | }, 249 | "nbformat": 4, 250 | "nbformat_minor": 4 251 | } 252 | -------------------------------------------------------------------------------- /docs/Analysis/zonal_stats_by_group.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"Open\n", 8 | "\n", 9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed." 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "# !pip install geemap" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "import os\n", 28 | "import ee\n", 29 | "import geemap" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "## Analyzing U.S. Land Cover" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "Map = geemap.Map()\n", 46 | "Map" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "### Add NLCD data\n", 54 | "\n", 55 | "NLCD: USGS National Land Cover Database\n", 56 | "\n", 57 | "https://developers.google.com/earth-engine/datasets/catalog/USGS_NLCD_RELEASES_2016_REL" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "dataset = ee.Image('USGS/NLCD/NLCD2016')\n", 67 | "landcover = ee.Image(dataset.select('landcover'))\n", 68 | "Map.addLayer(landcover, {}, 'NLCD 2016')\n", 69 | "\n", 70 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 71 | "Map.addLayer(states, {}, 'US States')" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "Map.add_legend(builtin_legend='NLCD')" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "### Calculate land cover compostion of each US state" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": null, 93 | "metadata": {}, 94 | "outputs": [], 95 | "source": [ 96 | "out_dir = os.path.expanduser('~/Downloads')\n", 97 | "if not os.path.exists(out_dir):\n", 98 | " os.makedirs(out_dir)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "nlcd_stats = os.path.join(out_dir, 'nlcd_stats_sum.csv') \n", 108 | " \n", 109 | "# statistics_type can be either 'SUM' or 'PERCENTAGE'\n", 110 | "# denominator can be used to convert square meters to other areal units, such as square kilimeters\n", 111 | "geemap.zonal_statistics_by_group(landcover, states, nlcd_stats, statistics_type='SUM', denominator=1000000, decimal_places=2)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": null, 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [ 120 | "nlcd_stats = os.path.join(out_dir, 'nlcd_stats_pct.csv') \n", 121 | "geemap.zonal_statistics_by_group(landcover, states, nlcd_stats, statistics_type='PERCENTAGE')" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "## Analyzing Global Land Cover" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "### Add MODIS global land cover data\n", 136 | "\n", 137 | "MCD12Q1.006 MODIS Land Cover Type Yearly Global 500m\n", 138 | "\n", 139 | "https://developers.google.com/earth-engine/datasets/catalog/MODIS_006_MCD12Q1" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "Map = geemap.Map()\n", 149 | "\n", 150 | "landcover = ee.Image('MODIS/006/MCD12Q1/2019_01_01') \\\n", 151 | " .select('LC_Type1')\n", 152 | "\n", 153 | "igbpLandCoverVis = {\n", 154 | " 'min': 1.0,\n", 155 | " 'max': 17.0,\n", 156 | " 'palette': [\n", 157 | " '05450a', '086a10', '54a708', '78d203', '009900', 'c6b044', 'dcd159',\n", 158 | " 'dade48', 'fbff13', 'b6ff05', '27ff87', 'c24f44', 'a5a5a5', 'ff6d4c',\n", 159 | " '69fff8', 'f9ffa4', '1c0dff'\n", 160 | " ],\n", 161 | "}\n", 162 | "\n", 163 | "Map.setCenter(6.746, 46.529, 2)\n", 164 | "Map.addLayer(landcover, igbpLandCoverVis, 'MODIS Land Cover')\n", 165 | "\n", 166 | "countries = ee.FeatureCollection('users/giswqs/public/countries')\n", 167 | "Map.addLayer(countries, {}, \"Countries\")\n", 168 | "\n", 169 | "Map" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "Map.add_legend(builtin_legend='MODIS/051/MCD12Q1')" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": null, 184 | "metadata": {}, 185 | "outputs": [], 186 | "source": [ 187 | "out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')\n", 188 | "global_stats = os.path.join(out_dir, 'global_stats_sum.csv') \n", 189 | "\n", 190 | "# statistics_type can be either 'SUM' or 'PERCENTAGE'\n", 191 | "# denominator can be used to convert square meters to other areal units, such as square kilimeters\n", 192 | "geemap.zonal_statistics_by_group(landcover, countries, global_stats, statistics_type='SUM', denominator=1000000, decimal_places=2)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "global_stats = os.path.join(out_dir, 'global_stats_pct.csv') \n", 202 | "geemap.zonal_statistics_by_group(landcover, countries, global_stats, statistics_type='PERCENTAGE')" 203 | ] 204 | } 205 | ], 206 | "metadata": { 207 | "hide_input": false, 208 | "kernelspec": { 209 | "display_name": "Python 3", 210 | "language": "python", 211 | "name": "python3" 212 | }, 213 | "language_info": { 214 | "codemirror_mode": { 215 | "name": "ipython", 216 | "version": 3 217 | }, 218 | "file_extension": ".py", 219 | "mimetype": "text/x-python", 220 | "name": "python", 221 | "nbconvert_exporter": "python", 222 | "pygments_lexer": "ipython3", 223 | "version": "3.8.5" 224 | }, 225 | "toc": { 226 | "base_numbering": 1, 227 | "nav_menu": {}, 228 | "number_sections": true, 229 | "sideBar": true, 230 | "skip_h1_title": true, 231 | "title_cell": "Table of Contents", 232 | "title_sidebar": "Table of Contents", 233 | "toc_cell": false, 234 | "toc_position": {}, 235 | "toc_section_display": true, 236 | "toc_window_display": false 237 | }, 238 | "varInspector": { 239 | "cols": { 240 | "lenName": 16, 241 | "lenType": 16, 242 | "lenVar": 40 243 | }, 244 | "kernels_config": { 245 | "python": { 246 | "delete_cmd_postfix": "", 247 | "delete_cmd_prefix": "del ", 248 | "library": "var_list.py", 249 | "varRefreshCmd": "print(var_dic_list())" 250 | }, 251 | "r": { 252 | "delete_cmd_postfix": ") ", 253 | "delete_cmd_prefix": "rm(", 254 | "library": "var_list.r", 255 | "varRefreshCmd": "cat(var_dic_list()) " 256 | } 257 | }, 258 | "types_to_exclude": [ 259 | "module", 260 | "function", 261 | "builtin_function_or_method", 262 | "instance", 263 | "_Feature" 264 | ], 265 | "window_display": false 266 | } 267 | }, 268 | "nbformat": 4, 269 | "nbformat_minor": 4 270 | } 271 | -------------------------------------------------------------------------------- /docs/AssetManagement/extract_values.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"Open\n", 8 | "\n", 9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed." 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "# !pip install geemap" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "# import geemap\n", 28 | "# geemap.update_package()" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "# Interactive extraction of pixel values and interactive region reduction" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Interactive extraction of pixel values" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "### Import libraries" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "import os\n", 59 | "import ee\n", 60 | "import geemap" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "### Create an interactive map" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "Map = geemap.Map()\n", 77 | "Map" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "### Add data to the map" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003') \\\n", 94 | " .select([0, 1, 2, 3, 4, 6])\n", 95 | "landsat_vis = {\n", 96 | " 'bands': ['B4', 'B3', 'B2'], \n", 97 | " 'gamma': 1.7\n", 98 | "}\n", 99 | "Map.addLayer(landsat7, landsat_vis, \"LE7_TOA_5YEAR/1999_2003\")\n", 100 | "\n", 101 | "Map.set_plot_options(add_marker_cluster=True)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "### Activate the plotting tool\n", 109 | "\n", 110 | "Tick the `Plotting` checkbox and click the mouse on the map to start displaying charts." 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "### Export pixel values to shapefile/csv" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "out_dir = os.path.expanduser('~/Downloads')\n", 127 | "# out_csv = os.path.join(out_dir, 'points.csv')\n", 128 | "out_shp = os.path.join(out_dir, 'points.shp')" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": null, 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "Map.extract_values_to_points(out_shp)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "## Interactive Region Reduction" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "### Import libraries" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "metadata": {}, 158 | "outputs": [], 159 | "source": [ 160 | "import geemap.colormaps as cm" 161 | ] 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "metadata": {}, 166 | "source": [ 167 | "### Create an interactive map" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [ 176 | "m = geemap.Map()" 177 | ] 178 | }, 179 | { 180 | "cell_type": "markdown", 181 | "metadata": {}, 182 | "source": [ 183 | "### Add add to the map" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "collection = ee.ImageCollection('MODIS/006/MOD13A2') \\\n", 193 | " .filterDate('2015-01-01', '2019-12-31') \\\n", 194 | " .select('NDVI')\n", 195 | "\n", 196 | "# Convert the image collection to an image.\n", 197 | "image = collection.toBands()\n", 198 | "\n", 199 | "palette = cm.palettes.ndvi\n", 200 | "\n", 201 | "ndvi_vis = {\n", 202 | " 'min': 0.0,\n", 203 | " 'max': 9000.0,\n", 204 | " 'palette': palette\n", 205 | "}\n", 206 | "\n", 207 | "m.addLayer(image, {}, 'MODIS NDVI Time-series')\n", 208 | "m.addLayer(image.select(0), ndvi_vis, 'MODIS NDVI VIS')\n", 209 | "\n", 210 | "m" 211 | ] 212 | }, 213 | { 214 | "cell_type": "markdown", 215 | "metadata": {}, 216 | "source": [ 217 | "### Set reducer" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": null, 223 | "metadata": {}, 224 | "outputs": [], 225 | "source": [ 226 | "m.set_plot_options(add_marker_cluster=True, marker=None)\n", 227 | "m.roi_reducer = ee.Reducer.mean()" 228 | ] 229 | }, 230 | { 231 | "cell_type": "markdown", 232 | "metadata": {}, 233 | "source": [ 234 | "### Export data" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": null, 240 | "metadata": {}, 241 | "outputs": [], 242 | "source": [ 243 | "out_dir = os.path.expanduser('~/Downloads')\n", 244 | "# out_csv = os.path.join(out_dir, 'points.csv')\n", 245 | "out_shp = os.path.join(out_dir, 'ndvi.shp')\n", 246 | "m.extract_values_to_points(out_shp)" 247 | ] 248 | }, 249 | { 250 | "cell_type": "markdown", 251 | "metadata": {}, 252 | "source": [ 253 | "## Creating training samples" 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": null, 259 | "metadata": {}, 260 | "outputs": [], 261 | "source": [ 262 | "import geemap" 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": null, 268 | "metadata": {}, 269 | "outputs": [], 270 | "source": [ 271 | "geemap.show_youtube(\"https://youtu.be/VWh5PxXPZw0\")" 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": null, 277 | "metadata": {}, 278 | "outputs": [], 279 | "source": [ 280 | "Map = geemap.Map()\n", 281 | "Map" 282 | ] 283 | } 284 | ], 285 | "metadata": { 286 | "_draft": { 287 | "nbviewer_url": "https://gist.github.com/3ebde541f34a1757035a67dee34939d0" 288 | }, 289 | "gist": { 290 | "data": { 291 | "description": "extract values to points", 292 | "public": true 293 | }, 294 | "id": "3ebde541f34a1757035a67dee34939d0" 295 | }, 296 | "hide_input": false, 297 | "kernelspec": { 298 | "display_name": "Python 3", 299 | "language": "python", 300 | "name": "python3" 301 | }, 302 | "language_info": { 303 | "codemirror_mode": { 304 | "name": "ipython", 305 | "version": 3 306 | }, 307 | "file_extension": ".py", 308 | "mimetype": "text/x-python", 309 | "name": "python", 310 | "nbconvert_exporter": "python", 311 | "pygments_lexer": "ipython3", 312 | "version": "3.8.5" 313 | }, 314 | "toc": { 315 | "base_numbering": 1, 316 | "nav_menu": {}, 317 | "number_sections": true, 318 | "sideBar": true, 319 | "skip_h1_title": true, 320 | "title_cell": "Table of Contents", 321 | "title_sidebar": "Table of Contents", 322 | "toc_cell": false, 323 | "toc_position": {}, 324 | "toc_section_display": true, 325 | "toc_window_display": false 326 | }, 327 | "varInspector": { 328 | "cols": { 329 | "lenName": 16, 330 | "lenType": 16, 331 | "lenVar": 40 332 | }, 333 | "kernels_config": { 334 | "python": { 335 | "delete_cmd_postfix": "", 336 | "delete_cmd_prefix": "del ", 337 | "library": "var_list.py", 338 | "varRefreshCmd": "print(var_dic_list())" 339 | }, 340 | "r": { 341 | "delete_cmd_postfix": ") ", 342 | "delete_cmd_prefix": "rm(", 343 | "library": "var_list.r", 344 | "varRefreshCmd": "cat(var_dic_list()) " 345 | } 346 | }, 347 | "types_to_exclude": [ 348 | "module", 349 | "function", 350 | "builtin_function_or_method", 351 | "instance", 352 | "_Feature" 353 | ], 354 | "window_display": false 355 | } 356 | }, 357 | "nbformat": 4, 358 | "nbformat_minor": 4 359 | } 360 | -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | tutorials.geemap.org -------------------------------------------------------------------------------- /docs/FeatureCollection/vector_styling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"Open" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Uncomment the following line to install [geemap](https://geemap.org) if needed." 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "# !pip install geemap" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "**Styling Earth Engine vector data**" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "import ee\n", 40 | "import geemap" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "# geemap.update_package()" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "## Use the default style" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "Map = geemap.Map()\n", 66 | "\n", 67 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 68 | "\n", 69 | "Map.addLayer(states, {}, \"US States\")\n", 70 | "Map" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "## Use Image.paint()" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "Map = geemap.Map()\n", 87 | "\n", 88 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 89 | "image = ee.Image().paint(states, 0, 3)\n", 90 | "\n", 91 | "Map.addLayer(image, {'palette': 'red'}, \"US States\")\n", 92 | "Map" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "## Use FeatureCollection.style()" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [ 108 | "Map = geemap.Map()\n", 109 | "\n", 110 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 111 | "style = {'color': '0000ffff', 'width': 2, 'lineType': 'solid', 'fillColor': '00000080'}\n", 112 | "\n", 113 | "Map.addLayer(states.style(**style), {}, \"US States\")\n", 114 | "Map" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "## Use add_styled_vector()" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "Map = geemap.Map()\n", 131 | "\n", 132 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 133 | "\n", 134 | "vis_params = {\n", 135 | " 'color': '000000', \n", 136 | " 'colorOpacity': 1,\n", 137 | " 'pointSize': 3,\n", 138 | " 'pointShape': 'circle',\n", 139 | " 'width': 2,\n", 140 | " 'lineType': 'solid', \n", 141 | " 'fillColorOpacity': 0.66 \n", 142 | "}\n", 143 | "\n", 144 | "palette = ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']\n", 145 | "\n", 146 | "Map.add_styled_vector(states, column=\"NAME\", palette=palette, layer_name=\"Styled vector\", **vis_params)\n", 147 | "Map" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "import geemap.colormaps as cm" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "Map = geemap.Map()\n", 166 | "\n", 167 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 168 | "\n", 169 | "vis_params = {\n", 170 | " 'color': '000000', \n", 171 | " 'colorOpacity': 1,\n", 172 | " 'pointSize': 3,\n", 173 | " 'pointShape': 'circle',\n", 174 | " 'width': 2,\n", 175 | " 'lineType': 'solid', \n", 176 | " 'fillColorOpacity': 0.66 \n", 177 | "}\n", 178 | "\n", 179 | "palette = list(cm.palettes.gist_earth.n12)\n", 180 | "\n", 181 | "Map.add_styled_vector(states, column=\"NAME\", palette=palette, layer_name=\"Styled vector\", **vis_params)\n", 182 | "Map" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": {}, 188 | "source": [ 189 | "## Use interactive GUI" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "Map = geemap.Map()\n", 199 | "\n", 200 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", 201 | "\n", 202 | "Map.addLayer(states, {}, \"US States\")\n", 203 | "Map" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": null, 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [] 212 | } 213 | ], 214 | "metadata": { 215 | "hide_input": false, 216 | "kernelspec": { 217 | "display_name": "Python 3", 218 | "language": "python", 219 | "name": "python3" 220 | }, 221 | "language_info": { 222 | "codemirror_mode": { 223 | "name": "ipython", 224 | "version": 3 225 | }, 226 | "file_extension": ".py", 227 | "mimetype": "text/x-python", 228 | "name": "python", 229 | "nbconvert_exporter": "python", 230 | "pygments_lexer": "ipython3", 231 | "version": "3.8.5" 232 | }, 233 | "toc": { 234 | "base_numbering": 1, 235 | "nav_menu": {}, 236 | "number_sections": true, 237 | "sideBar": true, 238 | "skip_h1_title": true, 239 | "title_cell": "Table of Contents", 240 | "title_sidebar": "Table of Contents", 241 | "toc_cell": false, 242 | "toc_position": { 243 | "height": "calc(100% - 180px)", 244 | "left": "10px", 245 | "top": "150px", 246 | "width": "262px" 247 | }, 248 | "toc_section_display": true, 249 | "toc_window_display": true 250 | }, 251 | "varInspector": { 252 | "cols": { 253 | "lenName": 16, 254 | "lenType": 16, 255 | "lenVar": 40 256 | }, 257 | "kernels_config": { 258 | "python": { 259 | "delete_cmd_postfix": "", 260 | "delete_cmd_prefix": "del ", 261 | "library": "var_list.py", 262 | "varRefreshCmd": "print(var_dic_list())" 263 | }, 264 | "r": { 265 | "delete_cmd_postfix": ") ", 266 | "delete_cmd_prefix": "rm(", 267 | "library": "var_list.r", 268 | "varRefreshCmd": "cat(var_dic_list()) " 269 | } 270 | }, 271 | "types_to_exclude": [ 272 | "module", 273 | "function", 274 | "builtin_function_or_method", 275 | "instance", 276 | "_Feature" 277 | ], 278 | "window_display": false 279 | } 280 | }, 281 | "nbformat": 4, 282 | "nbformat_minor": 4 283 | } 284 | -------------------------------------------------------------------------------- /docs/Image/conditional_operations.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/Image/conditional_operations.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Relational, conditional and Boolean operations**\n", 15 | "\n", 16 | "Reference: " 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "import ee\n", 26 | "import geemap" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "Map = geemap.Map(basemap=\"HYBRID\")" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "To perform per-pixel comparisons between images, use relational operators. To extract urbanized areas in an image, this example uses relational operators to threshold spectral indices, combining the thresholds with `And()`:" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "metadata": { 49 | "scrolled": false 50 | }, 51 | "outputs": [], 52 | "source": [ 53 | "# Load a Landsat 8 image.\n", 54 | "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n", 55 | "\n", 56 | "# Create NDVI and NDWI spectral indices.\n", 57 | "ndvi = image.normalizedDifference(['B5', 'B4'])\n", 58 | "ndwi = image.normalizedDifference(['B3', 'B5'])\n", 59 | "\n", 60 | "# Create a binary layer using logical operations.\n", 61 | "bare = ndvi.lt(0.2).And(ndwi.lt(0))\n", 62 | "\n", 63 | "# Mask and display the binary layer.\n", 64 | "Map.setCenter(-122.3578, 37.7726, 12)\n", 65 | "Map.addLayer(bare.selfMask(), {}, 'bare')\n", 66 | "\n", 67 | "Map" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "As illustrated by this example, the output of relational and boolean operators is either True (1) or False (0). To mask the 0's, you can mask the resultant binary image with itself. \n", 75 | "\n", 76 | "The binary images that are returned by relational and boolean operators can be used with mathematical operators. This example creates zones of urbanization in a nighttime lights image using relational operators and `image.add()`:" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 86 | "\n", 87 | "# Load a 2012 nightlights image.\n", 88 | "nl2012 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182012')\n", 89 | "lights = nl2012.select('stable_lights')\n", 90 | "Map.addLayer(lights, {}, 'Nighttime lights')\n", 91 | "\n", 92 | "# Define arbitrary thresholds on the 6-bit stable lights band.\n", 93 | "zones = lights.gt(30).add(lights.gt(55)).add(lights.gt(62))\n", 94 | "\n", 95 | "# Display the thresholded image as three distinct zones near Paris.\n", 96 | "palette = ['000000', '0000FF', '00FF00', 'FF0000']\n", 97 | "Map.setCenter(2.373, 48.8683, 8)\n", 98 | "Map.addLayer(zones, {'min': 0, 'max': 3, 'palette': palette}, 'development zones')\n", 99 | "\n", 100 | "Map" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "Note that the code in the previous example is equivalent to using a [ternary operator](http://en.wikipedia.org/wiki/%3F:) implemented by `expression()`:" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": { 114 | "scrolled": true 115 | }, 116 | "outputs": [], 117 | "source": [ 118 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 119 | "\n", 120 | "# Create zones using an expression, display.\n", 121 | "zonesExp = nl2012.expression(\n", 122 | " \"(b('stable_lights') > 62) ? 3\" +\n", 123 | " \": (b('stable_lights') > 55) ? 2\" +\n", 124 | " \": (b('stable_lights') > 30) ? 1\" +\n", 125 | " \": 0\"\n", 126 | ")\n", 127 | "Map.addLayer(zonesExp, {'min': 0, 'max': 3, 'palette': palette}, 'development zones (ternary)')\n", 128 | "Map.setCenter(2.373, 48.8683, 8)\n", 129 | "\n", 130 | "Map" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "Observe that in the previous expression example, the band of interest is referenced using the`b()` function, rather than a dictionary of variable names. (Learn more about image expressions on [this page](https://developers.google.com/earth-engine/image_math#expressions). Using either mathematical operators or an expression, the output is the same and should look something like Figure 2.\n", 138 | "\n", 139 | "Another way to implement conditional operations on images is with the `image.where()` operator. Consider the need to replace masked pixels with some other data. In the following example, cloudy pixels are replaced by pixels from a cloud-free image using `where()`:" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 149 | "\n", 150 | "# Load a cloudy Landsat 8 image.\n", 151 | "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20130603')\n", 152 | "Map.addLayer(image,\n", 153 | " {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5},\n", 154 | " 'original image')\n", 155 | "\n", 156 | "# Load another image to replace the cloudy pixels.\n", 157 | "replacement = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20130416')\n", 158 | "\n", 159 | "# Compute a cloud score band.\n", 160 | "cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud')\n", 161 | "Map.addLayer(cloud, {}, 'Cloud score')\n", 162 | "\n", 163 | "# Set cloudy pixels to the other image.\n", 164 | "replaced = image.where(cloud.gt(10), replacement)\n", 165 | "\n", 166 | "# Display the result.\n", 167 | "Map.centerObject(image, 9)\n", 168 | "Map.addLayer(replaced,\n", 169 | " {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5},\n", 170 | " 'clouds replaced')\n", 171 | "Map" 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": {}, 177 | "source": [ 178 | "In this example, observe the use of the `simpleCloudScore()` algorithm. This algorithm ranks pixels by cloudiness on a scale of 0-100, with 100 most cloudy. Learn more about `simpleCloudScore()` on the [Landsat Algorithms page](https://developers.google.com/earth-engine/landsat#simple-cloud-score)." 179 | ] 180 | } 181 | ], 182 | "metadata": { 183 | "anaconda-cloud": {}, 184 | "hide_input": false, 185 | "kernelspec": { 186 | "display_name": "Python 3", 187 | "language": "python", 188 | "name": "python3" 189 | }, 190 | "language_info": { 191 | "codemirror_mode": { 192 | "name": "ipython", 193 | "version": 3 194 | }, 195 | "file_extension": ".py", 196 | "mimetype": "text/x-python", 197 | "name": "python", 198 | "nbconvert_exporter": "python", 199 | "pygments_lexer": "ipython3", 200 | "version": "3.8.5" 201 | }, 202 | "toc": { 203 | "base_numbering": 1, 204 | "nav_menu": {}, 205 | "number_sections": true, 206 | "sideBar": true, 207 | "skip_h1_title": false, 208 | "title_cell": "Table of Contents", 209 | "title_sidebar": "Contents", 210 | "toc_cell": false, 211 | "toc_position": {}, 212 | "toc_section_display": true, 213 | "toc_window_display": false 214 | }, 215 | "varInspector": { 216 | "cols": { 217 | "lenName": 16, 218 | "lenType": 16, 219 | "lenVar": 40 220 | }, 221 | "kernels_config": { 222 | "python": { 223 | "delete_cmd_postfix": "", 224 | "delete_cmd_prefix": "del ", 225 | "library": "var_list.py", 226 | "varRefreshCmd": "print(var_dic_list())" 227 | }, 228 | "r": { 229 | "delete_cmd_postfix": ") ", 230 | "delete_cmd_prefix": "rm(", 231 | "library": "var_list.r", 232 | "varRefreshCmd": "cat(var_dic_list()) " 233 | } 234 | }, 235 | "types_to_exclude": [ 236 | "module", 237 | "function", 238 | "builtin_function_or_method", 239 | "instance", 240 | "_Feature" 241 | ], 242 | "window_display": false 243 | } 244 | }, 245 | "nbformat": 4, 246 | "nbformat_minor": 1 247 | } 248 | -------------------------------------------------------------------------------- /docs/Image/image_colorbar.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/Image/image_styling.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "# !pip install geemap" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "import ee\n", 26 | "import geemap\n", 27 | "import geemap.colormaps as cm" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "## Colormap" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "# geemap.update_package()" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "cm.palettes.dem" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "cm.palettes.ndvi" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "cm.palettes.ndwi" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "cm.get_palette('terrain', n_class=8)" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "cm.plot_colormap('terrain', width=8.0, height=0.4, orientation='horizontal')" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": { 95 | "scrolled": false 96 | }, 97 | "outputs": [], 98 | "source": [ 99 | "cm.list_colormaps()" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "metadata": { 106 | "scrolled": false 107 | }, 108 | "outputs": [], 109 | "source": [ 110 | "cm.plot_colormaps(width=12, height=0.4)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "## Colorbar" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "Map = geemap.Map()\n", 127 | "\n", 128 | "palette = cm.palettes.dem\n", 129 | "# palette = cm.palettes.terrain\n", 130 | "\n", 131 | "dem = ee.Image('USGS/SRTMGL1_003')\n", 132 | "vis_params = {\n", 133 | " 'min': 0,\n", 134 | " 'max': 4000,\n", 135 | " 'palette': palette}\n", 136 | "\n", 137 | "Map.addLayer(dem, vis_params, 'SRTM DEM')\n", 138 | "Map.add_colorbar(vis_params, label=\"Elevation (m)\", layer_name=\"SRTM DEM\")\n", 139 | "Map" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "Map.add_colorbar(vis_params, label=\"Elevation (m)\", orientation=\"vertical\", layer_name=\"SRTM DEM\")" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": null, 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "Map.add_colorbar(vis_params, label=\"Elevation (m)\", orientation=\"vertical\", layer_name=\"SRTM DEM\", transparent_bg=True)" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "Map.add_colorbar(vis_params, discrete=True, label=\"Elevation (m)\", orientation=\"vertical\", layer_name=\"SRTM DEM\")" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "## Legend" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": null, 179 | "metadata": {}, 180 | "outputs": [], 181 | "source": [ 182 | "legends = geemap.builtin_legends\n", 183 | "for legend in legends:\n", 184 | " print(legend)" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": null, 190 | "metadata": {}, 191 | "outputs": [], 192 | "source": [ 193 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 194 | "\n", 195 | "Map.add_basemap(\"FWS NWI Wetlands Raster\")\n", 196 | "Map.add_legend(builtin_legend=\"NWI\")\n", 197 | "\n", 198 | "Map" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": null, 204 | "metadata": {}, 205 | "outputs": [], 206 | "source": [ 207 | "Map = geemap.Map(basemap=\"HYBRID\")\n", 208 | "\n", 209 | "Map.add_basemap(\"NLCD 2016 CONUS Land Cover\")\n", 210 | "Map.add_legend(builtin_legend=\"NLCD\")\n", 211 | "\n", 212 | "Map" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [ 221 | "Map = geemap.Map()\n", 222 | "\n", 223 | "legend_dict = {\n", 224 | " '11 Open Water': '466b9f',\n", 225 | " '12 Perennial Ice/Snow': 'd1def8',\n", 226 | " '21 Developed, Open Space': 'dec5c5',\n", 227 | " '22 Developed, Low Intensity': 'd99282',\n", 228 | " '23 Developed, Medium Intensity': 'eb0000',\n", 229 | " '24 Developed High Intensity': 'ab0000',\n", 230 | " '31 Barren Land (Rock/Sand/Clay)': 'b3ac9f',\n", 231 | " '41 Deciduous Forest': '68ab5f',\n", 232 | " '42 Evergreen Forest': '1c5f2c',\n", 233 | " '43 Mixed Forest': 'b5c58f',\n", 234 | " '51 Dwarf Scrub': 'af963c',\n", 235 | " '52 Shrub/Scrub': 'ccb879',\n", 236 | " '71 Grassland/Herbaceous': 'dfdfc2',\n", 237 | " '72 Sedge/Herbaceous': 'd1d182',\n", 238 | " '73 Lichens': 'a3cc51',\n", 239 | " '74 Moss': '82ba9e',\n", 240 | " '81 Pasture/Hay': 'dcd939',\n", 241 | " '82 Cultivated Crops': 'ab6c28',\n", 242 | " '90 Woody Wetlands': 'b8d9eb',\n", 243 | " '95 Emergent Herbaceous Wetlands': '6c9fb8'\n", 244 | "}\n", 245 | "\n", 246 | "landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')\n", 247 | "Map.addLayer(landcover, {}, 'NLCD Land Cover')\n", 248 | "\n", 249 | "Map.add_legend(title=\"NLCD Land Cover Classification\", legend_dict=legend_dict, layer_name='NLCD Land Cover')\n", 250 | "\n", 251 | "Map" 252 | ] 253 | } 254 | ], 255 | "metadata": { 256 | "hide_input": false, 257 | "kernelspec": { 258 | "display_name": "Python 3", 259 | "language": "python", 260 | "name": "python3" 261 | }, 262 | "language_info": { 263 | "codemirror_mode": { 264 | "name": "ipython", 265 | "version": 3 266 | }, 267 | "file_extension": ".py", 268 | "mimetype": "text/x-python", 269 | "name": "python", 270 | "nbconvert_exporter": "python", 271 | "pygments_lexer": "ipython3", 272 | "version": "3.8.5" 273 | }, 274 | "toc": { 275 | "base_numbering": 1, 276 | "nav_menu": {}, 277 | "number_sections": true, 278 | "sideBar": true, 279 | "skip_h1_title": false, 280 | "title_cell": "Table of Contents", 281 | "title_sidebar": "Contents", 282 | "toc_cell": false, 283 | "toc_position": {}, 284 | "toc_section_display": true, 285 | "toc_window_display": false 286 | }, 287 | "varInspector": { 288 | "cols": { 289 | "lenName": 16, 290 | "lenType": 16, 291 | "lenVar": 40 292 | }, 293 | "kernels_config": { 294 | "python": { 295 | "delete_cmd_postfix": "", 296 | "delete_cmd_prefix": "del ", 297 | "library": "var_list.py", 298 | "varRefreshCmd": "print(var_dic_list())" 299 | }, 300 | "r": { 301 | "delete_cmd_postfix": ") ", 302 | "delete_cmd_prefix": "rm(", 303 | "library": "var_list.r", 304 | "varRefreshCmd": "cat(var_dic_list()) " 305 | } 306 | }, 307 | "types_to_exclude": [ 308 | "module", 309 | "function", 310 | "builtin_function_or_method", 311 | "instance", 312 | "_Feature" 313 | ], 314 | "window_display": false 315 | } 316 | }, 317 | "nbformat": 4, 318 | "nbformat_minor": 4 319 | } 320 | -------------------------------------------------------------------------------- /docs/Image/image_metadata.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/Image/image_metadata.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Image information and metadata**\n", 15 | "\n", 16 | "To explore image bands and properties in Python, `print()` the image with the `getInfo()` function. This information can also be accessed programmatically. For example, the following demonstrates how to access information about bands, projections and other metadata:" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "## Import libraries" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "import ee\n", 33 | "import geemap" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Create an interactive map " 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "Map = geemap.Map()\n", 50 | "Map" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "## Display data on the map" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "# Load an image.\n", 67 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 68 | "vis_params = {'bands': ['B5', 'B4', 'B3'], 'min': 0.0, 'max': 3000, 'opacity': 1.0, 'gamma': 1.2}\n", 69 | "\n", 70 | "# Center the map and display the image.\n", 71 | "Map.centerObject(image, zoom=8)\n", 72 | "Map.addLayer(image, vis_params, 'Landsat')" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "## Get image metadata" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | "Get information about the bands as a list." 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "bandNames = image.bandNames()\n", 96 | "print('Band names: ', bandNames.getInfo())" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "Get projection information from band 1. https://epsg.io/32610" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [ 112 | "b1proj = image.select('B1').projection()\n", 113 | "print('Band 1 projection: ', b1proj.getInfo()) " 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "Get scale (in meters) information from band 1." 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "b1scale = image.select('B1').projection().nominalScale()\n", 130 | "print('Band 1 scale: ', b1scale.getInfo()) " 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "Note that different bands can have different projections and scale." 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": null, 143 | "metadata": {}, 144 | "outputs": [], 145 | "source": [ 146 | "b10scale = image.select('B10').projection().nominalScale()\n", 147 | "print('Band 10 scale: ', b10scale.getInfo())" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "Get a list of all metadata properties." 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "properties = image.propertyNames()\n", 164 | "print('Metadata properties: ', properties.getInfo())" 165 | ] 166 | }, 167 | { 168 | "cell_type": "markdown", 169 | "metadata": {}, 170 | "source": [ 171 | "Get a specific metadata property." 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": null, 177 | "metadata": {}, 178 | "outputs": [], 179 | "source": [ 180 | "cloudiness = image.get('CLOUD_COVER')\n", 181 | "print('CLOUD_COVER: ', cloudiness.getInfo())" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "Get the timestamp and convert it to a date." 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": null, 194 | "metadata": {}, 195 | "outputs": [], 196 | "source": [ 197 | "date = ee.Date(image.get('system:time_start'))\n", 198 | "print('Timestamp: ', date.getInfo())" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": null, 204 | "metadata": {}, 205 | "outputs": [], 206 | "source": [ 207 | "date2 = date.format('YYYY-MM-dd')\n", 208 | "print('Timestamp: ', date2.getInfo())" 209 | ] 210 | }, 211 | { 212 | "cell_type": "markdown", 213 | "metadata": {}, 214 | "source": [ 215 | "## Use geemap to get image metadata" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": null, 221 | "metadata": {}, 222 | "outputs": [], 223 | "source": [ 224 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 225 | "image_props = geemap.image_props(image)" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": null, 231 | "metadata": {}, 232 | "outputs": [], 233 | "source": [ 234 | "image_props.getInfo()" 235 | ] 236 | } 237 | ], 238 | "metadata": { 239 | "anaconda-cloud": {}, 240 | "hide_input": false, 241 | "kernelspec": { 242 | "display_name": "Python 3", 243 | "language": "python", 244 | "name": "python3" 245 | }, 246 | "language_info": { 247 | "codemirror_mode": { 248 | "name": "ipython", 249 | "version": 3 250 | }, 251 | "file_extension": ".py", 252 | "mimetype": "text/x-python", 253 | "name": "python", 254 | "nbconvert_exporter": "python", 255 | "pygments_lexer": "ipython3", 256 | "version": "3.8.5" 257 | }, 258 | "toc": { 259 | "base_numbering": 1, 260 | "nav_menu": {}, 261 | "number_sections": true, 262 | "sideBar": true, 263 | "skip_h1_title": false, 264 | "title_cell": "Table of Contents", 265 | "title_sidebar": "Contents", 266 | "toc_cell": false, 267 | "toc_position": {}, 268 | "toc_section_display": true, 269 | "toc_window_display": false 270 | }, 271 | "varInspector": { 272 | "cols": { 273 | "lenName": 16, 274 | "lenType": 16, 275 | "lenVar": 40 276 | }, 277 | "kernels_config": { 278 | "python": { 279 | "delete_cmd_postfix": "", 280 | "delete_cmd_prefix": "del ", 281 | "library": "var_list.py", 282 | "varRefreshCmd": "print(var_dic_list())" 283 | }, 284 | "r": { 285 | "delete_cmd_postfix": ") ", 286 | "delete_cmd_prefix": "rm(", 287 | "library": "var_list.r", 288 | "varRefreshCmd": "cat(var_dic_list()) " 289 | } 290 | }, 291 | "types_to_exclude": [ 292 | "module", 293 | "function", 294 | "builtin_function_or_method", 295 | "instance", 296 | "_Feature" 297 | ], 298 | "window_display": false 299 | } 300 | }, 301 | "nbformat": 4, 302 | "nbformat_minor": 1 303 | } 304 | -------------------------------------------------------------------------------- /docs/Image/image_overview.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://github.com/giswqs/gee-tutorials/blob/master/Image/image_overview.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Image Overview**\n", 15 | "\n", 16 | "Raster data are represented as `Image` objects in Earth Engine. Images are composed of one or more bands and each band has its own name, data type, scale, mask and projection. Each image has metadata stored as a set of properties.\n", 17 | "\n", 18 | "In addition to loading images from the archive by an image ID, you can also create images from constants, lists or other suitable Earth Engine objects. The following illustrates methods for creating images, getting band subsets, and manipulating bands.\n", 19 | "\n", 20 | "More information about ee.Image can be found in the [Earth Engine Documentation](https://developers.google.com/earth-engine/guides/image_overview)." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "# !pip isntall geemap" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": null, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "import ee\n", 39 | "import geemap" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "## Loading a single-band image\n", 47 | "\n", 48 | "Images can be loaded by pasting an Earth Engine asset ID into the ee.Image constructor. You can find image IDs in the [data catalog](https://developers.google.com/earth-engine/datasets). For example, to load SRTM Digital Elevation Data:" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "Map = geemap.Map(center=(40, -100), zoom=4)\n", 58 | "Map" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "dem = ee.Image('CGIAR/SRTM90_V4')\n", 68 | "Map.addLayer(dem, {}, \"DEM\")" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "# Set visualization parameters.\n", 78 | "vis_params = {\n", 79 | " 'min': 0,\n", 80 | " 'max': 4000,\n", 81 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n", 82 | "Map.addLayer(dem, vis_params, \"DEM Vis\")" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "## Loading a multi-band image" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "Map = geemap.Map()\n", 99 | "# Load an image.\n", 100 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 101 | "\n", 102 | "# Center the map and display the image.\n", 103 | "Map.centerObject(image, zoom=8)\n", 104 | "Map.addLayer(image, {}, 'Landsat')\n", 105 | "\n", 106 | "Map" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "vis_params = {'bands': ['B5', 'B4', 'B3'], 'min': 0.0, 'max': 3000, 'opacity': 1.0, 'gamma': 1.2}\n", 116 | "Map.addLayer(image, vis_params, \"Landsat Vis\")" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "## Getting image properties" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 133 | "props = geemap.image_props(image)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "props.getInfo()" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "## Selecting image bands" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": null, 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 159 | "bands = image.select(['B5', 'B4', 'B3'])" 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": null, 165 | "metadata": {}, 166 | "outputs": [], 167 | "source": [ 168 | "Map.addLayer(bands, vis_params, 'Landsat B543')\n", 169 | "Map" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "## Renaming band names" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318')\n", 186 | "new_image = image.select(['B5', 'B4', 'B3'], ['NIR', 'Red', 'Green'])\n", 187 | "band_names = new_image.bandNames()" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "band_names.getInfo()" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": {}, 202 | "source": [ 203 | "## Adding a legend" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": null, 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [ 212 | "Map = geemap.Map()\n", 213 | "Map.add_basemap('HYBRID')\n", 214 | "Map" 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": null, 220 | "metadata": {}, 221 | "outputs": [], 222 | "source": [ 223 | "landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')\n", 224 | "Map.addLayer(landcover, {}, 'Land Cover')\n", 225 | "Map.add_legend(builtin_legend='NLCD', layer_name='Land Cover')" 226 | ] 227 | } 228 | ], 229 | "metadata": { 230 | "anaconda-cloud": {}, 231 | "hide_input": false, 232 | "kernelspec": { 233 | "display_name": "Python 3", 234 | "language": "python", 235 | "name": "python3" 236 | }, 237 | "language_info": { 238 | "codemirror_mode": { 239 | "name": "ipython", 240 | "version": 3 241 | }, 242 | "file_extension": ".py", 243 | "mimetype": "text/x-python", 244 | "name": "python", 245 | "nbconvert_exporter": "python", 246 | "pygments_lexer": "ipython3", 247 | "version": "3.8.5" 248 | }, 249 | "toc": { 250 | "base_numbering": 1, 251 | "nav_menu": {}, 252 | "number_sections": true, 253 | "sideBar": true, 254 | "skip_h1_title": false, 255 | "title_cell": "Table of Contents", 256 | "title_sidebar": "Contents", 257 | "toc_cell": false, 258 | "toc_position": { 259 | "height": "calc(100% - 180px)", 260 | "left": "10px", 261 | "top": "150px", 262 | "width": "384px" 263 | }, 264 | "toc_section_display": true, 265 | "toc_window_display": true 266 | }, 267 | "varInspector": { 268 | "cols": { 269 | "lenName": 16, 270 | "lenType": 16, 271 | "lenVar": 40 272 | }, 273 | "kernels_config": { 274 | "python": { 275 | "delete_cmd_postfix": "", 276 | "delete_cmd_prefix": "del ", 277 | "library": "var_list.py", 278 | "varRefreshCmd": "print(var_dic_list())" 279 | }, 280 | "r": { 281 | "delete_cmd_postfix": ") ", 282 | "delete_cmd_prefix": "rm(", 283 | "library": "var_list.r", 284 | "varRefreshCmd": "cat(var_dic_list()) " 285 | } 286 | }, 287 | "types_to_exclude": [ 288 | "module", 289 | "function", 290 | "builtin_function_or_method", 291 | "instance", 292 | "_Feature" 293 | ], 294 | "window_display": false 295 | } 296 | }, 297 | "nbformat": 4, 298 | "nbformat_minor": 1 299 | } 300 | -------------------------------------------------------------------------------- /docs/Image/math_operations.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/Image/math_operations.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Mathematical operations**\n", 15 | "\n", 16 | "Reference: \n", 17 | "\n", 18 | "Earth Engine supports many basic mathematical operators. They share some common features. Earth Engine performs math operations per pixel. When an operator is applied to an image, it's applied to each unmasked pixel of each band. In the case of operations on two images, the operation is only applied at the locations where pixels in both images are unmasked. Earth Engine automatically matches bands between images. When an operator is applied to two images, the images are expected to have the same number of bands so they can be matched pairwise. However, if one of the images has only a single band, it is matched with all of the bands in the other image, essentially replicating that band enough times to match the other image." 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "import ee\n", 28 | "import geemap" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "Map = geemap.Map()" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Operators" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "Math operators perform basic arithmetic operations on image bands. They take two inputs: either two images or one image and a constant term, which is interpreted as a single-band constant image with no masked pixels. Operations are performed per pixel for each band.\n", 52 | "\n", 53 | "As a simple example, consider the task of calculating the Normalized Difference Vegetation Index (NDVI) using Landsat imagery, where `add()`, `subtract()`, and `divide()` operators are used:\n", 54 | "\n", 55 | "![](https://wikimedia.org/api/rest_v1/media/math/render/svg/6e8f5257f485c39659111ddc8b81452984e6278f)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "# Load a 5-year Landsat 7 composite 1999-2003.\n", 65 | "landsat1999 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003')\n", 66 | "\n", 67 | "# Compute NDVI.\n", 68 | "\n", 69 | "NIR = landsat1999.select('B4')\n", 70 | "Red = landsat1999.select('B3')\n", 71 | "\n", 72 | "ndvi1999 = NIR.subtract(Red).divide(NIR.add(Red))\n", 73 | "# ndvi1999 = landsat1999.normalizedDifference(['B4', 'B3'])\n", 74 | "\n", 75 | "palette = [\n", 76 | " 'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',\n", 77 | " '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',\n", 78 | " '012E01', '011D01', '011301']\n", 79 | "\n", 80 | "Map.addLayer(ndvi1999, {'palette': palette}, \"NDVI 1999\")\n", 81 | "Map" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "Only the intersection of unmasked pixels between the two inputs are considered and returned as unmasked, all else are masked. In general, if either input has only one band, then it is used against all the bands in the other input. If the inputs have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in the first input's order. The type of the output pixels is the union of the input types.\n", 89 | "\n", 90 | "The following example of multi-band image subtraction demonstrates how bands are matched automatically, resulting in a “change vector” for each pixel for each co-occurring band." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "# Load a 5-year Landsat 7 composite 2008-2012.\n", 100 | "landsat2008 = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012')\n", 101 | "\n", 102 | "# Compute multi-band difference between the 2008-2012 composite and the\n", 103 | "# previously loaded 1999-2003 composite.\n", 104 | "diff = landsat2008.subtract(landsat1999)\n", 105 | "Map.addLayer(diff, {'bands': ['B4', 'B3', 'B2'], 'min': -32, 'max': 32}, 'difference')\n", 106 | "\n", 107 | "# Compute the squared difference in each band.\n", 108 | "squaredDifference = diff.pow(2)\n", 109 | "Map.addLayer(squaredDifference, {'bands': ['B4', 'B3', 'B2'], 'max': 1000}, 'squared diff.')\n", 110 | "Map" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "In the second part of this example, the squared difference is computed using `image.pow(2)`. For the complete list of mathematical operators handling basic arithmetic, trigonometry, exponentiation, rounding, casting, bitwise operations and more, see the API documentation (in the Docs tab of the [Earth Engine Code Editor](https://code.earthengine.google.com/))." 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "## Expressions\n", 125 | "To implement more complex mathematical expressions, it may be more convenient to use `image.expression()`, which parses a text representation of a math operation. The following example uses `expression()` to compute the Enhanced Vegetation Index (EVI):" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": null, 131 | "metadata": {}, 132 | "outputs": [], 133 | "source": [ 134 | "Map = geemap.Map()" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "# Load a Landsat 8 image.\n", 144 | "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n", 145 | "\n", 146 | "# Compute the EVI using an expression.\n", 147 | "evi = image.expression(\n", 148 | " '2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {\n", 149 | " 'NIR': image.select('B5'),\n", 150 | " 'RED': image.select('B4'),\n", 151 | " 'BLUE': image.select('B2')\n", 152 | "})\n", 153 | "\n", 154 | "Map.centerObject(image, 9)\n", 155 | "Map.addLayer(image, {'bands': ['B5', 'B4', 'B3']}, 'Landsat 8')\n", 156 | "Map.addLayer(evi, {'min': -1, 'max': 1, 'palette': ['FF0000', '00FF00']}, 'EVI')\n", 157 | "Map" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "Observe that the first argument to expression is the textual representation of the math operation, the second argument is a dictionary where the keys are variable names used in the expression and the values are the image bands to which the variables should be mapped. Bands in the image may be referred to as `b(\"band name\")` or `b(index)`, for example `b(0)`, instead of providing the dictionary. Note that division functions as it does in Python: dividing two integers results in an integer. For example `10 / 20 = 0`. To change this behavior, multiply one of the operands by `1.0: 10 * 1.0 / 20 = 0.5`. Supported expression operators are listed in the following table.\n", 165 | "\n", 166 | "![](https://i.imgur.com/TyXM4s9.png)" 167 | ] 168 | } 169 | ], 170 | "metadata": { 171 | "anaconda-cloud": {}, 172 | "hide_input": false, 173 | "kernelspec": { 174 | "display_name": "Python 3", 175 | "language": "python", 176 | "name": "python3" 177 | }, 178 | "language_info": { 179 | "codemirror_mode": { 180 | "name": "ipython", 181 | "version": 3 182 | }, 183 | "file_extension": ".py", 184 | "mimetype": "text/x-python", 185 | "name": "python", 186 | "nbconvert_exporter": "python", 187 | "pygments_lexer": "ipython3", 188 | "version": "3.8.5" 189 | }, 190 | "toc": { 191 | "base_numbering": 1, 192 | "nav_menu": {}, 193 | "number_sections": true, 194 | "sideBar": true, 195 | "skip_h1_title": false, 196 | "title_cell": "Table of Contents", 197 | "title_sidebar": "Contents", 198 | "toc_cell": false, 199 | "toc_position": {}, 200 | "toc_section_display": true, 201 | "toc_window_display": false 202 | }, 203 | "varInspector": { 204 | "cols": { 205 | "lenName": 16, 206 | "lenType": 16, 207 | "lenVar": 40 208 | }, 209 | "kernels_config": { 210 | "python": { 211 | "delete_cmd_postfix": "", 212 | "delete_cmd_prefix": "del ", 213 | "library": "var_list.py", 214 | "varRefreshCmd": "print(var_dic_list())" 215 | }, 216 | "r": { 217 | "delete_cmd_postfix": ") ", 218 | "delete_cmd_prefix": "rm(", 219 | "library": "var_list.r", 220 | "varRefreshCmd": "cat(var_dic_list()) " 221 | } 222 | }, 223 | "types_to_exclude": [ 224 | "module", 225 | "function", 226 | "builtin_function_or_method", 227 | "instance", 228 | "_Feature" 229 | ], 230 | "window_display": false 231 | } 232 | }, 233 | "nbformat": 4, 234 | "nbformat_minor": 1 235 | } 236 | -------------------------------------------------------------------------------- /docs/ImageCollection/cloud_free_composite.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/ImageCollection/cloud_free_composite.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import ee\n", 17 | "import geemap" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "Map = geemap.Map()\n", 27 | "Map" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "states = ee.FeatureCollection('TIGER/2018/States')\n", 37 | "TN = states.filter(ee.Filter.eq(\"NAME\", \"Tennessee\"))\n", 38 | "Map.addLayer(TN, {}, \"Tennessee\")" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "years = ee.List.sequence(2013, 2020)\n", 48 | "years.getInfo()" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "def yearly_image(year):\n", 58 | " \n", 59 | " start_date = ee.Date.fromYMD(year, 1, 1) \n", 60 | " end_date = start_date.advance(1, \"year\")\n", 61 | " \n", 62 | " collection = ee.ImageCollection('LANDSAT/LC08/C01/T1') \\\n", 63 | " .filterDate(start_date, end_date) \\\n", 64 | " .filterBounds(TN) \n", 65 | " \n", 66 | " image = ee.Algorithms.Landsat.simpleComposite(collection).clipToCollection(TN)\n", 67 | "\n", 68 | " return image" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "images = years.map(yearly_image)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "vis_params = {'bands': ['B5', 'B4', 'B3'], 'max': 128}" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "for index in range(0, 8):\n", 96 | " image = ee.Image(images.get(index))\n", 97 | " layer_name = \"Image \" + str(index + 2013)\n", 98 | " Map.addLayer(image, vis_params, layer_name)" 99 | ] 100 | } 101 | ], 102 | "metadata": { 103 | "hide_input": false, 104 | "kernelspec": { 105 | "display_name": "Python 3", 106 | "language": "python", 107 | "name": "python3" 108 | }, 109 | "language_info": { 110 | "codemirror_mode": { 111 | "name": "ipython", 112 | "version": 3 113 | }, 114 | "file_extension": ".py", 115 | "mimetype": "text/x-python", 116 | "name": "python", 117 | "nbconvert_exporter": "python", 118 | "pygments_lexer": "ipython3", 119 | "version": "3.8.5" 120 | }, 121 | "toc": { 122 | "base_numbering": 1, 123 | "nav_menu": {}, 124 | "number_sections": true, 125 | "sideBar": true, 126 | "skip_h1_title": false, 127 | "title_cell": "Table of Contents", 128 | "title_sidebar": "Contents", 129 | "toc_cell": false, 130 | "toc_position": {}, 131 | "toc_section_display": true, 132 | "toc_window_display": false 133 | }, 134 | "varInspector": { 135 | "cols": { 136 | "lenName": 16, 137 | "lenType": 16, 138 | "lenVar": 40 139 | }, 140 | "kernels_config": { 141 | "python": { 142 | "delete_cmd_postfix": "", 143 | "delete_cmd_prefix": "del ", 144 | "library": "var_list.py", 145 | "varRefreshCmd": "print(var_dic_list())" 146 | }, 147 | "r": { 148 | "delete_cmd_postfix": ") ", 149 | "delete_cmd_prefix": "rm(", 150 | "library": "var_list.r", 151 | "varRefreshCmd": "cat(var_dic_list()) " 152 | } 153 | }, 154 | "types_to_exclude": [ 155 | "module", 156 | "function", 157 | "builtin_function_or_method", 158 | "instance", 159 | "_Feature" 160 | ], 161 | "window_display": false 162 | } 163 | }, 164 | "nbformat": 4, 165 | "nbformat_minor": 5 166 | } 167 | -------------------------------------------------------------------------------- /docs/ImageCollection/image_collection_overview.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/ImageCollection/image_collection_overview.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Getting Started with Earth Engine ImageCollection**\n", 15 | "\n", 16 | "As illustrated in the [Get Started section](https://developers.google.com/earth-engine/guides/getstarted) and the [ImageCollection Information section](https://developers.google.com/earth-engine/guides/ic_info), Earth Engine provides a variety of convenience methods for filtering image collections. Specifically, many common use cases are handled by `imageCollection.filterDate()`, and `imageCollection.filterBounds()`. For general purpose filtering, use `imageCollection.filter()` with an ee.Filter as an argument. The following example demonstrates both convenience methods and `filter()` to identify and remove images with bad registration from an `ImageCollection`:" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "import ee\n", 26 | "import geemap" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "Map = geemap.Map()\n", 36 | "Map" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "## Get collection size" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "print(collection.size().getInfo())" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "## Get the first image" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "image = collection.first()\n", 78 | "geemap.image_props(image).getInfo()" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "Map.addLayer(image, {}, \"First image\")\n", 88 | "Map.centerObject(image, 6)\n", 89 | "Map" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "## Filter by dates\n", 97 | "\n", 98 | "https://developers.google.com/earth-engine/apidocs/ee-imagecollection-filterdate" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 108 | " .filterDate('2020-01-01', '2020-12-31')" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "print(collection.size().getInfo())" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "image2 = collection.first()\n", 127 | "Map.addLayer(image2, {}, \"Another image\")\n", 128 | "Map.centerObject(image2, 6)\n", 129 | "Map" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "## Filter by location\n", 137 | "\n", 138 | "https://developers.google.com/earth-engine/apidocs/ee-imagecollection-filterbounds" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": null, 144 | "metadata": {}, 145 | "outputs": [], 146 | "source": [ 147 | "roi = ee.Geometry.Point(-122.4488, 37.7589)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 157 | " .filterDate('2020-01-01', '2020-12-31') \\\n", 158 | " .filterBounds(roi)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [ 167 | "print(collection.size().getInfo())" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [ 176 | "Map = geemap.Map()\n", 177 | "image = collection.first()\n", 178 | "\n", 179 | "vis_param = {'min': 0, \n", 180 | " 'max': 2000, \n", 181 | " 'bands': ['B5', 'B4', 'B3'], \n", 182 | " 'gamma': 1.5}\n", 183 | "\n", 184 | "Map.addLayer(image, vis_param, \"First mage\")\n", 185 | "Map.centerObject(image, 8)\n", 186 | "\n", 187 | "Map" 188 | ] 189 | }, 190 | { 191 | "cell_type": "markdown", 192 | "metadata": {}, 193 | "source": [ 194 | "## Filter by metadata\n", 195 | "\n", 196 | "https://developers.google.com/earth-engine/apidocs/ee-imagecollection-filtermetadata" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [ 205 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 206 | " .filterDate('2020-01-01', '2020-12-31') \\\n", 207 | " .filterBounds(ee.Geometry.Point(-122.4488, 37.7589)) \\\n", 208 | " .filterMetadata('CLOUD_COVER', 'less_than', 10) \\\n", 209 | " .sort(\"CLOUD_COVER\")" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": null, 215 | "metadata": {}, 216 | "outputs": [], 217 | "source": [ 218 | "Map = geemap.Map()\n", 219 | "image = collection.first()\n", 220 | "\n", 221 | "vis_param = {'min': 0, \n", 222 | " 'max': 2000, \n", 223 | " 'bands': ['B5', 'B4', 'B3'], \n", 224 | " 'gamma': 1.5}\n", 225 | "\n", 226 | "Map.addLayer(image, vis_param, \"First mage\")\n", 227 | "Map.centerObject(image, 8)\n", 228 | "\n", 229 | "Map" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": null, 235 | "metadata": {}, 236 | "outputs": [], 237 | "source": [ 238 | "geemap.image_props(image).getInfo()" 239 | ] 240 | }, 241 | { 242 | "cell_type": "markdown", 243 | "metadata": {}, 244 | "source": [ 245 | "## Get image collection properties" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": null, 251 | "metadata": {}, 252 | "outputs": [], 253 | "source": [ 254 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", 255 | " .filterDate('2020-01-01', '2020-12-31') \\\n", 256 | " .filterBounds(ee.Geometry.Point(-122.4488, 37.7589)) \\\n", 257 | " .filterMetadata('CLOUD_COVER', 'less_than', 10)" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": null, 263 | "metadata": {}, 264 | "outputs": [], 265 | "source": [ 266 | "collection.aggregate_array('CLOUD_COVER').getInfo()" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": null, 272 | "metadata": {}, 273 | "outputs": [], 274 | "source": [ 275 | "collection.aggregate_array('system:id').getInfo()" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": null, 281 | "metadata": {}, 282 | "outputs": [], 283 | "source": [ 284 | "collection.aggregate_mean('CLOUD_COVER').getInfo()" 285 | ] 286 | } 287 | ], 288 | "metadata": { 289 | "anaconda-cloud": {}, 290 | "hide_input": false, 291 | "kernelspec": { 292 | "display_name": "Python 3", 293 | "language": "python", 294 | "name": "python3" 295 | }, 296 | "language_info": { 297 | "codemirror_mode": { 298 | "name": "ipython", 299 | "version": 3 300 | }, 301 | "file_extension": ".py", 302 | "mimetype": "text/x-python", 303 | "name": "python", 304 | "nbconvert_exporter": "python", 305 | "pygments_lexer": "ipython3", 306 | "version": "3.8.5" 307 | }, 308 | "toc": { 309 | "base_numbering": 1, 310 | "nav_menu": {}, 311 | "number_sections": true, 312 | "sideBar": true, 313 | "skip_h1_title": false, 314 | "title_cell": "Table of Contents", 315 | "title_sidebar": "Contents", 316 | "toc_cell": false, 317 | "toc_position": {}, 318 | "toc_section_display": true, 319 | "toc_window_display": false 320 | }, 321 | "varInspector": { 322 | "cols": { 323 | "lenName": 16, 324 | "lenType": 16, 325 | "lenVar": 40 326 | }, 327 | "kernels_config": { 328 | "python": { 329 | "delete_cmd_postfix": "", 330 | "delete_cmd_prefix": "del ", 331 | "library": "var_list.py", 332 | "varRefreshCmd": "print(var_dic_list())" 333 | }, 334 | "r": { 335 | "delete_cmd_postfix": ") ", 336 | "delete_cmd_prefix": "rm(", 337 | "library": "var_list.r", 338 | "varRefreshCmd": "cat(var_dic_list()) " 339 | } 340 | }, 341 | "types_to_exclude": [ 342 | "module", 343 | "function", 344 | "builtin_function_or_method", 345 | "instance", 346 | "_Feature" 347 | ], 348 | "window_display": false 349 | } 350 | }, 351 | "nbformat": 4, 352 | "nbformat_minor": 1 353 | } 354 | -------------------------------------------------------------------------------- /docs/ImageCollection/reducing_image_collection.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/ImageCollection/reducing_image_collection.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**Reducing an ImageCollection**\n", 15 | "\n", 16 | "To composite images in an `ImageCollection`, use `imageCollection.reduce()`. This will composite all the images in the collection to a single image representing, for example, the min, max, mean or standard deviation of the images. (See the Reducers section for more information about reducers). For example, to create a median value image from a collection:" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "## Create an interactive map" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "import ee\n", 33 | "import geemap" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [ 42 | "Map = geemap.Map()\n", 43 | "Map" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Compute a median image" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "# Load a Landsat 8 collection for a single path-row.\n", 60 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \\\n", 61 | " .filter(ee.Filter.eq('WRS_PATH', 44)) \\\n", 62 | " .filter(ee.Filter.eq('WRS_ROW', 34)) \\\n", 63 | " .filterDate('2014-01-01', '2015-01-01')\n", 64 | "\n", 65 | "# Compute a median image and display.\n", 66 | "median = collection.median()\n", 67 | "Map.setCenter(-122.3578, 37.7726, 12)\n", 68 | "Map.addLayer(median, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3}, 'median')" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "collection.size().getInfo()" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "collection.aggregate_array(\"system:id\").getInfo()" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": {}, 92 | "source": [ 93 | "## Use median reducer" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "At each location in the output image, in each band, the pixel value is the median of all unmasked pixels in the input imagery (the images in the collection). In the previous example, `median()` is a convenience method for the following call:" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "# Reduce the collection with a median reducer.\n", 110 | "median = collection.reduce(ee.Reducer.median())\n", 111 | "\n", 112 | "# Display the median image.\n", 113 | "Map.addLayer(median,\n", 114 | " {'bands': ['B4_median', 'B3_median', 'B2_median'], 'max': 0.3},\n", 115 | " 'also median')\n", 116 | "Map" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "## Create an image composite" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "states = ee.FeatureCollection('TIGER/2018/States')\n", 133 | "Map.addLayer(states, {}, \"US States\")" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "ca = states.filter(ee.Filter.eq(\"NAME\", \"California\"))\n", 143 | "Map.addLayer(ca, {}, \"California\")" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": null, 149 | "metadata": {}, 150 | "outputs": [], 151 | "source": [ 152 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \\\n", 153 | " .filterBounds(ca) \\\n", 154 | " .filterDate('2020-01-01', '2021-01-01')" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "collection.size().getInfo()" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "image = collection.median().clip(ca)\n", 173 | "Map.addLayer(image, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3}, 'Landsat 2020')" 174 | ] 175 | } 176 | ], 177 | "metadata": { 178 | "hide_input": false, 179 | "kernelspec": { 180 | "display_name": "Python 3", 181 | "language": "python", 182 | "name": "python3" 183 | }, 184 | "language_info": { 185 | "codemirror_mode": { 186 | "name": "ipython", 187 | "version": 3 188 | }, 189 | "file_extension": ".py", 190 | "mimetype": "text/x-python", 191 | "name": "python", 192 | "nbconvert_exporter": "python", 193 | "pygments_lexer": "ipython3", 194 | "version": "3.8.5" 195 | }, 196 | "toc": { 197 | "base_numbering": 1, 198 | "nav_menu": {}, 199 | "number_sections": true, 200 | "sideBar": true, 201 | "skip_h1_title": false, 202 | "title_cell": "Table of Contents", 203 | "title_sidebar": "Contents", 204 | "toc_cell": false, 205 | "toc_position": {}, 206 | "toc_section_display": true, 207 | "toc_window_display": false 208 | }, 209 | "varInspector": { 210 | "cols": { 211 | "lenName": 16, 212 | "lenType": 16, 213 | "lenVar": 40 214 | }, 215 | "kernels_config": { 216 | "python": { 217 | "delete_cmd_postfix": "", 218 | "delete_cmd_prefix": "del ", 219 | "library": "var_list.py", 220 | "varRefreshCmd": "print(var_dic_list())" 221 | }, 222 | "r": { 223 | "delete_cmd_postfix": ") ", 224 | "delete_cmd_prefix": "rm(", 225 | "library": "var_list.r", 226 | "varRefreshCmd": "cat(var_dic_list()) " 227 | } 228 | }, 229 | "types_to_exclude": [ 230 | "module", 231 | "function", 232 | "builtin_function_or_method", 233 | "instance", 234 | "_Feature" 235 | ], 236 | "window_display": false 237 | } 238 | }, 239 | "nbformat": 4, 240 | "nbformat_minor": 4 241 | } 242 | -------------------------------------------------------------------------------- /docs/ImageCollection/visualizing_time_series.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/giswqs/gee-tutorials/blob/master/ImageCollection/visualizing_time_series.ipynb)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import ee\n", 17 | "import geemap" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "# geemap.update_package()" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Visualizing weather data" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": { 40 | "scrolled": false 41 | }, 42 | "outputs": [], 43 | "source": [ 44 | "Map = geemap.Map()\n", 45 | "\n", 46 | "collection = ee.ImageCollection('NOAA/GFS0P25') \\\n", 47 | " .filterDate('2018-12-22', '2018-12-23') \\\n", 48 | " .limit(24) \\\n", 49 | " .select('temperature_2m_above_ground')\n", 50 | "\n", 51 | "vis_params = {\n", 52 | " 'min': -40.0,\n", 53 | " 'max': 35.0,\n", 54 | " 'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red']\n", 55 | "}\n", 56 | "\n", 57 | "first_image = collection.first()\n", 58 | "\n", 59 | "Map.addLayer(first_image, vis_params, \"First image\")\n", 60 | "Map.setCenter(-0.3490, 25.7900, 2)\n", 61 | "Map" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "image = collection.toBands()\n", 71 | "Map.addLayer(image, {}, \"Time series\", False)" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "labels = [str(n).zfill(2) + \":00\" for n in range(0, 24)]\n", 81 | "labels" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "Map.add_time_slider(collection, vis_params, labels=labels, time_interval=1)\n", 91 | "Map" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "## Visualizing vegetation data" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": { 105 | "scrolled": false 106 | }, 107 | "outputs": [], 108 | "source": [ 109 | "Map = geemap.Map()\n", 110 | "\n", 111 | "collection = ee.ImageCollection('MODIS/MCD43A4_006_NDVI') \\\n", 112 | " .filter(ee.Filter.date('2018-04-01', '2018-05-01')) \\\n", 113 | " .select(\"NDVI\")\\\n", 114 | "\n", 115 | "vis_params = {\n", 116 | " 'min': 0.0,\n", 117 | " 'max': 1.0,\n", 118 | " 'palette': [\n", 119 | " 'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',\n", 120 | " '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',\n", 121 | " '012E01', '011D01', '011301'\n", 122 | " ],\n", 123 | "}\n", 124 | "\n", 125 | "first_image = collection.first()\n", 126 | "\n", 127 | "Map.addLayer(first_image, vis_params, \"First image\")\n", 128 | "Map.setCenter(-7.03125, 31.0529339857, 2)\n", 129 | "Map" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "image = collection.toBands()\n", 139 | "Map.addLayer(image, {}, \"Time series\", False)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "labels = collection.aggregate_array(\"system:index\").getInfo()\n", 149 | "Map.add_time_slider(collection, vis_params, labels=labels, time_interval=1)" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "## Visualizing Landsat imagery" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "Map = geemap.Map()\n", 166 | "\n", 167 | "bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']\n", 168 | "image = ee.Image('LE7_TOA_5YEAR/1999_2003').select(bands)\n", 169 | "vis_params = {'min': 20, 'max': 200, 'gamma': 2.0}\n", 170 | "\n", 171 | "Map.add_time_slider(image, vis_params, labels=bands, time_interval=1)\n", 172 | "\n", 173 | "Map" 174 | ] 175 | } 176 | ], 177 | "metadata": { 178 | "hide_input": false, 179 | "kernelspec": { 180 | "display_name": "Python 3", 181 | "language": "python", 182 | "name": "python3" 183 | }, 184 | "language_info": { 185 | "codemirror_mode": { 186 | "name": "ipython", 187 | "version": 3 188 | }, 189 | "file_extension": ".py", 190 | "mimetype": "text/x-python", 191 | "name": "python", 192 | "nbconvert_exporter": "python", 193 | "pygments_lexer": "ipython3", 194 | "version": "3.8.5" 195 | }, 196 | "toc": { 197 | "base_numbering": 1, 198 | "nav_menu": {}, 199 | "number_sections": true, 200 | "sideBar": true, 201 | "skip_h1_title": false, 202 | "title_cell": "Table of Contents", 203 | "title_sidebar": "Contents", 204 | "toc_cell": false, 205 | "toc_position": {}, 206 | "toc_section_display": true, 207 | "toc_window_display": false 208 | }, 209 | "varInspector": { 210 | "cols": { 211 | "lenName": 16, 212 | "lenType": 16, 213 | "lenVar": 40 214 | }, 215 | "kernels_config": { 216 | "python": { 217 | "delete_cmd_postfix": "", 218 | "delete_cmd_prefix": "del ", 219 | "library": "var_list.py", 220 | "varRefreshCmd": "print(var_dic_list())" 221 | }, 222 | "r": { 223 | "delete_cmd_postfix": ") ", 224 | "delete_cmd_prefix": "rm(", 225 | "library": "var_list.r", 226 | "varRefreshCmd": "cat(var_dic_list()) " 227 | } 228 | }, 229 | "types_to_exclude": [ 230 | "module", 231 | "function", 232 | "builtin_function_or_method", 233 | "instance", 234 | "_Feature" 235 | ], 236 | "window_display": false 237 | } 238 | }, 239 | "nbformat": 4, 240 | "nbformat_minor": 4 241 | } 242 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | ## Google Earth Engine Tutorials 2 | 3 | [![image](https://colab.research.google.com/assets/colab-badge.svg)](https://gishub.org/geemap-colab) 4 | [![image](https://binder.pangeo.io/badge_logo.svg)](https://binder.pangeo.io/v2/gh/giswqs/geemap/master) 5 | [![image](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 6 | [![image](https://joss.theoj.org/papers/10.21105/joss.02305/status.svg)](https://joss.theoj.org/papers/10.21105/joss.02305) 7 | [![image](https://img.shields.io/badge/YouTube-Channel-red)](https://www.youtube.com/c/QiushengWu) 8 | [![image](https://img.shields.io/twitter/follow/giswqs?style=social)](https://twitter.com/giswqs) 9 | -------------------------------------------------------------------------------- /docs/overrides/main.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block content %} 4 | {% if page.nb_url %} 5 | 6 | {% include ".icons/material/download.svg" %} 7 | 8 | {% endif %} 9 | 10 | {{ super() }} 11 | {% endblock content %} 12 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: GEE Tutorials 2 | 3 | site_url: https://tutorials.geemap.org 4 | 5 | repo_url: https://github.com/giswqs/gee-tutorials 6 | 7 | theme: 8 | palette: 9 | scheme: preference 10 | name: material 11 | icon: 12 | repo: fontawesome/brands/github 13 | features: 14 | - navigation.instant 15 | # - navigation.expand 16 | # - navigation.tabs 17 | - search.highlight 18 | custom_dir: "docs/overrides" 19 | 20 | plugins: 21 | - search 22 | - mkdocstrings 23 | - git-revision-date 24 | # - pdf-export 25 | - mkdocs-jupyter: 26 | include_source: True 27 | # execute: True 28 | 29 | markdown_extensions: 30 | - attr_list 31 | - toc: 32 | permalink: true 33 | 34 | google_analytics: 35 | - UA-186406134-1 36 | - auto 37 | 38 | nav: 39 | - Home: index.md 40 | - Image: 41 | - Image/image_overview.ipynb 42 | - Image/image_visualization.ipynb 43 | - Image/image_metadata.ipynb 44 | - Image/math_operations.ipynb 45 | - Image/conditional_operations.ipynb 46 | - Image/image_colorbar.ipynb 47 | - Image Collection: 48 | - ImageCollection/image_collection_overview.ipynb 49 | - ImageCollection/reducing_image_collection.ipynb 50 | - ImageCollection/mapping_over_image_collection.ipynb 51 | - ImageCollection/cloud_free_composite.ipynb 52 | - ImageCollection/visualizing_time_series.ipynb 53 | - Feature Collection: 54 | - FeatureCollection/vector_styling.ipynb 55 | - Asset Management: 56 | - AssetManagement/export_data.ipynb 57 | - AssetManagement/extract_values.ipynb 58 | - Analysis: 59 | - Analysis/zonal_statistics.ipynb 60 | - Analysis/zonal_stats_by_group.ipynb 61 | - geemap: https://geemap.org 62 | - Blog: https://blog.gishub.org 63 | - YouTube Channel: https://www.youtube.com/c/QiushengWu 64 | - Report Issues: https://github.com/giswqs/gee-tutorials/issues 65 | 66 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | git+git://github.com/giswqs/geemap --------------------------------------------------------------------------------