GEEMODIS数据质量波段应用

MODIS质量控制数据应用

主要功能

使用MODIS的QA波段来进行云区掩膜,深海区域掩膜

代码

// Extract MODIS QA information from the "state_1km" QA band
// and use it to mask out cloudy and deep ocean areas.
//
// QA Band information is available at:
// https://lpdaac.usgs.gov/products/modis_products_table/mod09ga
// Table 1: 1-kilometer State QA Descriptions (16-bit)


/**
 * Returns an image containing just the specified QA bits.
 *
 * Args:
 *   image - The QA Image to get bits from.
 *   start - The first bit position, 0-based.
 *   end   - The last bit position, inclusive.
 *   name  - A name for the output image.
 */
var getQABits = function(image, start, end, newName) {
    // Compute the bits we need to extract.
    var pattern = 0;
    for (var i = start; i <= end; i++) {
       pattern += Math.pow(2, i);
    }
    return image.select([0], [newName])
                  .bitwiseAnd(pattern)
                  .rightShift(start);
};

// Reference a single MODIS MOD09GA image.
var image = ee.Image('MODIS/006/MOD09GA/2012_10_11');

// Select the QA band
var QA = image.select('state_1km');

// Get the cloud_state bits and find cloudy areas.
var cloud = getQABits(QA, 0, 1, 'cloud_state')
                    .expression("b(0) == 1 || b(0) == 2");

// Get the land_water_flag bits.
var landWaterFlag = getQABits(QA, 3, 5, 'land_water_flag');

// Create a mask that filters out deep ocean and cloudy areas.
var mask = landWaterFlag.neq(7).and(cloud.not());

// Add a map layer with the deep ocean and clouds areas masked out.
Map.addLayer(image.updateMask(mask),
  {
    bands: ['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03'],
    min: -100,
    max: 2000
  }, 'MOD09GA 143'
);

// Add a semi-transparent map layer that displays the clouds.
Map.addLayer(
    cloud.updateMask(cloud),
    {palette: 'FFFFFF', opacity: 0.8},
    'clouds'
);

步骤分析

  1. 定义函数getQABits
  2. 创建ee对象,获取MODIS数据
  3. 选择QA波段
  4. 获取云区
  5. 获取陆地水域区域
  6. 合并云区和水域区域
  7. 添加原始数据图层
  8. 添加一个显示云区域的图层

主要方法

定义了一个函数getQABits(image, start, end, newName),以下两个方法是在函数中使用的:

  1. ee.Image.bitwiseAnd()
    Calculates the bitwise AND of the input values for each matched pair of bands in image1 and image2. If either image1 or image2 has only 1 band, then it is used against all the bands in the other image. If the images have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in image1's order. The type of the output pixels is the union of the input types.
    Arguments:
    this:image1 (Image):
    The image from which the left operand bands are taken.
    image2 (Image):
    The image from which the right operand bands are taken.
    Returns: Image

计算输入影像的位"与"操作。
输入参数:
输入影像对象1,输入影像对象2

  1. ee.Image.rightShift()
    Calculates the signed right shift of v1 by v2 bits for each matched pair of bands in image1 and image2. If either image1 or image2 has only 1 band, then it is used against all the bands in the other image. If the images have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in image1's order. The type of the output pixels is the union of the input types.
    Arguments:
    this:image1 (Image):
    The image from which the left operand bands are taken.
    image2 (Image):
    The image from which the right operand bands are taken.
    Returns: Image

你可能感兴趣的:(GEEMODIS数据质量波段应用)