0

My objective is to extract random samples of Sentinel 2 images using the stratifiedSample function in Google Earth Engine. I want to use the « QA60 » band as a stratifier. Even though this is a very simple procedure, I do not manage to have a code that works on all S2 images. While the stratifiedSample function works fine on some images (and return, e.g. 10 samples/elements per classes), on others the function return 0 samples/elements (without throwing any kind of error message).

Here is a code to illustrate my problem : https://code.earthengine.google.com/2f8a97ed934eb444d309379b451a6986

In the code, I specified two S2 images : using the first one the stratifiedSample returns 0 elements, using the second one (currently grayed-out) stratifiedSample return the proper number of elements.

A first difference between the 2 images is that in the first one, non-cloud pixels in the QA60 band are masked, while they have a 0 value in the second image. I homogenized this issue with the “unmask()” function at line 16. After line 16, I cannot see any difference between the two images that would explain why stratifiedSample works in one case and not in the other…

Any idea on why stratifiedSample returns 0 elements?

1 Answer 1

1

The dropNulls option on stratifiedSample, which defaults to true, throws away any samples in which any of the bands are masked. For that image, the QA10 and QA20 bands are empty. Set that option to false, or remove those bands before sampling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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