Newer
Older

benjamin.jakimow@geo.hu-berlin.de
committed
def __contains__(self, mapView):
return mapView in self.mapViewsDefinitions
def __init__(self, iface):
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
from timeseriesviewer.ui.widgets import TimeSeriesViewerUI
self.ui = TimeSeriesViewerUI()
#init empty time series
self.TS = TimeSeries()
self.hasInitialCenterPoint = False

benjamin.jakimow@geo.hu-berlin.de
committed
self.TS.sigTimeSeriesDatesAdded.connect(self.datesAdded)
#init TS model
D = self.ui
#self.ICP = D.scrollAreaSubsetContent.layout()
#D.scrollAreaMapViews.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
#self.BVP = self.ui.scrollAreaMapViews.layout()
D.dockNavigation.connectTimeSeries(self.TS)
D.dockTimeSeries.connectTimeSeries(self.TS)
D.dockSensors.connectTimeSeries(self.TS)
D.dockProfiles.connectTimeSeries(self.TS)
self.spectralTemporalVis = D.dockProfiles
self.spatialTemporalVis = SpatialTemporalVisualization(self)
self.spatialTemporalVis.sigLoadingStarted.connect(self.ui.dockRendering.addStartedWork)
self.spatialTemporalVis.sigLoadingFinished.connect(self.ui.dockRendering.addFinishedWork)
self.spatialTemporalVis.sigShowProfiles.connect(self.spectralTemporalVis.loadCoordinate)
self.spectralTemporalVis.sigMoveToTSD.connect(self.spatialTemporalVis.navigateToTSD)
D.dockNavigation.sigSetSpatialExtent.connect(self.spatialTemporalVis.setSpatialExtent)
self.ValidatorPxX = QIntValidator(0,99999)
self.ValidatorPxY = QIntValidator(0,99999)
#connect actions with logic
#D.btn_showPxCoordinate.clicked.connect(lambda: self.showSubsetsStart())

benjamin.jakimow@geo.hu-berlin.de
committed
D.actionSelectCenter.triggered.connect(lambda : self.spatialTemporalVis.activateMapTool('selectCenter'))
#D.actionSelectArea.triggered.connect(lambda : self.spatialTemporalVis.activateMapTool('selectArea'))

benjamin.jakimow@geo.hu-berlin.de
committed
D.actionZoomMaxExtent.triggered.connect(lambda : self.zoomTo('maxExtent'))
D.actionZoomPixelScale.triggered.connect(lambda: self.zoomTo('pixelScale'))
D.actionZoomIn.triggered.connect(lambda: self.spatialTemporalVis.activateMapTool('zoomIn'))
D.actionZoomOut.triggered.connect(lambda: self.spatialTemporalVis.activateMapTool('zoomOut'))
D.actionPan.triggered.connect(lambda: self.spatialTemporalVis.activateMapTool('pan'))
D.actionIdentifyTimeSeries.triggered.connect(lambda: self.spatialTemporalVis.activateMapTool('identifyProfile'))
D.actionIdentifyMapLayers.triggered.connect(lambda: self.spatialTemporalVis.activateMapTool('identifyMapLayers'))
D.actionAddMapView.triggered.connect(self.spatialTemporalVis.createMapView)
D.actionAddTSD.triggered.connect(lambda : self.ua_addTSImages())
D.actionRemoveTSD.triggered.connect(lambda: self.TS.removeDates(self.ui.dockTimeSeries.selectedTimeSeriesDates()))
D.actionRefresh.triggered.connect(self.spatialTemporalVis.refresh)

benjamin.jakimow@geo.hu-berlin.de
committed
D.actionLoadTS.triggered.connect(self.loadTimeSeries)
D.actionClearTS.triggered.connect(self.clearTimeSeries)
D.actionSaveTS.triggered.connect(self.ua_saveTSFile)
D.actionAddTSExample.triggered.connect(self.ua_loadExampleTS)

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed
from timeseriesviewer.ui.widgets import AboutDialogUI, PropertyDialogUI

benjamin.jakimow@geo.hu-berlin.de
committed
D.actionAbout.triggered.connect(lambda: AboutDialogUI(self.ui).exec_())
D.actionSettings.triggered.connect(lambda : PropertyDialogUI(self.ui).exec_())
D.actionFirstTSD.triggered.connect(lambda: self.setDOISliderValue('first'))
D.actionLastTSD.triggered.connect(lambda: self.setDOISliderValue('last'))
D.actionNextTSD.triggered.connect(lambda: self.setDOISliderValue('next'))
D.actionPreviousTSD.triggered.connect(lambda: self.setDOISliderValue('previous'))
D.dockRendering.actionSetSubsetSize.triggered.connect(lambda : self.spatialTemporalVis.setSubsetSize(
D.dockRendering.subsetSize()))
D.actionSetExtent.triggered.connect(lambda: self.spatialTemporalVis.setSpatialExtent(self.ui.spatialExtent()))
self.canvasCrs = QgsCoordinateReferenceSystem()
if iface:
import timeseriesviewer
timeseriesviewer.QGIS_TSV_BRIDGE = QgisTsvBridge(iface, self)
self.ui.setQgsLinkWidgets()
def loadImageFiles(self, files):
assert isinstance(files, list)
self.TS.addFiles(files)
def loadTimeSeries(self, path=None, n_max=None):
if path is None or path is False:
path = QFileDialog.getOpenFileName(self.ui, 'Open Time Series file', '')
if os.path.exists(path):
M = self.ui.dockTimeSeries.tableView_TimeSeries.model()
M.beginResetModel()
self.clearTimeSeries()
self.TS.loadFromFile(path, n_max=n_max)
M.endResetModel()
def zoomTo(self, key):
if key == 'maxExtent':
ext = self.TS.getMaxSpatialExtent(self.ui.dockNavigation.crs())
self.spatialTemporalVis.setSpatialExtent(ext)
elif key == 'pixelScale':
s = ""
def icon(self):
return TimeSeriesViewer.icon()

benjamin.jakimow@geo.hu-berlin.de
committed
if not self.hasInitialCenterPoint:
if len(self.TS.data) > 0:
extent = self.TS.getMaxSpatialExtent()
self.spatialTemporalVis.setSubsetSize(self.ui.dockRendering.subsetSize())
self.spatialTemporalVis.setSpatialExtent(extent)

benjamin.jakimow@geo.hu-berlin.de
committed
self.hasInitialCenterPoint = True
if len(self.spatialTemporalVis.MVC) == 0:
self.spatialTemporalVis.createMapView()
self.spatialTemporalVis.createMapView()

benjamin.jakimow@geo.hu-berlin.de
committed
if len(self.TS.data) == 0:
self.hasInitialCenterPoint = False
def ua_saveTSFile(self):
path = QFileDialog.getSaveFileName(self.ui, caption='Save Time Series file')
if path is not None:
self.TS.saveToFile(path)
def ua_loadExampleTS(self):
from timeseriesviewer import PATH_EXAMPLE_TIMESERIES
if not os.path.exists(PATH_EXAMPLE_TIMESERIES):
QMessageBox.information(self.ui, 'File not found', '{} - this file describes an exemplary time series.'.format(path_example))

benjamin.jakimow@geo.hu-berlin.de
committed
self.loadTimeSeries(path=PATH_EXAMPLE_TIMESERIES)

benjamin.jakimow@geo.hu-berlin.de
committed
self.qgsCanvas.setMapTool(self.RectangleMapTool)

benjamin.jakimow@geo.hu-berlin.de
committed
self.qgsCanvas.setMapTool(self.PointMapTool)

benjamin.jakimow@geo.hu-berlin.de
committed
def setSpatialSubset(self, spatialExtent):
#keep specified CRS but translate extent
oldExtent = self.ui.spatialExtent()
self.spatialTemporalVis.setSpatialExtent(extent)

benjamin.jakimow@geo.hu-berlin.de
committed
def ua_TSprogress(self, v_min, v, v_max):
assert v_min <= v and v <= v_max
P = self.ui.progressBar
if P.minimum() != v_min or P.maximum() != v_max:
P.setRange(v_min, v_max)
else:
s = ""
P.setValue(v)

benjamin.jakimow@geo.hu-berlin.de
committed
def datesAdded(self, dates):
assert isinstance(dates, list)
self.ui.dockTimeSeries.tableView_TimeSeries.resizeColumnsToContents()

benjamin.jakimow@geo.hu-berlin.de
committed
self.timeseriesChanged()
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
# 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 ua_addTSD_to_QGIS(self, TSD, bands):
"""Removes the plugin menu item and icon """
self.iface.removeToolBarIcon(self.action)
self.ui.show()

