Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
self.icon_path = ':/plugins/EnMAPBox/icon.png'
self.add_action(
self.icon_path,
text=self.tr(u'EnMAP-Box'),
callback=self.run,
parent=self.iface.mainWindow())
def unload(self):
"""Removes the plugin menu item and icon from QGIS GUI."""
for action in self.actions:
self.iface.removePluginMenu(
self.tr(u'&EnMAP-Box'),
action)
self.iface.removeToolBarIcon(action)
# remove the toolbar
del self.toolbar
def run(self):
"""Run method that performs all the real work"""
#self.dlg.setWindowIcon(QIcon(self.icon_path))
# show the GUI
self.dlg.show()
if DEBUG:
pass
def ua_showPxCoordinate_start(self):
D = self.dlg
h_x = D.doubleSpinBox_subset_size_x.value() * 0.5
h_y = D.doubleSpinBox_subset_size_x.value() * 0.5
c_x = D.spinBox_coordinate_x.value()
c_y = D.spinBox_coordinate_y.value()
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(c_x - h_x, c_y + h_y)
ring.AddPoint(c_x + h_x, c_y + h_y)
ring.AddPoint(c_x + h_x, c_y - h_y)
ring.AddPoint(c_x - h_x, c_y - h_y)
bb = ogr.Geometry(ogr.wkbPolygon)
bb.AssignSpatialReference(self.TS.srs)
bb.AddGeometry(ring)
bbWkt = bb.ExportToWkt()
srsWkt = bb.GetSpatialReference().ExportToWkt()
self.ImageChipBuffer.setBoundingBox(bb)
D = self.dlg
size_x = D.spinBox_chipsize_x.value()
size_y = D.spinBox_chipsize_y.value()
ScrollArea = D.scrollArea
#S.setWidgetResizable(False)
#remove widgets
all_dates = self.TS.getDates()
if self.CPV is None:
ScrollArea.setLayout(QHBoxLayout())
self.CPV = ScrollArea.layout()
else:
diff = set(all_dates)
diff = diff.symmetric_difference(self.CHIPWIDGETS.keys())
if len(diff) != 0:
self.clearLayoutWidgets(self.CPV)
else:
for date, viewList in self.CHIPWIDGETS.items():
for imageLabel in viewList:
imageLabel.clear()
#initialize image labels
for i, date in enumerate(all_dates):
#LV = QVBoxLayout()
#LV.setSizeConstraint(QLayout.SetNoConstraint)
TSD = self.TS.data[date]
textLabel = QLabel('{}'.format(date.astype(str)))
textLabel.setToolTip(str(TSD))
#textLabel.setMinimumWidth(size_x)
#textLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
self.CPV.addWidget(textLabel, 0, i)
viewList = list()
for j, view in enumerate(self.VIEWS):
imageLabel=QLabel()
imageLabel.setFrameShape(QFrame.StyledPanel)
imageLabel.setMinimumSize(size_x, size_y)
imageLabel.setMaximumSize(size_x, size_y)
imageLabel.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed)
viewList.append(imageLabel)
self.CPV.addWidget(imageLabel,j+1, i)
self.CHIPWIDGETS[date] = viewList
#LH.addSpacerItem(Spacer(size_x, size_y))
ScrollArea.show()
#fill image labels
missing_dates = set()
missing_bands = set()
for i, date in enumerate(self.TS.getDates()):
required_bands = set()
for j, view in enumerate(self.VIEWS):
required_bands = required_bands.union(set(view.getBands()))
missing = self.ImageChipBuffer.getMissingBands(date, required_bands)
if len(missing) == 0:
self.ua_showPxCoordinate_addChips(None, date=date)
else:
missing_dates.add(date)
missing_bands = missing_bands.union(missing)
if len(missing_dates) > 0:
self.TS.getSpatialChips_parallel(bbWkt, srsWkt, dates=list(missing_dates), bands=list(missing_bands))
def ua_showPxCoordinate_addChips(self, results, date=None):
if results is not None:
date, chipData = results
self.ImageChipBuffer.addDataCube(date, chipData)
viewList = self.CHIPWIDGETS.get(date)
if viewList:
for j, view in enumerate(self.VIEWS):
imageLabel = viewList[j]
img = self.ImageChipBuffer.getChipImage(date, view)
pxMap = QPixmap.fromImage(img)
pxMap = pxMap.scaled(imageLabel.size(), Qt.KeepAspectRatio)
imageLabel.setPixmap(pxMap)
s = ""
pass
s = ""
pass
def clearLayoutWidgets(self, L):
if L is not None:
while L.count():
w = L.takeAt(0)
w.widget().deleteLater()
#if w is not None:
# w.widget().deleteLater()
def ua_addTSImages(self, files=None):
if files is None:
files = QFileDialog.getOpenFileNames()
if files:
M = self.dlg.tableView_TimeSeries.model()
M.beginResetModel()
self.TS.addFiles(files)
M.endResetModel()
nb = self.TS.nb
if len(self.VIEWS) == 0 and nb > 0:
if nb < 3:
bands = [1,1,1]
else:
self.ua_addView([3,2,1])
if nb >= 5:
self.ua_addView([4,5,3])
self.check_enabled()
def ua_addTSMasks(self, files=None):
if files is None:
files = QFileDialog.getOpenFileNames()
l = len(files)
if l > 0:
M = self.dlg.tableView_TimeSeries.model()
M.beginResetModel()
M.endResetModel()
self.check_enabled()
def setViewNames(self):
for i, w in enumerate(self.VIEWS):
w.setTitle('View {}'.format(i+1))
self.check_enabled()
def ua_addView(self, bands = [3,2,1]):
import imagechipviewsettings_widget
if len(self.TS.bandnames) > 0:
w = imagechipviewsettings_widget.ImageChipViewSettings(self.TS, parent=self.dlg)
w.setMaximumSize(w.size())
w.setMinimumSize(w.size())
w.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed)
#imageLabel.setMinimumSize(size_x, size_y)
#imageLabel.setMaximumSize(size_x, size_y)
#imageLabel.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed)
w.setBands(bands)
w.removeView.connect(lambda : self.ua_removeView(w))
self.VIEWS.append(w)
L = self.dlg.scrollArea_viewsWidget.layout()
L.addWidget(w)
self.dlg.scrollArea_views.show()
self.setViewNames()
self.check_enabled()
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
def ua_removeTSD(self, dates):
if dates is None:
selected = self.dlg.tableView_TimeSeries.selectedIndexes()
s = ""
M = self.dlg.tableView_TimeSeries.model()
M.beginResetModel()
for date in dates:
self.TS.removeDate(date)
M.endResetModel()
def ua_removeView(self,w):
self.VIEWS.remove(w)
L = self.dlg.scrollArea_viewsWidget.layout()
L.removeWidget(w)
w.deleteLater()
self.setViewNames()
def run_tests():
if False:
pathImg = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted\2014-07-26_LC82270652014207LGN00_BOA.vrt'
pathMsk = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted\2014-07-26_LC82270652014207LGN00_Msk.vrt'
TSD = TimeSeriesDatum(pathImg)
TSD.setMask(pathMsk)
print(TSD)
c = [670949.883,-786288.771]
w_x = w_y = 1000 #1km box
srs = TSD.getSpatialReference()
ring = ogr.Geometry(ogr.wkbLinearRing)
import itertools
for x,y in itertools.product([1000, -1000], repeat=2):
ring.AddPoint(c[0]+x, c[1]+y)
ring.AssignSpatialReference(srs)
bb = ogr.Geometry(ogr.wkbPolygon)
bb.AddGeometry(ring)
bb.AssignSpatialReference(srs)
def getChip3d_OLD(chips, r,g,b, range_r, range_g, range_b):
nl, ns = chips[r].shape
a3d = np.ndarray((3,nl,ns), dtype='float')
rgb_idx = [r,g,b]
ranges = [range_r, range_g, range_b]
for i, rgb_i in enumerate(rgb_idx):
range = ranges[i]
data = chips[rgb_i].astype('float')
data -= range[0]
data *= 255./range[1]
a3d[i,:] = data
np.clip(a3d, 0, 255, out=a3d)
return a3d.astype('uint8')
app=QApplication([])
main=PictureTest()
main.show()
range_r = [0,500]
range_g = [0,500]
range_b = [0,500]
bands = [3,2,1]
chipData = TSD.readSpatialChip(bb,bands=bands )
main.addNumpy(getChip3d(chipData, bands, (range_r, range_g, range_b)))
app.exec_()
exit(0)
if False:
dirSrc = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted'
filesImg = file_search(dirSrc, '2014*_BOA.vrt')
filesMsk = file_search(dirSrc, '2014*_Msk.vrt')
TS = TimeSeries(imageFiles=filesImg, maskFiles=filesMsk)
print(TS)
exit(0)
if True:
import PyQt4.Qt
a = PyQt4.Qt.QApplication([])
S = SenseCarbon_TSV(a)
S.run()
if False:
dirSrc = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted'
filesImg = file_search(dirSrc, '2014*_BOA.vrt')
filesMsk = file_search(dirSrc, '2014*_Msk.vrt')
S.ua_addTSImages(files=filesImg)
S.ua_addTSMasks(files=filesMsk)