-
Notifications
You must be signed in to change notification settings - Fork 1
/
CorrespondingStripsComparer.py
94 lines (79 loc) · 3.77 KB
/
CorrespondingStripsComparer.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
82
83
84
85
86
87
88
89
90
91
92
93
94
from opals import Import, Grid, Diff, Histo, Types, ZColor
from StripsFabric import StripsFabric
from StatsReportGenerator import StatsReportGenerator
import os
class CorrespondingStripsComparer:
'''
Class for comparing corresponding strips. For example one can compare strips from two periods:
one before correction and after correction.
For this purpose strips in strips definition file should have same name with additional ending (e.g. '_corrected').
Ending for corrected strips is set in StripsFabric object.
Parameters:
-----------
StripsFabric: StripsFabric object
get StripsFabric object necessary for further operations
result_raster_folder: string
folder name for resulting rasters and other elements (histo, reports)
'''
def __init__(self, StripsFabric, result_folder):
self.stripsFabric = StripsFabric
self.result_folder = os.path.join(self.stripsFabric.absolute_path, result_folder)
if not os.path.exists(self.result_folder):
os.makedirs(self.result_folder)
self.report = StatsReportGenerator(os.path.join(self.result_folder, 'corresponding_strips_stats.txt'))
'''
Run strips comparation.
'''
def compare(self):
strips_list = self.stripsFabric.getStripsPlusCorrectedFromFile()
base_strips_list = strips_list[::2]
corrected_strips_list = strips_list[1::2]
#now every strip has corresponding corrected strip in corrected_strips_list
#like element 0 in corrected_strip_list is corrected strip of element 0 in base_strips_list
i = 0
for base_strip in base_strips_list:
corrected_strip = corrected_strips_list[i]
i += 1
diff_name = os.path.splitext(os.path.basename(base_strip))[0] + '-' + os.path.splitext(os.path.basename(corrected_strip))[0]
diff_rasters_folder = os.path.join(self.result_folder, 'diff_corresponding_rasters')
if not os.path.exists(diff_rasters_folder):
os.makedirs(diff_rasters_folder)
diff_raster_file = os.path.join(diff_rasters_folder, diff_name + '.tif')
imp = Import.Import()
imp.inFile = base_strip + '.las'
imp.outFile = base_strip + '.odm'
imp.run()
imp_corr = Import.Import()
imp_corr.inFile = corrected_strip + '.las'
imp_corr.outFile = corrected_strip + '.odm'
imp_corr.run()
grid = Grid.Grid()
grid.inFile = imp.outFile
grid.outFile = base_strip + '_z.tif'
grid.interpolation = Types.GridInterpolator.movingPlanes
grid.gridSize = 0.5
grid.run()
grid_corr = Grid.Grid()
grid_corr.inFile = imp_corr.outFile
grid_corr.outFile = corrected_strip + '_z.tif'
grid_corr.interpolation = Types.GridInterpolator.movingPlanes
grid_corr.gridSize = 0.5
grid_corr.run()
diff = Diff.Diff()
diff.inFile = [base_strip + '_z.tif', corrected_strip + '_z.tif']
diff.outFile = diff_raster_file
diff.run()
zco = ZColor.ZColor()
zco.inFile = diff_raster_file
zco.outFile = os.path.join(diff_rasters_folder, diff_name + '_coloured.tif')
zco.palFile = r'$OPALS_ROOT\addons\pal\differencePal.xml'
zco.zRange = [-0.5,0.5]
zco.run()
histo = Histo.Histo()
histo.inFile = diff_raster_file
histo.plotFile = os.path.join(diff_rasters_folder, diff_name + '_histo.svg')
histo.binWidth = 0.02
histo.sampleRange = [-0.5, 0.5]
histo.run()
self.report.deduceFromHistogram(histo.histogram, diff_name)
self.report.summarize()