Last active
June 14, 2019 15:40
-
-
Save clubgisdotnet/6b130164058094cea086ed1c65fbd062 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var pt = ee.Geometry.Point(90.9186, 24.6823); | |
| // Load Sentinel-1 C-band SAR Ground Range collection (log scaling, VV co-polar) | |
| var collection = ee.ImageCollection('COPERNICUS/S1_GRD').filterBounds(pt) | |
| .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV')) | |
| .select('VV'); | |
| // Add dropdown for year | |
| var year = ['2018', '2017', '2016']; | |
| // Add dropdown for date | |
| var range = { | |
| 'January' : ['01-01', '01-31'], | |
| 'Februray': ['02-01', '02-28'], | |
| 'March' : ['03-01', '03-31'], | |
| 'April' : ['04-01', '04-30'], | |
| 'May' : ['05-01', '05-31'], | |
| 'June' : ['06-01', '06-30'], | |
| 'July' : ['07-01', '07-31'], | |
| 'August' : ['08-01', '08-31'], | |
| 'September' : ['09-01', '09-30'], | |
| 'October' : ['10-01', '10-31'] | |
| }; | |
| var selectYear = ui.Select({ | |
| items: year, | |
| value: year[0], | |
| style:{padding: '0px 0px 0px 10px', stretch: 'horizontal'} | |
| }); | |
| var selectMonths1 = ui.Select({ | |
| items: Object.keys(range).slice(0,5), | |
| value: Object.keys(range)[0], | |
| style: {stretch: 'horizontal'} | |
| }); | |
| var selectMonths2 = ui.Select({ | |
| items: Object.keys(range).slice(5,10), | |
| value: Object.keys(range)[5], | |
| style:{padding: '0px 10px 0px 0px', stretch: 'horizontal'} | |
| }); | |
| // Display map | |
| Map.centerObject(pt, 9); | |
| // Add button to run | |
| var runButton = ui.Button({ | |
| label: 'Calculate extent', | |
| onClick: function(){ | |
| // Threshold smoothed radar intensities to identify "flooded" areas. | |
| var SMOOTHING_RADIUS = 100; | |
| var DIFF_UPPER_THRESHOLD = -3; | |
| var before = collection.filterDate( | |
| selectYear.getValue() + "-" + range[selectMonths1.getValue()][0], | |
| selectYear.getValue() + "-" + range[selectMonths1.getValue()][1]) | |
| .mosaic(); | |
| var after = collection.filterDate( | |
| selectYear.getValue() + "-" + range[selectMonths2.getValue()][0], | |
| selectYear.getValue() + "-" + range[selectMonths2.getValue()][1]) | |
| .mosaic(); | |
| var diff_smoothed = after.focal_median(SMOOTHING_RADIUS, 'circle', 'meters') | |
| .subtract(before.focal_median(SMOOTHING_RADIUS, 'circle', 'meters')); | |
| var diff_thresholded = diff_smoothed.lt(DIFF_UPPER_THRESHOLD); | |
| Map.addLayer(diff_thresholded.updateMask(diff_thresholded), | |
| // create random color layers | |
| {palette: Math.floor(Math.random()*65280).toString(16)}, | |
| selectMonths1.getValue() | |
| + "-" + selectMonths2.getValue() | |
| + ", " + selectYear.getValue(), | |
| 1); | |
| }, | |
| style: {padding: '0px 10px', stretch: 'horizontal'} | |
| }); | |
| // Create a panel | |
| var panel = ui.Panel({ | |
| layout: ui.Panel.Layout.flow('vertical'), | |
| style: {width: '400px'} | |
| }); | |
| // Add the title | |
| var mapTitle = ui.Label('Flood status of Bangladesh'); | |
| mapTitle.style().set('color', 'blue'); | |
| mapTitle.style().set('fontWeight', 'bold'); | |
| mapTitle.style().set({ | |
| fontSize: '20px', | |
| padding: '10px' | |
| }); | |
| // Add description | |
| var mapDesc = ui.Label('The status of flood in Northeast Bangladesh as seen in Sentinel-1 satellite image. The SAR images are capable to see through cloud and measure the extent of surface water, where optical satellite (ie Landsat 8) can not.'); | |
| mapDesc.style().set({ | |
| fontSize: '16px', | |
| padding: '0px 10px' | |
| }); | |
| // Style cursor to crosshair | |
| Map.style().set('cursor', 'crosshair'); | |
| panel.add(mapTitle); | |
| panel.add(mapDesc); | |
| panel.add(ui.Panel([selectYear, selectMonths1, selectMonths2], | |
| ui.Panel.Layout.flow('horizontal'))); | |
| panel.add(runButton); | |
| ui.root.insert(0, panel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment