SHARE
TWEET

Untitled

a guest Jan 21st, 2020 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  2. // Extract Satellite Records Thom Brade 2019_12_13
  3. // > For the drone areas - in this case converted to raster for the purpose of uploading and managing
  4. // > Aim is monthly averages (climatologies) for all instruments and for all bands for each drone survey area
  5. // https://developers.google.com/earth-engine/sentinel1
  6. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  7.  
  8. // ######################################################################################################################################################
  9. // Load in drone raster (coded by id)
  10. // ######################################################################################################################################################
  11.  
  12. Map.setCenter(34.67, -18.97, 12);
  13.  
  14. // ######################################################################################################################################################
  15. // Date variables
  16. // https://developers.google.com/earth-engine/sentinel1
  17. // ######################################################################################################################################################
  18.  
  19. var s1Start = ee.Date("2014-01-01"); var s1End = ee.Date("2019-10-31");
  20.  
  21. // ######################################################################################################################################################
  22. // Sentinel 1 2014-present
  23. // ######################################################################################################################################################
  24.  
  25. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  26. // BAND RATIO FUNCTION
  27. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  28.  
  29. var addBandRatio = function(image){
  30.  
  31.   var ratio_dB = image.addBands(image.select('VV').divide(image.select('VH')).rename('Ratio_dB'));
  32.   var ratio_natural = image.addBands(image.select('VV_natural').divide(image.select('VH_natural')).rename('Ratio_natural'));
  33.  
  34.   return image.addBands(ratio_dB.addBands(ratio_natural));
  35.  
  36. };
  37.  
  38.  
  39. var addNaturalUnits = function(image){
  40.  
  41.   var natural_VV = ((image.select('VV').lt(0).multiply(10)).pow(image.select('VV').divide(10))).rename('VV_natural');
  42.   var natural_VH = ((image.select('VH').lt(0).multiply(10)).pow(image.select('VH').divide(10))).rename('VH_natural');
  43.  
  44.   return(image.addBands(natural_VV).addBands(natural_VH));
  45. };
  46.  
  47. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  48. // MAKE COLLECTION
  49. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  50.  
  51. var s1coll = ee.ImageCollection("COPERNICUS/S1_GRD")
  52.   .filterBounds(sa)
  53.   .filterDate(s1Start,s1End)
  54.   .filter(ee.Filter.eq('instrumentMode', 'IW'))
  55.    // Filter to get images with VV and VH dual polarization.
  56.   .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
  57.   .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
  58.  
  59. //print(addNaturalUnits(s1coll.first()))
  60. s1coll = s1coll.map(addNaturalUnits);
  61. s1coll = s1coll.map(addBandRatio);
  62.  
  63. print(s1coll.first());
  64.  
  65. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  66. // map a function that adds a band for day of year and year
  67.  
  68. var addDates = function(image){
  69.   var doy = image.date().getRelative('day', 'year');
  70.   var doyBand = ee.Image.constant(doy).uint16().rename('doy');
  71.   var mon = image.date().get('month');
  72.   var monBand = ee.Image.constant(mon).uint16().rename('month');
  73.   var year = image.date().get('year');
  74.   var yearBand = ee.Image.constant(year).uint16().rename('year');
  75.  return image.addBands(doyBand).addBands(monBand).addBands(yearBand);
  76. };
  77.  
  78. s1coll = s1coll.map(addDates);
  79. print(s1coll,10);
  80.  
  81. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  82. // Period of interest?
  83.  
  84. // var series1 = ui.Chart.image.doySeriesByYear(
  85. //     s1coll,'Ratio' ,sa, ee.Reducer.median(), 500);
  86. // print(series1);
  87.  
  88. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  89. // GET STATISTICS
  90. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  91.  
  92. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  93. // Combine reducers for single pass (can add as many as needed here)
  94. var reducer = ee.Reducer.percentile([50,70,90])
  95.   .combine({reducer2: ee.Reducer.stdDev(), sharedInputs: true});
  96.  
  97. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  98. // Function to iterate reduceRegions on collection
  99. var statsfun = function(image,list){
  100.   var newimg = image.reduceRegions({
  101.     collection: zones,
  102.     reducer: reducer,
  103.     scale: 30
  104.   });
  105.   return ee.List(list).add(newimg);
  106. };
  107.  
  108. var list = ee.List([]);
  109.  
  110. var stats = ee.List(s1coll.iterate(statsfun,list));
  111.  
  112. var statsOut = ee.FeatureCollection(stats).flatten();
  113.  
  114.  
  115. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  116. // Export the processed  FeatureCollection.
  117. // ------------------------------------------------------------------------------------------------------------------------------------------------------
  118.  
  119. Export.table.toDrive({
  120.   collection: statsOut,
  121.   description: 's1result',
  122.   fileFormat: 'CSV'
  123. });
  124.  
  125.  
  126. Map.addLayer(s1coll.select('Ratio_natural').median(), {min:0,max:5}, 'Ratio')
  127.  
  128. Map.addLayer(s1coll.select('Ratio_natural').median().gt(5), {palette:['yellow','red']}, 'Damage')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top