Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // Extract Satellite Records Thom Brade 2019_12_13
- // > For the drone areas - in this case converted to raster for the purpose of uploading and managing
- // > Aim is monthly averages (climatologies) for all instruments and for all bands for each drone survey area
- // https://developers.google.com/earth-engine/sentinel1
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // ######################################################################################################################################################
- // Load in drone raster (coded by id)
- // ######################################################################################################################################################
- Map.setCenter(34.67, -18.97, 12);
- // ######################################################################################################################################################
- // Date variables
- // https://developers.google.com/earth-engine/sentinel1
- // ######################################################################################################################################################
- var s1Start = ee.Date("2014-01-01"); var s1End = ee.Date("2019-10-31");
- // ######################################################################################################################################################
- // Sentinel 1 2014-present
- // ######################################################################################################################################################
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // BAND RATIO FUNCTION
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- var addBandRatio = function(image){
- var ratio_dB = image.addBands(image.select('VV').divide(image.select('VH')).rename('Ratio_dB'));
- var ratio_natural = image.addBands(image.select('VV_natural').divide(image.select('VH_natural')).rename('Ratio_natural'));
- return image.addBands(ratio_dB.addBands(ratio_natural));
- };
- var addNaturalUnits = function(image){
- var natural_VV = ((image.select('VV').lt(0).multiply(10)).pow(image.select('VV').divide(10))).rename('VV_natural');
- var natural_VH = ((image.select('VH').lt(0).multiply(10)).pow(image.select('VH').divide(10))).rename('VH_natural');
- return(image.addBands(natural_VV).addBands(natural_VH));
- };
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // MAKE COLLECTION
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- var s1coll = ee.ImageCollection("COPERNICUS/S1_GRD")
- .filterBounds(sa)
- .filterDate(s1Start,s1End)
- .filter(ee.Filter.eq('instrumentMode', 'IW'))
- // Filter to get images with VV and VH dual polarization.
- .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
- .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
- //print(addNaturalUnits(s1coll.first()))
- s1coll = s1coll.map(addNaturalUnits);
- s1coll = s1coll.map(addBandRatio);
- print(s1coll.first());
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // map a function that adds a band for day of year and year
- var addDates = function(image){
- var doy = image.date().getRelative('day', 'year');
- var doyBand = ee.Image.constant(doy).uint16().rename('doy');
- var mon = image.date().get('month');
- var monBand = ee.Image.constant(mon).uint16().rename('month');
- var year = image.date().get('year');
- var yearBand = ee.Image.constant(year).uint16().rename('year');
- return image.addBands(doyBand).addBands(monBand).addBands(yearBand);
- };
- s1coll = s1coll.map(addDates);
- print(s1coll,10);
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // Period of interest?
- // var series1 = ui.Chart.image.doySeriesByYear(
- // s1coll,'Ratio' ,sa, ee.Reducer.median(), 500);
- // print(series1);
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // GET STATISTICS
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // Combine reducers for single pass (can add as many as needed here)
- var reducer = ee.Reducer.percentile([50,70,90])
- .combine({reducer2: ee.Reducer.stdDev(), sharedInputs: true});
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // Function to iterate reduceRegions on collection
- var statsfun = function(image,list){
- var newimg = image.reduceRegions({
- collection: zones,
- reducer: reducer,
- scale: 30
- });
- return ee.List(list).add(newimg);
- };
- var list = ee.List([]);
- var stats = ee.List(s1coll.iterate(statsfun,list));
- var statsOut = ee.FeatureCollection(stats).flatten();
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- // Export the processed FeatureCollection.
- // ------------------------------------------------------------------------------------------------------------------------------------------------------
- Export.table.toDrive({
- collection: statsOut,
- description: 's1result',
- fileFormat: 'CSV'
- });
- Map.addLayer(s1coll.select('Ratio_natural').median(), {min:0,max:5}, 'Ratio')
- Map.addLayer(s1coll.select('Ratio_natural').median().gt(5), {palette:['yellow','red']}, 'Damage')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement