Newer
Older

Benjamin Jakimow
committed
wkt = osr.GetUserInputAsWKT(str(wkt))
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
if type(geometry) is QgsRectangle:
center = geometry.center()
x = center.x()
y = center.y()
dx = geometry.xMaximum() - geometry.xMinimum()
dy = geometry.yMaximum() - geometry.yMinimum()
if type(geometry) is QgsPoint:
x = geometry.x()
y = geometry.y()
if self.TS.srs is not None and not self.TS.srs.IsSame(canvas_srs):
print('Convert canvas coordinates to time series SRS')
g = ogr.Geometry(ogr.wkbPoint)
g.AddPoint(x,y)
g.AssignSpatialReference(canvas_srs)
g.TransformTo(self.TS.srs)
x = g.GetX()
y = g.GetY()
D.doubleSpinBox_subset_size_x.setValue(dx)
D.doubleSpinBox_subset_size_y.setValue(dy)
D.spinBox_coordinate_x.setValue(x)
D.spinBox_coordinate_y.setValue(y)
def qgs_handleMouseDown(self, pt, btn):
print('MOUSE DOWN')
print(pt)
print(btn)
def ua_TSprogress(self, v_min, v, v_max):
assert v_min <= v and v <= v_max
P = self.dlg.progressBar
if P.minimum() != v_min or P.maximum() != v_max:
P.setRange(v_min, v_max)
P.setValue(v)
def ua_datumAdded(self):
if len(self.TS) > 0:
if self.dlg.spinBox_coordinate_x.value() == 0.0 and \
self.dlg.spinBox_coordinate_y.value() == 0.0:
xmin, ymin, xmax, ymax = self.TS.getMaxExtent()
self.dlg.spinBox_coordinate_x.setRange(xmin, xmax)
self.dlg.spinBox_coordinate_y.setRange(ymin, ymax)
self.dlg.spinBox_coordinate_x.setValue(0.5*(xmin+xmax))
self.dlg.spinBox_coordinate_y.setValue(0.5*(ymin+ymax))
s = ""
self.dlg.cb_centerdate.setCurrentIndex(int(len(self.TS) / 2))
self.dlg.tableView_TimeSeries.resizeColumnsToContents()
def check_enabled(self):
D = self.dlg
hasTSV = len(self.VIEWS) > 0
hasQGIS = qgis_available
D.tabWidget_viewsettings.setEnabled(hasTS)
D.btn_showPxCoordinate.setEnabled(hasTS and hasTSV)
D.btn_selectByCoordinate.setEnabled(hasQGIS)
D.btn_selectByRectangle.setEnabled(hasQGIS)
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
# noinspection PyMethodMayBeStatic
def tr(self, message):
"""Get the translation for a string using Qt translation API.
We implement this ourselves since we do not inherit QObject.
:param message: String for translation.
:type message: str, QString
:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('EnMAPBox', message)
def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None):
"""Add a toolbar icon to the toolbar.
:param icon_path: Path to the icon for this action. Can be a resource
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
:type icon_path: str
:param text: Text that should be shown in menu items for this action.
:type text: str
:param callback: Function to be called when the action is triggered.
:type callback: function
:param enabled_flag: A flag indicating if the action should be enabled
by default. Defaults to True.
:type enabled_flag: bool
:param add_to_menu: Flag indicating whether the action should also
be added to the menu. Defaults to True.
:type add_to_menu: bool
:param add_to_toolbar: Flag indicating whether the action should also
be added to the toolbar. Defaults to True.
:type add_to_toolbar: bool
:param status_tip: Optional text to show in a popup when mouse pointer
hovers over the action.
:type status_tip: str
:param parent: Parent widget for the new action. Defaults None.
:type parent: QWidget
:param whats_this: Optional text to show in the status bar when the
mouse pointer hovers over the action.
:returns: The action that was created. Note that the action is also
added to self.actions list.
:rtype: QAction
"""
icon = QIcon(icon_path)
action = QAction(icon, text, parent)
action.triggered.connect(callback)
action.setEnabled(enabled_flag)
if status_tip is not None:
action.setStatusTip(status_tip)
if whats_this is not None:
action.setWhatsThis(whats_this)
if add_to_toolbar:
self.toolbar.addAction(action)
if add_to_menu:
self.iface.addPluginToMenu(
self.menu,
action)
self.actions.append(action)
return action
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
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(
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

Benjamin Jakimow
committed
def scrollToDate(self, date):
QApplication.processEvents()
HBar = self.dlg.scrollArea.horizontalScrollBar()
dates = list(self.CHIPWIDGETS.keys())
if len(dates) == 0:
return
#get date INDEX that is closest to requested date
if not isinstance(date, int):
i_doi = dates.index(sorted(dates, key=lambda d: abs(date - d))[0])
else:
i_doi = min([date, HBar.maximum()])
scrollValue = int(float(i_doi+1) / len(dates) * HBar.maximum())
HBar.setValue(scrollValue)
cx = D.spinBox_coordinate_x.value()
cy = D.spinBox_coordinate_y.value()
ring.AddPoint(cx - dx, cy + dy)
ring.AddPoint(cx + dx, cy + dy)
ring.AddPoint(cx + dx, cy - dy)
ring.AddPoint(cx - dx, cy - dy)
bb = ogr.Geometry(ogr.wkbPolygon)
bb.AddGeometry(ring)
bbWkt = bb.ExportToWkt()
srsWkt = None
if self.TS.srs:
bb.AssignSpatialReference(self.TS.srs)
srsWkt = bb.GetSpatialReference().ExportToWkt()
self.ImageChipBuffer.setBoundingBox(bb)
D = self.dlg
ratio = dx / dy
size_px = D.spinBox_chipsize_max.value()
if ratio > 1: #x is largest side
size_x = size_px
size_y = int(size_px / ratio)
else: #y is largest
size_y = size_px
size_x = int(size_px * ratio)
centerTSD = D.cb_centerdate.itemData(D.cb_centerdate.currentIndex())
if centerTSD is None:
idx = int(len(self.TS)/2)
centerTSD = D.cb_centerdate.itemData(idx)
D.cb_centerdate.setCurrentIndex(idx)
centerDate = centerTSD.getDate()
allDates = self.TS.getDates()
i_doi = allDates.index(centerDate)
if D.rb_showEntireTS.isChecked():
dates_of_interest = self.TS.getDates()
elif D.rb_showTimeWindow.isChecked():
i0 = max([0, i_doi-D.sb_ndates_before.value()])
ie = min([i_doi + D.sb_ndates_after.value(), len(allDates)-1])
dates_of_interest = allDates[i0:ie+1]
diff = set(dates_of_interest)
diff = diff.symmetric_difference(self.CHIPWIDGETS.keys())
self.clearLayoutWidgets(self.CPV)
self.CHIPWIDGETS.clear()

Benjamin Jakimow
committed
#LV = QVBoxLayout()
#LV.setSizeConstraint(QLayout.SetNoConstraint)
TSD = self.TS.data[date]
textLabel = QLabel('{}'.format(date.astype(str)))
textLabel.setToolTip(str(TSD))
self.CPV.addWidget(textLabel, 0, i)
viewList = list()
j = 1
for view in self.VIEWS:
imageLabel.setFrameShape(QFrame.StyledPanel)
imageLabel.setMinimumSize(size_x, size_y)
imageLabel.setMaximumSize(size_x+1, size_y+1)
imageLabel.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.CPV.addWidget(imageLabel,j, i)
j += 1
textLabel = QLabel('{}'.format(date.astype(str)))
textLabel.setToolTip(str(TSD))
self.CPV.addWidget(textLabel, j, i)
self.scrollToDate(centerDate)
s = ""
#ScrollArea.show()
#ScrollArea.horizontalScrollBar().setValue()
#fill image labels
missing_dates = set()
missing_bands = set()
for i, date in enumerate(dates_of_interest):
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)
missing_dates = list(missing_dates)
missing_dates = sorted(missing_dates, key=lambda d: abs(centerDate - d))
self.TS.getSpatialChips_parallel(bbWkt, srsWkt, dates=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]
imageLabel.clear()
#imageLabel.setScaledContents(True)
rgb = self.ImageChipBuffer.getChipRGB(date, view)
rgb2 = rgb.transpose([1,2,0]).copy('C')
qImg = qimage2ndarray.array2qimage(rgb2)
#img = QImage(rgb2.data, nl, ns, QImage.Format_RGB888)
pxMap = QPixmap.fromImage(qImg)
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()

Benjamin Jakimow
committed
QApplication.processEvents()
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
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.MinimumExpanding)
w.setBands(bands)
w.removeView.connect(lambda : self.ua_removeView(w))
L = self.dlg.scrollArea_viewsWidget.layout()
L.addWidget(w)
self.dlg.scrollArea_views.show()
def ua_removeTS(self):
#remove views
M = self.dlg.tableView_TimeSeries.model()
M.beginResetModel()
self.TS.clear()
M.endResetModel()
self.check_enabled()
M = self.dlg.tableView_TimeSeries.model()
M.beginResetModel()
def ua_removeView(self,w):
self.VIEWS.remove(w)
L = self.dlg.scrollArea_viewsWidget.layout()
L.removeWidget(w)
w.deleteLater()
self.setViewNames()
def getSelectedDates(self):
TV = self.dlg.tableView_TimeSeries
TVM = TV.model()
return [TVM.getTimeSeriesDatumFromIndex(idx).getDate() for idx in TV.selectionModel().selectedRows()]
def showRGBData(data):
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'
if False:
TSD = TimeSeriesDatum(pathImg)
TSD.setMask(pathMsk)
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)
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
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)
app=PyQt4.Qt.QApplication([])
dirSrc = r'\\141.20.140.107\NAS_Processing\SenseCarbonProcessing\BJ_NOC\01_RasterData\02_CuttedVRT'
filesImg = file_search(dirSrc, '20*_BOA.vrt')
#filesMsk = file_search(dirSrc, '2014*_Msk.vrt')
#S.ua_addTSImages(files=filesImg[0:1])
S.ua_addTSImages(files=filesImg)
#S.ua_addTSMasks(files=filesMsk)
#S.ua_addView(bands=[4,5,3])
if False:
import qgis.core
# supply path to where is your qgis installed
#QgsApplication.setPrefixPath("/Applications/QGIS_2.12.app/Contents/MacOS/QGIS", True)
# load providers
QgsApplication.initQgis()
a = QgsApplication([], True)
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)