|
|
```markdown
|
|
|
# Earth Engine Utilities
|
|
|
|
|
|
This code file provides a set of utilities for working with Google Earth Engine (GEE) to process satellite imagery. It includes functions for cloud masking, date slicing, and metadata management.
|
|
|
|
|
|
## Dependencies
|
|
|
- `ee` from `../../services/earth-engine`
|
|
|
- Utility functions from `../utils`
|
|
|
- Cloud scoring from `../imagery`
|
|
|
- Metadata constants from `../../common/metadata`
|
|
|
|
|
|
## Functions
|
|
|
|
|
|
### addGridPosition
|
|
|
Adds a grid position to an image based on its WRS path and row.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `element` (Object): The image element to which the grid position will be added.
|
|
|
|
|
|
**Returns:**
|
|
|
- `ee.Image`: The image with the added grid position.
|
|
|
|
|
|
### sliceByRevisit
|
|
|
Slices an image collection by a given revisit period starting from a specific date.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `collection` (ee.ImageCollection): The image collection to slice.
|
|
|
- `startingDate` (String): The starting date for the slice.
|
|
|
- `days` (Number): The number of days for the revisit period.
|
|
|
|
|
|
**Returns:**
|
|
|
- `ee.ImageCollection`: The sliced image collection.
|
|
|
|
|
|
### maskTOAClouds
|
|
|
Masks clouds in an image based on the Top of Atmosphere (TOA) reflectance.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `image` (ee.Image): The image to mask.
|
|
|
- `bandName` (String): The name of the band to use for cloud masking.
|
|
|
|
|
|
**Returns:**
|
|
|
- `ee.Image`: The cloud-masked image.
|
|
|
|
|
|
### acquireFromDate
|
|
|
Acquires an image from a specific date, mission, and geometry, and calculates the cloud ratio.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `date` (String): The date to acquire the image.
|
|
|
- `mission` (Object): The mission details including name, cycle, and bands.
|
|
|
- `geometry` (ee.Geometry): The geometry to clip the image to.
|
|
|
|
|
|
**Returns:**
|
|
|
- `ee.Image`: The processed image with cloud ratio metadata.
|
|
|
|
|
|
### processCollection
|
|
|
Processes an image collection to compute valid dates for image acquisition.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `mission` (Object): The mission details including name and cycle.
|
|
|
- `geometry` (ee.Geometry): The geometry to filter the image collection.
|
|
|
|
|
|
**Returns:**
|
|
|
- `ee.List`: A list of valid dates for image acquisition.
|
|
|
|
|
|
### generateCloudMap
|
|
|
Generates a cloud map for a list of dates, mission, and geometry.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `dates` (ee.List): The list of dates to generate the cloud map for.
|
|
|
- `mission` (Object): The mission details including name and bands.
|
|
|
- `geometry` (ee.Geometry): The geometry to clip the images to.
|
|
|
|
|
|
**Returns:**
|
|
|
- `ee.List`: A list of cloud ratios for each date.
|
|
|
|
|
|
### queryAvailable
|
|
|
Queries available images for a given mission and geometry.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `mission` (Object): The mission details including name and cycle.
|
|
|
- `geometry` (ee.Geometry): The geometry to filter the image collection.
|
|
|
|
|
|
**Returns:**
|
|
|
- `ee.Dictionary`: A dictionary mapping dates to cloud ratios.
|
|
|
|
|
|
### getAvailable
|
|
|
Placeholder function for getting available images.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `mission` (Object): The mission details.
|
|
|
- `geometry` (ee.Geometry): The geometry to filter the image collection.
|
|
|
|
|
|
### acquire
|
|
|
Acquires an image for a given date, mission, and geometry.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `mission` (Object): The mission details.
|
|
|
- `date` (String): The date to acquire the image.
|
|
|
- `geometry` (ee.Geometry): The geometry to clip the image to.
|
|
|
|
|
|
**Returns:**
|
|
|
- `ee.Image`: The acquired image.
|
|
|
|
|
|
### format
|
|
|
Formats properties into a string.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `properties` (Object): The properties to format.
|
|
|
|
|
|
**Returns:**
|
|
|
- `String`: The formatted string.
|
|
|
|
|
|
## Usage Example
|
|
|
|
|
|
```javascript
|
|
|
import EarthEngineUtils from './path/to/earth-engine-utils';
|
|
|
|
|
|
const mission = {
|
|
|
name: 'LANDSAT/LC08/C01/T1_TOA',
|
|
|
cycle: 16,
|
|
|
bands: {
|
|
|
qa: 'BQA'
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const geometry = ee.Geometry.Point([102.0, 17.0]);
|
|
|
|
|
|
// Query available images
|
|
|
const availableImages = EarthEngineUtils.queryAvailable(mission)(geometry);
|
|
|
|
|
|
// Acquire an image for a specific date
|
|
|
const date = '2021-01-01';
|
|
|
const image = EarthEngineUtils.acquire(mission)(date, geometry);
|
|
|
|
|
|
// Format properties
|
|
|
const properties = { 'system:time_start': '2021-01-01', 'cloud': 0.1 };
|
|
|
const formatted = EarthEngineUtils.format(properties);
|
|
|
console.log(formatted);
|
|
|
```
|
|
|
|
|
|
## Edge Cases and Assumptions
|
|
|
- Assumes that input data will be in the correct format.
|
|
|
- Handles cases where no valid images are found by returning `null`.
|
|
|
- Based on Google Earth Engine's API and its specific methods and data structures.
|
|
|
```
|
|
|
|