Retrieving Scene Classification from L2A in python

I’m trying to retrieve information about the L2A scene classification data based on the Sen2Cor algorithm using SentinelHubRequest from the sentinelhub python package. I would expect to get a number between 0 and 11, as described here. However, for every pixel I only get either 0 or 255.
I’m also trying to get the cloud and snow probabilities based on Sen2Cor. I would expect values between 0 and 100, but I again only get either 0 or 255.
I have to say that the masking seems to be done correctly (255 means cloud/snow on that pixel, 0 means that there isn’t), but it would be great if I could get the exact predicted values.

Below you can find both the evalscript that I’m using and the SentinelHubRequest definition.

evalscript_scl = """
    //VERSION=3

    function setup() {
        return {
            input: [{
                bands: ["SCL", "SNW", "CLD"]
            }],
            output: {
                bands: 3
            }
        };
    }

    function evaluatePixel(sample) {
        return [sample.SCL, sample.SNW, sample.CLD];
    }
"""

request = SentinelHubRequest(
        evalscript=evalscript_scl,
        input_data=[
            SentinelHubRequest.input_data(
                data_collection=DataCollection.SENTINEL2_L2A,
                time_interval=(timestamp - time_difference, timestamp + time_difference)
            )
        ],
        responses=[
            SentinelHubRequest.output_response('default', MimeType.PNG)
        ],
        bbox=bbox,
        size=bbox_to_dimensions(bbox, 10),
        config=config
    )

Any help in figuring out why I’m not getting the results I’m expecting would be great.

Thanks in advance!

There is just one missing, but crucial information: the output SampleType. By default, the output type is AUTO, where the service in this case obviously doesn’t work as expected. Changing your evalscript to:

evalscript_scl = """
    //VERSION=3

    function setup() {
        return {
            input: [{
                bands: ["SCL", "SNW", "CLD"]
            }],
            output: {
                bands: 3,
                sampleType: SampleType.UINT8
            }
        };
    }

    function evaluatePixel(sample) {
        return [sample.SCL, sample.SNW, sample.CLD];
    }
"""

will return scene classification values as expected.

1 Like

Ah thanks a lot! Just tried it, and works perfectly.