0

I have a use case where I need to export the SCL band from a median composite image that I created using EarthEngine. I have no problems with exporting the band, however when I look at the exported image, the values make no sense.

My understanding is that the SCL band should contain integer values between 1 and 11, however when I look at the exported images, my values are float between 0.0002 and 0.0009. the code I have posted below confirms this.

I am wondering if Earth Engine is doing something strange either when selecting the median, or when resampling so that Integer values of the band are not maintained?

Here is my code if you wish to test.

def clipImage(image):
    return image.clip(AOI)

def maskS2clouds(image):
    qa = image.select('QA60')
    cloudBitMask = 1 << 10
    cirrusBitMask = 1 << 11
    mask = qa.bitwiseAnd(cloudBitMask).eq(0).And(qa.bitwiseAnd(cirrusBitMask).eq(0))
    return image.updateMask(mask).divide(10000).copyProperties(image)

AOI = ee.Geometry.Polygon(
        [[[24.40875404125726, -12.502032301874605],
          [24.40875404125726, -12.970856040836589],
          [24.97180335766351, -12.970856040836589],
          [24.97180335766351, -12.502032301874605]]])

center = [-12.970856040836589, 24.40875404125726]

dataset = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED').filterDate('2021-01-01', '2021-12-30').filterBounds(AOI).filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',5)).map(clipImage).map(maskS2clouds)

s2_vis = dataset.median()

Max = s2_vis.select('SCL').reduceRegion(
        reducer = ee.Reducer.max(),
        geometry = AOI,
        scale =  20,
        maxPixels = 1e13)
print('Max Value is:')
print(Max.getInfo())

Min = s2_vis.select('SCL').reduceRegion(
        reducer = ee.Reducer.min(),
        geometry = AOI,
        scale =  20,
        maxPixels = 1e13)
print('Min Value is:')
print(Min.getInfo())

1 Answer 1

1

Your maskS2Clouds function divides the values of all bands, including SCL, by 10000 when it runs .divide(10000). Then, the .median() takes the median of all bands, including SCL.

To get meaningful integer SCL values you will need to avoid dividing them, or add the SCL band from the original image after dividing the others. Personally I would remove the divide(10000) from there and adjust your handling of the values later (e.g. in visualization parameters) to match.

Then you will also need to choose a different reducer for reducing the SCL band in the image collection — say, the mode reducer instead of median.

scl_image = dataset.select(['SCL']).mode()

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.