statgis.gee.utils#

Some image operations

Module Contents#

Functions#

calculate_covered_area(→ ee.Image)

Calculate the total covered area by an image in a specific region and add it as an attribute.

calculate_band_number(→ ee.Image)

Calculate the number of bands for an image.

statgis.gee.utils.calculate_covered_area(image: ee.Image, region: Union[ee.geometry, ee.Feature], scale: float) ee.Image#

Calculate the total covered area by an image in a specific region and add it as an attribute.

Parameters:
  • image (ee.Image) – Image of interest.

  • region (ee.Geometry | ee.Feature) – Region of interest.

  • scale (float) – Image scale

Returns:

image – Image with covered area attribute

Return type:

ee.Image

Example

Calculate the covered area by an image in an region:

>>> import ee
>>> from statgis.gee import landsat_functions, utils
>>> ee.Initialize()
>>> roi = ee.Geometry.BBox(-74.2726232, 4.6486206, -74.2776232, 4.6536206)
>>> image = (
...     ee.ImageCollection("LANDSAT/LC09/C02/T1_L2")
...     .map(landsat_functions.scaler)
...     .map(landsat_functions.cloud_mask)
...     .map(landsat_functions.rename_bands)
...     .first()
... )
>>> image = utils.calculate_covered_area(image, roi, 30)

Whit a lambda function we can calculate the covered area by all image in a collection:

>>> import ee
>>> from statgis.gee import landsat_functions, utils
>>> ee.Initialize()
>>> roi = ee.Geometry.BBox(-74.2726232, 4.6486206, -74.2776232, 4.6536206)
>>> image_collection = (
...     ee.ImageCollection("LANDSAT/LC09/C02/T1_L2")
...     .map(landsat_functions.scaler)
...     .map(landsat_functions.cloud_mask)
...     .map(landsat_functions.rename_bands)
...     .map(lambda img: utils.calculate_covered_area(img, roi, 30))
... )
statgis.gee.utils.calculate_band_number(image: ee.Image) ee.Image#

Calculate the number of bands for an image. :param image: Image of interest. :type image: ee.Image

Returns:

image – Image with band number as an attribute.

Return type:

ee.Image

Example

Calculate the number of bands for an image:

>>> import ee
>>> from statgis.gee import landsat_functions, utils
>>> ee.Initialize()
>>> roi = ee.Geometry.BBox(-74.2726232, 4.6486206, -74.2776232, 4.6536206)
>>> image = (
...     ee.ImageCollection("LANDSAT/LC09/C02/T1_L2")
...     .map(landsat_functions.scaler)
...     .map(landsat_functions.cloud_mask)
...     .map(landsat_functions.rename_bands)
...     .first()
... )
>>> image = utils.calculate_band_number(image)

Calculate the number of bands for all images in a collection:

>>> import ee
>>> from statgis.gee import landsat_functions, utils
>>> ee.Initialize()
>>> roi = ee.Geometry.BBox(-74.2726232, 4.6486206, -74.2776232, 4.6536206)
>>> image_collection = (
...     ee.ImageCollection("LANDSAT/LC09/C02/T1_L2")
...     .map(landsat_functions.scaler)
...     .map(landsat_functions.cloud_mask)
...     .map(landsat_functions.rename_bands)
...     .map(utils.calculate_band_number)
... )