Mapping water deprivations

What households in cambodia are deprived of clean water?

Households in Cambodia have three main sources of (drinking) water. Water from the pipe, water from the well and water from the tank. In this exercise we use survey information to estimate the likelihood of households to rely on one of the three sources.

step 1: copy the code below into the code editor. In this snippet we import a subset of the survey data and print the categories.

// import country data
var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017");
var kh = countries.filter(ee.Filter.eq("country_na", "Cambodia"));

// import the reference data
var referenceData = ee.FeatureCollection("projects/servir-mekong/undp/Training/WaterBinary")

// print binary classes

Step 2: import the relevant datasets and combine them into a single image

// import relevant raster datasets
var planet  = ee.Image("projects/cemis-camp/assets/Planet/202012").select(["b1","b2","b3","b4"],["red","green","blue","nir"]);
var roadDistPrimary = ee.Image("projects/servir-mekong/staticMaps/primaryRoads").rename("primaryRoads");
var roadDistSecondary = ee.Image("projects/servir-mekong/staticMaps/secondaryRoads").rename("secondaryRoads");
var roadDistTertiary = ee.Image("projects/servir-mekong/undp/distanceLayers/tertiaryRoads").rename("tertiaryRoads");
var streamDist = ee.Image("WWF/HydroSHEDS/15ACC").rename("stream").unmask(0);
var nightlight = ee.ImageCollection("NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG").filterDate("2020-01-01","2020-12-31").select("avg_rad").mean();
var waterLines = ee.Image("projects/servir-mekong/undp/distanceLayers/waterLinesDistance").rename("water");
var well = ee.Image("projects/servir-mekong/undp/distanceLayers/wellDistance").rename("well");
var waterDist = ee.Image("projects/servir-mekong/undp/distance/waterDist").rename("waterDist");
var waterLines = ee.Image("projects/servir-mekong/undp/distance/waterlineDistance").unmask(0).rename("waterlines");
var wp2020 = ee.Image("WorldPop/GP/100m/pop/KHM_2020").rename("wp");
var landcover = ee.Image("projects/cemis-camp/assets/landcover/lcv4/2020")

// combine raster data into a single image
var image = planet.addBands(roadDistPrimary )

Step 3: store the band names in a variable, we need them later for the random forest algorithm.

var bandNames = image.bandNames();

Step 4: create a dataset for household with a connection to a water pipe and people without.

// create the training dataset by filtering
var myClass = referenceData.filter(ee.Filter.eq("hh_d_water",0)).map(function(feat){return feat.set("class",1)}).limit(2200)
var otherClass = referenceData.filter(ee.Filter.eq("hh_d_water",1)).map(function(feat){return feat.set("class",0)}).limit(2200)


Step 6: combine the two datasets into a single dataset

// merge the two classes
var trainingData = myClass.merge(otherClass)

Step 7: sample the image, this will store all the pixel values for the points

// sample the image
var trainingSample = image.sampleRegions({collection:trainingData,scale:100});

Step 8: train the random forest classifier

// train the classifier in probability
var classifier = ee.Classifier.smileRandomForest(100).setOutputMode('PROBABILITY').train(trainingSample,"class",bandNames);

Step 9: get the variable importance and display it in a chart

// print the information of the classifier
var dict = classifier.explain();

// get the variable importance
var variable_importance = ee.Feature(null, ee.Dictionary(dict).get('importance'));
// get the variable importance
var variables = ee.Dictionary(ee.Dictionary(dict).get('importance'));
var keys = variables.keys();

// create a chart of the variable importance and show the chart
var chart =
  title: 'Random Forest Variable Importance',
  legend: {position: 'none'},
  hAxis: {title: 'Bands'},
  vAxis: {title: 'Importance'}

// print the chart

Step 10: classify the image and display the map

// classify the image
var classification = image.classify(classifier);
 // add the layer to the map
Map.addLayer(classification.clip(kh),{min:0,max:1,palette:"darkred,red,orange,yellow,green,darkgreen"},"edu Machine Learning");

Find all the code combined in a single script here.

Leave a Reply