earthengine-api/python/examples/ipynb/EarthEngineColabInstall.ipynb
Christopher Brown ba57b055e1 v0.1.167
2019-01-24 15:57:14 -08:00

150 lines
4.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "2j_Ok5BKJiXU"
},
"source": [
"*Copyright 2018 Google LLC.*\n",
"\n",
"*SPDX-License-Identifier: Apache-2.0*"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "GwrEeAOB_MXY"
},
"source": [
"# Earth Engine Colab installation\n",
"\n",
"This notebook demonstrates a simple installation of Earth Engine to a Colab notebook."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "b1EUdVhC3SCp"
},
"source": [
"# Colab setup\n",
"\n",
"This notebook section installs the Earth Engine Python API on your Colab virtual machine (VM) and will need to be executed each time a new Colab notebook is created. Colab VMs are recycled after they are idle for a while."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "pkke7LnZBuqI"
},
"source": [
"## Install Earth Engine\n",
"\n",
"The Earth Engine Python API and command line tools can be installed using [Python's `pip` package installation tool](https://pypi.org/project/pip/). The following notebook cell line is starts with `!` to indicate that a shell command should be invoked."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "JFv3jrBIG2av"
},
"outputs": [],
"source": [
"!pip install earthengine-api"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "GYUppo1t39B7"
},
"source": [
"## Authenticate to Earth Engine\n",
"\n",
"In order to access Earth Engine, signup at [signup.earthengine.google.com](https://signup.earthengine.google.com).\n",
"\n",
"Once you have signed up and the Earth Engine package is installed, use the `earthengine authenticate` shell command to create and store authentication credentials on the Colab VM. These credentials are used by the Earth Engine Python API and command line tools to access Earth Engine servers.\n",
"\n",
"You will need to follow the link to the permissions page and give this notebook access to your Earth Engine account. Once you have authorized access, paste the authorization code into the input box displayed in the cell output."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "Bgbfo1Ap37Bj"
},
"outputs": [],
"source": [
"import ee\n",
"\n",
"# Check if the server is authenticated. If not, display instructions that\n",
"# explain how to complete the process.\n",
"try:\n",
" ee.Initialize()\n",
"except ee.EEException:\n",
" !earthengine authenticate"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "5skJZQXSCdgd"
},
"source": [
"# Test the installation\n",
"\n",
"Import the Earth Engine library and initialize it with the authorization token stored on the notebook VM. Also import a display widget and display a thumbnail image of an Earth Engine dataset."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "BxAjoaeNHeOG"
},
"outputs": [],
"source": [
"import ee\n",
"from IPython.display import Image\n",
"\n",
"# Initialize the Earth Engine module.\n",
"ee.Initialize()\n",
"\n",
"# Display a thumbnail of a sample image asset.\n",
"Image(url=ee.Image('CGIAR/SRTM90_V4').getThumbUrl({'min': 0, 'max': 3000}))"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "Earth Engine Colab Install.ipynb",
"private_outputs": true,
"provenance": [],
"toc_visible": true,
"version": "0.3.2"
},
"kernelspec": {
"display_name": "Python 2",
"name": "python2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}