Created
May 15, 2020 22:50
-
-
Save jdbcode/054e8c0c39e052f91db635390a93f710 to your computer and use it in GitHub Desktop.
earth_engine_animation_to_drive.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "earth_engine_animation_to_drive.ipynb", | |
"provenance": [], | |
"toc_visible": true, | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/jdbcode/054e8c0c39e052f91db635390a93f710/earth_engine_animation_to_drive.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "224GqdsogBOI", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"This notebook demonstrates how to save an Earth Engine [image collection animation](https://developers.google.com/earth-engine/ic_visualization) to Google Drive." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "OEo726hQb_ij", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# Setup Earth Engine" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "V3aXlWq5bs3d", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import ee\n", | |
"\n", | |
"ee.Authenticate()\n", | |
"ee.Initialize()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "DHN4fEx6cEcD", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# Get URL for collection animation" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "2cepvwDdbWTz", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# Define an area of interest geometry with a global non-polar extent.\n", | |
"aoi = ee.Geometry.Polygon(\n", | |
" [[[-179.0, 78.0], [-179.0, -58.0], [179.0, -58.0], [179.0, 78.0]]], None,\n", | |
" False)\n", | |
"\n", | |
"# Import hourly predicted temperature image collection for northern winter\n", | |
"# solstice. Note that predictions extend for 384 hours; limit the collection\n", | |
"# to the first 24 hours.\n", | |
"temp_col = (ee.ImageCollection('NOAA/GFS0P25')\n", | |
" .filterDate('2018-12-22', '2018-12-23')\n", | |
" .limit(24)\n", | |
" .select('temperature_2m_above_ground'))\n", | |
"\n", | |
"# Define arguments for animation function parameters.\n", | |
"video_args = {\n", | |
" 'dimensions': 768,\n", | |
" 'region': aoi,\n", | |
" 'framesPerSecond': 7,\n", | |
" 'crs': 'EPSG:3857',\n", | |
" 'min': -40.0,\n", | |
" 'max': 35.0,\n", | |
" 'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red']\n", | |
"}\n", | |
"\n", | |
"# Get URL that will produce the animation when accessed.\n", | |
"gif_url = temp_col.getVideoThumbURL(video_args)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "U_kvGfQtcLGS", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# Save the animation to Google Drive" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "2SNd2m7OcapT", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## Mount Google Drive to Colab VM" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "1AaJ3wmXcOsK", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"from google.colab import drive\n", | |
"drive.mount('gdrive')" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "P49-qxd3dtTb", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## Download the animation to Google Drive" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "qNNYL7vLcoE0", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import urllib.request\n", | |
"\n", | |
"gif_name = 'gdrive/My Drive/ee_collection_animation.gif'\n", | |
"urllib.request.urlretrieve(gif_url, gif_name)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment