ubarsc / python-fmask

A set of command line utilities and Python modules that implement the ‘fmask’ algorithm
https://www.pythonfmask.org
GNU General Public License v3.0
75 stars 20 forks source link

A proposal to adapt Fmask for use in Google Earth Engine #42

Closed lopezvoliver closed 3 years ago

lopezvoliver commented 3 years ago

Hi all,

I would like to use Fmask with data in Google Earth Engine (GEE). Currently, only two algorithms have been integrated to GEE: ee.Algorithms.FMask.matchClouds, and ee.Algorithms.FMask.fillMinima. The Cloud Displacement Index algorithm for Sentinel-2 data is also available in GEE (see ee.Algorithms.Sentinel2.CDI).

It would be ideal if we could adapt the functions in python-fmask to be able to get the necessary inputs into the ee.Algorithms.FMask.matchClouds algorithm, i.e. the potential cloud and shadow mask images.

Does anyone have any experience using the GEE python API to do this?

I have been experimenting with this and so far have developed two functions in my python-fmask fork.

The first one creates the angles images for Sentinel-2 data (see notebook here):

fmask_demo_angles_img

The second function performs the potential cloud first pass (see notebook here) - including the use of the ee.Algorithms.Sentinel2.CDI function:

fmask_demo_reduced

If there is anyone interested in helping developing this, please let me know and I will create a pull request with what I have so far.

Also, if there is anyone who has successfully used the ee.Algorithms.FMask.matchClouds with Sentinel-2 L1C data in GEE without having to go through all this trouble, please share your solution!

gillins commented 3 years ago

@petescarth any thoughts on this... Have you played with cloud masking in Earth Engine?

neilflood commented 3 years ago

I know little about GEE, but looking at your code so far, it looks like there will end up being a fair amount of duplication. That scares me, as it implies that future maintenance would be double the work.

I note also a recent paper by the group at DLR (https://www.mdpi.com/2072-4292/13/1/137) which suggests that the Sen2Cor masks supplied by ESA are now perhaps better than Fmask. Are ESA's Sen2Cor masks already integrated into GEE?

I am not opposed, though - might be fun......

petescarth commented 3 years ago

Given the task here is to get the potential cloud and shadow mask images to run ee.Algorithms.FMask.matchClouds I'd tend to agree with @neilflood here, at least until testing shows that the FMask firstpass detection is better than the Sen2Cor or S2cloudless probabilities both of which are precomputed on Earth Engine.

That said, having a complete FMask flow on Earth Engine would help the community with cloud mask comparisons like the above and this (https://doi.org/10.3390/rs12081284) where FMask wins!

lopezvoliver commented 3 years ago

Thanks for the suggestions. For Sentinel2 there are indeed some cloud probabilities and related data already integrated (https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_CLOUD_PROBABILITY; QA60 band in https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2), so I'll work with these for now.

I might sporadically continue to experiment with this task as well (help is welcome of course). I'll let you know if I manage to do this.

neilflood commented 3 years ago

OK, I will close this issue for now, but feel free to re-open it if it seems appropriate.

I do agree with @petescarth that testing and comparing cloud and shadow masks is very hard and rarely very clear. My own tests on Sen2Cor masks have found they are often not as good as Fmask, but it does depend on where you look. They all have different strengths and weaknesses. Sadly, there are no really good solutions, only less bad solutions.

Good luck.