Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
giswqs
GitHub Repository: giswqs/geemap
Path: blob/master/tutorials/ImageCollection/02_image_collection_metadata.ipynb
2313 views
Kernel: Python 3

ImageCollection Information and Metadata

As with Images, there are a variety of ways to get information about an ImageCollection. The collection can be printed directly to the console, but the console printout is limited to 5000 elements. Collections larger than 5000 images will need to be filtered before printing. Printing a large collection will be correspondingly slower. The following example shows various ways of getting information about image collections programmatically:

Install Earth Engine API and geemap

Install the Earth Engine Python API and geemap. The geemap Python package is built upon the ipyleaflet and folium packages and implements several methods for interacting with Earth Engine data layers, such as Map.addLayer(), Map.setCenter(), and Map.centerObject(). 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, folium, 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). Note that Google Colab currently does not support ipyleaflet (source). Therefore, if you are using geemap with Google Colab, you should use import geemap.foliumap. If you are using geemap with binder or a local Jupyter notebook server, you can use import geemap, which provides more functionalities for capturing user input (e.g., mouse-clicking and moving).

# Installs geemap package import subprocess try: import geemap except ImportError: print("geemap package not installed. Installing ...") subprocess.check_call(["python", "-m", "pip", "install", "geemap"]) # Checks whether this notebook is running on Google Colab try: import google.colab import geemap.foliumap as emap except: import geemap as emap # Authenticates and initializes Earth Engine import ee try: ee.Initialize() except Exception as e: ee.Authenticate() ee.Initialize()

Create an interactive map

The default basemap is Google Satellite. Additional basemaps can be added using the Map.add_basemap() function.

Map = geemap.Map(center=[40, -100], zoom=4) Map.add_basemap("ROADMAP") # Add Google Map Map

Add Earth Engine Python script

# Load a Landsat 8 ImageCollection for a single path-row. collection = ( ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA") .filter(ee.Filter.eq("WRS_PATH", 44)) .filter(ee.Filter.eq("WRS_ROW", 34)) .filterDate("2014-03-01", "2014-08-01") ) print("Collection: ", collection.getInfo())
# Get the number of images. count = collection.size() print("Count: ", count.getInfo())
# Get the date range of images in the collection. range = collection.reduceColumns(ee.Reducer.minMax(), ["system:time_start"]) print( "Date range: ", ee.Date(range.get("min")).getInfo(), ee.Date(range.get("max")).getInfo(), )
# Change the date format. range = collection.reduceColumns(ee.Reducer.minMax(), ["system:time_start"]) start_date = ee.Date(range.get("min")).format("YYYY-MM-dd") end_date = ee.Date(range.get("max")).format("YYYY-MM-dd") print("Date range: ", start_date.getInfo(), end_date.getInfo())
# Get statistics for a property of the images in the collection. sunStats = collection.aggregate_stats("SUN_ELEVATION") print("Sun elevation statistics: ", sunStats.getInfo())
# Get statistics for a property of the images in the collection. clouds = collection.aggregate_array("CLOUD_COVER") print("Cloud covers: ", clouds.getInfo())
# Sort by a cloud cover property, get the least cloudy image. image = ee.Image(collection.sort("CLOUD_COVER").first()) print("Least cloudy image: ", image.propertyNames().getInfo()) print("\nCloud cover: ", image.get("CLOUD_COVER").getInfo())
# Limit the collection to the 10 most recent images. recent = collection.sort("system:time_start", False).limit(10) images = recent.aggregate_array("system:index").getInfo() print("Recent images:") for image in images: print(image)

Display Earth Engine data layers

Map.addLayerControl() Map