|
|
# Code Documentation
|
|
|
|
|
|
## Overview
|
|
|
This code file is designed to interact with the Google Earth Engine (GEE) to process satellite imagery data. It includes functions to filter and manipulate image collections, mask clouds, and generate cloud coverage maps. The code is particularly focused on handling data from different satellite missions, such as LANDSAT and Sentinel.
|
|
|
|
|
|
## Dependencies
|
|
|
- Google Earth Engine (GEE)
|
|
|
- External utility functions from `../utils`
|
|
|
- Metadata handling from `../../common/metadata`
|
|
|
- Cloud scoring from `../imagery`
|
|
|
- LANDSAT-specific algorithms from `../../algorithms/satellite/landsat`
|
|
|
|
|
|
## Functions
|
|
|
|
|
|
### `addGridPosition(element)`
|
|
|
Adds grid position metadata to an image.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `element`: The image element to which the grid position will be added.
|
|
|
|
|
|
**Returns:**
|
|
|
- An image with the grid position metadata.
|
|
|
|
|
|
### `sliceByRevisit(collection, startingDate, days)`
|
|
|
Slices an image collection by a specified revisit period.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `collection`: The image collection to be sliced.
|
|
|
- `startingDate`: The starting date for the slice.
|
|
|
- `days`: The number of days for the revisit period.
|
|
|
|
|
|
**Returns:**
|
|
|
- A filtered image collection.
|
|
|
|
|
|
### `getImageDate(image)`
|
|
|
Extracts the date from an image ID.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `image`: The image from which the date will be extracted.
|
|
|
|
|
|
**Returns:**
|
|
|
- A JavaScript `Date` object representing the image date.
|
|
|
|
|
|
### `maskS2Clouds(img, geometry, bandName, scale, imgDateParam)`
|
|
|
Masks clouds in Sentinel-2 images based on cloud and cirrus bitmasks.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `img`: The image to be processed.
|
|
|
- `geometry`: The geometry for the region of interest.
|
|
|
- `bandName`: The name of the QA band.
|
|
|
- `scale`: The scale for the cloud masking.
|
|
|
- `imgDateParam`: Optional parameter for the image date.
|
|
|
|
|
|
**Returns:**
|
|
|
- The cloud coverage ratio.
|
|
|
|
|
|
### `acquireFromDate(date, mission, geometry)`
|
|
|
Acquires an image from a specified date and mission, and processes it for cloud coverage.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `date`: The date for which the image is to be acquired.
|
|
|
- `mission`: The satellite mission (e.g., LANDSAT, Sentinel).
|
|
|
- `geometry`: The geometry for the region of interest.
|
|
|
|
|
|
**Returns:**
|
|
|
- An image with cloud coverage metadata.
|
|
|
|
|
|
### `processCollection(mission, geometry)`
|
|
|
Processes an image collection to compute valid dates for image acquisition.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `mission`: The satellite mission.
|
|
|
- `geometry`: The geometry for the region of interest.
|
|
|
|
|
|
**Returns:**
|
|
|
- A list of valid dates.
|
|
|
|
|
|
### `generateCloudMap(dates, mission, geometry)`
|
|
|
Generates a cloud coverage map for a list of dates.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `dates`: A list of dates.
|
|
|
- `mission`: The satellite mission.
|
|
|
- `geometry`: The geometry for the region of interest.
|
|
|
|
|
|
**Returns:**
|
|
|
- A list of cloud coverage values.
|
|
|
|
|
|
### `queryAvailable(mission)`
|
|
|
Returns a function that queries available images for a given mission and geometry.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `mission`: The satellite mission.
|
|
|
|
|
|
**Returns:**
|
|
|
- A function that takes `geometry` as a parameter and returns a dictionary of dates and cloud coverage values.
|
|
|
|
|
|
### `getAvailable(mission)`
|
|
|
Returns a function that gets available images for a given mission and geometry.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `mission`: The satellite mission.
|
|
|
|
|
|
**Returns:**
|
|
|
- A function that takes `geometry` as a parameter and returns a dictionary of dates and cloud coverage values.
|
|
|
|
|
|
### `acquire(mission)`
|
|
|
Returns a function that acquires an image for a given mission, date, and geometry.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `mission`: The satellite mission.
|
|
|
|
|
|
**Returns:**
|
|
|
- A function that takes `date` and `geometry` as parameters and returns the acquired image.
|
|
|
|
|
|
### `format(properties)`
|
|
|
Formats image properties for display.
|
|
|
|
|
|
**Parameters:**
|
|
|
- `properties`: The properties of the image.
|
|
|
|
|
|
**Returns:**
|
|
|
- A formatted string of the image properties.
|
|
|
|
|
|
## Usage Examples
|
|
|
|
|
|
### Acquiring an Image
|
|
|
```javascript
|
|
|
const mission = { name: "LANDSAT" };
|
|
|
const date = "2022-01-01";
|
|
|
const geometry = ee.Geometry.Point([0, 0]);
|
|
|
|
|
|
const image = acquireFromDate(date, mission, geometry);
|
|
|
console.log(image.getInfo());
|
|
|
```
|
|
|
|
|
|
### Generating a Cloud Map
|
|
|
```javascript
|
|
|
const dates = ["2022-01-01", "2022-01-02"];
|
|
|
const mission = { name: "Sentinel-2" };
|
|
|
const geometry = ee.Geometry.Point([0, 0]);
|
|
|
|
|
|
const cloudMap = generateCloudMap(dates, mission, geometry);
|
|
|
console.log(cloudMap.getInfo());
|
|
|
```
|
|
|
|
|
|
## Edge Cases and Assumptions
|
|
|
- Assumes that the input data will always be in the correct format.
|
|
|
- Handles cases where the image ID is not available by logging an error.
|
|
|
- Assumes that the `CLOUDY_PIXEL_PERCENTAGE` property is present in the image metadata for cloud masking.
|
|
|
|
|
|
## References
|
|
|
- Google Earth Engine Documentation: [https://developers.google.com/earth-engine](https://developers.google.com/earth-engine)
|
|
|
- LANDSAT Algorithms: [../../algorithms/satellite/landsat](../../algorithms/satellite/landsat)
|
|
|
|