TransWikia.com

Extracting the coverage of reduced resolution

Geographic Information Systems Asked by Muis de Kogel on January 1, 2021

I have the following reprojected dataset:

//The reprojection variables
var crs = 'EPSG:3857';
var scale = 30000;

//import Datasets
var MOD = ee.ImageCollection('MODIS/006/MOD10A1')
.select('NDSI_Snow_Cover').filterDate('2017-07-01')
.map(function(img){ return img.gte(40).clip(C_A)});
Map.addLayer(MOD,{},'MODIS_FUll')

var MOD_rp = MOD.map(function(img){var rr = img.reduceResolution({
  reducer:ee.Reducer.sum().unweighted(),maxPixels:15000,
bestEffort:false}).reproject({crs:crs,scale:scale});
  return ee.Image(rr)});

I would like to mask all pixels with a coverage less then 30%. This information is visible when I click pixels in the inspector tab:

snapshot of inspector tab

However, I cannot find it in the properties. Is there a way to extract this info?

One Answer

It's not very obvious how to get that '%' of cover directly, at least for me. However, you can easily make a mask image for image with cover <30%. Therefore, first make all pixel values 1, using something like img.gt(-99). Reproject that image into your new projection.

Then, I approximated the amount of original pixels in the new projection. You will have to find out what that is in your area of interest. As an example, I zoomed in to the north of Greenland, where it is about 125 MODIS pixels inside the new resolution. At the equator, it goes up to at least 4000 MODIS pixels.

Multiply that by 0.3 to get the value of each pixel required to make a mask of % cover > 30. Then we do the same operation on the original image you already did, and update the image with the above described mask.

You can check your original image and the image with the update 30% cover image in the inspector: Link code

// DEFINE THE NUMBER OF PIXELS INSIDE THE NEW PROJECTION
var numPixels = 125;

//import Datasets
var MOD = ee.ImageCollection('MODIS/006/MOD10A1')
        .select('NDSI_Snow_Cover').filterDate('2017-07-01');

// Map over the image collection
var MOD_rp = MOD.map(function(img){
  // Now we are first masking all pixels which have <30% of cover
  // first make all values 1 using gt(-99)
  var rr = img.gt(-99).reduceResolution({
                      reducer:ee.Reducer.sum().unweighted(),
                      maxPixels:15000,
                      bestEffort:false})
            .reproject({crs:crs,scale:scale});
  // return the masked image
  // NOTE TO CHECK HOW MANY PIXELS ARE RESENT IN THE NEW PROJECTION
  var maskNEW_resolution = rr.updateMask(rr.gt(numPixels*0.3));
  // Now apply the original mask (gt(40)) on the origonal resolution MODIS image
  var snowCoverGT_40 = img.gte(40);
  // Reproject the Origonal MODIS image into the new projection
  var snowCoverNew_resolution = snowCoverGT_40.reduceResolution({
                      reducer:ee.Reducer.sum().unweighted(),
                      maxPixels:15000,
                      bestEffort:false})
            .reproject({crs:crs,scale:scale});
  // return the snow cover, updated where the piel cover is < 30%
  return snowCoverNew_resolution.updateMask(maskNEW_resolution);
});

As an addition to your code: you were adding imageCollection to the map (of only one image, defined by the filterDate). Generally, you want to make mosaics using a reducer (like mean, median), or present single images on the map. Therefore, I added images to the map using imageCollection.first(). Furthermore, MODIS images are global, therefore I don't think there is any need to clip the image to a certain area. If you want pixel information of a certain area, you can specify the geometry in the arguments of reduceRegion().

Answered by Kuik on January 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP