Code Overview
This code file provides several utility functions for working with satellite imagery using the Google Earth Engine (GEE) API. The primary functionalities include scoring cloud ratios, generating layers, creating thumbnails, and calculating cumulative windows for histograms.
Dependencies
- Google Earth Engine (GEE) API
- Custom classes and utilities from local modules
Functions
scoreCloudRatio
Calculates the cloud ratio in a given region based on a masked image.
Parameters
-
masked
(ee.Image): The masked image with cloud presence indicated by pixel values. -
bandName
(string): The name of the band to be analyzed. -
geometry
(ee.Geometry): The region of interest. -
scale
(number, default=30): The scale for the reduction. -
maxPixels
(number, default=1e12): The maximum number of pixels to include in the reduction.
Returns
-
ee.Number
: The cloud ratio in the specified region.
Example
const cloudRatio = scoreCloudRatio(maskedImage, 'cloudBand', regionGeometry);
scoreClouds
Scores clouds in an image based on a quality assessment (QA) band.
Parameters
-
image
(ee.Image): The input image. -
geometry
(ee.Geometry): The region of interest. -
qa
(string): The QA band to be used for cloud scoring.
Returns
-
ee.Image
: The input image with an added property "CLOUDS" indicating the cloud ratio.
Example
const cloudScoredImage = scoreClouds(inputImage, regionGeometry, 'QA60');
generateLayer
Generates a visualization layer from an image.
Parameters
-
image
(ee.Image): The input image. -
mission
(string): The mission name (e.g., 'Landsat', 'Sentinel'). -
name
(string): The name of the layer. -
params
(object): Visualization parameters.
Returns
-
Layer
: A new Layer object.
Example
const layer = generateLayer(inputImage, 'Landsat', 'LayerName', visualizationParams);
createThumbnail
Creates a thumbnail URL for an image.
Parameters
-
image
(ee.Image): The input image. -
geometry
(ee.Geometry): The region of interest. -
params
(object): Thumbnail parameters. -
callback
(function): Callback function to handle the thumbnail URL.
Returns
-
string
: The thumbnail URL.
Example
const thumbnailUrl = createThumbnail(inputImage, regionGeometry, thumbnailParams, callback);
createThumbnailCSqueeze
Creates a thumbnail URL for an image with specific scaling factors applied.
Parameters
-
image
(ee.Image): The input image. -
geometry
(ee.Geometry): The region of interest. -
params
(object): Thumbnail parameters. -
callback
(function): Callback function to handle the thumbnail URL.
Returns
-
string
: The thumbnail URL.
Example
const thumbnailUrl = createThumbnailCSqueeze(inputImage, regionGeometry, thumbnailParams, callback);
cumulativeWindow
Calculates the cumulative window of a histogram by removing a specified percentile of pixels from each side.
Parameters
-
fullHistogram
(ee.Dictionary): The full histogram dictionary. -
percentile
(number | ee.Number): The percentile to be removed from each side.
Returns
-
ee.List
: The cumulative window bounds (min/max).
Example
const windowBounds = cumulativeWindow(histogramDict, 0.05);
Edge Cases and Assumptions
- Assumes that input data is in the correct format and within expected ranges.
- Handles large datasets by setting appropriate
maxPixels
values. - Specific scaling factors are applied for Landsat Collection 2 images.
References
- Google Earth Engine API: https://developers.google.com/earth-engine