-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding new raster layers: water, population, forest gain #89
Merged
SofiaAldabet
merged 1 commit into
develop
from
feature/cloud_functions/GRASS-259-261-280
Dec 11, 2024
+133
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
cloud_functions/earth_engine_tiler/src/geeAssets/forest-gain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ContinuousDataset } from './earth-engine-dataset'; | ||
import ee from '@google/earthengine'; | ||
import { EarthEngineUtils } from "../earth-engine-utils"; | ||
|
||
export const ForestGain: ContinuousDataset = { | ||
assetPath: { | ||
default: "projects/glad/GLCLU2020/Forest_gain" | ||
}, | ||
|
||
vizParams: { | ||
bands: ['b1'], | ||
min: 0, | ||
max: 1, | ||
palette: ['#008000'] | ||
}, | ||
|
||
areYearsValid(startYear?: number, endYear?: number): boolean { | ||
// This Asset is static, and year selector is irrelevant | ||
return true; | ||
}, | ||
|
||
getEEAsset() { | ||
// Apply mask | ||
const rawImage = ee.Image(this.assetPath.default); | ||
const maskedImage = rawImage | ||
.select('b1') | ||
.updateMask(rawImage); // Mask out no-data pixels | ||
|
||
return maskedImage; | ||
}, | ||
|
||
async getMapUrl(z, x, y, startYear, endYear) { | ||
const image = this.getEEAsset() | ||
|
||
const mapId = await EarthEngineUtils.getMapId(image, this.vizParams); | ||
|
||
return ee.data.getTileUrl( mapId, x, y, z ); | ||
}, | ||
}; |
50 changes: 50 additions & 0 deletions
50
cloud_functions/earth_engine_tiler/src/geeAssets/population-count.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ContinuousDataset } from './earth-engine-dataset'; | ||
import ee from '@google/earthengine'; | ||
import { EarthEngineUtils } from "../earth-engine-utils"; | ||
|
||
export const PopulationCount: ContinuousDataset = { | ||
assetPath: { | ||
1975: "JRC/GHSL/P2023A/GHS_POP/1975", | ||
1990: "JRC/GHSL/P2023A/GHS_POP/1990", | ||
2020: "JRC/GHSL/P2023A/GHS_POP/2020" | ||
}, | ||
|
||
vizParams: { | ||
bands: ['population_count'], | ||
min: 0.0, | ||
max: 100.0, | ||
palette: ['000004', '320A5A', '781B6C', 'BB3654', 'EC6824', 'FBB41A', 'FCFFA4'] | ||
}, | ||
|
||
areYearsValid(startYear?: number, endYear?: number): boolean { | ||
const validYears = [1975, 1990, 2020]; | ||
if (!startYear || !validYears.includes(startYear)) { | ||
throw new Error(`Start Year '${startYear}' is not valid. Valid years are: ${validYears.join(", ")}`); | ||
} | ||
return true; | ||
}, | ||
|
||
getEEAsset(startYear: string) { // Change the parameter to string as per the type definition | ||
// Load the asset for the specified year | ||
const assetPath = this.assetPath[parseInt(startYear)]; // Convert the string to number if necessary | ||
if (!assetPath) { | ||
throw new Error(`Asset not found for year '${startYear}'`); | ||
} | ||
|
||
// Load the image and apply masking logic | ||
const rawImage = ee.Image(assetPath); | ||
return rawImage.updateMask(rawImage.gt(0)); // Mask out pixels with value 0 | ||
}, | ||
|
||
async getMapUrl(z: number, x: number, y: number, startYear: number, endYear?: number) { | ||
// Validate the year and get the asset | ||
this.areYearsValid(startYear, endYear); | ||
const image = this.getEEAsset(startYear); | ||
|
||
// Generate the mapId with visualization parameters | ||
const mapId = await EarthEngineUtils.getMapId(image, this.vizParams); | ||
|
||
// Return the Tile URL | ||
return ee.data.getTileUrl(mapId, x, y, z); | ||
}, | ||
}; |
34 changes: 34 additions & 0 deletions
34
cloud_functions/earth_engine_tiler/src/geeAssets/surface-water.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ContinuousDataset } from './earth-engine-dataset'; | ||
import ee from '@google/earthengine'; | ||
import {EarthEngineUtils} from "../earth-engine-utils"; | ||
|
||
|
||
export const SurfaceWater: ContinuousDataset = { | ||
assetPath: { | ||
default: "JRC/GSW1_4/GlobalSurfaceWater" | ||
}, | ||
|
||
vizParams: { | ||
bands: ['occurrence'], | ||
min: 0, | ||
max: 100, | ||
palette: ['ffffff', 'ffbbbb', '0000ff'] | ||
}, | ||
|
||
areYearsValid (startYear?: number, endYear?: number) : boolean { | ||
//This Asset is static, and year selector are irrelevant | ||
return true; | ||
}, | ||
|
||
getEEAsset() { | ||
return ee.Image(this.assetPath.default); | ||
}, | ||
|
||
async getMapUrl(z, x, y, startYear, endYear) { | ||
const image = this.getEEAsset() | ||
|
||
const mapId = await EarthEngineUtils.getMapId(image, this.vizParams); | ||
|
||
return ee.data.getTileUrl( mapId, x, y, z ); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check for this validation here, as it is done previously on the validation block of the main GET endpoint