acolite / acolite

ACOLITE: generic atmospheric correction module
GNU General Public License v3.0
160 stars 63 forks source link

relative path for ac.config['data_dir'] #4

Closed sentinel3 closed 2 years ago

sentinel3 commented 3 years ago

Hello Vanhellemont, great effort to make this popular AC module open source! we tried it recently, and our student encountered an issue with error message: FileNotFoundError: [Errno 2] No such file or directory: 'data/RSR/S3A_OLCI.txt'

After tracing back the issue, I notice it is because in the config/config.txt, it default sets: data_dir=data, which is a relative path. when the program runs outside the installation folder, this relative data path cannot be found even if I manually update and add the acolite installation path to PYTHONPATH .

To solve this issue, I temporarily set data_dir=/absolute/path/to/data, which works

For a more permanent solution, I think it would be better to convert the relative paths to absolute paths in the scripts. For instance: sentinel3/l1_convert.py:59: rsr_file = ac.config['data_dir']+'/RSR/'+sensor+'.txt', modified to something like:

import os,pathlib
acolite_install_dir=pathlib.Path(__file__).parent.parent.parent.absolute()  #python2: os.path.dirname(os.path.abspath(__file__))
rsr_file = os.path.join(acolite_install_dir, ac.config['data_dir'], 'RSR', sensor+'.txt')

or even better, directly update the ac.config['data_dir'] during initiation such as in acolite_run.py?

hope this is helpful,

Chui Zeng Environment and Climate Change Canada

acolite commented 3 years ago

Hi Chui Zeng

Thanks for your message! The data directory is indeed a relative path in the config file, and was initiated as an absolute path in ac.config during the import if the relative path could not be found: https://github.com/acolite/acolite/blob/14532fa71e230e129bc7578ece593811130bd3f4/acolite/__init__.py

This did work for several years, and for many users on different platforms. I now think the issue occurs when you are launching acolite from another location that also has a "data" directory. The import then assumes you want to use that data directory instead of the one in acolite/data. This is quite a common directory name, so I am amused that it did not come up before! Maybe people are running acolite mostly from its own directory! :-)

As I do want people to be able to move their data directory, in the last commit I changed the import strategy, only using the paths from the config file if they are provided as absolute, otherwise it is assumed they are relative paths in the default acolite location.

Does this latest fix work for you?

Quinten

sentinel3 commented 3 years ago

Thank you Quinten for the quick response! It currently works with the absolute path I assigned it and our student is frequently using acolite remotely now, so I will test in our next update for this issue. thank you! Chui,

acolite commented 2 years ago

Hi Chui

I believe the last commit https://github.com/acolite/acolite/commit/ff54641945f5f3f1c3654533b8691448c2e44515 would fully resolve this issue.

Feel free to reopen the issue if the problem persists!

Quinten