multiply-org / atmospheric_correction

Sentinel 2 and Landsat 8 Atmospheric correction
http://www2.geog.ucl.ac.uk/~ucfafyi/
GNU Affero General Public License v3.0
35 stars 11 forks source link

JP2 not recognized as a supported file format #16

Closed SFrav closed 4 years ago

SFrav commented 4 years ago

Using SIAC-V2.3.5 and GDAL 2.3.3 on a recent Sentinel 2 observation returns the following error: ... .jp2' not recognized as a supported file format.

This is returned after the following output: Doing per pixel angle resampling.

Do you have any suggestions on how to address this?

P.S. Thank you for contributing to open source EO tools. This has the potential to be quite useful for batch processing.

MarcYin commented 4 years ago

Hi,

This error generally comes from either gdal not compiled with jpg2000 driver or the jp2 file is corrupted. So, firstly please check the file is OK. If the file is OK, you will probably need to uninstall gdal first and reinstall gdal with conda install -c conda-forge gdal>2.1.

Thanks a lot for your testing of SIAC and it has been used to do large processing (thousands of files) on the UK Jasmin platform. If you have any issue of using it to do large scale processing, we are happy to help you to resolve it.

Marc.

SFrav commented 4 years ago

Hi Marc, Thanks for the speedy response.

I see the issue - I have a few versions of GDAL on my system and was looking at the formats in the OSGEO4W install, not the Anaconda virtual environment install. I've reinstalled gdal as you suggested above, but still no jpg2000 drivers. I'll try and start again with a new environment and see if that helps.

It should be an easy fix, so will mark as closed.

By the way, there was an extra dependency that I needed to install: gp_emulator

MarcYin commented 4 years ago

Hi, thanks a lot for the reminds and I will add it to the dependency list in the next version.

SFrav commented 4 years ago

All working well now. Just waiting on MCD43 downloads to test the correction. Thanks again

MarcYin commented 4 years ago

Hi, the downloading of MCD43 is bit slow, so for batch processing, you may consider to get hold of all the required MCD43 in the first place as earthdata.nasa.gov would only allow you to download 5 file at the same time.

SFrav commented 4 years ago

Maybe an issue to a gdal versioning, I have the following error: ERROR 1: TIFFRewriteDirectory:Error fetching directory count. This occurs towards the end of the function, after the output "Composing RGB".

I'm using gdal 2.2.2 and libgdal 2.2.2, in Python 3.6.

Two posts suggest that this is related to gdal

I thought it might be to do with gdal.Translate (in _compose_rgb, line 573 in the_correction.py), but gdal.Translate works well when testing in Python eg, this works: gdal.Translate('output.tif', input, format = 'PNG', widthPct=10, heightPct=10, resampleAlg=gdal.GRA_Bilinear).

Any suggestions would be appreciated. No rush - enjoy your weekend!

MarcYin commented 4 years ago

Hi, I saw this error appeared sometime (rarely) before but cannot find out the reason behind it. When I checked the composed RGB, they are all OK so it's bizarre. I have looked through the issues related to this, it seems that this error is likely to related to libtiff library used in gdal. So, again this is likely to be a gdal issue so maybe a fresh installation of gdal in a new environment is required to make sure that the libraries are compatible and up to date. Suggested gdal installation is with: conda update --all -c conda-forge conda install -c conda-forge gdal>2.1

SFrav commented 4 years ago

I've been trying a few different configurations this one progressed the furthest: conda env create --file=saic.yml #Using the environment yml on github conda activate siac conda install -c f0xy -c conda-forge siac conda update --all -c conda-forge conda install -c conda-forge "gdal>2.1" #Not needed as update does the job

It gave an error when doing pixel angle resampling File "C:\Users\Simon\Anaconda3\envs\siac\lib\site-packages\SIAC\s2_angle.py", line 316, in resample_s2_angles example_file = toa_refs[1] IndexError: list index out of range

Also, I noticed that the BOA_RGB.tif file was created from previous runs.

I'll keep at it...

MarcYin commented 4 years ago

Just realised that you are using Windows system, but the whole code is developed under linux platform and I have not tested it with a windows machine...It's good to know that it runs till composing RGB in your first run, so my suggestion of the installation would be:

conda env create --file=saic.yml #Using the environment yml on github
conda update --all -c conda-forge
conda activate siac
pip install gp_emulator # since it's missing
pip install https://github.com/MarcYin/SIAC/archive/master.zip
SFrav commented 4 years ago

Yes, I should have mentioned that I've been troubleshooting on a Windows machine. I tried on Arch Linux with pip, but didn't get that far.

After Composing RGB, I get a message saying that it's done.

This time I used pip and c++ build tools from visual studio. Using Python 3.6 in a virtual environment:

pip install -U pylibjpeg-openjpeg
pip install numpy==1.19.3 #error with 1.19.4
#Download gdal whl https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
pip install GDAL-3.1.4-cp36-cp36m-win_amd64.whl
pip install gp_emulator
pip install https://github.com/MarcYin/SIAC/archive/master.zip