Sentinel-2 cloud mask with fmask

I am aware that this does not concern SNAP or sen2cor. I still post it here because more people working with Sentinel-2 frequent this forum than stackoverflow.

I’m trying to run fmask on a Sentinel-2 granule. I downloaded the 3.2 version of Windows stand alone software for Sentinel 2 from https://github.com/prs021/fmask When I try to run fmask by calling the FmaskMSI.exe through cmd from the folder containing the Sentinel-2 Granule (or from within the granule folder) i get the following error:

No L*MTL.txt header in the current folder!
Output argument "clr_pct" (and maybe others) not assigned during call to "autoFmask".
MATLAB:unassignedOutputs

TheL*MTL.txt suggests that its’s looking for a Landsat type product but i specifically point to the Sentinel-2 installation of fmask

How do i get fmask to run for Sentinel-2 data?

Good afternoon unnic,

I also use fmask, but the python-version:

http://pythonfmask.org/en/latest/
https://anaconda.org/rios/python-fmask

With this version I have no trouble.

Cheers, Merry Christmas and Happy New Year. :slight_smile:
Andreas

2 Likes

Could be that the standalone version of FmaskMSI has not been updated for the new Sentinel-2 naming conventions. I know that for FmaskMSI for Matlab, has not been updated for this, it will only take pre-December L1C products, and even then it is buggy. I will probably also use Fmask in the coming days, so I will see if I can recreate the issue.

1 Like

Ok, @unnic I have an update.

First of all, the error message is refers to Landsat because the Sentinel-2 standalone version is a in my opinion a minimalist implementation of the Landsat code. It uses the MATLAB Runtime, which allows people with out MATLAB (on which the original Fmask was made) to still run the code.

Anyway, I installed standalone Windows version of Fmask for Sentinel-2 and added it to my user environment variables. When running it I encountered the same error you had when running FmaskMSI.exe from the IMG_DATA folder. For me, the solution was simply to run FmaskMSI.exe one folder up, so that you are in the folder named after the granule you wish to process. For example, the command below (in cmd) worked:

H:\L1C\S2A_OPER_PRD_MSIL1C_PDMC_20160515T122731_R105_V20160515T052948_20160515T052948.SAFE\GRANULE\S2A_OPER_MSI_L1C_TL_MTI__20160515T091926_A004678_T43SGR_N02.02>FmaskMSI

However, I noticed you said you tried this and it didn’t work. So I tried it on post-December data and it gave me your error again. In other words, the standalone version of Fmask has not been updated to handle the new Sentinel-2 naming conventions. In fact, it only seems to work on pre-mid-August data, because I get another error after that date:

H:\L1C\S2A_OPER_PRD_MSIL1C_PDMC_20160824T211343_R105_V20160823T052652_20160823T053523.SAFE\GRANULE\S2A_OPER_MSI_L1C_TL_SGS__20160823T110255_A006108_T43SGR_N02.04>Fmask 3.2.1 beta version start …
Cloud, cloud shadow, and snow detection for Sentinel 2 (Landsat 8 images without TIRS scenario)
Cloud/cloud shadow/snow dilated by 3/3/0 pixels (default)
Cloud probability threshold of 22.50% (default)
Struct contents reference from a non-struct array object.
Error in Build_SunViewGeometry_MSI (line 159)
Error in nd2toarbt_msi (line 37)
Error in plcloud (line 41)
Error in Fmask (line 7)
Error in autoFmask (line 167)
MATLAB:structRefFromNonStruct

I believe this error is purely in MATLAB, I recall encountering it in the plain MATLAB version for Sentinel and it has something to do with the way struct data is read or handled (maybe changed in MATLAB 2016a update (which was released around August)). But the exact reason for why it does this differently for post-August data I don’t know. That said, this github thread seems to give some clues. I know it is an easy, but tedious fix in the MATLAB code, but not sure if that is possible or, indeed, desirable to do with the standalone version.

So as @abgbaumann recommended, I believe the python implementation is for Sentinel-2 the best way to go, because due to the way it is implemented is not affected by the naming convention change, plus it is fairly up-to-date. One thing I did notice, is that the output from the standalone and python version differed a fair amount, so that is worth noting.

Cheers

1 Like

@abgbaumann @pxv8780

I’m trying to run python fmask.
I the docs it’s stated that the command
fmask_sentinel2makeAnglesImage.py -i ../S2*.xml -o angles.img
needs to be executed.

In the current file format there are no files that match the query S2*.xml.
Present are: MTD_DS.xml, MTD_TL.xml, MTD_MSIL1C.xml, INSPIRE.xml where MTD_TL.xml seems to be the one that contains the required information. But none of the xmls work with fmask_sentinel2makeAnglesImage.py

It seems like the script assumes the old file format. How do you get the angles.img?

Good afternoon unnic.

Indeed it is still the old file format, but the XML just have new names. The xml file you are looking for would be:

in the GRANULE directory, the the tile directory: MTD_TL.xml (originally: S2A_USER_MTD_L2A_TL_SGS__20160727T160726_A005725_T31TEH.xml).

If you open it, then you can search for ‘angle’ in the file and you will see something like that:

<Tile_Angles metadataLevel="Standard">
  <Sun_Angles_Grid>
    <Zenith>
      <COL_STEP unit="m">5000</COL_STEP>
      <ROW_STEP unit="m">5000</ROW_STEP>
      <Values_List>
        <VALUES>27.9179 27.8927 27.8676 27.8425 27.8174 27.7924 27.7674 27.7424 27.7176 27.6927 27.6679 27.6431 27.6184 27.5937 27.5691 27.5445 27.52 27.4955 27.471 27.4466 27.4223 27.398 27.3737</VALUES>
        <VALUES>27.8796 27.8544 27.8292 27.8041 27.779 27.7539 27.7289 27.704 27.679 27.6542 27.6293 27.6045 27.5798 27.5551 27.5304 27.5058 27.4813 27.4567 27.4323 27.4078 27.3835 27.3591 27.3348</VALUES>
        <VALUES>27.8414 27.8161 27.7909 27.7657 27.7406 27.7155 27.6905 27.6655 27.6405 27.6156 27.5908 27.566 27.5412 27.5165 27.4918 27.4671 27.4425 27.418 27.3935 27.369 27.3446 27.3203 27.296</VALUES>
        <VALUES>27.8031 27.7778 27.7526 27.7274 27.7022 27.6771 27.652 27.627 27.602 27.5771 27.5522 27.5274 27.5026 27.4778 27.4531 27.4285 27.4038 27.3793 27.3547 27.3303 27.3058 27.2814 27.2571</VALUES>
        <VALUES>27.7648 27.7395 27.7143 27.689 27.6639 27.6387 27.6136 27.5886 27.5636 27.5386 27.5137 27.4888 27.464 27.4392 27.4145 27.3898 27.3652 27.3406 27.316 27.2915 27.267 27.2426 27.2183</VALUES>
        <VALUES>27.7266 27.7013 27.676 27.6507 27.6255 27.6004 27.5752 27.5502 27.5251 27.5001 27.4752 27.4503 27.4255 27.4006 27.3759 27.3512 27.3265 27.3019 27.2773 27.2528 27.2283 27.2038 27.1794</VALUES>
        <VALUES>27.6884 27.663 27.6377 27.6124 27.5872 27.562 27.5369 27.5118 27.4867 27.4617 27.4367 27.4118 27.3869 27.3621 27.3373 27.3125 27.2878 27.2632 27.2386 27.214 27.1895 27.165 27.1406</VALUES>
        <VALUES>27.6502 27.6248 27.5995 27.5742 27.5489 27.5237 27.4985 27.4734 27.4483 27.4232 27.3982 27.3733 27.3484 27.3235 27.2987 27.2739 27.2492 27.2245 27.1999 27.1753 27.1508 27.1263 27.1018</VALUES>
        <VALUES>27.612 27.5866 27.5612 27.5359 27.5106 27.4853 27.4601 27.435 27.4099 27.3848 27.3598 27.3348 27.3099 27.285 27.2601 27.2353 27.2106 27.1859 27.1612 27.1366 27.112 27.0875 27.063</VALUES>
        <VALUES>27.5739 27.5484 27.523 27.4976 27.4723 27.447 27.4218 27.3966 27.3715 27.3464 27.3213 27.2963 27.2714 27.2465 27.2216 27.1968 27.172 27.1472 27.1226 27.0979 27.0733 27.0488 27.0243</VALUES>
        <VALUES>27.5357 27.5102 27.4848 27.4594 27.4341 27.4088 27.3835 27.3583 27.3331 27.308 27.2829 27.2579 27.2329 27.208 27.1831 27.1582 27.1334 27.1086 27.0839 27.0592 27.0346 27.01 26.9855</VALUES>
        <VALUES>27.4976 27.4721 27.4466 27.4212 27.3958 27.3705 27.3452 27.32 27.2948 27.2696 27.2445 27.2195 27.1944 27.1695 27.1445 27.1197 27.0948 27.07 27.0453 27.0206 26.9959 26.9713 26.9468</VALUES>
        <VALUES>27.4595 27.4339 27.4084 27.383 27.3576 27.3322 27.3069 27.2817 27.2564 27.2313 27.2061 27.181 27.156 27.131 27.106 27.0811 27.0563 27.0315 27.0067 26.982 26.9573 26.9326 26.9081</VALUES>
        <VALUES>27.4214 27.3958 27.3703 27.3448 27.3194 27.294 27.2687 27.2434 27.2181 27.1929 27.1678 27.1426 27.1176 27.0925 27.0676 27.0426 27.0177 26.9929 26.9681 26.9433 26.9186 26.894 26.8694</VALUES>
        <VALUES>27.3833 27.3577 27.3322 27.3067 27.2812 27.2558 27.2304 27.2051 27.1798 27.1546 27.1294 27.1043 27.0792 27.0541 27.0291 27.0041 26.9792 26.9543 26.9295 26.9047 26.88 26.8553 26.8307</VALUES>
        <VALUES>27.3452 27.3196 27.294 27.2685 27.243 27.2176 27.1922 27.1668 27.1415 27.1163 27.0911 27.0659 27.0408 27.0157 26.9906 26.9657 26.9407 26.9158 26.891 26.8661 26.8414 26.8167 26.792</VALUES>
        <VALUES>27.3072 27.2815 27.2559 27.2304 27.2049 27.1794 27.154 27.1286 27.1033 27.078 27.0527 27.0275 27.0024 26.9773 26.9522 26.9272 26.9022 26.8773 26.8524 26.8276 26.8028 26.778 26.7534</VALUES>
        <VALUES>27.2692 27.2435 27.2179 27.1923 27.1667 27.1412 27.1158 27.0904 27.065 27.0397 27.0144 26.9892 26.964 26.9389 26.9138 26.8887 26.8637 26.8388 26.8139 26.789 26.7642 26.7394 26.7147</VALUES>
        <VALUES>27.2312 27.2055 27.1798 27.1542 27.1286 27.1031 27.0776 27.0522 27.0268 27.0014 26.9761 26.9509 26.9257 26.9005 26.8754 26.8503 26.8253 26.8003 26.7754 26.7505 26.7256 26.7008 26.6761</VALUES>
        <VALUES>27.1932 27.1674 27.1418 27.1161 27.0905 27.065 27.0395 27.014 26.9886 26.9632 26.9379 26.9126 26.8874 26.8622 26.837 26.8119 26.7869 26.7618 26.7369 26.712 26.6871 26.6623 26.6375</VALUES>
        <VALUES>27.1552 27.1294 27.1037 27.0781 27.0524 27.0269 27.0013 26.9758 26.9504 26.925 26.8996 26.8743 26.849 26.8238 26.7986 26.7735 26.7484 26.7234 26.6984 26.6735 26.6486 26.6237 26.5989</VALUES>
        <VALUES>27.1173 27.0915 27.0657 27.04 27.0144 26.9888 26.9632 26.9377 26.9122 26.8868 26.8614 26.836 26.8108 26.7855 26.7603 26.7351 26.71 26.685 26.6599 26.635 26.61 26.5852 26.5603</VALUES>
        <VALUES>27.0793 27.0535 27.0277 27.002 26.9763 26.9507 26.9251 26.8995 26.874 26.8486 26.8232 26.7978 26.7725 26.7472 26.722 26.6968 26.6716 26.6465 26.6215 26.5965 26.5715 26.5466 26.5218</VALUES>
      </Values_List>
    </Zenith>
    <Azimuth>
      <COL_STEP unit="m">5000</COL_STEP>
      <ROW_STEP unit="m">5000</ROW_STEP>
      <Values_List>
        <VALUES>145.38 145.491 145.602 145.713 145.825 145.936 146.048 146.159 146.271 146.383 146.495 146.608 146.72 146.832 146.945 147.058 147.171 147.284 147.397 147.51 147.624 147.737 147.851</VALUES>
        <VALUES>145.337 145.448 145.559 145.671 145.782 145.893 146.005 146.117 146.229 146.341 146.453 146.565 146.677 146.79 146.902 147.015 147.128 147.241 147.354 147.468 147.581 147.695 147.808</VALUES>
        <VALUES>145.294 145.405 145.516 145.628 145.739 145.85 145.962 146.074 146.186 146.298 146.41 146.522 146.634 146.747 146.86 146.972 147.085 147.198 147.312 147.425 147.538 147.652 147.766</VALUES>
        <VALUES>145.251 145.362 145.473 145.585 145.696 145.807 145.919 146.031 146.143 146.255 146.367 146.479 146.592 146.704 146.817 146.93 147.043 147.156 147.269 147.382 147.496 147.609 147.723</VALUES>
        <VALUES>145.208 145.319 145.43 145.541 145.653 145.764 145.876 145.988 146.1 146.212 146.324 146.436 146.549 146.661 146.774 146.887 147 147.113 147.226 147.339 147.453 147.566 147.68</VALUES>
        <VALUES>145.165 145.276 145.387 145.498 145.61 145.721 145.833 145.944 146.056 146.168 146.281 146.393 146.505 146.618 146.731 146.843 146.956 147.07 147.183 147.296 147.41 147.523 147.637</VALUES>
        <VALUES>145.121 145.232 145.343 145.455 145.566 145.678 145.789 145.901 146.013 146.125 146.237 146.35 146.462 146.575 146.687 146.8 146.913 147.026 147.14 147.253 147.366 147.48 147.594</VALUES>
        <VALUES>145.078 145.189 145.3 145.411 145.523 145.634 145.746 145.858 145.97 146.082 146.194 146.306 146.419 146.531 146.644 146.757 146.87 146.983 147.096 147.21 147.323 147.437 147.551</VALUES>
        <VALUES>145.034 145.145 145.256 145.368 145.479 145.59 145.702 145.814 145.926 146.038 146.15 146.263 146.375 146.488 146.6 146.713 146.826 146.939 147.053 147.166 147.28 147.393 147.507</VALUES>
        <VALUES>144.99 145.101 145.212 145.324 145.435 145.547 145.658 145.77 145.882 145.994 146.107 146.219 146.331 146.444 146.557 146.67 146.783 146.896 147.009 147.123 147.236 147.35 147.464</VALUES>
        <VALUES>144.946 145.057 145.168 145.28 145.391 145.503 145.615 145.726 145.838 145.95 146.063 146.175 146.288 146.4 146.513 146.626 146.739 146.852 146.965 147.079 147.192 147.306 147.42</VALUES>
        <VALUES>144.902 145.013 145.124 145.236 145.347 145.459 145.57 145.682 145.794 145.906 146.019 146.131 146.244 146.356 146.469 146.582 146.695 146.808 146.922 147.035 147.149 147.262 147.376</VALUES>
        <VALUES>144.858 144.969 145.08 145.192 145.303 145.415 145.526 145.638 145.75 145.862 145.975 146.087 146.2 146.312 146.425 146.538 146.651 146.764 146.878 146.991 147.105 147.219 147.332</VALUES>
        <VALUES>144.814 144.925 145.036 145.147 145.259 145.37 145.482 145.594 145.706 145.818 145.93 146.043 146.155 146.268 146.381 146.494 146.607 146.72 146.834 146.947 147.061 147.174 147.288</VALUES>
        <VALUES>144.769 144.88 144.991 145.103 145.214 145.326 145.438 145.549 145.661 145.774 145.886 145.998 146.111 146.224 146.337 146.45 146.563 146.676 146.789 146.903 147.016 147.13 147.244</VALUES>
        <VALUES>144.724 144.836 144.947 145.058 145.17 145.281 145.393 145.505 145.617 145.729 145.841 145.954 146.066 146.179 146.292 146.405 146.518 146.632 146.745 146.858 146.972 147.086 147.2</VALUES>
        <VALUES>144.68 144.791 144.902 145.013 145.125 145.237 145.348 145.46 145.572 145.684 145.797 145.909 146.022 146.135 146.248 146.361 146.474 146.587 146.7 146.814 146.928 147.042 147.155</VALUES>
        <VALUES>144.635 144.746 144.857 144.969 145.08 145.192 145.303 145.415 145.527 145.64 145.752 145.865 145.977 146.09 146.203 146.316 146.429 146.542 146.656 146.769 146.883 146.997 147.111</VALUES>
        <VALUES>144.59 144.701 144.812 144.924 145.035 145.147 145.259 145.37 145.483 145.595 145.707 145.82 145.932 146.045 146.158 146.271 146.384 146.498 146.611 146.725 146.838 146.952 147.066</VALUES>
        <VALUES>144.545 144.656 144.767 144.878 144.99 145.102 145.213 145.325 145.437 145.55 145.662 145.775 145.887 146 146.113 146.226 146.339 146.453 146.566 146.68 146.793 146.907 147.021</VALUES>
        <VALUES>144.499 144.61 144.722 144.833 144.945 145.056 145.168 145.28 145.392 145.505 145.617 145.729 145.842 145.955 146.068 146.181 146.294 146.408 146.521 146.635 146.748 146.862 146.976</VALUES>
        <VALUES>144.454 144.565 144.676 144.788 144.899 145.011 145.123 145.235 145.347 145.459 145.572 145.684 145.797 145.91 146.023 146.136 146.249 146.362 146.476 146.59 146.703 146.817 146.931</VALUES>
        <VALUES>144.408 144.519 144.631 144.742 144.854 144.965 145.077 145.189 145.301 145.414 145.526 145.639 145.751 145.864 145.977 146.09 146.204 146.317 146.431 146.544 146.658 146.772 146.886</VALUES>
      </Values_List>
    </Azimuth>

