build_json.py 1.81 KB
Newer Older
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
#!/usr/bin/env python

import sys
import os.path as op
import json
import argparse

def show_help():
    """Show help of the build_json script for theia N2A products"""
    print "This script is used to build json configuration file use then to compute snow mask using OTB applications on Spot/LandSat/Sentinel-2 products from theia platform"
    print "Usage: python build_theia_json -s [landsat|s2|take5] -d image_directory -e srtm_tile -o file.json"
    print "python run_snow_detector.py help to show help"


#----------------- MAIN ---------------------------------------------------

def main():
    """ Script to build json from theia N2A product"""

    parser = argparse.ArgumentParser(description='Build json from THEIA product')

    parser.add_argument("-s", help="select input sensors")
    parser.add_argument("-d", help="input dir")
    parser.add_argument("-o", help="input dir")
    parser.add_argument("-do", help="input dir")

    args = parser.parse_args()
    
    #print(args.accumulate(args.integers))

    #Parse sensor
    if (args.s == 's2'):
        multi=10
    #Build json file
    data = {}

    data["general"]={
        "pout":args.do,
        "nodata":-10000,
        "ram":1024,
	"nb_threads":1,
	"generate_vector":"false",
	"preprocessing":"false",
	"log":"true",
	"multi":10
    }

    data["cloud"]={
        "shadow_mask":32,
        "all_cloud_mask":1,
        "high_cloud_mask":128,
        "rf":12,
        "red_darkcloud":500,
        "red_backtocloud":100
    }
    data["snow"]={
        "dz":100,
        "ndsi_pass1":0.4,
        "red_pass1":200,
        "ndsi_pass2":0.15,
        "red_pass2":120,
        "fsnow_lim":0.1,
        "fsnow_total_lim":0.001
    }
    
    fp = open(args.o, 'w')
    fp.write(json.dumps(data,indent=4, sort_keys=True))
    fp.close()
      
if __name__ == "__main__":
    main()