-
Notifications
You must be signed in to change notification settings - Fork 17
/
run_pyDMS.py
81 lines (69 loc) · 2.98 KB
/
run_pyDMS.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
# -*- coding: utf-8 -*-
"""
@author: radoslaw guzinski
Copyright: (C) 2017, Radoslaw Guzinski
"""
import os
import time
from osgeo import gdal
import pyDMS.pyDMSUtils as utils
from pyDMS.pyDMS import DecisionTreeSharpener, NeuralNetworkSharpener
from pyDMS.pyDMS import REG_sknn_ann, REG_sklearn_ann
highResFilename = r""
lowResFilename = r""
lowResMaskFilename = r""
outputFilename = r""
##########################################################################################
if __name__ == "__main__":
useDecisionTree = True
commonOpts = {"highResFiles": [highResFilename],
"lowResFiles": [lowResFilename],
"lowResQualityFiles": [lowResMaskFilename],
"lowResGoodQualityFlags": [255],
"cvHomogeneityThreshold": 0,
"movingWindowSize": 15,
"disaggregatingTemperature": True}
dtOpts = {"perLeafLinearRegression": True,
"linearRegressionExtrapolationRatio": 0.25}
sknnOpts = {'hidden_layer_sizes': (10,),
'activation': 'tanh'}
nnOpts = {"regressionType": REG_sklearn_ann,
"regressorOpt": sknnOpts}
start_time = time.time()
if useDecisionTree:
opts = commonOpts.copy()
opts.update(dtOpts)
disaggregator = DecisionTreeSharpener(**opts)
else:
opts = commonOpts.copy()
opts.update(nnOpts)
disaggregator = NeuralNetworkSharpener(**opts)
print("Training regressor...")
disaggregator.trainSharpener()
print("Sharpening...")
downscaledFile = disaggregator.applySharpener(highResFilename, lowResFilename)
print("Residual analysis...")
residualImage, correctedImage = disaggregator.residualAnalysis(downscaledFile, lowResFilename,
lowResMaskFilename,
doCorrection=True)
print("Saving output...")
highResFile = gdal.Open(highResFilename)
if correctedImage is not None:
outImage = correctedImage
else:
outImage = downscaledFile
# outData = utils.binomialSmoother(outData)
outFile = utils.saveImg(outImage.GetRasterBand(1).ReadAsArray(),
outImage.GetGeoTransform(),
outImage.GetProjection(),
outputFilename)
residualFile = utils.saveImg(residualImage.GetRasterBand(1).ReadAsArray(),
residualImage.GetGeoTransform(),
residualImage.GetProjection(),
os.path.splitext(outputFilename)[0] + "_residual" +
os.path.splitext(outputFilename)[1])
outFile = None
residualFile = None
downsaceldFile = None
highResFile = None
print(time.time() - start_time, "seconds")