Mask clouds in sentinel-3 OLCI data

I’m trying to download cloud free data from Sentinel-3 by exploiting the QUALITY-FLAGS bright condition (bit position 27).
This is the code I developed:

                    time_interval = ('2016-10-01T00:00:00.000000000', '2018-09-30T23:59:59.000000000')
                    roi_bbox = BBox(bbox=[10.6803682, 44.9699252, 10.830368199999999, 45.119925200000004], crs=CRS.WGS84)

                    indices_evalscript = """
                                            function setup() {
                                                return {
                                                    input: ["B17", "B08", "QUALITY_FLAGS"],
                                                        id: "bands",
                                                        bands: 2,
                                                        sampleType: SampleType.FLOAT32
                                                        id: "CLOUD_MASK",
                                                        bands: 1,
                                                        sampleType: SampleType.bool_
                                            function evaluatePixel(sample) {
                                                let cld = (sample.QUALITY_FLAGS & 134217728);
                                                return {
                                                   CLOUD_MASK: [cld],
                                                   bands: [sample.B17, sample.B08]

                    add_indices = SentinelHubEvalscriptTask(
                        features=[(FeatureType.DATA, "bands"),
                                  (FeatureType.MASK, "CLOUD_MASK")],
                    class AddValidDataMaskTask(EOTask):
                        def execute(self, eopatch):
                            eopatch.mask["VALID_DATA"] =  ~(eopatch.mask["CLOUD_MASK"])
                            return eopatch
                    input_node = EONode(add_indices)
                    filter_clouds = EONode(AddValidDataMaskTask(),inputs=[input_node])
                    output_node = EONode(OutputTask("final_eopatch"), inputs=[filter_clouds])
                    workflow = EOWorkflow([input_node, filter_clouds, output_node])
                    result = workflow.execute({input_node: {"bbox": roi_bbox, "time_interval": time_interval}})
                    eopatch_clean = result.outputs['final_eopatch']

I am probably doing something wrong, since I get this error

DownloadFailedException: Failed to download from:
with HTTPError:
400 Client Error: Bad Request for url:
Server response: "{"status": 400, "reason": "Bad Request", "message": "Script failed to return.", "code": "RENDERER_EXCEPTION"}"

Any clues as to why?

Hello Paolo,

the problem you have comes from your defined sampleType for the CLOUD_MASK input. The sampleType bool_ does not exist. For a list of all existing Sample Types see here: Evalscript V3

So if you replace this to SampleType.UINT8, your script should be working.

Thank you! Now it has been solved. But I have another issue now:
I would like to apply a coregistration to the obtained data:

                params = {'MaxIters': 500}
                coregister_ecc = ECCRegistrationTask((FeatureType.DATA, 'BANDS'), valid_mask_feature=(FeatureType.MASK, 'VALID_DATA'), channel=0, params=params)
                eopatch_ecc = coregister_ecc(eopatch_clean)

I got this error

error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\video\src\ecc.cpp:574: error: (-7:Iterations do not converge) NaN encountered. in function 'cv::findTransformECC'

This is due to the presence of NaN when my box contains the boundary of the the sentinel-3 tile (outside data are labelled as NaN). Is there a known solution to this problem?

You might want to try setting the NaN values to some defined NoData value beforehand (e.g. -9999). I am not sure how that might impact the coregistration but it is worth a try.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.