0

I have an Image Collection of Images that have pixels with values of either 1000, 1000, or 1. I want to know which pixels, over the years have a value of '1000' 75% of the time, which pixels have a value of '100', 75% of the time, and which pixels have a value of '1' 75% of the time. Time being years (each image in the collection represents a single year). However, some Images do not have pixels for that year (so we have null values I assume). So, is it possible to find the 75% without knowing how many years of actual data (does GEE just ignore the null values if I were to run a calculation on the Image Collection), or... do I need to answer the following question?

How do you find out for every pixel (land area), how many years of data an Image Collection stacked together has? Some years do not have data (i.e., a pixel may have data 4/5 years in the Image Collection, another pixel may have data 3/5 years in the Image Collection). How do you do this in Google Earth Engine and then store it as a variable I can do calculations on? Or how do you count the non-null pixels and return them as an image for calculations?

1 Answer 1

2

In your question, you should provide some code where you tried to solve your problem.

Here's one way to approach this. See the inline comments.

// Four band image (total, 1, 100, 1000) containing counts
var counts = collection // collection contains single-band images with the class
  .map(function (image) { // Turn into band per class
    return image
      .rename('total')
      .addBands([
        image.updateMask(image.eq(1)).rename('1'),
        image.updateMask(image.eq(100)).rename('100'),
        image.updateMask(image.eq(1000)).rename('1000'),
      ])
  })
  .reduce(ee.Reducer.count()) // Image with not-masked-pixel count
  .regexpRename('(.*)_count', '$1') // Drop _count from band name
  .clip(geometry)

// Three band image (1, 100, 1000) containing percentages of total
var percentages = counts
  .select(['1', '100', '1000'])
  .divide(counts.select('total'))
  .multiply(100)
  
var maskedPercentages = percentages
  .updateMask(percentages.gte(75)) // At least 75%
  

https://code.earthengine.google.com/0b45a33afd089a662f3158ad27374d0f

1
  • 1
    Please use the Get Link button in the Code Editor May 28, 2021 at 11:08

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.