This is an example of using pydeck to animate a Google Earth Engine ImageCollection
object. To install and run this notebook locally, refer to the Pydeck Earth Engine documentation.
To see this example online, view the JavaScript version.
Import required packages:
from pydeck_earthengine_layers import EarthEngineLayer
import pydeck as pdk
import ee
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/.
try:
ee.Initialize()
except Exception as e:
ee.Authenticate()
ee.Initialize()
This example uses the Global Forecast System 384-Hour Predicted Atmosphere Data dataset, which contains a weather forecast model produced by the National Centers for Environmental Prediction (NCEP)
Import the dataset by creating an Earth Engine object that references it.
# 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
# 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.
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:
view_state = pdk.ViewState(latitude=36, longitude=10, zoom=1)
r = pdk.Deck(
layers=[layer],
initial_view_state=view_state
)
r.show()
DeckGLWidget(custom_libraries=[{'libraryName': 'EarthEngineLayerLibrary', 'resourceUri': 'https://unpkg.com/@u…