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
74 stars 21 forks source link

FloatingPointError when running fmask-python #78

Closed paolodeidda closed 1 month ago

paolodeidda commented 1 month ago

Hello, I am writing since I have been trying to use python-fmask but when I run the code I get a FloatingPointError: overflow encountered in scalar subtract.

These are the steps I followed:

I installed the package with mamba: mamba create -n fmask_env python-fmask

I used the package from the command line: fmask_sentinel2Stacked -o S2A_20210103_T32TPS_cloud_mask.img --safedir ./temp/S2A_MSIL1C_20210103T101411_N0209_R022_T32TPS_20210103T111051.SAFE

And the output I got is:

0...10...20...30...40...50...60...70...80...90...100 - done.
Traceback (most recent call last):
  File "/home/pdeidda/mambaforge/envs/fmask_env/bin/fmask_sentinel2Stacked", line 11, in <module>
    sys.exit(mainRoutine())
             ^^^^^^^^^^^^^
  File "/home/pdeidda/mambaforge/envs/fmask_env/lib/python3.12/site-packages/fmask/cmdline/sentinel2Stacked.py", line 386, in mainRoutine
    fmask.doFmask(fmaskFilenames, fmaskConfig)
  File "/home/pdeidda/mambaforge/envs/fmask_env/lib/python3.12/site-packages/fmask/fmask.py", line 196, in doFmask
    interimShadowmask = matchShadows(fmaskConfig, interimCloudmask, 
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pdeidda/mambaforge/envs/fmask_env/lib/python3.12/site-packages/fmask/fmask.py", line 1153, in matchShadows
    matchedShadowNdx = matchOneShadow(cloudmask, shadowEntry, potentialShadow, Tcloudbase, 
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pdeidda/mambaforge/envs/fmask_env/lib/python3.12/site-packages/fmask/fmask.py", line 1267, in matchOneShadow
    r = row0 - rowOff
        ~~~~~^~~~~~~~
FloatingPointError: overflow encountered in scalar subtract

I got the same error using the package from a python script, as well as with different S2 images.

I was wondering if you had already encountered this error and if you have any ideas on how to solve it (I will keep working on it and update and close this issue in case I find a solution).

Thanks in advance, Paolo

neilflood commented 1 month ago

Hi @paolodeidda

Thanks. No, I have not seen that one before, but it looks serious.

I wondered whether this is a very recent installation? As of yesterday, conda-forge now defaults to numpy-2.0, and I am just now doing some checking of this, and finding that there are some changes I had not anticipated, which will need to be fixed. This may be related, or not.

So, what versions of numpy, gdal and rios are installed with fmask?

paolodeidda commented 1 month ago

Hi @neilflood, thank you very much for your quick reply.

In the conda environment I have:

I leave attached the list of packages installed with fmask (I renamed it from .yml to .txt). Paolo fmask_env.txt

neilflood commented 1 month ago

OK, thanks. My guess is that this problem is related to numpy-2.0, and I will need to fix something. Until then, I suggest that you work with the numpy==1.26.4. If that does not work, please let me know.

paolodeidda commented 1 month ago

Thanks a lot! I have just tried with downgraded numpy and it works. I will then close the issue. Thank you very much again, Paolo

neilflood commented 3 weeks ago

Hi @paolodeidda

Just letting you know that the updated version of python-fmask is now available on conda-forge. I fixed the problem you were having with numpy-2, and everything now seems fine again.

Thanks again for bringing it to my attention, much appreciated.