0

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?

0

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().

3
  • thanks for our reply. A bit of clarification, the reason why I want to use the percentage as a property is because I need to do a lot of stuff in the unreduced resolution first, then I would like this property as a mask, however, I am afraid that if I do it later, that this coverage percentage will disapear. Besides this I need an accurate mask, so estimating how many pixels are in the reduced resolution is my last resort. – Muis de Kogel May 28 '19 at 8:03
  • Then I am wondering why you actually want to reproject the sinusoidal MODIS projection? – Kuik May 28 '19 at 12:35
  • I am trying to work on this problem: link, but in a different way. Instead of using a featurecollection as a grid, and needing a function within a function, I am making a raster with a pixel as grid cell, with the correct value, and using a probability density function for the elevation steps. – Muis de Kogel May 29 '19 at 8:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.