本文我们将介绍哨兵2数据去云分析,同样是使用QA60去云,我们这里先看一下影像
Sentinel-2号是高分辨率多光谱成像卫星,携带一枚多光谱成像仪(MSI),分为2A和2B两颗卫星,其中一颗卫星的重访周期为10天,两颗互补,重访周期为5天(纬度较高的欧洲地区,仅需3天),常用于陆地监测,可提供植被、土壤和水覆盖、内陆水路及海岸区域等图像,还可用于紧急救援服务。
Sentinel-2数据集中包含的数据为L1C级产品数据,是经正射校正和亚像元级几何精校正后的大气表观反射率产品,包含13个UINT16光谱带,3个QA频段,其中一个(QA60)是具有云掩码信息的位掩码频段。
名称 | 中心波长(nm) | 分辨率(m) | 描述信息 | |
---|---|---|---|---|
A | B | |||
B1 | 443.9 | 442.3 | 60 | Aerosols |
B2 | 496.6 | 492.1 | 10 | Blue |
B3 | 560 | 559 | 10 | Green |
B4 | 664.5 | 665 | 10 | Red |
B5 | 703.9 | 703.8 | 20 | Red Edge 1 |
B6 | 740.2 | 739.1 | 20 | Red Edge 2 |
B7 | 782.5 | 779.7 | 20 | Red Edge 3 |
B8 | 835.1 | 833 | 10 | NIR |
B8A | 864.8 | 864 | 20 | Red Edge 4 |
B9 | 945 | 943.2 | 60 | Water vapor |
B10 | 1373.5 | 1376.9 | 60 | Cirrus |
B11 | 1613.7 | 1610.4 | 20 | SWIR 1 |
B12 | 2202.4 | 2185.7 | 20 | SWIR 2 |
QA10 | 443.9 | 442.3 | 10 | -- |
QA20 | -- | -- | 20 | -- |
QA60 | -- | -- | 60 | -- |
Bitmask for QA60 | |
---|---|
|
影像属性:
id | string | 影像名称 |
date | string | 影像日期 |
cloudyPixelPercentage | double | 云量覆盖百分比 |
代码:
var geometry0 = pie.FeatureCollection('user/xg346049806/shanxibianjie').first().geometry();
/*******************1. Sentinel-2 利用cloudyPixelPercentage属性筛选含云量**************/
var images1 = pie.ImageCollection("S2/L1C")
.filterDate('2020-07-01', '2020-07-30')
.filterBounds(geometry0);
print("images1",images1)
var images2 = pie.ImageCollection("S2/L1C")
.filterDate('2020-07-01', '2020-07-30')
.filterBounds(geometry0)
.filter(pie.Filter.lt('cloudyPixelPercentage',5));
print("images2",images2)
//定义显示的样式
var visParam = {
min:0,
max:3000,
bands:["B4","B3","B2"]
};
//分别加载不同影像
//添加云量2.66%的影像
var image = pie.Image("S2/L1C/43SED_20200701")
.select(["B4","B3","B2"]);
Map.centerObject(image,7)
Map.addLayer(image, visParam, "2.66%Cloud");
//添加云量11.83%的影像
var image = pie.Image("S2/L1C/43SED_20200704")
.select(["B4","B3","B2"]);
Map.addLayer(image, visParam, "11.83%Cloud");
/**********2. Sentinel-2 利用QA波段实现去云操作***************/
function maskS2clouds(image) {
var qa = image.select("QA60");
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
var mask = qa
.bitwiseAnd(cloudBitMask)
.eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask);
}
//按数据id加载Sentinel-2 MSI单景影像
var img = pie.Image("S2/L1C/43SED_20200704").select(["B4", "B3", "B2", "QA60"]);
print("img", img);
var rmCloud = maskS2clouds(img);
print("rmCloud", rmCloud);
//定位地图中心
Map.centerObject(img, 8);
//加载显示影像
Map.addLayer(
img.select(["B4", "B3", "B2"]),
{ min: 0, max: 3000 },
"Sen-rawImage"
);
Map.addLayer(
rmCloud.select(["B4", "B3", "B2"]),
{ min: 0, max: 3000 },
"Sen-rmCloud"
);
原始影像结果:
去云后影像结果:
影像去云:
利用算法进行去云后的结果:
var geometry0 = pie.FeatureCollection('user/xg346049806/shanxibianjie').first().geometry();
//************************3. Sentinel-2 算法去云 ******************/
var S2Image = pie.ImageCollection("S2/L1C")
.filterBounds(geometry0)
.filterDate("2020-06-01","2020-06-09")
.select(["B4", "B3", "B2", "QA60"]).mosaic().clip(geometry0);
//计算云掩膜
var cloudMask = pie.Algorithm.Sentinel2.cloudMask(S2Image,"Sentinel2");
//选择2,3,4波段做掩膜运算
var S2_rm_mask = S2Image.select(["B4","B3","B2"]).updateMask(cloudMask.not());
// Sentinel2数据去云显示
var visParam = {
min: 0,
max: 3000
};
Map.centerObject(S2Image,8)
Map.addLayer(S2_rm_mask.select(["B4","B3","B2"]),visParam,"MaskImage");