68942

Google Earth Engine: mask clouds and map a function over an image collection of different sensors

Question:

I want to combine all the Landsat sensors from 1985 up today in Google Earth Engine, remove the clouds and calculate the time-series of the NBR index. As a new GEE user I have the following:

// find all data and filter them by date var lst5 = ee.ImageCollection('LANDSAT/LT5_SR').filterDate('1984-10-01', '2011-10-01'); var lst7 = ee.ImageCollection('LANDSAT/LE7_SR').filterDate('2011-10-01', '2013-04-07'); var lst8 = ee.ImageCollection('LANDSAT/LC8_SR').filterDate('2013-04-07', '2018-05-01'); var lst7_08 = ee.ImageCollection('LANDSAT/LE7_SR').filterDate('2007-12-01', '2008-02-01'); var lst7_92 = ee.ImageCollection('LANDSAT/LT4_SR').filterDate('1992-01-02', '1992-04-01'); // Combine all landsat data, 1985 through 2015 var everything = ee.ImageCollection(lst5.merge(lst7)); everything = everything.merge(lst8); everything = everything.merge(lst7_08); everything = everything.merge(lst7_92); var alltogether = ee.ImageCollection(everything.filterDate('1984-01-01', '2018-05-01'));

From this point, I do not know how to remove the clouds and calculate the NBR index (<a href="http://wiki.landscapetoolbox.org/doku.php/remote_sensing_methods:normalized_burn_ratio" rel="nofollow">NBR index here)</a> for every image in my final collection.

Can anyone help me?

Thank you.

<strong>EDIT:</strong>

I think that I need to map a normalizedDifference function over my collection in order to get the NBR index but I am not sure how to do this for my collection with the different sensors.

Answer1:

You've got quite a lot going on here, but here's what I think you want. You should check this very carefully to ensure it's behaving as intended:

// Function to cloud mask Landsat 8. var maskL8SR = function(image) { // Bits 3 and 5 are cloud shadow and cloud, respectively. var cloudShadowBitMask = ee.Number(2).pow(3).int(); var cloudsBitMask = ee.Number(2).pow(5).int(); // Get the QA band. var qa = image.select('pixel_qa'); // Both flags should be set to zero, indicating clear conditions. var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).and( qa.bitwiseAnd(cloudsBitMask).eq(0)); return image // Scale the data to reflectance and temperature. .select(['B5', 'B7'], ['NIR', 'SWIR']).multiply(0.0001) .addBands(image.select(['B11'], ['Thermal']).multiply(0.1)) .updateMask(mask); }; // Function to cloud mask Landsats 5-7 var maskL57SR = function(image) { var qa = image.select('pixel_qa'); // Second bit must be zero, meaning none to low cloud confidence. var mask1 = qa.bitwiseAnd(ee.Number(2).pow(7).int()).eq(0).and( qa.bitwiseAnd(ee.Number(2).pow(3).int()).lte(0)); // cloud shadow // This gets rid of irritating fixed-pattern noise at the edge of the images. var mask2 = image.select('B.*').gt(0).reduce('min'); return image .select(['B4', 'B7'], ['NIR', 'SWIR']).multiply(0.0001) .addBands(image.select(['B6'], ['Thermal']).multiply(0.1)) .updateMask(mask1.and(mask2)); }; // find all data and filter them by date var lst5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR') .filterDate('1984-10-01', '2011-10-01') .map(maskL57SR) var lst7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR') .filterDate('2011-10-01', '2013-04-07') .map(maskL57SR) var lst8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') .filterDate('2013-04-07', '2018-05-01') .map(maskL8SR) var lst7_08 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR') .filterDate('2007-12-01', '2008-02-01') .map(maskL57SR) var lst7_92 = ee.ImageCollection('LANDSAT/LT04/C01/T1_SR') .filterDate('1992-01-02', '1992-04-01') .map(maskL57SR) // Combine all landsat data, 1985 through 2015 var everything = ee.ImageCollection(lst5.merge(lst7)); everything = everything.merge(lst8); everything = everything.merge(lst7_08); everything = everything.merge(lst7_92); // NBR: var nbrFunction = function(image) { image = ee.Image(image) return image.addBands(image.expression( '(nir - 0.0001 * swir * thermal) / ' + '(nir + 0.0001 * swir * thermal)', { nir: image.select(['NIR']), swir: image.select(['SWIR']), thermal: image.select(['Thermal']) }).rename('NBR').clamp(-1, 1)); }; everything = everything.map(nbrFunction); var check = ee.Image(everything.first()); Map.centerObject(check); Map.addLayer(check);

Recommend

  • Convert Python date to Unix timestamp
  • How to label data points in matplotlib scatter plot while looping through pandas dataframes?
  • Get both date and time in milliseconds
  • how to download any file to any device and view?
  • After message type e, program doesn't return to selection-screen ABAP
  • How to convert NAnt function “path::combine(path1, path2)” to MSBuild?
  • Get pretty git rev name
  • Simplifying the use of meshgrid in Matlab
  • Combine two small queries (that group by different values) into one query
  • How to implement simple validation in Scala
  • Regex for Specific Tag
  • Counting problem C#
  • Where these are stored?
  • How can we prepend rows to a react native list-view?
  • abstracting over a collection
  • How can I tell a form not to dispose a particular control when it closes?
  • KnockoutObservableArray with typed elements in TypeScript
  • R Split data.frame using a column that represents and on/off switch
  • presentShareDialogWithParams posts to FB wall, but callback handler results say error
  • What's the purpose of QString?
  • Jackson Parser: ignore deserializing for type mismatch
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • Breeze - Deleted Items nav properties bug
  • how to adjust image in a panel in Java swing?
  • Fetching methods from BroadcastReceiver to update UI
  • javaw.exe and eclipse startup problems
  • Possible to stop flickering java tooltip in heavyweight mode?
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • script to move all files from one location to another location
  • Symfony2: How to get request parameter
  • GridView Sorting works once only
  • retrieve vertices with no linked edge in arangodb
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • WPF Applying a trigger on binding failure
  • JTable with a ScrollPane misbehaving
  • need help with bizarre java.net.HttpURLConnection behavior
  • Running Map reduces the dimensions of the matrices
  • Android Heatmap on canvas or ImageView
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?