 https://www.geospatialecology.com

# Environmental Monitoring and Modelling

## Objective

Managing water resources requires spatially explicit knowledge of where water is located in landscapes, and how it varies over time. The objective of this lab is to map the presence of surface water from space, and calculate the inundation frequency of different water bodies.

### Acknowledgments

• USAID, SERVER Mekong, NASA, Winrock International, adpc

## Mapping water from space

We will make use of the Landsat 8 TOA Tier 1 collection for this exercise (LANDSAT/LC08/C01/T1_TOA).

```var L8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');
```
• Define a region of interest using the geometry rectangle tool. Rename it (roi). We will use the vicinity of Menindee Lakes for this example, located between Broken Hill and Ivanhoe in NSW, Australia.
• Next we will set the desired date range that we are interested in. Landsat 8 is available from April 2013 to present
```// Set the desired the start and end dates
var startdate = ee.Date('2013-05-01');
var enddate = ee.Date('2019-09-30');

// Select  Landsat  8  images  within  the  specified  time  and spatial range
var l8images = L8.filterDate(startdate, enddate)
.filterBounds(roi);
```

• This next piece of code shows an alternative way of dealing with clouds by masking
```//Makes  a  function  to  mask  the  clouds
var cloudThresh = 20;
var cloudFunction = function(image){
var scored = ee.Algorithms.Landsat.simpleCloudScore(image);
var quality = scored.select('cloud');
var cloudy = quality.gt(cloudThresh);
};
```
• Now we can write a function to map the mask over the collection
```//  Map  the  function  over  the  Landsat  8  collection.

//Display  the  median  of  the  image  collection  for  the ROI
Map.centerObject(roi, 8);
min: 0,
max: 0.5,
bands: ['B5', 'B4', 'B3']
}, 'Landsat 8 False colour median');
```

## The Normalised Difference Water Index (NDWI)

• The following lines of code create a function to calculate NDWI - the Normalised Difference Water Index. We need the NIR and green bands for this as NDWI = (G - NIR)/(G + NIR).
• The second part of the code uses the function to calculate NDWI for each image in the collection that intersects our roi and date range.
• The third part of the code maps NDWI spatially to show the maximum spatial extent of water over our date range.
```// Creating the function to calculate the NDWI
var ndwi = img.normalizedDifference(['B3', 'B5']).rename('NDWI');
}

// Add NDWI to the collection
var l8ndwi = L8
.filterBounds(roi)
.filterDate(startdate, enddate)
.map(cloudFunction)
.select(['B3', 'B5'])

// Map NDWI spatially
{bands: 'NDWI', min: 0, max:1, palette: ['darkblue']}, 'NDWI L8');
```
• If we are interested in a particular year we can map it like this, using 2018 as an example.
```// Choose a year and make NDWI map
var year = 2018;
var ndwiViz = {bands:'NDWI',min:0,max:1,palette:['darkblue']};
var ndwiYEAR = l8ndwi.filterDate({
start: ee.Date.fromYMD(year, 1, 1),
end: ee.Date.fromYMD(year, 12, 31)
}).max();
```
• Lastly, we can compute the frequency of inundation. This involves a bit of maths as shown below.
```//Computing frequency of inundation
var waterBinary = l8ndwi.select('NDWI').map(function(image) {
return image.gt(0);
});
var frequency = waterBinary.sum().divide(waterBinary.count());