Or does it not have the information inside? Did you try an other dataset too?

Cheers,
Andreas

I tried that .xml.

using the cmd command
fmask_sentinel2makeAnglesImage.py -i MTD_TL.xml -o angles.img
i get no error, no output (just the options of the .py listed)

directly calling it through python python fmask_sentinel2makeAnglesImage.py -i MTD_TL.xml -o angles.img
returns a numpy error

    RuntimeWarning: invalid value encountered in rint
  return round(decimals, out)

edit: ok, with the second command the angles.img is still created despite the warning. fmask_sentinel2Stacked.py seems to be working as well

1 Like

@abgbaumann

is the fmask output the same as in other implementations

0 => clear land pixel

1 => clear water pixel

2 => cloud shadow

3 => snow

4 => cloud

255 => no observation

I get extensive areas that seem clear land to me classified as cloud shadow, with no clear land in the whole image left.

Hello unnic

No, the codes are a little bit different. See in the printscreen of http://pythonfmask.org/en/latest/fmask_fmask.html?highlight=output Shadow is truely often too pessimistic. I think it is in relation that out of S-2 no cloud height can be computed (missing thermal band). Because of that a default value is used (I found it once, but can not find the source anymore) and all the shadows look bigger than they actually are.

Cheers,
Andreas

thank you, I’ve been looking for that page and missed it somehow.

