forked from acolite/acolite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch_acolite.py
84 lines (70 loc) · 2.92 KB
/
launch_acolite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
## wrapper to launch ACOLITE GUI/CLI
## QV 2018
## last modifications QV 2018-09-12 renamed from acolite.py and added main test
## QV 2019-02-21 ignore numpy errors
## QV 2021-01-05 added freeze_support call for binary GUI
## QV 2021-04-01 updated for generic ACOLITE
## QV 2021-05-19 added print of import errors
## QV 2022-04-14 added agh
def launch_acolite():
## need to run freeze_support for PyInstaller binary generation
from multiprocessing import Process, freeze_support
freeze_support()
## import sys to parse arguments
import sys, os
import datetime
import argparse
## import acolite source
try:
import acolite as ac
except:
print('Could not import ACOLITE source')
print("Error:", sys.exc_info())
return()
try:
from osgeo import ogr,osr,gdal
except:
print('Could not import osgeo')
print("Error:", sys.exc_info())
return()
## fix matplotlib backend to Agg
## skip import if --nogfx is given
if not (('--cli' in sys.argv) & ('--nogfx' in sys.argv)):
import matplotlib
matplotlib.use("Agg")
## run command line if --cli provided, otherwise use gui
parser = argparse.ArgumentParser(description='ACOLITE')
parser.add_argument('--settings', help='settings file', default=None)
parser.add_argument('--settings_agh', help='settings file for agh', default=None)
parser.add_argument('--inputfile', help='list of images', default=None)
parser.add_argument('--output', help='output directory', default=None)
parser.add_argument('--sensor', help='comma separated sensor list for LUT retrieval', default=None)
args, unknown = parser.parse_known_args()
if '--retrieve_luts' in sys.argv:
ac.acolite.acolite_luts(sensor=args.sensor)
return()
## run AGH
if args.settings_agh is not None:
import acolite.gee
acolite.gee.agh_run(settings=args.settings_agh, acolite_settings=args.settings)
return()
## command line processing, run acolite_run directly
if '--cli' in sys.argv:
time_start = datetime.datetime.now() ## time of processing start
## add input/output if changed
inputfile, output = None, None
if args.inputfile is not None: inputfile = args.inputfile.split(',')
if args.output is not None: output = args.output
## run processing
if args.settings is None:
print('No settings file given')
return()
if not os.path.exists(args.settings):
print('Settings file {} does not exist.'.format(args.settings))
return()
ac.acolite.acolite_run(args.settings, inputfile=inputfile, output=output)
else:
ret = ac.acolite.acolite_gui(sys.argv, version=ac.version)
return()
if __name__ == '__main__':
launch_acolite()