Skip to content

Commit

Permalink
Updated notebook examples
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Mar 19, 2020
1 parent 5e3f068 commit ab440a1
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 1,858 deletions.
36 changes: 24 additions & 12 deletions examples/notebooks/earthengine_js_to_ipynb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"metadata": {},
"source": [
"<table class=\"ee-notebook-buttons\" align=\"left\">\n",
" <td><a target=\"_blank\" href=\"https://github.com/giswqs/geemap/tree/master/examples/earthengine_js_to_ipynb.ipynb\"><img width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /> View source on GitHub</a></td>\n",
" <td><a target=\"_blank\" href=\"https://nbviewer.jupyter.org/github/giswqs/geemap/blob/master/examples/earthengine_js_to_ipynb.ipynb\"><img width=26px src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/883px-Jupyter_logo.svg.png\" />Notebook Viewer</a></td>\n",
" <td><a target=\"_blank\" href=\"https://mybinder.org/v2/gh/giswqs/geemap/master?filepath=examples/earthengine_js_to_ipynb.ipynb\"><img width=58px src=\"https://mybinder.org/static/images/logo_social.png\" />Run in binder</a></td>\n",
" <td><a target=\"_blank\" href=\"https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/earthengine_js_to_ipynb.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /> Run in Google Colab</a></td>\n",
" <td><a target=\"_blank\" href=\"https://github.com/giswqs/geemap/tree/master/examples/notebooks/earthengine_js_to_ipynb.ipynb\"><img width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /> View source on GitHub</a></td>\n",
" <td><a target=\"_blank\" href=\"https://nbviewer.jupyter.org/github/giswqs/geemap/blob/master/examples/notebooks/earthengine_js_to_ipynb.ipynb\"><img width=26px src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/883px-Jupyter_logo.svg.png\" />Notebook Viewer</a></td>\n",
" <td><a target=\"_blank\" href=\"https://mybinder.org/v2/gh/giswqs/geemap/master?filepath=examples/notebooks/earthengine_js_to_ipynb.ipynb\"><img width=58px src=\"https://mybinder.org/static/images/logo_social.png\" />Run in binder</a></td>\n",
" <td><a target=\"_blank\" href=\"https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/notebooks/earthengine_js_to_ipynb.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /> Run in Google Colab</a></td>\n",
"</table>"
]
},
Expand All @@ -18,10 +18,11 @@
"source": [
"## Automatic conversion from Earth Engine JavaScripts to Python scripts\n",
"\n",
"### Install the geemap Python package\n",
"### Install Earth Engine API and geemap\n",
"Install the [Earth Engine Python API](https://developers.google.com/earth-engine/python_install) and [geemap](https://github.com/giswqs/geemap). The **geemap** Python package is built upon the [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) and [folium](https://github.com/python-visualization/folium) packages and implements several methods for interacting with Earth Engine data layers, such as `Map.addLayer()`, `Map.setCenter()`, and `Map.centerObject()`.\n",
"The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its [dependencies](https://github.com/giswqs/geemap#dependencies), including earthengine-api, folium, and ipyleaflet.\n",
"\n",
"The [**geemap**](https://github.com/giswqs/geemap) Python package builds on the [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) package and implements several methods for displaying Earth Engine data layers, such as `Map.addLayer()`, `Map.setCenter()`, and `Map.centerObject()`.\n",
"The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its dependencies, including earthengine-api and ipyleaflet."
"**Important note**: A key difference between folium and ipyleaflet is that ipyleaflet is built upon ipywidgets and allows bidirectional communication between the front-end and the backend enabling the use of the map to capture user input, while folium is meant for displaying static data only ([source](https://blog.jupyter.org/interactive-gis-in-jupyter-with-ipyleaflet-52f9657fa7a)). Note that [Google Colab](https://colab.research.google.com/) currently does not support ipyleaflet ([source](https://github.com/googlecolab/colabtools/issues/60#issuecomment-596225619)). Therefore, if you are using geemap with Google Colab, you should use [`import geemap.eefolium`](https://github.com/giswqs/geemap/blob/master/geemap/eefolium.py). If you are using geemap with [binder](https://mybinder.org/) or a local Jupyter notebook server, you can use [`import geemap`](https://github.com/giswqs/geemap/blob/master/geemap/geemap.py), which provides more functionalities for capturing user input (e.g., mouse-clicking and moving)."
]
},
{
Expand Down Expand Up @@ -55,11 +56,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Processing /home/qiusheng/geemap/ModisQaBands.js\n",
"Processing /home/qiusheng/geemap/FromName.js\n",
"Processing /home/qiusheng/geemap/NormalizedDifference.js\n",
"Processing /home/qiusheng/geemap/QualityMosaic.js\n",
"Processing /home/qiusheng/geemap/ClippedComposite.js\n",
"Converting Earth Engine JavaScripts to Python scripts...\n",
"\n",
"Processing 1/5: /home/qiusheng/geemap/ModisQaBands.js\n",
"Processing 2/5: /home/qiusheng/geemap/FromName.js\n",
"Processing 3/5: /home/qiusheng/geemap/NormalizedDifference.js\n",
"Processing 4/5: /home/qiusheng/geemap/QualityMosaic.js\n",
"Processing 5/5: /home/qiusheng/geemap/ClippedComposite.js\n",
"Python scripts saved at: /home/qiusheng/geemap\n"
]
}
Expand Down Expand Up @@ -96,10 +99,19 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Converting Earth Engine Python scripts to Jupyter notebooks ...\n",
"\n",
"Processing 1/5: /home/qiusheng/geemap/ModisQaBands_qgis.py\n",
"\n",
"Processing 2/5: /home/qiusheng/geemap/QualityMosaic_qgis.py\n",
"\n",
"Processing 3/5: /home/qiusheng/geemap/FromName_qgis.py\n",
"\n",
"Processing 4/5: /home/qiusheng/geemap/NormalizedDifference_qgis.py\n",
"\n",
"Processing 5/5: /home/qiusheng/geemap/ClippedComposite_qgis.py\n",
"\n",
"Executing Earth Engine Jupyter notebooks ...\n",
"\n",
"Processing 1/5: /home/qiusheng/geemap/NormalizedDifference.ipynb ...\n",
"\n",
Expand Down
162 changes: 31 additions & 131 deletions examples/notebooks/geemap_and_earthengine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"metadata": {},
"source": [
"<table class=\"ee-notebook-buttons\" align=\"left\">\n",
" <td><a target=\"_blank\" href=\"https://github.com/giswqs/geemap/tree/master/examples/geemap_and_earthengine.ipynb\"><img width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /> View source on GitHub</a></td>\n",
" <td><a target=\"_blank\" href=\"https://nbviewer.jupyter.org/github/giswqs/geemap/blob/master/examples/geemap_and_earthengine.ipynb\"><img width=26px src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/883px-Jupyter_logo.svg.png\" />Notebook Viewer</a></td>\n",
" <td><a target=\"_blank\" href=\"https://mybinder.org/v2/gh/giswqs/geemap/master?filepath=examples/geemap_and_earthengine.ipynb\"><img width=58px src=\"https://mybinder.org/static/images/logo_social.png\" />Run in binder</a></td>\n",
" <td><a target=\"_blank\" href=\"https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/geemap_and_earthengine.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /> Run in Google Colab</a></td>\n",
" <td><a target=\"_blank\" href=\"https://github.com/giswqs/geemap/tree/master/examples/notebooks/geemap_and_earthengine.ipynb\"><img width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /> View source on GitHub</a></td>\n",
" <td><a target=\"_blank\" href=\"https://nbviewer.jupyter.org/github/giswqs/geemap/blob/master/examples/notebooks/geemap_and_earthengine.ipynb\"><img width=26px src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/883px-Jupyter_logo.svg.png\" />Notebook Viewer</a></td>\n",
" <td><a target=\"_blank\" href=\"https://mybinder.org/v2/gh/giswqs/geemap/master?filepath=examples/notebooks/geemap_and_earthengine.ipynb\"><img width=58px src=\"https://mybinder.org/static/images/logo_social.png\" />Run in binder</a></td>\n",
" <td><a target=\"_blank\" href=\"https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/notebooks/geemap_and_earthengine.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /> Run in Google Colab</a></td>\n",
"</table>"
]
},
Expand All @@ -17,46 +17,42 @@
"metadata": {},
"source": [
"## Install Earth Engine API and geemap\n",
"Install the [Earth Engine Python API](https://developers.google.com/earth-engine/python_install) and [geemap](https://github.com/giswqs/geemap). The **geemap** Python package builds on the [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) package and implements several methods for displaying Earth Engine data layers, such as `Map.addLayer()`, `Map.setCenter()`, and `Map.centerObject()`.\n",
"The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its dependencies, including earthengine-api and ipyleaflet."
"Install the [Earth Engine Python API](https://developers.google.com/earth-engine/python_install) and [geemap](https://github.com/giswqs/geemap). The **geemap** Python package is built upon the [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) and [folium](https://github.com/python-visualization/folium) packages and implements several methods for interacting with Earth Engine data layers, such as `Map.addLayer()`, `Map.setCenter()`, and `Map.centerObject()`.\n",
"The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its [dependencies](https://github.com/giswqs/geemap#dependencies), including earthengine-api, folium, and ipyleaflet.\n",
"\n",
"**Important note**: A key difference between folium and ipyleaflet is that ipyleaflet is built upon ipywidgets and allows bidirectional communication between the front-end and the backend enabling the use of the map to capture user input, while folium is meant for displaying static data only ([source](https://blog.jupyter.org/interactive-gis-in-jupyter-with-ipyleaflet-52f9657fa7a)). Note that [Google Colab](https://colab.research.google.com/) currently does not support ipyleaflet ([source](https://github.com/googlecolab/colabtools/issues/60#issuecomment-596225619)). Therefore, if you are using geemap with Google Colab, you should use [`import geemap.eefolium`](https://github.com/giswqs/geemap/blob/master/geemap/eefolium.py). If you are using geemap with [binder](https://mybinder.org/) or a local Jupyter notebook server, you can use [`import geemap`](https://github.com/giswqs/geemap/blob/master/geemap/geemap.py), which provides more functionalities for capturing user input (e.g., mouse-clicking and moving)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Installs geemap package\n",
"import subprocess\n",
"\n",
"try:\n",
" import geemap\n",
"except ImportError:\n",
" print('geemap package not installed. Installing ...')\n",
" subprocess.check_call([\"python\", '-m', 'pip', 'install', 'geemap'])\n",
" import geemap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import and authenticate Earth Engine"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Checks whether this notebook is running on Google Colab\n",
"try:\n",
" import google.colab\n",
" import geemap.eefolium as emap\n",
"except:\n",
" import geemap as emap\n",
"\n",
"# Authenticates and initializes Earth Engine\n",
"import ee\n",
"\n",
"try:\n",
" ee.Initialize()\n",
"except Exception as e:\n",
" ee.Authenticate()\n",
" ee.Initialize()"
" ee.Initialize() "
]
},
{
Expand All @@ -68,27 +64,11 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2fe4a13d9a064dc8a39577ee7f42a05e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[40, -100], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_t…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"import geemap\n",
"Map = geemap.Map(center=(40, -100), zoom=4)\n",
"Map = emap.Map(center=(40, -100), zoom=4)\n",
"Map"
]
},
Expand All @@ -101,17 +81,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mount Everest elevation (m): 8729\n"
]
}
],
"outputs": [],
"source": [
"# Add Earth Engine dataset\n",
"image = ee.Image('USGS/SRTMGL1_003')\n",
Expand Down Expand Up @@ -143,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -159,7 +131,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -175,52 +147,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ad537c8ddac04c86b0a534db003ac7ad",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Label(value='')"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a8f732703555486ea1ec0eba941ec96e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Label(value='')"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "09d1923950ed43e7ba80319c9009a9e7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[40, -100], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_t…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"import ee\n",
"import geemap\n",
Expand Down Expand Up @@ -276,24 +205,9 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7019a3e27d594e3da75f8245fcf796f2",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[45, 30], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_tex…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"import ee\n",
"import geemap\n",
Expand Down Expand Up @@ -362,20 +276,6 @@
"\n",
"Map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit ab440a1

Please sign in to comment.