很多时候我们在长时间序列的研究中会忽略使用Landsat7 因为充满条带,而且在使用的时候我们因为需要填充,所以比较麻烦,但是我们今天使用一个填充函数来快速实现后,然后进行下一步ndvi和LST的计算。
函数:这里影像填充函数时间设定的是一年前后影像当期的,然后通过线性来计算结局和斜率最后让填充影像填入按照这个方式来进行计算,
var GapFill = function(image) { var start = image.date().advance(-1, 'year'); var end = image.date().advance(1, 'year'); var fill = l7.filterDate(start, end).median(); var regress = fill.addBands(image); var regress = regress.select(regress.bandNames().sort()); var fit = regress.reduceNeighborhood(ee.Reducer.linearFit().forEach(image.bandNames()), kernel, null, false); var offset = fit.select('.*_offset'); var scale = fit.select('.*_scale'); var scaled = fill.multiply(scale).add(offset); return image.unmask(scaled, true); };
代码:
var point = /* color: #98ff00 */ /* shown: false */ /* displayProperties: [ { "type": "rectangle" } ] */ ee.Geometry.Polygon( [[[71.92283798912835, 34.38383276176222], [71.92283798912835, 34.32147587459247], [72.0574205086596, 34.32147587459247], [72.0574205086596, 34.38383276176222]]], null, false); Map.addLayer(point) var cloudMaskL7 = function(image) { var qa = image.select('pixel_qa'); var cloud = qa.bitwiseAnd(1 << 5) .and(qa.bitwiseAnd(1 << 7)) .or(qa.bitwiseAnd(1 << 3)); var mask2 = image.mask().reduce(ee.Reducer.min()); return image.updateMask(cloud.not()).updateMask(mask2); }; var l7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR') .map(cloudMaskL7); var kernelSize = 10; var kernel = ee.Kernel.square(kernelSize * 30, 'meters', false); var GapFill = function(image) { var start = image.date().advance(-1, 'year'); var end = image.date().advance(1, 'year'); var fill = l7.filterDate(start, end).median(); var regress = fill.addBands(image); var regress = regress.select(regress.bandNames().sort()); var fit = regress.reduceNeighborhood(ee.Reducer.linearFit().forEach(image.bandNames()), kernel, null, false); var offset = fit.select('.*_offset'); var scale = fit.select('.*_scale'); var scaled = fill.multiply(scale).add(offset); return image.unmask(scaled, true); }; // TESTING CODE Map.centerObject(point, 11); var check = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR') .filterBounds(point) .filterDate('2004-01-01', '2004-12-31'); var checkImage = ee.Image(check.first()); var visParams = {bands: ['B4', 'B3', 'B2'], min: 200, max: 5500}; Map.addLayer(checkImage.clip(point), visParams, 'source'); // Test composite. var checkStart = checkImage.date().advance(-1, 'year'); var checkEnd = checkImage.date().advance(1, 'year'); var composite = l7.filterDate(checkStart, checkEnd).median(); Map.addLayer(composite.clip(point), visParams, 'median'); // Rough implementation for comparison. var replaced = checkImage.unmask(composite); Map.addLayer(replaced.clip(point), visParams, 'simple'); // Fancy implementation. var filled = ee.Image(check.map(GapFill).median()); Map.addLayer(filled.clip(point), visParams, 'filled'); //median { var ndvi = filled.normalizedDifference(['B4', 'B3']).rename('NDVI'); var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']}; print(ndvi,'ndvi'); Map.addLayer(ndvi.clip(point), ndviParams, 'ndvi'); } //select thermal band 10(with brightness tempereature), no calculation var thermal= filled.select('B6').multiply(0.1); var b10Params = {min: 291.918, max: 302.382, palette: ['blue', 'white', 'green']}; Map.addLayer(thermal.clip(point), b10Params, 'thermal'); // find the min and max of NDVI { var min = ee.Number(ndvi.reduceRegion({ reducer: ee.Reducer.min(), geometry: point, scale: 30, maxPixels: 1e9 }).values().get(0)); print(min, 'min'); var max = ee.Number(ndvi.reduceRegion({ reducer: ee.Reducer.max(), geometry: point, scale: 30, maxPixels: 1e9 }).values().get(0)); print(max, 'max') } //fractional vegetation { var fv =(ndvi.subtract(min).divide(max.subtract(min))).pow(ee.Number(2)).rename('FV'); print(fv, 'fv'); Map.addLayer(fv.clip(point)); } //Emissivity var a= ee.Number(0.004); var b= ee.Number(0.986); var EM=fv.multiply(a).add(b).rename('EMM'); var imageVisParam3 = {min: 0.9865619146722164, max:0.989699971371314}; Map.addLayer(EM.clip(point), imageVisParam3,'EMM'); //LST in Celsius Degree bring -273.15 //NB: In Kelvin don't bring -273.15 var LST = thermal.expression( '(Tb/(1 + (0.00115* (Tb / 1.438))*log(Ep)))-273.15', { 'Tb': thermal.select('B6'), 'Ep': EM.select('EMM') }).rename('LST'); var viz = {min: 16, max:37, palette: [ '040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6', '0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef', '3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f', 'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d', 'ff0000', 'de0101', 'c21301', 'a71001', '911003' ]} Map.addLayer(LST.clip(point), viz, 'LST');
填充后的RGB影像