Export and cloud mask Google Earth Engine imagery with automated composite creation and filtering capabilities.
—
Advanced operations on Earth Engine image collections including filtering, compositing, and batch processing with cloud masking support. The collection functionality is accessed through the .gd accessor on ee.ImageCollection objects.
The main accessor class for Earth Engine image collections, registered as .gd on ee.ImageCollection objects.
class ImageCollectionAccessor:
def __init__(self, ee_coll: ee.ImageCollection): ...Filter image collections based on various criteria including cloud coverage, date ranges, and geographic regions.
def filter(
self,
start_date: str | datetime | ee.Date = None,
end_date: str | datetime | ee.Date = None,
region: dict | ee.Geometry = None,
fill_portion: float | ee.Number = None,
cloudless_portion: float | ee.Number = None,
custom_filter: str = None,
**kwargs
) -> ee.ImageCollection:
"""
Filter the collection on date, region, filled/cloud-free portion, and custom criteria.
Parameters:
- start_date (str | datetime | ee.Date, optional): Start date, in ISO format if string
- end_date (str | datetime | ee.Date, optional): End date, in ISO format if string
- region (dict | ee.Geometry, optional): Geographic region filter
- fill_portion (float | ee.Number, optional): Minimum fill percentage (0-100)
- cloudless_portion (float | ee.Number, optional): Minimum cloudless percentage (0-100)
- custom_filter (str, optional): Custom filter expression
- **kwargs: Additional filter parameters
Returns:
ee.ImageCollection: Filtered collection
"""Create temporal composites from image collections using various algorithms.
def composite(
self,
method: CompositeMethod = CompositeMethod.median,
region: dict | ee.Geometry = None,
scale: float = None,
date_range: tuple = None,
**kwargs
) -> ee.Image:
"""
Create a composite image from the collection.
Parameters:
- method (CompositeMethod): Compositing algorithm
- region (dict | ee.Geometry, optional): Composite region
- scale (float, optional): Composite scale in meters
- date_range (tuple, optional): Date range for temporal filtering
- **kwargs: Additional compositing parameters
Returns:
ee.Image: Composite image
"""Export an entire image collection with various splitting and organization options.
def export(
self,
description: str,
folder: str = None,
region: dict | ee.Geometry = None,
scale: float = None,
split: str = 'images',
export_type: ExportType = ExportType.drive,
**kwargs
) -> list[ee.batch.Task]:
"""
Export the image collection.
Parameters:
- description (str): Base description for export tasks
- folder (str, optional): Destination folder name
- region (dict | ee.Geometry, optional): Export region
- scale (float, optional): Export scale in meters
- split (str): Split method ('images' or 'bands')
- export_type (ExportType): Export destination type
- **kwargs: Additional export parameters
Returns:
list[ee.batch.Task]: List of export tasks
"""Download an entire collection to local storage with parallel processing.
def download(
self,
region: dict | ee.Geometry = None,
scale: float = None,
max_images: int = None,
concurrent: int = 4,
**kwargs
) -> list:
"""
Download the image collection.
Parameters:
- region (dict | ee.Geometry, optional): Download region
- scale (float, optional): Download scale in meters
- max_images (int, optional): Maximum number of images to download
- concurrent (int): Number of concurrent downloads
- **kwargs: Additional download parameters
Returns:
list: List of downloaded image data
"""Add cloud mask bands to all images in a collection.
def addMaskBands(self, **kwargs) -> ee.ImageCollection:
"""
Add mask bands to all images in the collection.
Parameters:
- **kwargs: Cloud masking parameters applied to all images
Returns:
ee.ImageCollection: Collection with mask bands added
"""Apply cloud masking to all images in a collection.
def maskClouds(self) -> ee.ImageCollection:
"""
Apply cloud masking to all images in the collection.
Returns:
ee.ImageCollection: Cloud-masked collection
"""Create a new collection from a list of images with cloud masking support.
@staticmethod
def fromImages(images: list | ee.List) -> ee.ImageCollection:
"""
Create an image collection with cloud masking support.
Parameters:
- images: Sequence of images or anything that can construct an image
Returns:
ee.ImageCollection: Collection with cloud masking support
"""Access collection metadata, properties, and schema information.
@property
def properties(self) -> dict:
"""Get collection properties as a dictionary."""
@property
def schema(self) -> dict:
"""Get collection schema information."""
@property
def info(self) -> dict:
"""Get collection info including size and date range."""
@property
def schemaPropertyNames(self) -> tuple[str]:
"""Get names of properties to include in schema."""
@property
def schemaTable(self) -> str:
"""Get formatted table of schema information."""
@property
def propertiesTable(self) -> str:
"""Get formatted table of collection properties."""Create a medoid composite from the collection using spectral distance metrics.
def medoid(self, bands: list | ee.List = None) -> ee.Image:
"""
Create a medoid composite using spectral distance metrics.
Parameters:
- bands (list | ee.List, optional): Bands to use for medoid calculation
Returns:
ee.Image: Medoid composite image
"""import ee
import geedim
from datetime import datetime
geedim.Initialize()
# Load and filter a Landsat collection
collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2') \
.filterDate('2020-01-01', '2020-12-31') \
.filterBounds(ee.Geometry.Point(-122.4194, 37.7749).buffer(50000))
# Search with cloud filtering
filtered = collection.gd.search(
start_date='2020-06-01',
end_date='2020-09-30',
cloudless_portion=75,
fill_portion=90
)
print(f"Found {filtered.size().getInfo()} images")# Create median composite
region = ee.Geometry.Rectangle([-122.5, 37.7, -122.3, 37.8])
median_composite = collection.gd.composite(
method=geedim.CompositeMethod.median,
region=region,
scale=30
)
# Create quality mosaic (best pixel based on cloud distance)
quality_composite = collection.gd.composite(
method=geedim.CompositeMethod.q_mosaic,
region=region,
scale=30
)
# Create medoid composite
medoid_composite = collection.gd.composite(
method=geedim.CompositeMethod.medoid,
region=region,
scale=30
)# Export entire collection split by images
tasks = collection.gd.export(
description='landsat_collection',
folder='batch_export',
region=region,
scale=30,
split='images',
export_type=geedim.ExportType.drive
)
# Start all export tasks
for task in tasks:
task.start()
# Export split by bands
band_tasks = collection.gd.export(
description='landsat_bands',
folder='band_export',
region=region,
scale=30,
split='bands',
export_type=geedim.ExportType.cloud
)# Get collection properties
props = collection.gd.properties
date_range = props.get('date_range')
image_count = props.get('count')
# Get schema information
schema = collection.gd.schema
property_names = schema.get('properties', [])
# Analyze cloud coverage
cloud_stats = collection.gd.cloudCoverage(region=region)# Create collection from specific images
image_ids = [
'LANDSAT/LC08/C02/T1_L2/LC08_173083_20200601',
'LANDSAT/LC08/C02/T1_L2/LC08_173083_20200717',
'LANDSAT/LC08/C02/T1_L2/LC08_173083_20200802'
]
images = [ee.Image(img_id) for img_id in image_ids]
custom_collection = ee.ImageCollection.gd.fromImages(images)
# Add mask bands and mask clouds for entire collection
masked_collection = custom_collection.gd.addMaskBands(
mask_cirrus=True,
mask_shadows=True
).maskClouds()Install with Tessl CLI
npx tessl i tessl/pypi-geedim