CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-geedim

Export and cloud mask Google Earth Engine imagery with automated composite creation and filtering capabilities.

Pending
Overview
Eval results
Files

export-download.mddocs/

Export and Download

Export images and collections to various formats including GeoTIFF, Google Drive, Cloud Storage, and in-memory arrays with configurable parameters. Geedim provides both Earth Engine export tasks and direct download capabilities.

Capabilities

Export Types

Enumeration of available export destinations.

class ExportType(Enum):
    """Enumeration for export destinations."""
    
    drive = 'drive'
    """Export to Google Drive."""
    
    asset = 'asset'  
    """Export to Earth Engine asset."""
    
    cloud = 'cloud'
    """Export to Google Cloud Storage."""

Resampling Methods

Enumeration of resampling methods for reprojection and scaling.

class ResamplingMethod(Enum):
    """Enumeration for resampling methods."""
    
    near = 'near'
    """Nearest neighbor resampling."""
    
    bilinear = 'bilinear'
    """Bilinear interpolation."""
    
    bicubic = 'bicubic' 
    """Bicubic interpolation."""
    
    average = 'average'
    """Average resampling."""

File Format Drivers

Enumeration of supported output file formats.

class Driver(Enum):
    """Enumeration for image file formats."""
    
    gtiff = 'gtiff'
    """GeoTIFF format."""
    
    cog = 'cog'
    """Cloud Optimized GeoTIFF."""

Image Export

Export individual images with comprehensive parameter control.

def export(
    self,
    filename: str,
    type: ExportType = ExportType.drive,
    folder: str = None,
    wait: bool = True,
    **export_kwargs
) -> ee.batch.Task:
    """
    Export image to specified destination using a batch task.
    
    Parameters:
    - description (str): Task description and output filename
    - folder (str, optional): Destination folder name
    - region (dict | ee.Geometry, optional): Export region bounds
    - scale (float, optional): Export pixel scale in meters
    - crs (str, optional): Coordinate reference system (EPSG code)
    - export_type (ExportType): Export destination
    - driver (Driver): Output file format
    - dtype (str): Output data type ('auto', 'uint8', 'uint16', 'float32', etc.)
    - nodata (float, optional): NoData value
    - **kwargs: Additional export parameters
    
    Returns:
    ee.batch.Task: Earth Engine export task
    """

Collection Export

Export entire image collections with splitting options.

def export(
    self,
    description: str,
    folder: str = None,
    region: dict | ee.Geometry = None,
    scale: float = None,
    split: str = 'images',
    max_images: int = 5000,
    export_type: ExportType = ExportType.drive,
    **kwargs
) -> list[ee.batch.Task]:
    """
    Export image collection with splitting options.
    
    Parameters:
    - description (str): Base description for export tasks
    - folder (str, optional): Destination folder name
    - region (dict | ee.Geometry, optional): Export region bounds
    - scale (float, optional): Export pixel scale in meters
    - split (str): Split method ('images' or 'bands')
    - max_images (int): Maximum number of images to export
    - export_type (ExportType): Export destination
    - **kwargs: Additional export parameters
    
    Returns:
    list[ee.batch.Task]: List of export tasks
    """

Image Download

Download images directly to memory or local files.

def download(
    self,
    filename: str = None,
    region: dict | ee.Geometry = None,  
    scale: float = None,
    crs: str = None,
    dtype: str = 'auto',
    resampling: ResamplingMethod = ResamplingMethod.near,
    num_threads: int = None,
    **kwargs
):
    """
    Download image to memory or file.
    
    Parameters:
    - filename (str, optional): Output filename. If None, returns array/dataset
    - region (dict | ee.Geometry, optional): Download region bounds
    - scale (float, optional): Download pixel scale in meters
    - crs (str, optional): Coordinate reference system
    - dtype (str): Output data type
    - resampling (ResamplingMethod): Resampling method
    - num_threads (int, optional): Number of download threads
    - **kwargs: Additional download parameters
    
    Returns:
    numpy.ndarray | xarray.Dataset | None: Downloaded data or None if saved to file
    """

Collection Download

Download entire collections with parallel processing.

def download(
    self,
    folder: str = None,
    region: dict | ee.Geometry = None,
    scale: float = None,
    max_images: int = None,
    concurrent: int = 4,
    **kwargs
) -> list:
    """
    Download collection with parallel processing.
    
    Parameters:
    - folder (str, optional): Output folder path
    - region (dict | ee.Geometry, optional): Download region bounds
    - scale (float, optional): Download pixel scale in meters
    - max_images (int, optional): Maximum images to download
    - concurrent (int): Number of concurrent downloads
    - **kwargs: Additional download parameters
    
    Returns:
    list: List of downloaded arrays/datasets or filenames
    """

Usage Examples

Basic Image Export

import ee
import geedim

geedim.Initialize()

# Load and process image
image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_173083_20200601')
masked_image = image.gd.addMaskBands().maskClouds()

# Define region
region = ee.Geometry.Rectangle([-122.5, 37.7, -122.3, 37.8])

# Export to Google Drive
drive_task = masked_image.gd.export(
    description='landsat_export',
    folder='geedim_exports',
    region=region,
    scale=30,
    crs='EPSG:4326',
    export_type=geedim.ExportType.drive,
    driver=geedim.Driver.cog
)

# Start export task
drive_task.start()
print(f"Export task ID: {drive_task.id}")

Cloud Storage Export

# Export to Google Cloud Storage
cloud_task = masked_image.gd.export(
    description='landsat_cloud',
    folder='gs://my-bucket/geedim-exports',
    region=region,
    scale=30,
    export_type=geedim.ExportType.cloud,
    dtype='uint16',
    nodata=0
)

cloud_task.start()

Earth Engine Asset Export

# Export to Earth Engine Asset
asset_task = masked_image.gd.export(
    description='landsat_asset',
    folder='users/username/geedim_assets',
    region=region,
    scale=30,
    export_type=geedim.ExportType.asset
)

asset_task.start()

Direct Download

# Download to NumPy array
array = masked_image.gd.download(
    region=region,
    scale=30,
    dtype='float32',
    resampling=geedim.ResamplingMethod.bilinear
)

print(f"Downloaded array shape: {array.shape}")
print(f"Data type: {array.dtype}")

# Download to file
masked_image.gd.download(
    filename='landsat_download.tif',
    region=region,
    scale=30,
    dtype='uint16'
)

Xarray Integration

# Download as Xarray Dataset (requires xarray dependency)
try:
    dataset = masked_image.gd.download(
        region=region,
        scale=30,
        dtype='float32',
        format='xarray'  
    )
    
    print(f"Dataset dimensions: {dataset.dims}")
    print(f"Data variables: {list(dataset.data_vars)}")
    print(f"Coordinates: {list(dataset.coords)}")
    
    # Access bands
    red_band = dataset['B4']
    nir_band = dataset['B5']
    
    # Calculate NDVI
    ndvi = (nir_band - red_band) / (nir_band + red_band) 
    
except ImportError:
    print("Xarray not available, using NumPy array")
    array = masked_image.gd.download(region=region, scale=30)

Collection Export

# Load collection
collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2') \
    .filterDate('2020-06-01', '2020-09-30') \
    .filterBounds(region) \
    .limit(10)

# Export collection split by images
tasks = collection.gd.export(
    description='landsat_collection',
    folder='collection_export',
    region=region,
    scale=30,
    split='images',
    export_type=geedim.ExportType.drive
)

# Start all tasks
for i, task in enumerate(tasks):
    task.start()
    print(f"Started task {i+1}/{len(tasks)}: {task.id}")

# Export split by bands
band_tasks = collection.gd.export(
    description='landsat_bands',
    folder='band_export',
    region=region,
    scale=30,
    split='bands',
    max_images=5
)

Batch Download

# Download collection to folder
downloaded_files = collection.gd.download(
    folder='collection_downloads',
    region=region,
    scale=60,  # Lower resolution for faster download
    max_images=5,
    concurrent=2,  # Parallel downloads
    dtype='uint16'
)

print(f"Downloaded {len(downloaded_files)} files")

# Download to memory (be careful with memory usage)
arrays = collection.limit(3).gd.download(
    region=region,
    scale=120,  # Much lower resolution
    concurrent=3
)

for i, array in enumerate(arrays):
    print(f"Array {i+1} shape: {array.shape}")

Advanced Export Configuration

# Custom export with all parameters
advanced_task = masked_image.gd.export(
    description='advanced_export',
    folder='advanced_exports',
    region=region,
    scale=30,
    crs='EPSG:3857',  # Web Mercator
    export_type=geedim.ExportType.drive,
    driver=geedim.Driver.cog,
    dtype='float32',
    nodata=-9999,
    # Additional Earth Engine export parameters
    maxPixels=1e9,
    shardSize=256,
    fileDimensions=4096
)

advanced_task.start()

# Monitor task progress
import time

while advanced_task.active():
    print(f"Task status: {advanced_task.status()['state']}")
    time.sleep(30)

print(f"Final status: {advanced_task.status()}")

Tiled Downloads

# Download large regions using tiling
from geedim.tile import Tiler

# Create tiler for large region
large_region = ee.Geometry.Rectangle([-123, 37, -121, 39])

tiler = Tiler(
    region=large_region,
    scale=30,
    tile_size=512,  # 512x512 pixel tiles
    overlap=64      # 64 pixel overlap
)

# Download tiles in parallel
tile_arrays = []
for tile in tiler.tiles:
    tile_array = masked_image.gd.download(
        region=tile.region,
        scale=tile.scale,
        dtype='uint16'
    )
    tile_arrays.append(tile_array)

print(f"Downloaded {len(tile_arrays)} tiles")

Install with Tessl CLI

npx tessl i tessl/pypi-geedim

docs

cloud-masking.md

collection-operations.md

compositing.md

export-download.md

image-processing.md

index.md

initialization.md

tile.json