I get an output resolution of 26.15385 meters. Even if I run fmask on 10m res data on input.
Is that normal behaviour or am I missing any settings?

There I have no clue if this is a normal behaviour. I did not check this until now, because I was usually only interested in the cloud layer, and therefore I never checked the actual resolution. But did you clarify the 10m resolution in the first command prompt?

gdalbuildvrt -resolution user -tr 10 10 -separate allbands.vrt S2*_B0[1-8].jp2 S2*_B8A.jp2 S2*_B09.jp2 S2*_B1[0-2].jp2

1 Like

that did it, thanks.

Unfortunately the cloud & shadow detection doesn’t seem to be working that well. Especially when taking into account the processing time comparing to the SCL product.

I have done separate tests with the Python version and Matlab version, the Python version takes much longer 30-60 minutes and is much worse quality. Matlab version is faster and better classfication. The classes are as mentioned above different per implementation:

Python classes
0 - null
1 - clear
2 - cloud
3 - shadow
4 - snow
5 - water
input dimensions - same as L1C product
output dimensions - 10980 x 10980 (using gdalbuildvrt resolution “-tr 10 10” tag)

Matlab (Sentinel2 Version) classes
0 - clear
1 - water
2 - shadow
3 - snow
4 - cloud
5 - thin/cirrus clouds
255 - null
input dimensions - same as L1C product
output dimensions - 5490 x 5490

