// Example GEE Code - Abulug catchment // v1.0 November 2021 // richard.boothroyd@glasgow.ac.uk // Note: Landsat Collection 1 is now deprecated in Google Earth Engine. Please use the "GEE_Code_Abulug_Migrated.txt". // Goal: Export binary images of the active river channel over 2-year time periods (to calculate locational probabilities). No binary image cleaning is applied within GEE. // Note: This code can take a while to run (approx 30 mins), to reduce the run-time comment out some of the yearRanges. // Sets user-defined parameters: var folder = ('Locational_Probability_Example'); var river = ('Abulug'); var scale = 30; var mndwi_param = -0.4; var ndvi_param = 0.20; var buffer_1 = ee.FeatureCollection('users/rjboothroyd1/WP1_20_Largest_Trunk_Only_Buffered_Simplified/Abulug_3000m_Buffered_500m_Simplified'); var buffer_1 = buffer_1.geometry().transform('EPSG:4326', 10); var roi = buffer_1; Map.addLayer(roi, {color: 'FFFF00'}, 'ROI'); Map.centerObject(roi,12) var sites = [ [roi] ] var yearRanges = [ [1988, 1990], [1990, 1992], [1992, 1994], [1994, 1996], [1996, 1998], [1998, 2000], [2000, 2002], [2002, 2004], [2004, 2006], [2006, 2008], [2008, 2010], [2010, 2012], [2012, 2014], [2014, 2016], [2016, 2018], [2018, 2020] ] // Prepares Landsat dataset and multispectral functions // Standardise band names, merge Landsat data*/ var bn8 = ['B1', 'B2', 'B3', 'B4', 'B6', 'pixel_qa', 'B5', 'B7']; var bn7 = ['B1', 'B1', 'B2', 'B3', 'B5', 'pixel_qa', 'B4', 'B7']; var bn5 = ['B1', 'B1', 'B2', 'B3', 'B5', 'pixel_qa', 'B4', 'B7']; var bns = ['uBlue', 'Blue', 'Green', 'Red', 'Swir1', 'BQA', 'Nir', 'Swir2']; var ls5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_SR").select(bn5, bns); var ls7 = (ee.ImageCollection("LANDSAT/LE07/C01/T1_SR") .filterDate('1999-04-15', '2003-05-30') // exclude LE7 images that affected by failure of Scan Line Corrector (SLC) .select(bn7, bns)); var ls8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR").select(bn8, bns); var merged = ls5.merge(ls7).merge(ls8); // Functions for active river belt classification var Ndvi = function(image) { // calculate normalized difference vegetation index var ndvi = image.normalizedDifference(['Nir', 'Red']).rename('ndvi'); return(ndvi); }; var Mndwi = function(image) { // calculate modified normalized difference water index var mndwi = image.normalizedDifference(['Green', 'Swir1']).rename('mndwi'); return(mndwi); }; // Loop over years sites.forEach(function (site) { yearRanges.forEach(function (yearRange) { exportTimeseries(site, yearRange) }) }) function exportTimeseries(site, yearRange) { var sDate_T1 = ee.Date.fromYMD(yearRange[0], 1, 1); var eDate_T1 = ee.Date.fromYMD(yearRange[1], 1, 1); // Filter date range, roi and apply simple cloud processing var imgCol = merged.filterDate(sDate_T1, eDate_T1) .filterBounds(roi) .map(function(image) { var cloudShadowBitMask = 1 << 3; var cloudsBitMask = 1 << 5; var qa = image.select('BQA'); var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0) .and(qa.bitwiseAnd(cloudsBitMask).eq(0)); return image.updateMask(mask).resample('bicubic').multiply(0.0001).clip(roi).set('system:time_start',sDate_T1); }); // print(imgCol.limit(1)); // print(imgCol.size(),'T1: Number of tiles used'); // print(imgCol); // Apply approach to classify active channel: var mndwi_scaled = (imgCol.map(Mndwi).map(function(i) { return i.unitScale(-0.4, 1).clamp(0, 1) }).reduce(ee.Reducer.percentile([10]))) var mndwi_out = (mndwi_scaled.gt(0)); var ndvi_scaled = (imgCol.map(Ndvi).map(function(i) { return i.unitScale(-1, 0.2).clamp(0, 1) }).reduce(ee.Reducer.percentile([10]))) var ndvi_out = (ndvi_scaled.lt(1)); var active_map = (mndwi_out).and(ndvi_out).rename('active'); var size = imgCol.size().getInfo() var list = imgCol.toList(size) for (var n=0; n