统计研究区内Landsat和Sentinel影像逐年逐月数量

统计研究区内Landsat影像数量

2021-08-28 17:11:39 星期六
导出结果为数量csv文件

var ROI = ee.FeatureCollection("users/xxx/xxx");
function cloudmask(image) {
  // Remove edge pixels that don't occur in all bands
  var mask1 = image.mask().select('B.*').reduce(ee.Reducer.min());
  return image.updateMask(mask1);
}
function setImageInfo(image){
  var date = image.get("SENSING_TIME");//获取影像时间
  var year=ee.Date(date).get("year");
  image=image.set("year",year);//设置属性 年
  var month=ee.Date(date).get("month");
  image=image.set("month",month);//设置属性 月
  var day=ee.Date(date).get("day");
  image=image.set("day",day);//设置属性 日
  return image;
}
///////////////////////////////////////////////////////
//------------------Landsat5--------------------------//
var colTM2 = ee.ImageCollection("LANDSAT/LT05/C01/T1_SR")
                .filterDate('1989-01-01', '2012-05-31')
                .filterBounds(ROI)
                .map(cloudmask)
                .map(setImageInfo);
print(colTM2)
//export imageCollection information
Export.table.toDrive({
  collection:colTM2,
  description:"L5_Stat",
  fileNamePrefix:"L5_Stat",
  fileFormat:"CSV",
  selectors:["year","month","day","WRS_PATH","WRS_ROW"]});
////////////////////////////////////////////////////////
//------------------Landsat7--------------------------//
var colETM = ee.ImageCollection("LANDSAT/LE07/C01/T1_SR")
                .filterDate('1999-01-01', '2003-05-31')
                .filterBounds(ROI)
                .map(cloudmask)
                .map(setImageInfo);
//export imageCollection information
Export.table.toDrive({
  collection:colETM,
  description:"L7_Stat",
  fileNamePrefix:"L7_Stat",
  fileFormat:"CSV",
  selectors:["year","month","day","WRS_PATH","WRS_ROW"]});
///////////////////////////////////////////////////////
//------------------Landsat8--------------------------//
var colOLI = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
                .filterDate('2013-01-01', '2019-12-31')
                .filterBounds(ROI)
                .map(cloudmask)
                .map(setImageInfo);
//export imageCollection information
Export.table.toDrive({
  collection:colOLI,
  description:"L8_Stat",
  fileNamePrefix:"L8_Stat",
  fileFormat:"CSV",
  selectors:["year","month","day","WRS_PATH","WRS_ROW"]});


function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return image.updateMask(mask).divide(10000);
}



function setImageInfo(image){
  var date = image.get("system:time_start");//获取影像时间
  var year=ee.Date(date).get("year");
  image=image.set("year",year);//设置属性 年
  var month=ee.Date(date).get("month");
  image=image.set("month",month);//设置属性 月
  var day=ee.Date(date).get("day");
  image=image.set("day",day);//设置属性 日
  return image;
}


var S2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
                  .filterDate('2015-04-01', '2022-04-01')
                  // Pre-filter to get less cloudy granules.
                  .filterBounds(roi)
                  //.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20))
                  
                  //.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',40))
                  //.filter(ee.Filter.gte('CLOUDY_PIXEL_PERCENTAGE',20))
                  
                  
                  //.filter(ee.Filter.gte('CLOUDY_PIXEL_PERCENTAGE',80))
                  .map(setImageInfo);
//print(S2)

//export imageCollection information
Export.table.toDrive({
  collection:S2,
  description:"S2dt_Stat",
  fileNamePrefix:"S2dt_Stat",
  fileFormat:"CSV",
  selectors:["year","month","day","CLOUDY_PIXEL_PERCENTAGE"]});
var sentinel1 =  ee.ImageCollection('COPERNICUS/S1_GRD');
// Filter Sentinel-1 collection for study area, date ranges and polarization components
var sCollection =  sentinel1
                    //filter by aoi and time
                   .filterDate('2015-04-01', '2022-04-01')
                  // Pre-filter to get less cloudy granules.
                  .filterBounds(roi)
                    // Filter to get images with VV and VH dual polarization
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    // Filter to get images collected in interferometric wide swath mode.
                    .filter(ee.Filter.eq('instrumentMode', 'IW')).map(setImageInfo);
// Also filter based on the orbit: descending or ascending mode
var desc = sCollection.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));
var asc = sCollection.filter(ee.Filter.eq('orbitProperties_pass', 'ASCENDING'));
// Inspect number of tiles returned after the search; we will use the one with more tiles
print("descending tiles ",desc.size());
print("ascending tiles ",asc.size());
// Also Inspect one file
print(asc);

Export.table.toDrive({
  collection:sCollection,
  description:"S1dt_Stat",
  fileNamePrefix:"S1dt_Stat",
  fileFormat:"CSV",
  selectors:["year","month","day","resolution_meters"]});

//在python中基于年和月统计影像数量 云量

import pandas as pd
df=pd.read_csv(r"C:\Users\dyw\Downloads\S2dt_Stat.csv")

num_20=df.loc[df['CLOUDY_PIXEL_PERCENTAGE']<20].groupby(['year']).count()
num_40=df.loc[(df['CLOUDY_PIXEL_PERCENTAGE'] >= 20) & (df['CLOUDY_PIXEL_PERCENTAGE'] < 40)].groupby(['year']).count()
num_60=df.loc[(df['CLOUDY_PIXEL_PERCENTAGE'] >= 40) & (df['CLOUDY_PIXEL_PERCENTAGE'] < 60)].groupby(['year']).count()
num_80=df.loc[(df['CLOUDY_PIXEL_PERCENTAGE'] >= 60) & (df['CLOUDY_PIXEL_PERCENTAGE'] < 80)].groupby(['year']).count()
num_100=df.loc[(df['CLOUDY_PIXEL_PERCENTAGE'] >= 80)].groupby(['year']).count()

month_20=df.loc[df['CLOUDY_PIXEL_PERCENTAGE']<20].groupby(['month']).count()

S1df=pd.read_csv(r"C:\Users\dyw\Downloads\S1dt_Stat.csv")

num_s1=S1df.groupby(['year']).count()
posted @ 2021-08-28 17:22  icydengyw  阅读(189)  评论(1编辑  收藏  举报