:py:mod:`statgis.gee.utils` =========================== .. py:module:: statgis.gee.utils .. autoapi-nested-parse:: Some image operations Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: statgis.gee.utils.calculate_covered_area statgis.gee.utils.calculate_band_number .. py:function:: 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. :param image: Image of interest. :type image: ee.Image :param region: Region of interest. :type region: ee.Geometry | ee.Feature :param scale: Image scale :type scale: float :returns: **image** -- Image with covered area attribute :rtype: ee.Image .. rubric:: 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)) ... ) .. py:function:: 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. :rtype: ee.Image .. rubric:: 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) ... )