API¶
- class geedim.image.ImageAccessor(ee_image)¶
Bases:
objectAccessor for
ee.Image.- Parameters:
ee_image (ee.Image) – Image to access.
- property stac: dict[str, Any] | None¶
STAC dictionary.
Noneif there is no STAC entry for this image.
- property date: datetime | None¶
Acquisition date & time.
Noneif thesystem:time_startproperty is not present.
- property shape: tuple[int, int] | None¶
(height, width) dimensions of the minimum scale band in pixels.
Noneif the image has no fixed projection.
- property nodata: float | int | None¶
Masked pixel value used by Earth Engine when exporting.
For integer
dtype, this is the minimum possibledtypevalue, and for floating pointdtype, it isfloat('-inf').
- property profile: dict[str, Any] | None¶
Export image profile for Rasterio.
Noneif the image has no fixed projection.
- property geometry: dict | None¶
GeoJSON geometry of the image extent.
Noneif the image has no fixed projection.
- static monitorTask(task, label=None)¶
Monitor and display the progress of an export task.
- Parameters:
task (Task) – Earth Engine task to monitor (e.g. as returned by
toGoogleCloud()).label (str | None) – Optional label for progress display. Defaults to the task description.
- Return type:
None
- projection(min_scale=True)¶
Return the projection of the minimum / maximum scale band.
- Parameters:
min_scale (bool) – Whether to return the projection of the minimum (
True), or maximum (False) scale band.- Returns:
Projection.
- Return type:
Projection
- fixed()¶
Whether the image has a fixed projection.
- Return type:
Number
- resample(method)¶
Resample the image.
Extends
ee.Image.resample()by providing anaveragemethod for downsampling and returning images without fixed projections (e.g. composites) unaltered.Composites can be resampled by resampling their component images.
See https://developers.google.com/earth-engine/guides/resample for background information.
- Parameters:
method (ResamplingMethod | str) – Resampling method to use. With the
averagemethod, the image is reprojected to the minimum scale projection before resampling.- Returns:
Resampled image if the source has a fixed projection, otherwise the source image.
- Return type:
Image
- toDType(dtype)¶
Convert the image data dtype.
- Parameters:
dtype (str) – A NumPy / Rasterio data type to convert to.
- Returns:
Converted image.
- Return type:
Image
- scaleOffset()¶
Apply any STAC scales and offsets to the image (e.g. for converting digital numbers to physical units).
- Returns:
Scaled and offset image if STAC scales and offsets are available, otherwise the source image.
- Return type:
Image
- regionCoverage(region=None, scale=None, **kwargs)¶
Find the percentage of a region covered by each band of this image. The image is treated as a mask image e.g. as returned by
ee.Image.mask().- Parameters:
region (dict | Geometry) – Region over which to find coverage as a GeoJSON dictionary or
ee.Geometry. Defaults to the image geometry.scale (float | Number) – Scale at which to find coverage. Defaults to the minimum scale of the image bands.
kwargs – Optional keyword arguments for
ee.Image.reduceRegion(). Defaults tobestEffort=True.
- Returns:
Dictionary with band name keys, and band cover percentage values.
- Return type:
Dictionary
- addMaskBands(**kwargs)¶
Return this image with mask and related bands added.
Existing mask bands are overwritten except if this image has no fixed projection, in which case no bands are added or overwritten.
- Parameters:
mask_cirrus (bool) – Whether to mask cirrus clouds. Valid for Landsat 8-9 images, and for Sentinel-2 images with the
qamask_method. Defaults toTrue.mask_shadows (bool) – Whether to mask cloud shadows. Valid for Landsat images, and for Sentinel-2 images with the
qaorcloud_probmask_method. Defaults toTrue.mask_saturation (bool) – Whether to mask saturation. Valid for Landsat images. Defaults to
False.mask_nonphysical (bool) – Whether to mask reflectance outside the 0-1 reflectance range. Valid for Landsat surface reflectance images, and Sentinel-2 images. Defaults to
False.mask_aerosols (bool) – Whether to mask high aerosol levels. Valid for Landsat 8-9 surface reflectance images. Defaults to
False.mask_method (CloudMaskMethod) – Method used to mask clouds. Valid for Sentinel-2 images. Defaults to
cloud_score.prob (float) – Cloud probability threshold (%). Valid for Sentinel-2 images with the
cloud_probmask_method. Defaults to60.dark (float) – NIR threshold [0-1]. NIR values below this threshold are potential cloud shadows. Valid for Sentinel-2 images with the
qaorcloud_probmask_method. Defaults to0.15.shadow_dist (int) – Maximum distance (m) to look for cloud shadows from cloud edges. Valid for Sentinel-2 images with the
qaorcloud_probmask_method. Defaults to1000.buffer (int) – Distance (m) to dilate cloud. Valid for Sentinel-2 images with the
qaorcloud_probmask_method. Defaults to50.cdi_thresh (float) – Cloud Displacement Index threshold. Values below this threshold are considered potential clouds. If this parameter is
None(the default), the index is not used. Valid for Sentinel-2 images with theqaorcloud_probmask_method. See https://developers.google.com/earth-engine/apidocs/ee-algorithms-sentinel2-cdi for details.max_cloud_dist (int) – Maximum distance (m) to look for clouds when forming the cloud distance band. Valid for Landsat and Sentinel-2 images. Defaults to
5000.score (float) – Cloud Score+ threshold. Valid for Sentinel-2 images with the
cloud_scoremask_method. Defaults to0.6.cs_band (CloudScoreBand) – Cloud Score+ band to threshold. Valid for Sentinel-2 images with the
cloud_scoremask_method. Defaults tocs.
- Returns:
Image with added mask bands.
- Return type:
Image
- maskClouds()¶
Return this image with cloud mask applied when supported, otherwise return this image unaltered.
Mask bands should be added with
addMaskBands()before calling this method.- Returns:
Masked image.
- Return type:
Image
- prepareForExport(crs=None, crs_transform=None, shape=None, region=None, scale=None, resampling=near, dtype=None, scale_offset=False, bands=None)¶
Prepare the image for export.
Warning
Depending on the supplied arguments, the prepared image may be a reprojected and clipped version of the source. This type of image is not recommended for use in map display or further computation.
- Parameters:
crs (str | None) – CRS of the prepared image as a well-known authority (e.g. EPSG) or WKT string. Defaults to the CRS of the minimum scale band.
crs_transform (Sequence[float] | None) – Georeferencing transform of the prepared image, as a sequence of 6 numbers. In row-major order: [xScale, xShearing, xTranslation, yShearing, yScale, yTranslation].
shape (tuple[int, int] | None) – (height, width) dimensions of the prepared image in pixels.
region (dict[str, Any] | Geometry | None) – Region defining the prepared image bounds as a GeoJSON dictionary or
ee.Geometry. Defaults to the image geometry. Ignored ifcrs_transformis supplied.scale (float | None) – Pixel scale (m) of the prepared image. Defaults to the minimum scale of the image bands. Ignored if
crs_transformis supplied.resampling (str | ResamplingMethod) – Resampling method to use for reprojecting. Ignored for images without fixed projections e.g. composites. Composites can be resampled by resampling their component images.
dtype (str | None) – Data type of the prepared image (
uint8,int8,uint16,int16,uint32,int32,float32orfloat64). Defaults to the minimum size data type able to represent all image bands.scale_offset (bool) – Whether to apply any STAC band scales and offsets to the image (e.g. for converting digital numbers to physical units).
bands (list[str | int] | str | List) – Bands to include in the prepared image as a list of names / indexes, or a regex string. Defaults to all bands.
- Returns:
Prepared image.
- Return type:
Image
- toGoogleCloud(filename, type=drive, folder=None, wait=True, **kwargs)¶
Export the image to a raster file on Google Drive, Earth Engine asset, or raster file on Google Cloud Storage, using a batch task.
prepareForExport()can be called before this method to apply export parameters.- Parameters:
filename (str) – Destination file or asset name (excluding extension).
type (ExportType) – Export type.
folder (str | None) – Google Drive folder (when
typeisdrive), Earth Engine asset project (whentypeisasset), or Google Cloud Storage bucket (whentypeiscloud). Can include sub-folders, or an image collection name iftypeisasset. Iftypeisassetandfolderis not supplied,filenameshould be a valid Earth Engine asset ID. Required iftypeiscloud.wait (bool) – Whether to wait for the export to complete before returning.
kwargs – Additional arguments to the
typedependent Earth Engine function:Export.image.toDrive(),Export.image.toAsset()orExport.image.toCloudStorage().
- Returns:
Export task, started if
waitisFalse, or completed ifwaitisTrue.- Return type:
Task
- toGeoTIFF(file, overwrite=False, nodata=True, driver=gtiff, max_tile_size=4, max_tile_dim=10000, max_tile_bands=1024, max_requests=32, max_cpus=None)¶
Export the image to a GeoTIFF file.
Export projection and bounds are defined by
crs,transformandshape, and data type bydtype.prepareForExport()can be called before this method to apply export parameters.The image is retrieved as separate tiles which are downloaded and decompressed concurrently. Tile size can be controlled with
max_tile_size,max_tile_dimandmax_tile_bands, and download / decompress concurrency withmax_requestsandmax_cpus.GeoTIFF default namespace tags are written with
properties, and band tags withbandProps.- Parameters:
file (PathLike | str | OpenFile) – Destination file. Can be a path or URI string, or an
OpenFileobject in binary mode ('wb').overwrite (bool) – Whether to overwrite the destination file if it exists.
nodata (bool | int | float) – How to set the GeoTIFF nodata tag. If
True(the default), the nodata tag is set tonodata. Otherwise, ifFalse, the nodata tag is not set. A custom value can also be provided, in which case the nodata tag is set to this value. Usually, a custom value would be supplied when the image has been unmasked withee.Image.unmask(nodata).max_tile_size (float) – Maximum tile size (MB). Should be less than the Earth Engine size limit (32 MB).
max_tile_dim (int) – Maximum tile width / height (pixels). Should be less than the Earth Engine limit (10000).
max_tile_bands (int) – Maximum number of tile bands. Should be less than the Earth Engine limit (1024).
max_requests (int) – Maximum number of concurrent tile downloads. Should be less than the max concurrent requests quota.
max_cpus (int | None) – Maximum number of tiles to decompress concurrently. Defaults to one less than the number of CPUs, or one, whichever is greater. Values larger than the default can stall the asynchronous event loop and are not recommended.
- Return type:
None
- toNumPy(masked=False, structured=False, max_tile_size=4, max_tile_dim=10000, max_tile_bands=1024, max_requests=32, max_cpus=None)¶
Export the image to a NumPy array.
Export projection and bounds are defined by
crs,transformandshape, and data type bydtype.prepareForExport()can be called before this method to apply export parameters.The image is retrieved as separate tiles which are downloaded and decompressed concurrently. Tile size can be controlled with
max_tile_size,max_tile_dimandmax_tile_bands, and download / decompress concurrency withmax_requestsandmax_cpus.- Parameters:
masked (bool) – Return a
ndarraywith masked pixels set to thenodatavalue (False), or aMaskedArray(True).structured (bool) – Return a 3D array with (row, column, band) dimensions and a numerical
dtype(False), or a 2D array with (row, column) dimensions and a structureddtyperepresenting the image bands (True).max_tile_size (float) – Maximum tile size (MB). Should be less than the Earth Engine size limit (32 MB).
max_tile_dim (int) – Maximum tile width / height (pixels). Should be less than the Earth Engine limit (10000).
max_tile_bands (int) – Maximum number of tile bands. Should be less than the Earth Engine limit (1024).
max_requests (int) – Maximum number of concurrent tile downloads. Should be less than the max concurrent requests quota.
max_cpus (int | None) – Maximum number of tiles to decompress concurrently. Defaults to one less than the number of CPUs, or one, whichever is greater. Values larger than the default can stall the asynchronous event loop and are not recommended.
- Returns:
NumPy array.
- Return type:
- toXarray(masked=False, max_tile_size=4, max_tile_dim=10000, max_tile_bands=1024, max_requests=32, max_cpus=None)¶
Export the image to an Xarray DataArray.
Export projection and bounds are defined by
crs,transformandshape, and data type bydtype.prepareForExport()can be called before this method to apply export parameters.The image is retrieved as separate tiles which are downloaded and decompressed concurrently. Tile size can be controlled with
max_tile_size,max_tile_dimandmax_tile_bands, and download / decompress concurrency withmax_requestsandmax_cpus.DataArray attributes include
crs,transformandnodatavalues for compatibility with rioxarray, as well aseeandstacJSON strings of the Earth Engine property and STAC dictionaries.- Parameters:
masked (bool) – Set masked pixels in the returned array to the
nodatavalue (False), or to NaN (True). IfTrue, the imagedtypeis integer, and one or more pixels are masked, the returned array is converted to a minimal floating point type able to representdtype.max_tile_size (float) – Maximum tile size (MB). Should be less than the Earth Engine size limit (32 MB).
max_tile_dim (int) – Maximum tile width / height (pixels). Should be less than the Earth Engine limit (10000).
max_tile_bands (int) – Maximum number of tile bands. Should be less than the Earth Engine limit (1024).
max_requests (int) – Maximum number of concurrent tile downloads. Should be less than the max concurrent requests quota.
max_cpus (int | None) – Maximum number of tiles to decompress concurrently. Defaults to one less than the number of CPUs, or one, whichever is greater. Values larger than the default can stall the asynchronous event loop and are not recommended.
- Returns:
Image DataArray.
- Return type:
- class geedim.collection.ImageCollectionAccessor(ee_coll)¶
Bases:
objectAccessor for
ee.ImageCollection.- Parameters:
ee_coll (ee.ImageCollection) – Image collection to access.
- static fromImages(images)¶
Create an image collection with support for cloud masking, from the given images.
Images from spectrally compatible Landsat collections can be combined i.e. Landsat-4 with Landsat-5, and Landsat-8 with Landsat-9. Otherwise, images should belong to the same collection. Images may include composites created with
composite(), which are treated as belonging to the collection of their component images.Use this method (instead of
ee.ImageCollectionoree.ImageCollection.fromImages()) to support cloud masking on a collection built from a sequence of images.- Parameters:
images (Any) – Sequence of images, or anything that can be used to construct an image.
- Returns:
Image collection.
- Return type:
ImageCollection
- property info: dict[str, Any]¶
Earth Engine information as returned by
ee.ImageCollection.getInfo(), but limited to the first 5000 images.
- property stac: dict[str, Any] | None¶
STAC dictionary.
Noneif there is no STAC entry for this collection.
- property schema: dict[str, dict]¶
Dictionary of property abbreviations and descriptions used to form
schemaTableandpropertiesTable.
- property properties: dict[str, dict[str, Any]]¶
Dictionary of image properties. Keys are the image indexes and values the image property dictionaries.
- property propertiesTable: str¶
The
schemadefined subset ofproperties, abbreviated and formatted as a printable table string.
- addMaskBands(**kwargs)¶
Return this collection with mask and related bands added.
Existing mask bands are overwritten, except on images without fixed projections, where no mask bands are added or overwritten.
- Parameters:
kwargs – Cloud masking arguments - see
geedim.image.ImageAccessor.addMaskBands()for details.- Returns:
Image collection with added mask bands.
- Return type:
ImageCollection
- maskClouds()¶
Return this collection with cloud masks applied when supported, otherwise return this collection unaltered.
Mask bands should be added with
addMaskBands()before calling this method.- Returns:
Masked image collection.
- Return type:
ImageCollection
- medoid(bands=None)¶
Find the medoid composite of the collection images.
See https://www.mdpi.com/2072-4292/5/12/6481 for a description of the method.
- filter(start_date=None, end_date=None, region=None, fill_portion=None, cloudless_portion=None, custom_filter=None, **kwargs)¶
Filter the collection on date, region, filled / cloud-free portion, and custom criteria.
Filled and cloud-free portions are only included in returned image
propertieswhen one or both offill_portion/cloudless_portionare supplied. Iffill_portionorcloudless_portionare supplied,regionis required.Filter speeds can be improved by supplying multiple of the
start_date,end_date,regionandcustom_filterarguments.- Parameters:
start_date (str | datetime | Date) – Start date, in ISO format if a string.
end_date (str | datetime | Date) – End date, in ISO format if a string. Defaults to a millisecond after
start_dateifstart_dateis supplied. Ignored ifstart_dateis not supplied.region (dict | Geometry) – Region that images should intersect as a GeoJSON dictionary or
ee.Geometry.fill_portion (float | Number) – Lower limit on the filled (valid) portion of
region(%).cloudless_portion (float | Number) – Lower limit on the cloud-free portion of the filled portion of
region(%).custom_filter (str | None) – Custom image property filter expression e.g.
property > value. See the Earth Engine docs for details.kwargs – Cloud masking arguments used for
cloudless_portion- seegeedim.image.ImageAccessor.addMaskBands()for details.
- Returns:
Filtered image collection.
- Return type:
ImageCollection
- composite(method=None, mask=True, resampling=near, date=None, region=None, **kwargs)¶
Create a composite from the images in the collection.
- Parameters:
method (CompositeMethod | str) – Compositing method. By default,
q_mosaicis used for cloud mask supported collections, andmosaicotherwise.mask (bool) – Whether to cloud mask images before compositing. No effect if cloud masking is not supported.
resampling (ResamplingMethod | str) – Resampling method to use on images before compositing.
date (str | datetime | Date) – Sort component images by the absolute difference between their capture time and this date. If a string, it should be in ISO format. Images are sorted by their capture time if both
dateandregionareNone(the default).region (dict | Geometry) – Sort component images by their cloud-free portion inside this region when cloud masking is supported, otherwise sort by their filled (valid) portion. Can be a GeoJSON dictionary or
ee.Geometry. Images are sorted by their capture date if bothdateandregionareNone(the default).kwargs – Cloud/shadow masking arguments - see
geedim.image.ImageAccessor.addMaskBands()for details.
- Returns:
Composite image.
- Return type:
Image
- prepareForExport(crs=None, crs_transform=None, shape=None, region=None, scale=None, resampling=near, dtype=None, scale_offset=False, bands=None)¶
Prepare the collection for export.
Warning
The prepared collection images are reprojected and clipped versions of their source images. This type of image is not recommended for use in map display or further computation.
- Parameters:
crs (str | None) – CRS of the prepared images as a well-known authority (e.g. EPSG) or WKT string. Defaults to the CRS of the minimum scale band of the first image.
crs_transform (Sequence[float] | None) – Georeferencing transform of the prepared images, as a sequence of 6 numbers. In row-major order: [xScale, xShearing, xTranslation, yShearing, yScale, yTranslation].
shape (tuple[int, int] | None) – (height, width) dimensions of the prepared images in pixels.
region (dict[str, Any] | Geometry | None) – Region defining the prepared image bounds as a GeoJSON dictionary or
ee.Geometry. Defaults to the geometry of the first image. Ignored ifcrs_transformis supplied.scale (float | None) – Pixel scale (m) of the prepared images. Defaults to the minimum scale of the first image’s bands. Ignored if
crs_transformis supplied.resampling (str | ResamplingMethod) – Resampling method to use for reprojecting. Ignored for images without fixed projections e.g. composites. Composites can be resampled by resampling their component images.
dtype (str | None) – Data type of the prepared images (
uint8,int8,uint16,int16,uint32,int32,float32orfloat64). Defaults to the minimum size data type able to represent all the first image’s bands.scale_offset (bool | None) – Whether to apply any STAC band scales and offsets to the images (e.g. for converting digital numbers to physical units).
bands (list[str | int] | str | None) – Bands to include in the prepared images as a list of names / indexes, or a regex string. Defaults to all bands of the first image.
- Returns:
Prepared collection.
- Return type:
ImageCollection
- toGoogleCloud(type=drive, folder=None, wait=True, split=bands, **kwargs)¶
Export the collection to raster files on Google Drive, Earth Engine assets, or raster files on Google Cloud Storage, using batch tasks.
All bands in the collection should share the same projection, bounds and data type.
prepareForExport()can be called before this method to apply export parameters and create an export-ready collection.A maximum of 5000 images can be exported.
- Parameters:
type (ExportType) – Export type.
folder (str | None) – Google Drive folder (when
typeisdrive), Earth Engine asset project (whentypeisasset), or Google Cloud Storage bucket (whentypeiscloud). Can include sub-folders, or an image collection name iftypeisasset. Required iftypeisassetorcloud.wait (bool) – Whether to wait for the exports to complete before returning.
split (str | SplitType) – Export a file / asset for each collection band (
bands), or for each collection image (images). Files / assets are named with their band name, and band descriptions / names set to thesystem:indexproperty of the band’s source image, whensplitisbands. Otherwise, files / assets are named with thesystem:indexproperty of the source image, and band descriptions / names set to the image band names, whensplitisimages. Band names are prefixed with'B_'ifsplitisbandsandtypeisasset.kwargs – Additional arguments to the
typedependent Earth Engine function:Export.image.toDrive(),Export.image.toAsset()orExport.image.toCloudStorage().
- Returns:
List of image export tasks, started if
waitisFalse, or completed ifwaitisTrue.- Return type:
list[Task]
- toGeoTIFF(dirname, overwrite=False, split=bands, nodata=True, driver=gtiff, max_tile_size=4, max_tile_dim=10000, max_tile_bands=1024, max_requests=32, max_cpus=None)¶
Export the collection to GeoTIFF files.
Export projection and bounds are defined by the
crs,transformandshapeproperties, and the data type by thedtypeproperty of the collection images. All bands in the collection should share the same projection, bounds and data type.prepareForExport()can be called before this method to apply export parameters and create an export-ready collection.Images are retrieved as separate tiles which are downloaded and decompressed concurrently. Tile size can be controlled with
max_tile_size,max_tile_dimandmax_tile_bands, and download / decompress concurrency withmax_requestsandmax_cpus.When
splitisimages, GeoTIFF default namespace tags are written with theproperties, and band tags with thebandPropsattributes of their source images.A maximum of 5000 images can be exported.
- Parameters:
dirname (PathLike | str | OpenFile) – Destination directory. Can be a path or URI string, or an
OpenFileobject.overwrite (bool) – Whether to overwrite destination files if they exist.
split (str | SplitType) – Export a file for each collection band (
bands), or for each collection image (images). Files are named with their band name, and file band descriptions are set to thesystem:indexproperty of the band’s source image, whensplitisbands. Otherwise, files are named with thesystem:indexproperty of the file’s source image, and file band descriptions are set to the image band names, whensplitisimages.nodata (bool | int | float) – How to set the GeoTIFF nodata tags. If
True(the default), the nodata tags are set to thenodatavalue of the collection images. Otherwise, ifFalse, the nodata tags are not set. A custom value can also be provided, in which case the nodata tags are set to this value. Usually, a custom value would be supplied when the collection images have been unmasked withee.Image.unmask(nodata).max_tile_size (float) – Maximum tile size (MB). Should be less than the Earth Engine size limit (32 MB).
max_tile_dim (int) – Maximum tile width / height (pixels). Should be less than the Earth Engine limit (10000).
max_tile_bands (int) – Maximum number of tile bands. Should be less than the Earth Engine limit (1024).
max_requests (int) – Maximum number of concurrent tile downloads. Should be less than the max concurrent requests quota.
max_cpus (int | None) – Maximum number of tiles to decompress concurrently. Defaults to one less than the number of CPUs, or one, whichever is greater. Values larger than the default can stall the asynchronous event loop and are not recommended.
- Return type:
None
- toNumPy(masked=False, structured=False, split=bands, max_tile_size=4, max_tile_dim=10000, max_tile_bands=1024, max_requests=32, max_cpus=None)¶
Export the collection to a NumPy array.
Export projection and bounds are defined by the
crs,transformandshapeproperties, and the data type by thedtypeproperty of the collection images. All bands in the collection should share the same projection, bounds and data type.prepareForExport()can be called before this method to apply export parameters and create an export-ready collection.Images are retrieved as separate tiles which are downloaded and decompressed concurrently. Tile size can be controlled with
max_tile_size,max_tile_dimandmax_tile_bands, and download / decompress concurrency withmax_requestsandmax_cpus.A maximum of 5000 images can be exported.
- Parameters:
masked (bool) – Return a
ndarraywith masked pixels set to the sharednodatavalue of the collection images (False), or aMaskedArray(True).structured (bool) – Return a 4D array with a numerical
dtype(False), or a 2D array with a structureddtype(True). Array dimension ordering, and structureddtypefields depend on the value ofsplit.split (str | SplitType) – Return a 4D array with (row, column, band, image) dimensions (
bands), or a 4D array with (row, column, image, band) dimensions (images), whenstructuredisFalse. Otherwise, return a 2D array with (row, column) dimensions and a structureddtyperepresenting images nested in bands (bands), or a 2D array with (row, column) dimensions and a structureddtyperepresenting bands nested in images (images), whenstructuredisTrue.max_tile_size (float) – Maximum tile size (MB). Should be less than the Earth Engine size limit (32 MB).
max_tile_dim (int) – Maximum tile width / height (pixels). Should be less than the Earth Engine limit (10000).
max_tile_bands (int) – Maximum number of tile bands. Should be less than the Earth Engine limit (1024).
max_requests (int) – Maximum number of concurrent tile downloads. Should be less than the max concurrent requests quota.
max_cpus (int | None) – Maximum number of tiles to decompress concurrently. Defaults to one less than the number of CPUs, or one, whichever is greater. Values larger than the default can stall the asynchronous event loop and are not recommended.
- Returns:
NumPy array.
- Return type:
- toXarray(masked=False, split=bands, max_tile_size=4, max_tile_dim=10000, max_tile_bands=1024, max_requests=32, max_cpus=None)¶
Export the collection to an Xarray Dataset.
Export projection and bounds are defined by the
crs,transformandshapeproperties, and the data type by thedtypeproperty of the collection images. All bands in the collection should share the same projection, bounds and data type.prepareForExport()can be called before this method to apply export parameters and create an export-ready collection.Images are retrieved as separate tiles which are downloaded and decompressed concurrently. Tile size can be controlled with
max_tile_size,max_tile_dimandmax_tile_bands, and download / decompress concurrency withmax_requestsandmax_cpus.DataArray attributes include
crs,transformandnodatavalues for compatibility with rioxarray, as well aseeandstacJSON strings of the Earth Engine property and STAC dictionaries.A maximum of 5000 images can be exported.
- Parameters:
masked (bool) – Set masked pixels in the returned dataset to the shared
nodatavalue of the collection images (False), or to NaN (True). IfTrue, the export data type is integer, and one or more pixels are masked, the returned dataset is converted to a minimal floating point type able to represent the export data type.split (str | SplitType) – Return a dataset with bands as variables (
bands), or a dataset with images as variables (images). Variables are named with their band name, and time coordinates are converted from thesystem:start_timeproperty of the images whensplitisbands. Variables are named with thesystem:indexproperty of their image, and band coordinates are set to image band names whensplitisimages.max_tile_size (float) – Maximum tile size (MB). Should be less than the Earth Engine size limit (32 MB).
max_tile_dim (int) – Maximum tile width / height (pixels). Should be less than the Earth Engine limit (10000).
max_tile_bands (int) – Maximum number of tile bands. Should be less than the Earth Engine limit (1024).
max_requests (int) – Maximum number of concurrent tile downloads. Should be less than the max concurrent requests quota.
max_cpus (int | None) – Maximum number of tiles to decompress concurrently. Defaults to one less than the number of CPUs, or one, whichever is greater. Values larger than the default can stall the asynchronous event loop and are not recommended.
- Returns:
Xarray Dataset.
- Return type:
- class geedim.enums.CompositeMethod(*values)¶
Bases:
_StrChoiceEnumEnumeration for the compositing method i.e. the method for finding a composite pixel from the corresponding component image pixels.
- q_mosaic = 'q-mosaic'¶
Use the unmasked pixel with the highest cloud distance (distance to nearest cloud). When more than one pixel has the same cloud distance, the first one is used.
- mosaic = 'mosaic'¶
Use the first unmasked pixel.
- medoid = 'medoid'¶
Medoid of the unmasked pixels i.e. the pixel from the image with the minimum sum of spectral distances to the rest of the images. Where more than one pixel has the same summed distance, the first one is used. See https://www.mdpi.com/2072-4292/5/12/6481 for detail.
- median = 'median'¶
Median of the unmasked pixels.
- mode = 'mode'¶
Mode of the unmasked pixels.
- mean = 'mean'¶
Mean of the unmasked pixels.
- class geedim.enums.CloudMaskMethod(*values)¶
Bases:
_StrChoiceEnumEnumeration for the Sentinel-2 cloud masking method.
- cloud_prob = 'cloud-prob'¶
Threshold the Sentinel-2 Cloud Probability.
Deprecated since version 1.9.0: Please use the
cloud_scoremethod.
- qa = 'qa'¶
Bit mask the
QA60quality assessment band.Deprecated since version 1.9.0: Please use the
cloud_scoremethod.
- cloud_score = 'cloud-score'¶
Threshold the Sentinel-2 Cloud Score+.
- class geedim.enums.CloudScoreBand(*values)¶
Bases:
_StrChoiceEnumEnumeration for the Sentinel-2 Cloud Score+ band to use with the
cloud_scorecloud masking method.- cs = 'cs'¶
Pixel quality score based on spectral distance from a (theoretical) clear reference.
- cs_cdf = 'cs_cdf'¶
Value of the cumulative distribution function of possible
csvalues for the estimatedcsvalue.
- class geedim.enums.ResamplingMethod(*values)¶
Bases:
_StrChoiceEnumEnumeration for the resampling method.
- near = 'near'¶
Nearest neighbour.
- bilinear = 'bilinear'¶
Bilinear.
- bicubic = 'bicubic'¶
Bicubic.
- average = 'average'¶
Average.
- class geedim.enums.ExportType(*values)¶
Bases:
_StrChoiceEnumEnumeration for the export type.
- drive = 'drive'¶
Export to Google Drive.
- asset = 'asset'¶
Export to Earth Engine asset.
- cloud = 'cloud'¶
Export to Google Cloud Storage.
- class geedim.enums.SpectralDistanceMetric(*values)¶
Bases:
_StrChoiceEnumEnumeration for the spectral distance metric.
- sam = 'sam'¶
Spectral angle mapper.
- sid = 'sid'¶
Spectral information divergence.
- sed = 'sed'¶
Squared euclidean distance.
- emd = 'emd'¶
Earth movers distance.
- class geedim.enums.SplitType(*values)¶
Bases:
_StrChoiceEnumEnumeration for how an image collection is split when exporting.
- bands = 'bands'¶
Split collection by band.
- images = 'images'¶
Split collection by image.
- class geedim.enums.Driver(*values)¶
Bases:
_StrChoiceEnumEnumeration for the image file format.
- gtiff = 'gtiff'¶
GeoTIFF.
- cog = 'cog'¶
Cloud Optimised GeoTIFF.
- class geedim.mask.MaskedImage(ee_image, mask=False, region=None, **kwargs)¶
Bases:
BaseImageA class for encapsulating an Earth Engine image.
Mask and related bands are added to the supplied
ee_imagewhen it has a fixed projection.Deprecated since version 2.0.0: Please use the
ee.Image.gdaccessor instead.- Parameters:
ee_image (ee.Image) – Image to encapsulate.
mask (bool) – Whether to mask the image.
region (dict | ee.Geometry) – Region over which to find filled and cloud-free portions for the image, as a GeoJSON dictionary or
ee.Geometry. Portions are stored in the image properties. IfNone, portions are not found (the default).kwargs – Cloud masking parameters - see
addMaskBands()for details.
- property ee_image: Image¶
Encapsulated Earth Engine image.
- static from_id(image_id, **kwargs)¶
Create a MaskedImage instance from an Earth Engine image ID.
- Parameters:
image_id (str) – ID of the Earth Engine image to encapsulate.
kwargs – Keyword arguments to pass to
MaskedImage.
- Returns:
Image.
- Return type:
- download(filename, overwrite=False, num_threads=None, nodata=True, driver=gtiff, max_tile_size=4, max_tile_dim=10000, max_tile_bands=1024, max_requests=32, max_cpus=None, **export_kwargs)¶
Export the image to a GeoTIFF file.
The image is retrieved as separate tiles which are downloaded and decompressed concurrently. Tile size can be controlled with
max_tile_size,max_tile_dimandmax_tile_bands, and download / decompress concurrency withmax_requestsandmax_cpus.GeoTIFF default namespace tags are written with
properties, and band tags withband_properties.- Parameters:
filename (PathLike | str | OpenFile) – Destination file. Can be a path or URI string, or an
OpenFileobject in binary mode ('wb').overwrite (bool) – Whether to overwrite the destination file if it exists.
num_threads (int | None) – Deprecated and has no effect.
max_requestsandmax_cpuscan be used to limit concurrency.nodata (bool | int | float) – How to set the GeoTIFF nodata tag. If
True(the default), the nodata tag is set tonodata. Otherwise, ifFalse, the nodata tag is not set. A custom value can also be provided, in which case the nodata tag is set to this value. Usually, a custom value would be supplied when the image has been unmasked withee.Image.unmask(nodata).max_tile_size (float) – Maximum tile size (MB). Should be less than the Earth Engine size limit (32 MB).
max_tile_dim (int) – Maximum tile width / height (pixels). Should be less than the Earth Engine limit (10000).
max_tile_bands (int) – Maximum number of tile bands. Should be less than the Earth Engine limit (1024).
max_requests (int) – Maximum number of concurrent tile downloads. Should be less than the max concurrent requests quota.
max_cpus (int | None) – Maximum number of tiles to decompress concurrently. Defaults to one less than the number of CPUs, or one, whichever is greater. Values larger than the default can stall the asynchronous event loop and are not recommended.
export_kwargs – Arguments to
prepareForExport().
- Return type:
None
- export(filename, type=drive, folder=None, wait=True, **export_kwargs)¶
Export the image to a raster file on Google Drive, Earth Engine asset, or raster file on Google Cloud Storage, using a batch task.
- Parameters:
filename (str) – Destination file or asset name (excluding extension).
type (ExportType) – Export type.
folder (str | None) – Google Drive folder (when
typeisdrive), Earth Engine asset project (whentypeisasset), or Google Cloud Storage bucket (whentypeiscloud). Can include sub-folders, or an image collection name iftypeisasset. Iftypeisassetandfolderis not supplied,filenameshould be a valid Earth Engine asset ID. Required iftypeiscloud.wait (bool) – Whether to wait for the export to complete before returning.
export_kwargs – Arguments to
prepareForExport().
- Returns:
Export task, started if
waitisFalse, or completed ifwaitisTrue.- Return type:
Task
- property footprint: dict | None¶
GeoJSON geometry of the image extent.
Noneif the image has no fixed projection.
- mask_clouds()¶
Apply the cloud mask if supported, otherwise leave the image unaltered.
- static monitor_export(task, label=None)¶
Monitor and display the progress of an export task.
- class geedim.collection.MaskedCollection(ee_collection, add_props=None)¶
Bases:
ImageCollectionAccessorA class for encapsulating an Earth Engine image collection.
Deprecated since version 2.0.0: Please use the
ee.ImageCollection.gdaccessor instead.- Parameters:
ee_collection (ee.ImageCollection) – Image collection to encapsulate.
add_props (list[str] | None) – Additional image properties to include in
schemaandproperties.
- classmethod from_name(name, add_props=None)¶
Create a MaskedCollection from an Earth Engine image collection ID.
- Parameters:
name (str) – Image collection ID.
add_props (list[str] | None) – Additional image properties to include in
schemaandproperties.
- Returns:
Image collection.
- Return type:
- classmethod from_list(image_list, add_props=None)¶
Create a MaskedCollection with support for cloud masking, that contains the given images.
Images from spectrally compatible Landsat collections can be combined i.e. Landsat-4 with Landsat-5, and Landsat-8 with Landsat-9. Otherwise, images should all belong to the same collection. Images may include composites as created with
composite(). Composites are treated as belonging to the collection of their component images.Use this method (instead of
ee.ImageCollection()oree.ImageCollection.fromImages()) to support cloud masking on a collection built from a sequence of images.- Parameters:
- Returns:
Image collection.
- Return type:
- property ee_collection: ImageCollection¶
Encapsulated Earth Engine image collection.
- property image_type: type¶
MaskedImageclass for images inee_collection.
- property stats_scale: float | None¶
Scale to use for finding mask portions.
Noneif there is no STAC band information for this collection.
- property schema: dict[str, dict]¶
Dictionary of property abbreviations and descriptions used to form
schema_table,propertiesandproperties_table.
- property properties: dict[str, dict[str, Any]]¶
Dictionary of image properties. Keys are the image IDs and values the image property dictionaries.
- property properties_table: str¶
propertiesabbreviated withschemaand formatted as a printable table string.
- search(*args, **kwargs)¶
Filter the collection on date, region, filled / cloud-free portion, and custom criteria.
Filled and cloud-free portions are only included in returned image
propertieswhen one or both offill_portion/cloudless_portionare supplied. Iffill_portionorcloudless_portionare supplied,regionis required.Filter speeds can be improved by supplying multiple of the
start_date,end_date,regionandcustom_filterarguments.- Parameters:
start_date – Start date, in ISO format if a string.
end_date – End date, in ISO format if a string. Defaults to a millisecond after
start_dateifstart_dateis supplied. Ignored ifstart_dateis not supplied.region – Region that images should intersect as a GeoJSON dictionary or
ee.Geometry.fill_portion – Lower limit on the filled (valid) portion of
region(%).cloudless_portion – Lower limit on the cloud-free portion of the filled portion of
region(%).custom_filter – Custom image property filter expression e.g.
property > value. See the Earth Engine docs for details.kwargs – Cloud masking arguments used for
cloudless_portion- seegeedim.image.ImageAccessor.addMaskBands()for details.
- Returns:
Filtered image collection.
- Return type:
- composite(*args, **kwargs)¶
Create a composite from the images in the collection.
- Parameters:
method – Compositing method. By default,
q_mosaicis used for cloud mask supported collections, andmosaicotherwise.mask – Whether to cloud mask images before compositing. No effect if cloud masking is not supported.
resampling – Resampling method to use on images before compositing.
date – Sort component images by the absolute difference between their capture time and this date. If a string, it should be in ISO format. Images are sorted by their capture time if both
dateandregionareNone(the default).region – Sort component images by their cloud-free portion inside this region when cloud masking is supported, otherwise sort by their filled (valid) portion. Can be a GeoJSON dictionary or
ee.Geometry. Images are sorted by their capture date if bothdateandregionareNone(the default).kwargs – Cloud/shadow masking arguments - see
geedim.image.ImageAccessor.addMaskBands()for details.
- Returns:
Composite image.
- Return type: