Skip to content

Commit

Permalink
add code for creating the total sum layer for livestock
Browse files Browse the repository at this point in the history
  • Loading branch information
SofiaAldabet authored and KevSanchez committed Dec 2, 2024
1 parent 8941a81 commit e57ceda
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ export const GriddedLivestockCommonStyles =
'<ColorMapEntry color="#883886" quantity="5000" label="≤ 5,000" />' +
'<ColorMapEntry color="#390147" quantity="300000" label="> 5,000" />' +
'</ColorMap>' +
'</RasterSymbolizer>'

export const GriddedLivestockTotalStyle =

'<RasterSymbolizer>' +
'<ColorMap type="ramp" extended="false">' +
'<ColorMapEntry color="#ffffff" quantity="0" label="0" />' +
'<ColorMapEntry color="#b2ebf2" quantity="500" label="≤ 500" />' +
'<ColorMapEntry color="#80deea" quantity="1000" label="≤ 1,000" />' +
'<ColorMapEntry color="#68b0c3" quantity="5000" label="≤ 5,000" />' +
'<ColorMapEntry color="#3f8b9c" quantity="10000" label="≤ 10,000" />' +
'<ColorMapEntry color="#c766fc" quantity="50000" label="≤ 50,000" />' +
'<ColorMapEntry color="#883886" quantity="100000" label="≤ 100,000" />' +
'<ColorMapEntry color="#390147" quantity="10000000" label="> 100,000" />' +
'</ColorMap>' +
'</RasterSymbolizer>'
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { CategoricalDataset } from './earth-engine-dataset';
import ee from '@google/earthengine';
import { EarthEngineUtils } from "../earth-engine-utils";
import { GriddedLivestockBuffalo } from './gridded-livestock-buffalo';
import { GriddedLivestockCattle } from './gridded-livestock-cattle';
import { GriddedLivestockChicken } from './gridded-livestock-chicken';
import { GriddedLivestockDuck } from './gridded-livestock-duck';
import { GriddedLivestockGoat } from './gridded-livestock-goat';
import { GriddedLivestockHorse } from './gridded-livestock-horse';
import { GriddedLivestockPig } from './gridded-livestock-pig';
import { GriddedLivestockSheep } from './gridded-livestock-sheep';
import { GriddedLivestockTotalStyle } from "./common-styles-utils";

export const GriddedLivestockTotal: CategoricalDataset = {
assetPath: {
},
bandName: 'b1',
sldStyles: GriddedLivestockTotalStyle,

areYearsValid(startYear?: number, endYear?: number): boolean {
// This Asset is static, and year selector is irrelevant
return true;
},

// Unmask(0) gives 0 to no data pixels so that they can be included in the sum
getEEAsset() {
const buffaloImage = ee.Image(GriddedLivestockBuffalo.assetPath.default).select(GriddedLivestockBuffalo.bandName).unmask(0);
const cattleImage = ee.Image(GriddedLivestockCattle.assetPath.default).select(GriddedLivestockCattle.bandName).unmask(0);
const chickenImage = ee.Image(GriddedLivestockChicken.assetPath.default).select(GriddedLivestockChicken.bandName).unmask(0);
const duckImage = ee.Image(GriddedLivestockDuck.assetPath.default).select(GriddedLivestockDuck.bandName).unmask(0);
const goatImage = ee.Image(GriddedLivestockGoat.assetPath.default).select(GriddedLivestockGoat.bandName).unmask(0);
const horseImage = ee.Image(GriddedLivestockHorse.assetPath.default).select(GriddedLivestockHorse.bandName).unmask(0);
const pigImage = ee.Image(GriddedLivestockPig.assetPath.default).select(GriddedLivestockPig.bandName).unmask(0);
const sheepImage = ee.Image(GriddedLivestockSheep.assetPath.default).select(GriddedLivestockSheep.bandName).unmask(0);

// Sum all the images
const totalImage = buffaloImage
.add(cattleImage)
.add(chickenImage)
.add(duckImage)
.add(goatImage)
.add(horseImage)
.add(pigImage)
.add(sheepImage);

return totalImage;
},

async getMapUrl(z, x, y) {
const image = this.getEEAsset().sldStyle(this.sldStyles);
const mapId = await EarthEngineUtils.getMapId(image);
return ee.data.getTileUrl(mapId, x, y, z);
},
};
2 changes: 2 additions & 0 deletions cloud_functions/earth_engine_tiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {ModisNetPrimaryProductionChange} from './geeAssets/modis-net-primary-pro
import {AnthropogenicBiomes} from './geeAssets/anthropogenic-biomes';
import {LivestockProductionSystems} from './geeAssets/livestock-production-systems';
import {ForestLoss} from './geeAssets/forest-loss';
import {GriddedLivestockTotal} from './geeAssets/gridded-livestock-total';
import {GriddedLivestockBuffalo} from './geeAssets/gridded-livestock-buffalo';
import {GriddedLivestockCattle} from './geeAssets/gridded-livestock-cattle';
import {GriddedLivestockChicken} from './geeAssets/gridded-livestock-chicken';
Expand All @@ -29,6 +30,7 @@ const assets: Record<Tilesets, EarthEngineDataset> = {
[Tilesets.anthropogenic_biomes]: AnthropogenicBiomes,
[Tilesets.livestock_production_systems]: LivestockProductionSystems,
[Tilesets.forest_loss]: ForestLoss,
[Tilesets.gridded_livestock_total]: GriddedLivestockTotal,
[Tilesets.gridded_livestock_buffalo]: GriddedLivestockBuffalo,
[Tilesets.gridded_livestock_cattle]: GriddedLivestockCattle,
[Tilesets.gridded_livestock_chicken]: GriddedLivestockChicken,
Expand Down
1 change: 1 addition & 0 deletions cloud_functions/earth_engine_tiler/src/tile-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum Tilesets {
anthropogenic_biomes = "anthropogenic_biomes",
livestock_production_systems = "livestock_production_systems",
forest_loss = "forest_loss",
gridded_livestock_total = "gridded_livestock_total",
gridded_livestock_buffalo = "gridded_livestock_buffalo",
gridded_livestock_cattle = "gridded_livestock_cattle",
gridded_livestock_chicken = "gridded_livestock_chicken",
Expand Down

0 comments on commit e57ceda

Please sign in to comment.