File: create_doris_input_xml.py

package info (click to toggle)
doris 5.0.3~beta%2Bdfsg-19
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 6,944 kB
  • sloc: cpp: 43,560; python: 8,213; csh: 3,636; sh: 2,527; ansic: 649; makefile: 337; xml: 208
file content (163 lines) | stat: -rw-r--r-- 6,689 bytes parent folder | download | duplicates (4)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import xml.etree.ElementTree as ET
import os
from datetime import datetime

class CreateDorisInputXml(object):

    def __init__(self, input_file):
        self.input_file_dict={}
        self.dem_folder=''
        if(len(input_file)==0):
            self._create_xml()
        else:
            self._read_xml(input_file)


    def _create_xml(self):
        # This will first create the framework with data folders the stackfolder should contain
        # a dorisparameters file.

        input = False
        while input == False:
            user_input = input("Enter the path to the archive data folder: ")
            if os.path.exists(user_input):
                self.input_file_dict['sar_data_folder'] = user_input
                input = True
            else:
                print('The path is incorrect, use another path')

        input = False
        while input == False:
            user_input = input("Which polarisation do you want to use (vv,hh,vh,hv): ")
            if user_input in ['vv', 'hh', 'vh', 'hv']:
                self.input_file_dict['polarisation'] = user_input
                input = True
            else:
                print('This polarisation does not exist')

        input = False
        while input == False:
            user_input = input("Which track do you want to work with? (explore on https://scihub.copernicus.eu/dhus/) : ")
            try:
                input = str(int(user_input)).zfill(3)
                self.input_file_dict['track'] = user_input
                input = True
            except:
                print('This track does not exist')

        input = False
        while input == False:
            user_input = input("Is this track ascending or descending? (asc/dsc) : ")
            if user_input in ['asc', 'dsc']:
                self.input_file_dict['direction'] = user_input
                input = True
            else:
                print('Input should either be asc or dsc')

        input = False
        while input == False:
            self.input_file_dict['datastack_folder'] = input("Enter the path to the folder of new datastack: ")
            if os.path.exists(self.input_file_dict['datastack_folder']):
                input = True
            else:
                print('The path is incorrect, use another path')

        input = False
        while input == False:
            self.input_file_dict['shape_file_path'] = input("Enter full path to the shapefile: ")
            if os.path.exists(self.input_file_dict['shape_file_path']) and self.input_file_dict['shape_file_path'].endswith('.shp'):
                input = True
            else:
                print('The path is incorrect, use another path')

        input = False
        while input == False:
            user_input = input("Enter the path to the folder of the orbit files: ")
            if os.path.exists(user_input):
                self.input_file_dict['orbits_folder'] = user_input
                input = True
            else:
                print('The path is incorrect, use another path')

        input = False
        while input == False:
            user_input = input("Do you want to generate the DEM file automaticly (Yes/No): ").lower()
            if user_input == 'yes' or user_input == 'no':
                self.input_file_dict['generate_dem'] = user_input
                input = True
            else:
                print('You should use either yes or no')

        input = False
        while input == False:
            self.input_file_dict['dem_processing_folder'] = input("Enter path to the dem folder: ")
            self.input_file_dict['dem_folder'] = os.path.join(self.input_file_dict['datastack_folder'], 'dem')
            if os.path.exists(self.input_file_dict['dem_processing_folder']):
                input = True
            else:
                print('The path is incorrect, use another path')

        input = False
        while input == False:
            user_input = input("Do you want to use parallel computing (Yes/No): ").lower()
            if user_input == 'yes' or user_input == 'no':
                self.input_file_dict['parallel'] = user_input
                input = True
            else:
                print('You should use either yes of no')

        if user_input == 'yes':
            nodes = input("How many cores do you want to use: ")
            self.input_file_dict['cores'] = nodes

        input = False
        while input == False:
            user_input = input("What is the start date of your stack in yyyy-mm-dd (can be changed later): ").lower()
            try:
                date = datetime.strptime(user_input, '%Y-%m-%d')
                self.input_file_dict['start_date'] = user_input
                input = True
            except:
                print('Format not recognized, 01-01-2014 chosen')
                self.input_file_dict['start_date'] = user_input

        input = False
        while input == False:
            user_input = input("What is the end date of your stack in yyyy-mm-dd (can be changed later): ").lower()
            try:
                date = datetime.strptime(user_input, '%Y-%m-%d')
                self.input_file_dict['end_date'] = user_input
                input = True
            except:
                print('Format not recognized, 01-01-2050 chosen')
                self.input_file_dict['end_date'] = user_input

        input = False
        while input == False:
            user_input = input("What is the master date of your stack in yyyy-mm-dd (can be changed later): ").lower()
            try:
                date = datetime.strptime(user_input, '%Y-%m-%d')
                self.input_file_dict['master_date'] = user_input
                input = True
            except:
                print('Format not recognized, 01-01-2016 chosen. Check https://scihub.copernicus.eu/dhus/#/home for valid date')
                self.input_file_dict['master_date'] = user_input

        xml_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'doris_input_template.xml')
        tree = ET.parse(xml_file)
        self.settings = tree.getroot()

        for key in self.input_file_dict.keys():
            self.settings.find('*/' + key).text = self.input_file_dict.get(key)

        tree.write(os.path.join(self.input_file_dict['datastack_folder'], 'doris_input.xml'))

        return self.input_file_dict

    def _read_xml(self, input_file):
        xml_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), input_file)
        tree = ET.parse(xml_file)
        self.settings = tree.getroot()

    def get_value(self, key):
        return self.settings.find('*/' + key).text