1

My aim is to resample MOD10A1/MYD10A1 to the same scale as that of MOD11A1/MYD11A1, mask the image collection to obtain the best pixels, and finally to obtain the time series plot of the total area covered by the masked pixels on a daily basis across Bhagirathi basin. The GEE code is displayed below. Within the code, 'Bhagirathi', 'Nubra' and 'Uppershyok' are the shapefile assets used.

The NDSI_Snow_Cover_Basic_QA band has 16 bits in which 0 value represents best quality. In such a case should I check for all the 16 bits or any one bit is enough ?

NDSI_Snow_Cover_Basic_QA

Bits 0-15: QA

0: Best

1: Good

2: Ok

3: Poor-not currently in use

211: Night

239: Ocean

NDSI_Snow_Cover_Algorithm_Flags_QA

Bit 0: Inland water

Bit 1: Low visible screen failed. Snow detection reversed

Bit 2: Low NDSI screen failed. Snow detection reversed

Bit 7: Solar zenith screen failed (angles exceed 70°), uncertainty increased

var locations = Bhagirathi.merge(Nubra).merge(Uppershyok);

//aqua daily LST dataset (1km spatial resolution)
var AquaLST = ee.ImageCollection('MODIS/006/MYD11A1')
                .filter(ee.Filter.date('2010-06-01', '2010-07-01'))
                .select('LST_Day_1km')
                .map(function(img) {
                    return img.clip(locations);
                })
                .first();

//aqua daily snow cover dataset (500m spatial resolution) to be resampled to 1km using aqua daily LST dataset
var AquaSnowCover = ee.ImageCollection('MODIS/006/MYD10A1')
                       .filter(ee.Filter.date('2002-07-04', '2010-01-01'))
                       .select('NDSI_Snow_Cover','NDSI_Snow_Cover_Basic_QA','NDSI_Snow_Cover_Algorithm_Flags_QA')
                       .map(function(img) {
                          return img.reproject({ crs: AquaLST.projection() })
                                    .clip(locations);
                       });

//terra daily snow cover dataset (500m spatial resolution) to be resampled to 1km using aqua daily LST dataset
var TerraSnowCover = ee.ImageCollection('MODIS/006/MOD10A1')
                        .filter(ee.Filter.date('2000-02-24', '2010-01-01'))
                        .select('NDSI_Snow_Cover','NDSI_Snow_Cover_Basic_QA','NDSI_Snow_Cover_Algorithm_Flags_QA')
                        .map(function(img) {
                          return img.reproject({ crs: AquaLST.projection() })
                                    .clip(locations);
                        });

//create mask to extract only 'best' and 'good' quality data (values 0 and 1 in all the 16 bits)
//also create mask to extract pixels without inland water (bit0),
//no visible screen failure (bit1), no ndsi screen failure (bit2) and
//no solar zenith screen failure (bit7) 
//Refer:-   https://developers.google.com/earth-engine/datasets/catalog/MODIS_006_MOD10A1?hl=en
var filter = function(image){ 
  var basicQA = image.select('NDSI_Snow_Cover_Basic_QA');
  var basicBitMask = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9|1<<10|1<<11|1<<12|1<<13|1<<14|1<<15;
  var basicBitwiseResult = basicQA.bitwiseAnd(basicBitMask);
  var basicMask = basicBitwiseResult.eq(0).or(basicBitwiseResult.eq(1));
  var flagsQA = image.select('NDSI_Snow_Cover_Algorithm_Flags_QA');
  var inland = 1<<0;
  var visible = 1<<1;
  var ndsi = 1<<2;
  var solar = 1<<7;
  var Inland = (flagsQA.bitwiseAnd(inland)).eq(0);
  var Visible = (flagsQA.bitwiseAnd(visible)).eq(0);
  var NDSI = (flagsQA.bitwiseAnd(ndsi)).eq(0);
  var Solar = (flagsQA.bitwiseAnd(solar)).eq(0);
  var mask = basicMask.and(Inland).and(Visible).and(NDSI).and(Solar);
  image = image.updateMask(mask);
  //Calculation of masked pixel area
  var area = mask.divide(mask)
                 .multiply(ee.Image.pixelArea())
                 .rename('Area')
                 .divide(1e6);
  image = image.addBands(area);
  var stats = area.reduceRegion({
    reducer: ee.Reducer.sum(), 
    geometry: Bhagirathi, 
    scale: 1000,
  });
  return image.set(stats);
};

//apply basic & flags QA mask to image collection
var ASC = AquaSnowCover.map(filter);
var TSC = TerraSnowCover.map(filter);

//Charting Aqua Snow Cover over Bhagirathi
print(Chart.image.series(ASC.select('Area'), Bhagirathi,ee.Reducer.sum()).setOptions({
   title: "Time Series of MODIS Aqua Daily Snow Cover across Bhagirathi",
   hAxis: {
     title: "Time Period",
     titleTextStyle: {italic: false, bold: true}
   },
   vAxis: {
     title: "Snow Cover Area",
     titleTextStyle: {italic: false, bold: true}
   },
   colors: ["Red"]
}));

//Charting Terra Snow Cover over Bhagirathi
print(Chart.image.series(TSC.select('Area'), Bhagirathi,ee.Reducer.sum()).setOptions({
   title: "Time Series of MODIS Terra Daily Snow Cover across Bhagirathi",
   hAxis: {
     title: "Time Period",
     titleTextStyle: {italic: false, bold: true}
   },
   vAxis: {
     title: "Snow Cover Area",
     titleTextStyle: {italic: false, bold: true}
   },
   colors: ["Red"]
}));

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.