#!/usr/bin/env python # coding: utf-8 # # Pydeck + Earth Engine: ImageCollection Animation # # This is an example of using [pydeck](https://pydeck.gl) to animate a Google Earth Engine `ImageCollection` object. To install and run this notebook locally, refer to the [Pydeck Earth Engine documentation](https://earthengine-layers.com/docs/developer-guide/pydeck-integration). # # To see this example online, view the [JavaScript version][js-example]. # # [js-example]: https://earthengine-layers.com/examples/image-collection # Import required packages: # In[1]: from pydeck_earthengine_layers import EarthEngineLayer import pydeck as pdk import ee # ### Authenticate with Earth Engine # # Using Earth Engine requires authentication. If you don't have a Google account approved for use with Earth Engine, you'll need to request access. For more information and to sign up, go to https://signup.earthengine.google.com/. # In[2]: try: ee.Initialize() except Exception as e: ee.Authenticate() ee.Initialize() # ### GFS Temperature Forecast Dataset # # This example uses the [Global Forecast System 384-Hour Predicted Atmosphere Data][gfs] dataset, which contains a weather forecast model produced by the National Centers for Environmental Prediction (NCEP) # # [gfs]: https://developers.google.com/earth-engine/datasets/catalog/NOAA_GFS0P25 # Import the dataset by creating an Earth Engine object that references it. # In[3]: # Initialize an ee.ImageColllection object referencing the Global Forecast System dataset image_collection = ee.ImageCollection('NOAA/GFS0P25') # Select images from December 22, 2018 image_collection = image_collection.filterDate('2018-12-22', '2018-12-23') # Choose the first 24 images in the ImageCollection image_collection = image_collection.limit(24) # Select a single band to visualize image_collection = image_collection.select('temperature_2m_above_ground') # Create a `vis_params` object that defines how EarthEngine should style the `ImageCollection` # In[4]: # Style temperature values between -40C and 35C, # with lower values shades of blue, purple, and cyan, # and higher values shades of green, yellow, and red vis_params = { 'min': -40.0, 'max': 35.0, 'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red'] }; # Create a new `EarthEngineLayer` with this dataset that can then be passed to Pydeck. # In[5]: layer = EarthEngineLayer( image_collection, vis_params, animate=True, id="global_weather") # Then just pass this layer to a `pydeck.Deck` instance, and call `.show()` to create a map: # In[6]: view_state = pdk.ViewState(latitude=36, longitude=10, zoom=1) r = pdk.Deck( layers=[layer], initial_view_state=view_state ) r.show() # In[ ]: