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

image-processing.mddocs/

Image Processing

Process individual Earth Engine images with cloud masking, export, and download capabilities. The image processing functionality is accessed through the .gd accessor on ee.Image objects, providing automatic cloud and shadow detection for Landsat 4-9 and Sentinel-2 imagery.

Capabilities

Image Accessor

The main accessor class for Earth Engine images, registered as .gd on ee.Image objects.

class ImageAccessor:
    def __init__(self, ee_image: ee.Image): ...

Add Mask Bands

Add cloud mask and related bands to an image. Mask bands are automatically determined based on the image collection type (Landsat or Sentinel-2).

def addMaskBands(self, **kwargs) -> ee.Image:
    """
    Add mask and related bands to the image.
    
    Parameters:
    - **kwargs: Cloud masking parameters specific to the image collection
      - For Sentinel-2: method (CloudMaskMethod), prob (float), cloud_dist (float)
      - For Landsat: mask_cirrus (bool), mask_shadows (bool)
    
    Returns:
    ee.Image: Image with mask bands added
    """

Mask Clouds

Apply cloud masking to an image using the mask bands added by addMaskBands().

def maskClouds(self) -> ee.Image:
    """
    Apply cloud mask to the image.
    
    Returns:
    ee.Image: Cloud-masked image
    """

Export Image

Export an image to various destinations including Google Drive, Google Cloud Storage, or Earth Engine Assets.

def export(
    self,
    filename: str,
    type: ExportType = ExportType.drive,
    folder: str = None,
    wait: bool = True,
    **export_kwargs
) -> ee.batch.Task:
    """
    Export the image to the specified destination using a batch task.
    
    Parameters:
    - filename (str): Destination file or asset name (excluding extension)
    - type (ExportType): Export destination type
    - folder (str, optional): Destination folder name
    - wait (bool): Whether to wait for export completion before returning
    - **export_kwargs: Additional export parameters for prepareForExport
    
    Returns:
    ee.batch.Task: Earth Engine export task
    """

Download Image

Download an image to local memory as NumPy arrays, Xarray datasets, or save to local files.

def download(
    self,
    region: dict | ee.Geometry = None,
    scale: float = None,
    crs: str = None,
    dtype: str = 'auto',
    resampling: ResamplingMethod = ResamplingMethod.near,
    **kwargs
):
    """
    Download the image to local memory or file.
    
    Parameters:
    - region (dict | ee.Geometry, optional): Download region
    - scale (float, optional): Download scale in meters
    - crs (str, optional): Coordinate reference system
    - dtype (str): Output data type ('auto', 'uint8', 'uint16', 'float32', etc.)
    - resampling (ResamplingMethod): Resampling method for reprojection
    - **kwargs: Additional download parameters
    
    Returns:
    numpy.ndarray | xarray.Dataset: Downloaded image data
    """

Region Coverage

Calculate coverage statistics for an image over a specified region.

def regionCoverage(
    self,
    region: dict | ee.Geometry = None,
    scale: float | ee.Number = None,
    maxPixels: int = 1e6,
    bestEffort: bool = True
) -> dict:
    """
    Calculate region coverage statistics.
    
    Parameters:
    - region (dict | ee.Geometry, optional): Region of interest
    - scale (float | ee.Number, optional): Analysis scale in meters  
    - maxPixels (int): Maximum pixels to analyze
    - bestEffort (bool): Use best effort for large regions
    
    Returns:
    dict: Coverage statistics by band
    """

GeoTIFF Export

Export an image directly to a GeoTIFF file with configurable options.

def toGeoTIFF(
    self,
    file: os.PathLike | str | OpenFile,
    overwrite: bool = False,
    nodata: bool | int | float = True,
    driver: str | Driver = Driver.gtiff,
    **kwargs
) -> None:
    """
    Download and save the image as a GeoTIFF file.
    
    Parameters:
    - file (os.PathLike | str | OpenFile): Output file path
    - overwrite (bool): Whether to overwrite existing files
    - nodata (bool | int | float): Nodata value handling
    - driver (str | Driver): Output file format driver
    - **kwargs: Additional parameters for prepareForExport
    
    Returns:
    None
    """

