Newer
Older
self.plotData3D.clear()
pi = self.plot2D.getPlotItem()
plotItems = pi.listDataItems()
for p in plotItems:
p.clear()
p.update()
if len(self.TS) > 0:
rng = [self.TS[0].date, self.TS[-1].date]
rng = [date2num(d) for d in rng]
self.plot2D.getPlotItem().setRange(xRange=rng)
QApplication.processEvents()
if self.plot3D:
pass
if not isinstance(self.plotSettingsModel, PlotSettingsModel):
return
assert isinstance(spatialPoint, SpatialPoint)
assert isinstance(self.TS, TimeSeries)
LUT_bandIndices = dict()
for sensor in self.TS.Sensors:
LUT_bandIndices[sensor] = self.plotSettingsModel.requiredBands(sensor)
paths = []
bandIndices = []
for tsd in self.TS:
if tsd.isVisible():
paths.append(tsd.pathImg)
bandIndices.append(LUT_bandIndices[tsd.sensor])
self.pixelLoader.setNumberOfProcesses(SETTINGS.value('n_threads', 1))
self.pixelLoader.startLoading(paths, spatialPoint, bandIndices=bandIndices)
self.ui.setWindowTitle('{} | {} {}'.format(self.ui.baseTitle, str(spatialPoint.toString()), spatialPoint.crs().authid()))
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.setSymbol(sensorView.markerSymbol)
p.setSymbolSize(sensorView.markerSize)
p.setSymbolBrush(sensorView.markerBrush)
p.setSymbolPen(sensorView.markerPen)
p.setPen(sensorView.linePen)
p.setVisible(sensorView.isVisible())
p.update()
self.plot2D.update()
if sensorView is None:
for sv in self.plotSettingsModel.items:
self.setData(sv)
else:
assert isinstance(sensorView, SensorPlotSettings)
self.setData2D(sensorView)
@QtCore.pyqtSlot()
def updatePlot(self):
if self.updateRequested:
self.setData()
self.updateRequested = False
def setData(self, sensorView = None):
self.updateLock = True
if sensorView is None:
for sv in self.plotSettingsModel.mSensorPlotSettings:
self.setData(sv)
else:
assert isinstance(sensorView, SensorPlotSettings)
self.setData2D(sensorView)
self.updateLock = False
def removeSensor(self, sensor):
s = ""
self.plotSettingsModel.removeSensor(sensor)
if sensor in self.plotData2D.keys():
#remove from settings model
self.plotSettingsModel.removeSensor(sensor)
self.plotData2D.pop(sensor)
self.pxCollection.removeSensor(sensor)
# remove from px layer dictionary
#self.sensorPxLayers.pop(sensor)
#todo: remove from plot
s = ""
def setData2D(self, sensorView):
assert isinstance(sensorView, SensorPlotSettings)
if sensorView.sensor() not in self.plotData2D.keys():
plotDataItem = self.plot2D.plot(name=sensorView.sensor().name(), pen=None, symbol='o', symbolPen=None)
plotDataItem.sigPointsClicked.connect(self.onObservationClicked)
self.plotData2D[sensorView.sensor()] = plotDataItem
self.setVisibility2D(sensorView)
plotDataItem = self.plotData2D[sensorView.sensor()]
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)
i = np.argsort(dates)
plotDataItem.appendData()
plotDataItem.setData(x=dates[i], y=values[i], data=tsds[i])
def setData3D(self, *arg):
pass
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
# 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()
1163
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
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()
SViz = SpectralTemporalVisualization(ui)
SViz.connectTimeSeries(TS)
from example.Images import Img_2014_01_15_LC82270652014015LGN00_BOA
TS.addFiles([Img_2014_01_15_LC82270652014015LGN00_BOA])
ext = TS.getMaxSpatialExtent()
cp = SpatialPoint(ext.crs(),ext.center())