I managed to make a fix with the Matlab version if you are interested, it requires the Matlab version, because you can’t change it in the Standalone version.

1 Like

Thanks for confirming.
I don’t have a Matlab lincence.
Maybe you can still post your solution somwhere for other people to access (and maybe one of them creates a new standalone :wink: )

Hi there,
thanks for sharing your experiences with fmask on Sentinel-2 images. I found the conversation very interesting!

@pxv8780: Could you please specify what exactly “worse quality” means when referring to fmask-python in contrast to fmask-Matlab? Unfortunately I don’t have Matlab and would like to know if/how I should use fmask-python.

I am comparing the Sen2Cor-Cloudmask and fmask-python at the moment. I processed several S2A tiles from Northern & Southern Europe as well as India (old & new S2 file format). Technically all worked fine so far. I made the experience that both are different but usable under bright conditions.

Under “dark” winter conditions in Northern Europe fmask-python doesn’t behave as expected though. It seems to classify the whole tiles as cloudy even if they are mainly clear. It’s the same on all tiles tested so far. Seems to be related to the illumination conditions. Does anybody have similar experiences?

Cheers

Hi @fschlenz

It is a bit hard to explain, but as I understand it the Python version is a complete recoding of the Fmask paper and therefore does not use any of the Fmask author’s original Matlab code, the Matlab version for Sentinel is simply the Landsat version made compatible with Sentinel. So the Matlab version is closer to the original.