Benjamin Jakimow
committed
def scrollToDate(self, date_of_interest):

Benjamin Jakimow
committed
QApplication.processEvents()
HBar = self.ui.scrollArea_imageChips.horizontalScrollBar()
TSDs = list(self.CHIPWIDGETS.keys())
if len(TSDs) == 0:

Benjamin Jakimow
committed
return
#get date INDEX that is closest to requested date
if type(date_of_interest) is str:
date_of_interest = np.datetime64(date_of_interest)
if type(date_of_interest) is np.datetime64:
i_doi = TSDs.index(sorted(TSDs, key=lambda TSD: abs(date_of_interest - TSD.getDate()))[0])
else:
i_doi = date_of_interest

Benjamin Jakimow
committed
step = int(float(HBar.maximum()) / (len(TSDs)+1))
HBar.setSingleStep(step)
HBar.setPageStep(step*5)
HBar.setValue(i_doi * step)

Benjamin Jakimow
committed
def showSubset(self, renderJob, pixmap):
assert isinstance(renderJob, RenderJob)
chipLabel = self.CHIPWIDGETS[renderJob.TSD][renderJob.destinationId]
chipLabel.setPixmap(pixmap)
chipLabel.setFixedSize(pixmap.size())
chipLabel.update()
s = ""
def ua_collect_date(self, ICL, event):
if self.ui.rb_labeling_activate.isChecked():
txt = self.ui.tb_labeling_text.toPlainText()
reg = re.compile('\d{4}-\d{2}-\d{2}', re.I | re.MULTILINE)
dates = set([np.datetime64(m) for m in reg.findall(txt)])
doi = ICL.TSD.getDate()
if event.button() == Qt.LeftButton:
elif event.button() == Qt.MiddleButton and doi in dates:
dates.remove(doi)
dates = sorted(list(dates))
txt = ' '.join([d.astype(str) for d in dates])
self.ui.tb_labeling_text.setText(txt)
def clearLayoutWidgets(self, L):
if L is not None:
while L.count():
w = L.takeAt(0)
if w.widget():
w.widget().deleteLater()

Benjamin Jakimow
committed
QApplication.processEvents()
def ua_addTSImages(self, files=None):
if files is None:
files = QFileDialog.getOpenFileNames()
if files:
self.TS.addFiles(files)
M = self.ui.dockTimeSeries.tableView_TimeSeries.model()
M.beginResetModel()
self.TS.clear()
M.endResetModel()
def getSelectedTSDs(self):
TV = self.ui.tableView_TimeSeries
TVM = TV.model()
return [TVM.getTimeSeriesDatumFromIndex(idx) for idx in TV.selectionModel().selectedRows()]
def disconnect_signal(signal):
while True:
try:
signal.disconnect()
except TypeError:
break
def showRGBData(data):
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)
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
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')
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)))
dirSrcLS = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted'
filesImgLS = file_search(dirSrcLS, '2014*_BOA.vrt')
filesMsk = file_search(dirSrcLS, '2014*_Msk.vrt')
TS = TimeSeries(imageFiles=filesImgLS, maskFiles=filesMsk)
app=PyQt4.Qt.QApplication([])
dirSrcLS = r'\\141.20.140.107\NAS_Processing\SenseCarbonProcessing\BJ_NOC\01_RasterData\02_CuttedVRT'
dirSrcRE = r'\\141.20.140.91\SAN_RSDBrazil\RapidEye\3A_VRTs'
filesImgRE = file_search(dirSrcRE, '*.vrt', recursive=True)
#filesMsk = file_search(dirSrc, '2014*_Msk.vrt')
S.ua_addTSImages(files=filesImgLS[0:2])
S.ua_addTSImages(files=filesImgRE[0:2])
#S.ua_addTSImages(files=filesImgLS)
#S.ua_addTSImages(files=filesImgRE)
#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)
dirSrcLS = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted'
filesImgLS = file_search(dirSrcLS, '2014*_BOA.vrt')
filesMsk = file_search(dirSrcLS, '2014*_Msk.vrt')
S.ua_addTSImages(files=filesImgLS)
S.ua_addTSMasks(files=filesMsk)
if __name__ == '__main__':