Newer
Older
self.plotSettingsModel = PlotSettingsModel(self.pxCollection, parent=self)
self.plotSettingsModel.sigSensorAdded.connect(self.setData)
self.plotSettingsModel.sigVisibilityChanged.connect(self.setVisibility)
#self.plotSettingsModel.sigVisibilityChanged.connect(self.loadData)
self.plotSettingsModel.sigDataChanged.connect(self.setData)
#self.plotSettingsModel.sigVisiblityChanged.connect(self.refresh)
self.plotSettingsModel.rowsInserted.connect(self.onRowsInserted)

benjamin.jakimow@geo.hu-berlin.de
committed
#self.plotSettingsModel.modelReset.connect(self.updatePersistantWidgets)
self.TV.setModel(self.plotSettingsModel)
self.delegate = PlotSettingsWidgetDelegate(self.TV)
self.TV.setItemDelegateForColumn(2, self.delegate)
self.TV.setItemDelegateForColumn(3, self.delegate)
#self.TV.setItemDelegateForColumn(3, PointStyleDelegate(self.TV))
for s in self.pxCollection.sensorPxLayers.keys():
self.plotSettingsModel.addSensor(s)
self.pxCollection.sigPixelAdded.connect(lambda : self.setData())
self.pxCollection.sigPixelRemoved.connect(self.clear)
self.ui.pixelLoader.sigLoadingStarted.connect(self.clear)
self.ui.pixelLoader.sigLoadingFinished.connect(lambda : self.plot2D.enableAutoRange('x', False))
# self.VIEW.setItemDelegateForColumn(3, PointStyleDelegate(self.VIEW))
self.plotData2D = dict()
self.plotData3D = dict()
self.setData()

benjamin.jakimow@geo.hu-berlin.de
committed
def updatePersistantWidgets(self):
model = self.TV.model()
if model:
colExpression = model.columnames.index('y-value')
colStyle = model.columnames.index('style')
for row in range(model.rowCount()):
idxExpr = model.createIndex(row, colExpression)
idxStyle = model.createIndex(row, colStyle)
#self.TV.closePersistentEditor(idxExpr)
#self.TV.closePersistentEditor(idxStyle)
self.TV.openPersistentEditor(idxExpr)
self.TV.openPersistentEditor(idxStyle)
#self.TV.openPersistentEditor(model.createIndex(start, colStyle))
s = ""
def onRowsInserted(self, parent, start, end):
model = self.TV.model()
if model:
colExpression = model.columnames.index('y-value')
colStyle = model.columnames.index('style')
while start <= end:
idxExpr = model.createIndex(start, colExpression)
idxStyle = model.createIndex(start, colStyle)
self.TV.openPersistentEditor(idxExpr)
self.TV.openPersistentEditor(idxStyle)
start += 1
#self.TV.openPersistentEditor(model.createIndex(start, colStyle))
s = ""
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
def onObservationClicked(self, plotDataItem, points):
for p in points:
tsd = p.data()
print(tsd)
s =""
def clear(self):
#first remove from pixelCollection
self.pxCollection.clearPixels()
self.plotData2D.clear()
self.plotData3D.clear()
pi = self.plot2D.getPlotItem()
plotItems = pi.listDataItems()
for p in plotItems:
p.clear()
p.update()
if len(self.ui.TS) > 0:
rng = [self.ui.TS[0].date, self.ui.TS[-1].date]
rng = [date2num(d) for d in rng]
self.plot2D.getPlotItem().setRange(xRange=rng)
QApplication.processEvents()
if self.plot3D:
pass
def setVisibility(self, sensorView):
assert isinstance(sensorView, SensorPlotSettings)
self.setVisibility2D(sensorView)
def setVisibility2D(self, sensorView):
assert isinstance(sensorView, SensorPlotSettings)
p = self.plotData2D[sensorView.sensor]
p.setData(symbol=sensorView.markerSymbol, symbolBrush=sensorView.markerBrush,
symbolPen=sensorView.markerPen, symbolSize=sensorView.markerSize,
pen = sensorView.linePen, width=sensorView.linePen.width())
p.setVisible(sensorView.isVisible)
p.update()
self.plot2D.update()
s =""
def setData(self, sensorView = None):
if sensorView is None:
for sv in self.plotSettingsModel.items:
self.setData(sv)
else:
assert isinstance(sensorView, SensorPlotSettings)
self.setData2D(sensorView)
pass
def setData2D(self, sensorView):
assert isinstance(sensorView, SensorPlotSettings)
if sensorView.sensor not in self.plotData2D.keys():
#plotDataItem = SensorPoints(name=sensorView.sensor.name(), pen=None, symbol='o', symbolPen=None)
#plotDataItem = pg.ScatterPlotItem(name=sensorView.sensor.name(), pen= {'color': 'w', 'width': 2},brush=QColor('green'), symbol='o')
#self.plot2D.addItem(plotDataItem)