But a couple things I notice, the Python version takes significantly longer 1-2 hours (at 10m resolution) vs 2-3 minutes of Matlab (note: the Matlab version is always 20m resolution). I haven’t tested Python at lower resolutions. In some extreme cases the Python version for my data marks the image as 100% cloud cover, when the Matlab version is around 30%… So that is a clear error.

The data I am using to test this data is not ideal, but that was my intention. (North India)

Here is a image for comparison… you can see that neither are perfect, but Fmask matlab seems more consistent.

Hope that helps.

As for the Matlab code change, in reply to @unnic

In the file Build_SunViewGeometry_MSI.m around lines 155 to 200 or so, you need to alternate between the following code depending on if it is before or after August 2016, but this seems to work for most of my data.

Pre-August:

%%%%%% PRE-AUGUST
   if length(S)==1
     DetectFootPrint.Ndect(1) = str2num(S(1).eop_colon_MaskFeature.Attributes.gml_colon_id(24:25));
     disp('attention')
     DetectFootPrint.Nband(1) = find(strcmp(bandIdList, S(1).eop_colon_MaskFeature.Attributes.gml_colon_id(21:22)));
     Vect = str2num(S(1).eop_colon_MaskFeature.eop_colon_extentOf.gml_colon_Polygon.gml_colon_exterior.gml_colon_LinearRing.gml_colon_posList.Text);
     Vect = reshape(Vect' , [3 length(Vect)/3 ])';
     DetectFootPrint.Data{1,1} = Vect ;
     %     Z = MSIinfo.Angles.VZA(:,:,MSIinfo.Angles.bandIdList==DetectFootPrint.Nband(1),MSIinfo.Angles.DeteIdList==DetectFootPrint.Ndect(1)) ;
   else
     if Pppplot == 1
       figure
       hold on
       sym = 'oxoxoxoxox';
     end
     for i = 1:length(S)
       DetectFootPrint.Ndect(i,1) = str2num(S{i}.eop_colon_MaskFeature.Attributes.gml_colon_id(24:25));
       %       DetectFootPrint.Nband(i,1) = strcmp(MSIinfo.bandIdList , S{i}.eop_colon_MaskFeature.Attributes.gml_colon_id(21:22));
       DetectFootPrint.Nband(i,1) = strcmp(bandIdList , S{i}.eop_colon_MaskFeature.Attributes.gml_colon_id(21:22));
       
       Vect = str2num(S{i}.eop_colon_MaskFeature.eop_colon_extentOf.gml_colon_Polygon.gml_colon_exterior.gml_colon_LinearRing.gml_colon_posList.Text);
       Vect = reshape(Vect' , [3 length(Vect)/3 ])';
       DetectFootPrint.Data{i,1} = Vect ;
       if Pppplot == 1
         
         IDX = knnsearch(X10m,DetectFootPrint.Data{i,1}(:,1));
         Ximg = X10m(IDX);
         IDX = knnsearch(Y10m,DetectFootPrint.Data{i,1}(:,2));
         Yimg = Y10m(IDX);
         plot(Ximg,Yimg,'k')
         Z = MSIinfo.Angles.VAA(:,:,MSIinfo.Angles.bandIdList==DetectFootPrint.Nband(i),MSIinfo.Angles.DeteIdList==DetectFootPrint.Ndect(i)) ;
         scatter(X5kmat(:),Y5kmat(:),30,Myreshape(Z),sym(i))
       end
     end
   end
   %   axis image
%%%%%% END PRE-AUGUST

Post-August:

    %%%%%% POST-AUGUST
      if length(S.eop_colon_MaskFeature)==1
        DetectFootPrint.Ndect(1) = str2num(S.eop_colon_MaskFeature.Attributes.gml_colon_id(24:25));
        disp('attention')
        DetectFootPrint.Nband(1) = find(strcmp(bandIdList, S.eop_colon_MaskFeature.Attributes.gml_colon_id(21:22)));
        Vect = str2num(S(1).eop_colon_MaskFeature.eop_colon_extentOf.gml_colon_Polygon.gml_colon_exterior.gml_colon_LinearRing.gml_colon_posList.Text);
        Vect = reshape(Vect' , [3 length(Vect)/3 ])';
        DetectFootPrint.Data{1,1} = Vect ;
        %     Z = MSIinfo.Angles.VZA(:,:,MSIinfo.Angles.bandIdList==DetectFootPrint.Nband(1),MSIinfo.Angles.DeteIdList==DetectFootPrint.Ndect(1)) ;
      else
        if Pppplot == 1
          figure
          hold on
          sym = 'oxoxoxoxox';
        end
        for i = 1:length(S.eop_colon_MaskFeature)
          DetectFootPrint.Ndect(i,1) = str2num(S.eop_colon_MaskFeature{i}.Attributes.gml_colon_id(24:25));
          %       DetectFootPrint.Nband(i,1) = strcmp(MSIinfo.bandIdList , S{i}.eop_colon_MaskFeature.Attributes.gml_colon_id(21:22));
          DetectFootPrint.Nband(i,1) = strcmp(bandIdList , S.eop_colon_MaskFeature{i}.Attributes.gml_colon_id(21:22));
          
          Vect = str2num(S.eop_colon_MaskFeature{i}.eop_colon_extentOf.gml_colon_Polygon.gml_colon_exterior.gml_colon_LinearRing.gml_colon_posList.Text);
          Vect = reshape(Vect' , [3 length(Vect)/3 ])';
          DetectFootPrint.Data{i,1} = Vect ;
          if Pppplot == 1
            
            IDX = knnsearch(X10m,DetectFootPrint.Data{i,1}(:,1));
            Ximg = X10m(IDX);
            IDX = knnsearch(Y10m,DetectFootPrint.Data{i,1}(:,2));
            Yimg = Y10m(IDX);
            plot(Ximg,Yimg,'k')
            Z = MSIinfo.Angles.VAA(:,:,MSIinfo.Angles.bandIdList==DetectFootPrint.Nband(i),MSIinfo.Angles.DeteIdList==DetectFootPrint.Ndect(i)) ;
            scatter(X5kmat(:),Y5kmat(:),30,Myreshape(Z),sym(i))
          end
        end
      end
      
    %%%%%%%% END POST-AUGUST

The main cause of the error was the way the directory/struct in Matlab was read, for example, in pre-August it might have been 1 folder with 12 files, post-August it turned into 12 folders with 1 file each… or something like that.

Cheers

1 Like

Thanks for sharing your results @pxv8780!
This is very interesting! It fits perfectly to my results. All winter scenes I processd from Northern Europe get 100% cloud cover by Fmask-python, even if mostly clear. On summer scenes Fmask-python looks really good (mostly comparable or better than Sen2Cor). Also in India.

The largely increased processing time is weird.

If both Fmask-versions are so different it doesn’t look like Fmask-python can be used as is. I am wondering wether this is really an error or only something that has to do with configuration…

Do you have experience with configuring Fmask-python? Especially the “cloud probability threshold” mentioned on the official Fmask website (https://github.com/prs021/fmask). I don’t find it in fmask-python…

I don’t have much experience with cloud probability threshold, I know there are some things you can configure in the Python Fmask, but I think you have to get into the code to do that. Atm, I don’t have time to do that. As for cloud probability threshold with Fmask Matlab, I use the default setting, because even though they may not be ideal, it removed a parameter and gives consistency when comparing results from multiple scenes.

Hi there,

just to let you know: I am discussing the Fmask-python issue (100% cloud coverage in partly clear high latitude winter Sentinel-2 images) with the developer here: https://bitbucket.org/chchrsc/python-fmask/issues/11/100-clouds-in-mostly-clear-s2-images-under.

He has offered support on this…

2 Likes

Hello everyone,

I see lots of people talking about Fmask (the python one). So i just decided to use it.
But i’m a totall newbie in python…
I use Anaconda to install the different package and run the Fmask.
And i am now stuck with my file wich i would try to visualize (the file is in .img format).

Did someone know how to handle this ? And maybe get a .jp2 instead of the .img ?
I already try to the ‘output.img’ by ‘output.jp2’ seems to doesn’t work…

Any help would be appreciate, thank you.