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

Running Python Fmask on Sentinel-2 data #14

Closed gillins closed 7 years ago

gillins commented 7 years ago

Original report by Felipe de Lucia Lobo (Bitbucket: FLLobo, ).


Hello,

I am trying to run fmask on python for the first time. I have installed phython_fmask in my computer just fine. However, when try the first command line (gdalbuildvrt -resolution user -tr 20 20 -separate allbands.vrt _B0[1-8].jp2 _B8A.jp2 _B09.jp2 _B1[0-2].jp2) it does not recognize the input file. I tried several forms for the input image file, no luck.

Two questions: 1) What folder in the image data should I call the function? the GRANULE one? 2) What is the standard input data format for gsalbuildvrt? For example: S2A_OPER_MSI_L1C_TL_SGS__20160305T231645_A003668_T19KHA_B01.jp2 ?

I am stuck here, any help, please? I am using Windows 10 OS.

thank you

Felipe

gillins commented 7 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Hi Felipe,

this is just a limitation with the Windows command line. The example command line was written to make sense for the Linux command line, and uses Linux's better wild card notation.

One of my colleagues wrote an extra utility to help with this, as noted near the top of the Command Line Examples section of the doco page (http://pythonfmask.org/en/latest/#command-line-examples).

So, if you use the following, I think it should work. You need to be in the folder which has the .jp2 files, which I think is GRANULE/IMG_DATA (from memory).

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

Let me know if this is what you needed.

Neil

gillins commented 7 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Correction:

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

gillins commented 7 years ago

Original comment by Felipe de Lucia Lobo (Bitbucket: FLLobo, ).


Hi Neil,

Thank you for the quick answer. When I call 'fmask_expandWildcards...' on Windows Command Prompt (already in IMG_DATA folder) it says that 'fmask_expandWildcards' is not recognized as an internal or external command, operable program or batch file.

But when I type only 'gdalbuildvrt' it gives me the usage parameters and notes normally. It seems it has been successfully installed but the command is not right. Any suggestion?

Thanks

gillins commented 7 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Hmmm... try it with fmask_expandWildcards.py.

I confess I never use Windows, so I have never tried this. I should fix it properly in the main commands, instead of needing this extra utility, but try this for now.

gillins commented 7 years ago

Original comment by Felipe de Lucia Lobo (Bitbucket: FLLobo, ).


Unfortunately, not. Perhaps, I messing up something. I will keep looking for solutions. Let me know if you have alternatives. Thanks

gillins commented 7 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


OK, the other alternative is just to give it each file name explicitly. The wild card patterns are just there to save typing. You can give a command with the .jp2 files in the order which the patterns would give, explicitly, and then it will work.

So, the order of the bands should be 1 2 3 4 5 6 7 8 8A 9 10 11 12 (but you are actually putting in each full .jp2 filename).

gillins commented 7 years ago

Original comment by Felipe de Lucia Lobo (Bitbucket: FLLobo, ).


Hi Neil,

I have tried that as in my first post. 'gdalbuildvrt -resolution user -tr 20 20 -separate allbands.vrt S2A_OPER_MSI_L1C_TL_SGS__20160305T231645_A003668_T19KHA_B01.jp2 etc' But it does not recognize the file "0...10...20...30...40...50...60...70...80...90...100 - done. ERROR 4: S2A...B01.jp2 not recognized as a supported file format."

gillins commented 7 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Hi Felipe,

OK, this is a separate problem, I think. This message is coming from GDAL, and indicates that the version of GDAL does not have the JPEG2000 driver included, or has the wrong variant. You can check this by doing

gdal_translate --long-usage

and see which JPEG2000 driver it has (if any). I know that the JP2OpenJPEG driver will work, but GDAL has a few others available, and I don't know if all of them are compatible with the jp2 files which ESA supplies.

Neil

gillins commented 7 years ago

Original comment by Felipe de Lucia Lobo (Bitbucket: FLLobo, ).


Hi Neil,

Yes, installing gdal as following worked (thanks to my friend Vitor):

conda create -n gdal2 -c conda-forge gdal activate gdal2

But on the following step: 'fmask_sentinel2makeAnglesImage.py' is not recognized as an internal or external command, operable program or batch file. I guess is a Windows issue here..

gillins commented 7 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Hi Felipe,

I think that means you will now need to re-install pythonfmask into that conda environment. Conda sets up the environment so that it manages everything in it, and does not know about things that were installed in a different environment.

OK, that sounds like you have got through the worst problems. I will mark this issue as closed, since I think we have now covered all the things that might have been going wrong in this case.

good luck Neil

gillins commented 7 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Seems like the main problems were in getting the environment right.