run_snow_detector.py 1.38 KB
Newer Older
1
2
#!/usr/bin/env python

3
import sys
4
import os.path as op
5
6
7
import json
from s2snow import snow_detector

8
9
VERSION = "1.2"

10
11

def show_help():
12
13
14
15
16
    """Show help of the run_snow_detector script"""
    print "This script is used to run the snow detector module that compute snow mask using OTB applications on Spot/LandSat/Sentinel-2 products from theia platform"
    print "Usage: python run_snow_detector.py param.json"
    print "python run_snow_detector.py version to show version"
    print "python run_snow_detector.py help to show help"
17

18

19
20
21
def show_version():
    print VERSION

22
23
# ----------------- MAIN ---------------------------------------------------

24
25
26
27

def main(argv):
    """ main script of snow extraction procedure"""

28
    json_file = argv[1]
29

30
    # Load json_file from json files
31
    with open(json_file) as json_data_file:
32
33
        data = json.load(json_data_file)

34
35
36
    general = data["general"]
    pout = general.get("pout")
    log = general.get("log", True)
37

38
39
40
    if log:
        sys.stdout = open(op.join(pout, "stdout.log"), 'w')
        sys.stderr = open(op.join(pout, "stderr.log"), 'w')
41

42
43
    sd = snow_detector.snow_detector(data)
    sd.detect_snow(2)
44

45
if __name__ == "__main__":
46
    if len(sys.argv) != 2:
47
48
49
50
51
52
53
54
        show_help()
    else:
        if sys.argv[1] == "version":
            show_version()
        elif sys.argv[1] == "help":
            show_help()
        else:
            main(sys.argv)