sentinel2-cloud-detector
sentinel2-cloud-detector copied to clipboard
How to use Cloud-Detector on locally stored data
Hello, I am trying to use the Cloud-detector on locally stored S2-Images in .SAFE format. Do I have to resample the bands to have the same pixel-size etc. or is there a way to do this? I did not find any so far, any help is appreciated.
Thanks, Felix
There are already a couple of past issues with discussions about this and even some code:
- https://github.com/sentinel-hub/sentinel2-cloud-detector/issues/1
- https://github.com/sentinel-hub/sentinel2-cloud-detector/issues/4
- https://github.com/sentinel-hub/sentinel2-cloud-detector/issues/14
You are also welcome to contribute some code or an example notebook that would better showcase this use-case.
Hi, I am trying do the same of @kesslerf, this scene L1C_T22KFU_A030809_20230129T132230. I have used code @pksorensen (posted in #1) and I have received different layer mask then I was using WMS Requests. Using the images stored on the local disk, clouds were detected for the whole area. I Try to change resolution and same result. what could i be doing wrong?
I am not sure I am answering your question, but if you are comparing the cloud masks from Sentinel Hub service, and cloud masks computed from locally downloaded Sentinel-2 scene, they may be different because:
- WMS request is over smaller window
- WMS request could be retrieving data from different scene if time interval in the request is not precise enough
- WMS request could be in different coordinate reference system than the original Sentinel-2 image
- WMS request could be at different resolution than the original Sentinel-2 image
- WMS request might be returning data in different data type (e.g. uint8)
- WMS request automatically returns harmonised reflectances, while your Sentinel-2 image might have negative digital numbers, resulting in slightly different data (see https://forum.sentinel-hub.com/t/sentinel-2-processing-baseline-changes-and-harmonizevalues/4635)
That being said, even if the WMS request is done in a way that the results are identical to the Sentinel-2 image, the cloud mask (CLM band) from Sentinel-Hub service will be different from the one run locally because the CLM band is
- computed at 160 m/px resolution
- computed using different parameters for the cloud detector than the default values, and applies slightly different morphological operations to produce the final the map.
To come as close to the CLM band results using downloaded Sentinel-2 scene, the parameters should be: threshold=0.4, average_over=22, dilation_size=11
.
Does that answer your question?
Hi @batic. Thanks for replying, your answer was a great help. I discovered that the problem was in converting the DNs to reflectance values, the offset parameter was missing. In the scene I tested, RADIO_ADD_OFFSET is equal to 1000 for all bands. So Reflectance = (DN - 1000)/10000. Before I was using only DN/10000. I changed the values less than zero to zero as well. Doing this I got exactly the same values for the matrices, when compared with SentinelHub. Then I generated the cloud mask with the same parameters used by sentinelhub and got the same result.
Happy to hear that!