benjamin.jakimow@geo.hu-berlin.de
committed
plotDataItem = self.plot2D.plot(name=sensorView.sensor.name(), pen=None, symbol='o', symbolPen=None)
#plotDataItem.curve.setClickable(True)
plotDataItem.sigPointsClicked.connect(self.onObservationClicked)
#self.plot2D.scene().addItem(plotDataItem)
#self.plot2D.setMenuEnabled(True)
#self.plot2D.addItem(plotDataItem)
self.plotData2D[sensorView.sensor] = plotDataItem
self.setVisibility2D(sensorView)
plotDataItem = self.plotData2D[sensorView.sensor]

benjamin.jakimow@geo.hu-berlin.de
committed
plotDataItem.setToolTip('Values {}'.format(sensorView.sensor.name()))
#https://github.com/pyqtgraph/pyqtgraph/blob/5195d9dd6308caee87e043e859e7e553b9887453/examples/customPlot.py
tsds, values = self.pxCollection.dateValues(sensorView.sensor, sensorView.expression)
if len(tsds) > 0:
dates = np.asarray([date2num(tsd.date) for tsd in tsds])
values = np.asarray(values)
#spots = []
#for i, tsd in enumerate(tsds):
# spots.append({'pos':(dates[i], values[i])})
#plotDataItem.setPoints(spots)
#plotDataItem.invalidate()
#self.plot2D.invalidate()
#self.setVisibility2D()
#plotDataItem.setPoints(x=dates, y=values, data=tsds)
plotDataItem.setData(x=dates, y=values, data=tsds)
#plotDataItem.scatter.addPoints(x=dates, y=values, data=tsds)
def setData3D(self, *arg):
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
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
pass
def testPixelLoader():
# prepare QGIS environment
if sys.platform == 'darwin':
PATH_QGS = r'/Applications/QGIS.app/Contents/MacOS'
os.environ['GDAL_DATA'] = r'/usr/local/Cellar/gdal/1.11.3_1/share'
else:
# assume OSGeo4W startup
PATH_QGS = os.environ['QGIS_PREFIX_PATH']
assert os.path.exists(PATH_QGS)
qgsApp = QgsApplication([], True)
QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns')
QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns/qgis')
qgsApp.setPrefixPath(PATH_QGS, True)
qgsApp.initQgis()
gb = QGroupBox()
gb.setTitle('Sandbox')
PL = PixelLoader()
PL.setNumberOfThreads(1)
if False:
files = ['observationcloud/testdata/2014-07-26_LC82270652014207LGN00_BOA.bsq',
'observationcloud/testdata/2014-08-03_LE72270652014215CUB00_BOA.bsq'
]
else:
from utils import file_search
searchDir = r'H:\LandsatData\Landsat_NovoProgresso'
files = file_search(searchDir, '*227065*band4.img', recursive=True)
#files = files[0:3]
lyr = QgsRasterLayer(files[0])
coord = lyr.extent().center()
crs = lyr.crs()
l = QVBoxLayout()
btnStart = QPushButton()
btnStop = QPushButton()
prog = QProgressBar()
tboxResults = QPlainTextEdit()
tboxResults.setMaximumHeight(300)
tboxThreads = QPlainTextEdit()
tboxThreads.setMaximumHeight(200)
label = QLabel()
label.setText('Progress')
def showProgress(n,m,md):
prog.setMinimum(0)
prog.setMaximum(m)
prog.setValue(n)
info = []
for k, v in md.items():
info.append('{} = {}'.format(k,str(v)))
tboxResults.setPlainText('\n'.join(info))
#tboxThreads.setPlainText(PL.threadInfo())
qgsApp.processEvents()
PL.sigPixelLoaded.connect(showProgress)
btnStart.setText('Start loading')
btnStart.clicked.connect(lambda : PL.startLoading(files, coord, crs))
btnStop.setText('Cancel')
btnStop.clicked.connect(lambda: PL.cancelLoading())
lh = QHBoxLayout()
lh.addWidget(btnStart)
lh.addWidget(btnStop)
l.addLayout(lh)
l.addWidget(prog)
l.addWidget(tboxThreads)
l.addWidget(tboxResults)
gb.setLayout(l)
gb.show()
#rs.setBackgroundStyle('background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #222, stop:1 #333);')
#rs.handle.setStyleSheet('background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #282, stop:1 #393);')
qgsApp.exec_()
qgsApp.exitQgis()
if __name__ == '__main__':
import site, sys
from timeseriesviewer import sandbox
qgsApp = sandbox.initQgisEnvironment()
if True:
from timeseriesviewer.tests import *
TS = TestObjects.timeSeries()
d.connectTimeSeries(TS)
ext = TS.getMaxSpatialExtent()
cp = SpatialPoint(ext.crs(),ext.center())
d.loadCoordinate(cp)