-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_openstack.py
More file actions
executable file
·86 lines (70 loc) · 3.09 KB
/
Copy pathmain_openstack.py
File metadata and controls
executable file
·86 lines (70 loc) · 3.09 KB
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
"""
Copyright (C) 2025 Argyros Argyridis arargyridis at gmail dot com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os, sys, threading
import shutil
from time import sleep
from StatsExtractor.Backend.DataCrawler import DataCrawler
from StatsExtractor.Backend.ZonalStatsExtractor import ZonalStatsExtractor
#from StatsExtractor.Backend.MapserverImporter import MapserverImporter
from AnomalyDetectors.LongTermComparisonAnomalyDetector import run as runLongTermComparisonAnomalyDetector
from Libs.Constants import Constants
from Libs.ConfigurationParser import ConfigurationParser
from StatsExtractor.WebService.Backend.PointValueExtractor import PointValueExtractor
from osgeo import gdal
gdal.DontUseExceptions()
def main():
if len(sys.argv) < 2:
print("usage: python main.py config_file")
return 1
config = sys.argv[1]
# loading constants
Constants.load(config)
cfg = ConfigurationParser(config)
if cfg.parse() == 1:
print("error in configuration file! exiting")
return 1
#cleaning temporary paths
if os.path.isdir(cfg.filesystem.tmpPath):
shutil.rmtree(cfg.filesystem.tmpPath)
os.makedirs(cfg.filesystem.tmpPath, exist_ok=True)
for pid in Constants.PRODUCT_INFO:
if Constants.PRODUCT_INFO[pid].productType in ["raw", "lts"]:
inDir = cfg.filesystem.imageryPath
if Constants.PRODUCT_INFO[pid].productType == "lts":
inDir = cfg.filesystem.ltsPath
obj = DataCrawler(cfg, Constants.PRODUCT_INFO[pid], False)
obj.importProductFromLocalStorage(inDir)
# obj.fetchOrValidateAgainstVITO(dir="/home/argyros/Desktop/data/BIOPAR/", storageDir=cfg.filesystem.imageryPath)
elif Constants.PRODUCT_INFO[pid].productType == "anomaly":
inDir = cfg.filesystem.anomalyProductsPath
tmpDir = os.path.join(inDir, Constants.PRODUCT_INFO[pid].productNames[0])
os.makedirs(tmpDir, exist_ok=True)
print("Computing anomalies!")
# runLongTermComparisonAnomalyDetector(pid, config)
cmd = """AnomalyExtractor "{0}" "{1}" """.format(config, pid)
os.system(cmd)
print(Constants.PRODUCT_INFO[pid].productNames[0])
cmd = "CogGenerator {0}".format(config)
os.system(cmd)
#fetching stratifications and compute stats for each strata
query = "SELECT id, description FROM stratification s ORDER BY id"
res = cfg.pgConnections[cfg.statsInfo.connectionId].fetchQueryResult(query)
for row in res:
print("Extracting statistics for : {0}".format(row[1]))
statsCmd = """StatsExtractor "{0}" "{1}" """.format(config, row[0])
print(statsCmd)
os.system(statsCmd)
return 0
if __name__ == "__main__":
main()