面朝大海,春暖华开

focus on scientific computue, 3dgis, spatial database
专注于科学计算、GIS空间分析

 

GEE云量计算简单云量估计 主要功能 从数据集中选择云量最小的像素,输出展示

 GEE云量计算

作者:赤豆冰棍
链接:https://www.jianshu.com/p/b9e8de78c951

简单云量估计

主要功能

从数据集中选择云量最小的像素,输出展示

代码

// SimpleCloudScore, an example of computing a cloud-free composite with L8

// by selecting the least-cloudy pixel from the collection.

 

// A mapping from a common name to the sensor-specific bands.

var LC8_BANDS = ['B2',   'B3',    'B4',  'B5',  'B6',    'B7',    'B10'];

var STD_NAMES = ['blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'temp'];

 

// Compute a cloud score.  This expects the input image to have the common

// band names: ["red", "blue", etc], so it can work across sensors.

var cloudScore = function(img) {

  // A helper to apply an expression and linearly rescale the output.

  var rescale = function(img, exp, thresholds) {

    return img.expression(exp, {img: img})

        .subtract(thresholds[0]).divide(thresholds[1] - thresholds[0]);

  };

 

  // Compute several indicators of cloudyness and take the minimum of them.

  var score = ee.Image(1.0);

  // Clouds are reasonably bright in the blue band.

  score = score.min(rescale(img, 'img.blue', [0.1, 0.3]));

 

  // Clouds are reasonably bright in all visible bands.

  score = score.min(rescale(img, 'img.red + img.green + img.blue', [0.2, 0.8]));

 

  // Clouds are reasonably bright in all infrared bands.

  score = score.min(

      rescale(img, 'img.nir + img.swir1 + img.swir2', [0.3, 0.8]));

 

  // Clouds are reasonably cool in temperature.

  score = score.min(rescale(img, 'img.temp', [300, 290]));

 

  // However, clouds are not snow.

  var ndsi = img.normalizedDifference(['green', 'swir1']);

  return score.min(rescale(ndsi, 'img', [0.8, 0.6]));

};

 

// Filter the TOA collection to a time-range and add the cloudscore band.

var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')

    .filterDate('2017-05-01', '2017-07-01')

    .map(function(img) {

      // Invert the cloudscore so 1 is least cloudy, and rename the band.

      var score = cloudScore(img.select(LC8_BANDS, STD_NAMES));

      score = ee.Image(1).subtract(score).select([0], ['cloudscore']);

      return img.addBands(score);

    });

 

// Define visualization parameters for a true color image.

var vizParams = {bands: ['B4', 'B3', 'B2'], max: 0.4, gamma: 1.6};

Map.setCenter(-120.24487, 37.52280, 8);

Map.addLayer(collection.qualityMosaic('cloudscore'), vizParams);

 

步骤分析

  1. 创建LC8波段顺序名称列表
  2. 定义函数cloudScore用于计算云量
  3. 创建数据集对象,获取LC8数据,使用时间筛选,选择云量(cloudscore)波段,获取1-cloudscore结果作为score新波段,添加到该景影像中
  4. 定义显示参数
  5. 设置地图中心,缩放等级
  6. 添加图层,图层内容使用函数cloudScore来计算数据集中的所有数据,并且返回云量最少部分,镶嵌成为一个图层用于显示

主要方法

  1. ee.Image.qualityMosaic()
    Composites all the images in a collection, using a quality band as a per-pixel ordering function.
    Arguments:
    this:collection (ImageCollection):
    The collection to mosaic.
    qualityBand (String):
    The name of the quality band in the collection.
    Returns: Image

组合一个数据集内的所有数据,使用一个质量控制波段来决定像素值
输入参数:数据集,质量控制波段名称



 

posted on 2023-11-27 22:00  风过 无痕  阅读(121)  评论(0编辑  收藏  举报

导航

向日葵支付宝收钱码