Prepare for Export

Prepare an image for export by setting projection, resampling, and other parameters.

def prepareForExport(
    self,
    crs: str = None,
    crs_transform: Sequence[float] = None, 
    shape: tuple[int, int] = None,
    region: dict | ee.Geometry = None,
    scale: float = None,
    dtype: str = 'auto',
    resampling: ResamplingMethod | str = ResamplingMethod.near,
    **kwargs
) -> ee.Image:
    """
    Prepare image for export with specified projection and parameters.
    
    Parameters:
    - crs (str, optional): Target coordinate reference system
    - crs_transform (Sequence[float], optional): Affine transform coefficients
    - shape (tuple[int, int], optional): Output image dimensions (height, width)
    - region (dict | ee.Geometry, optional): Clipping region
    - scale (float, optional): Output pixel size in CRS units
    - dtype (str): Output data type ('auto', 'uint8', 'uint16', 'float32', etc.)
    - resampling (ResamplingMethod | str): Resampling method
    - **kwargs: Additional parameters
    
    Returns:
    ee.Image: Prepared image ready for export
    """

Projection

Get the projection of the minimum scale band.

def projection(self, min_scale: bool = True) -> ee.Projection:
    """
    Get the projection of the minimum or first scale band.
    
    Parameters:
    - min_scale (bool): Whether to use minimum scale band (True) or first band (False)
    
    Returns:
    ee.Projection: Image projection
    """

Fixed Projection Check

Check if the image has a fixed projection.

def fixed(self) -> ee.Number:
    """
    Check if the image has a fixed projection.
    
    Returns:
    ee.Number: 1 if fixed projection, 0 otherwise
    """

Resample

Resample the image using the specified method.

def resample(self, method: ResamplingMethod | str) -> ee.Image:
    """
    Resample the image using the specified resampling method.
    
    Parameters:
    - method (ResamplingMethod | str): Resampling method
    
    Returns:
    ee.Image: Resampled image
    """

Convert Data Type

Convert image to the specified data type.

def toDType(self, dtype: str) -> ee.Image:
    """
    Convert the image to the specified data type.
    
    Parameters:
    - dtype (str): Target data type ('uint8', 'uint16', 'int16', 'float32', etc.)
    
    Returns:
    ee.Image: Image with converted data type
    """

Scale and Offset Correction

Apply scale and offset corrections based on STAC metadata.

def scaleOffset(self) -> ee.Image:
    """
    Apply scale and offset corrections from STAC metadata.
    
    Returns:
    ee.Image: Scale and offset corrected image
    """

Usage Examples

Basic Image Processing

import ee
import geedim

geedim.Initialize()

# Load and process a Landsat image
image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_173083_20160101')

# Add mask bands and apply cloud masking
masked_image = image.gd.addMaskBands(mask_cirrus=True, mask_shadows=True).maskClouds()

# Define region of interest
region = ee.Geometry.Point(-122.4194, 37.7749).buffer(10000)

# Export to Google Drive
task = masked_image.gd.export(
    filename='landsat_processed',
    folder='geedim_exports',
    region=region,
    scale=30,
    type=geedim.ExportType.drive
)
task.start()

Sentinel-2 Processing

# Load Sentinel-2 image
s2_image = ee.Image('COPERNICUS/S2_SR_HARMONIZED/20200101T185751_20200101T185931_T10SEG')

# Add mask bands with cloud score method
masked_s2 = s2_image.gd.addMaskBands(
    method=geedim.CloudMaskMethod.cloud_score,
    prob=0.6,
    cloud_dist=1000
).maskClouds()

# Download to NumPy array
region = ee.Geometry.Rectangle([-122.5, 37.7, -122.3, 37.8])
array = masked_s2.gd.download(
    region=region,
    scale=10,
    dtype='uint16'
)

Image Information and Properties

# Get image information
info = image.gd.info

# Check if image has fixed projection
is_fixed = image.gd.fixed()

# Get region coverage statistics
coverage = image.gd.regionCoverage(
    region=region,
    scale=30,
    maxPixels=1e6
)

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