Commit 32ba1cad authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

EOTimeSeriesViewer: fiext exportMapsToImages()


refactored module imports
smaller fixed
cleaned repo from old files
Signed-off-by: Benjamin Jakimow's avatarBenjamin Jakimow benjamin.jakimow@geo.hu-berlin.de <benjamin.jakimow@geo.hu-berlin.de>
parent cef65607
......@@ -857,6 +857,8 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
assert isinstance(mapCanvas, MapCanvas)
mapCanvas.timedRefresh()
tsd = mapCanvas.tsd()
if not isinstance(tsd, TimeSeriesDate):
continue
mv = mapCanvas.mapView()
assert isinstance(mv, MapView)
mapCanvas.waitWhileRendering()
......
......@@ -176,6 +176,8 @@ def value(key: Keys, default=None):
print(error, file=sys.stderr)
except Exception as otherError:
s = ""
if value is None:
value = default
return value
......
......@@ -21,6 +21,7 @@
"""
import os
import copy
import re
from osgeo import gdal
import numpy as np
from collections import OrderedDict
......@@ -28,11 +29,11 @@ from xml.etree import ElementTree
from qgis.PyQt.QtCore import Qt, QModelIndex, QAbstractTableModel, QItemSelectionModel, QTimer
from qgis.PyQt.QtGui import QColor
from qgis.PyQt.QtWidgets import QHeaderView, QDialog, QDialogButtonBox, QFileDialog
from qgis.core import QgsRasterLayer, QgisInterface, QgsProviderRegistry, QgsProject
from qgis.gui import QgsFileWidget
from qgis.core import QgsRasterLayer, QgsProviderRegistry, QgsProject
from qgis.gui import QgsFileWidget, QgisInterface
import qgis.utils
from .utils import read_vsimem, loadUi
from .virtualrasters import VRTRaster, VRTRasterBand, VRTRasterInputSourceBand
from eotimeseriesviewer.utils import read_vsimem, loadUi
from eotimeseriesviewer.virtualrasters import VRTRaster, VRTRasterBand, VRTRasterInputSourceBand
from eotimeseriesviewer import DIR_UI
from eotimeseriesviewer.dateparser import extractDateTimeGroup
......
# -*- coding: utf-8 -*-
"""
Demonstrates use of GLScatterPlotItem with rapidly-updating plots.
"""
## Add path to library (just for examples; you do not need this)
import qgis
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import numpy as np
from tests import initQgisApplication
app = initQgisApplication()
w = gl.GLViewWidget()
w.opts['distance'] = 20
w.show()
w.setWindowTitle('pyqtgraph example: GLScatterPlotItem')
g = gl.GLGridItem()
w.addItem(g)
##
## First example is a set of points with pxMode=False
## These demonstrate the ability to have points with real size down to a very small scale
##
pos = np.empty((53, 3))
size = np.empty((53))
color = np.empty((53, 4))
pos[0] = (1,0,0); size[0] = 0.5; color[0] = (1.0, 0.0, 0.0, 0.5)
pos[1] = (0,1,0); size[1] = 0.2; color[1] = (0.0, 0.0, 1.0, 0.5)
pos[2] = (0,0,1); size[2] = 2./3.; color[2] = (0.0, 1.0, 0.0, 0.5)
z = 0.5
d = 6.0
for i in range(3,53):
pos[i] = (0,0,z)
size[i] = 2./d
color[i] = (0.0, 1.0, 0.0, 0.5)
z *= 0.5
d *= 2.0
sp1 = gl.GLScatterPlotItem(pos=pos, size=size, color=color, pxMode=False)
sp1.translate(5,5,0)
w.addItem(sp1)
##
## Second example shows a volume of points with rapidly updating color
## and pxMode=True
##
pos = np.random.random(size=(100000,3))
pos *= [10,-10,10]
pos[0] = (0,0,0)
color = np.ones((pos.shape[0], 4))
d2 = (pos**2).sum(axis=1)**0.5
size = np.random.random(size=pos.shape[0])*10
sp2 = gl.GLScatterPlotItem(pos=pos, color=(1,1,1,1), size=size)
phase = 0.
w.addItem(sp2)
##
## Third example shows a grid of points with rapidly updating position
## and pxMode = False
##
pos3 = np.zeros((100,100,3))
pos3[:,:,:2] = np.mgrid[:100, :100].transpose(1,2,0) * [-0.1,0.1]
pos3 = pos3.reshape(10000,3)
d3 = (pos3**2).sum(axis=1)**0.5
sp3 = gl.GLScatterPlotItem(pos=pos3, color=(1,1,1,.3), size=0.1, pxMode=False)
w.addItem(sp3)
def update():
## update volume colors
global phase, sp2, d2
s = -np.cos(d2*2+phase)
color = np.empty((len(d2),4), dtype=np.float32)
color[:,3] = np.clip(s * 0.1, 0, 1)
color[:,0] = np.clip(s * 3.0, 0, 1)
color[:,1] = np.clip(s * 1.0, 0, 1)
color[:,2] = np.clip(s ** 3, 0, 1)
sp2.setData(color=color)
phase -= 0.1
## update surface positions and colors
global sp3, d3, pos3
z = -np.cos(d3*2+phase)
pos3[:,2] = z
color = np.empty((len(d3),4), dtype=np.float32)
color[:,3] = 0.3
color[:,0] = np.clip(z * 3.0, 0, 1)
color[:,1] = np.clip(z * 1.0, 0, 1)
color[:,2] = np.clip(z ** 3, 0, 1)
sp3.setData(pos=pos3, color=color)
t = QtCore.QTimer()
t.timeout.connect(update)
t.start(50)
app.exec_()
\ No newline at end of file
from qgis.core import *
from qgis.gui import *
from eotimeseriesviewer.tests import start_app, TestObjects
app = start_app()
lyr = TestObjects.createRasterLayer()
QgsProject.instance().addMapLayer(lyr)
c = QgsMapCanvas()
c.setLayers([lyr])
c.setDestinationCrs(lyr.crs())
c.setExtent(c.fullExtent())
c.show()
d = QgsAdvancedDigitizingDockWidget(c)
d.show()
mapTool = QgsMapToolCapture(c, d, QgsMapToolCapture.CapturePolygon)
c.setMapTool(mapTool)
mapTool.activate()
app.exec_()
\ No newline at end of file
from qgis.gui import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
from eotimeseriesviewer.utils import *
viewModes = ['timeXmapview', 'mapviewXtime', 'time2Xmapview']
class MapViewGridLayout(QGridLayout):
def __init__(self):
pass
def setViewMode(self, viewMode=str):
assert viewMode in viewModes
from eotimeseriesviewer.tests import start_app
app = start_app()
from qgis._3d import *
engine = QgsWindow3DEngine()
w = engine.window()
w.show()
app.exec_()
app.quit()
\ No newline at end of file
import os, re, io, importlib, uuid, unittest
import qgis.testing
......@@ -8,13 +7,13 @@ from eotimeseriesviewer import *
from eotimeseriesviewer.utils import *
from eotimeseriesviewer.timeseries import *
DIR_SENTINEL = r''
DIR_PLEIADES = r'H:\Pleiades'
DIR_RAPIDEYE = r'Y:\RapidEye\3A'
DIR_LANDSAT = jp(DIR_EXAMPLES, 'Images')
DIR_VRT = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\02_CuttedVRT'
class TestFileFormatLoading(EOTSVTestCase):
@classmethod
......@@ -54,26 +53,23 @@ class TestFileFormatLoading(EOTSVTestCase):
self.assertEqual(len(files), len(self.TS))
s = ""
def test_loadOSARIS_GRD(self):
testDir = r'Q:\Processing_BJ\99_OSARIS_Testdata\Loibl-2019-OSARIS-Ala-Archa\Coherences'
if os.path.isdir(testDir):
files = file_search(testDir, re.compile(r'.*\.grd$'))
for i, path in enumerate(files):
tss = TimeSeriesSource.create(path)
self.assertIsInstance(tss, TimeSeriesSource)
self.assertTrue(tss.crs().isValid())
self.TS.addSources([path], runAsync=False)
self.assertEqual(len(self.TS), i+1)
self.assertEqual(len(self.TS), i + 1)
tss = self.TS[0][0]
self.assertIsInstance(tss, TimeSeriesSource)
sensor = self.TS[0].sensor()
self.assertIsInstance(sensor, SensorInstrument)
def test_ForceLevel2(self):
path = r'J:\diss_bj\level2\s-america\X0050_Y0025\20140601_LEVEL2_LND08_BOA.tif'
......@@ -82,8 +78,9 @@ class TestFileFormatLoading(EOTSVTestCase):
testData = r'J:\diss_bj\level2\s-america\X0049_Y0025'
if os.path.isdir(testData):
files = list(file_search(testData, '*IMP.tif'))
if len(files) > 10:
files = files[0:10]
for i, path in enumerate(files):
self.TS.addSources([path], runAsync=False)
self.assertEqual(len(self.TS), i + 1)
......@@ -102,9 +99,6 @@ class TestFileFormatLoading(EOTSVTestCase):
tss = TimeSeriesSource.create(p)
s = ""
def test_nestedVRTs(self):
# load VRTs pointing to another VRT pointing to Landsat imagery
searchDir = DIR_VRT
......@@ -117,12 +111,14 @@ class TestFileFormatLoading(EOTSVTestCase):
def test_loadRapidEye(self):
# load RapidEye
searchDir =DIR_RAPIDEYE
searchDir = DIR_RAPIDEYE
if not os.path.isdir(searchDir):
print('DIR_RAPIDEYE undefined. skip test.')
return
files = file_search(searchDir, '*.tif', recursive=True)
files = [f for f in files if not re.search(r'_(udm|browse)\.tif$', f)]
if len(files) > 10:
files = files[0:10]
self.TS.addSources(files, runAsync=False)
self.assertEqual(len(files), len(self.TS.sourceUris()))
......@@ -133,22 +129,19 @@ class TestFileFormatLoading(EOTSVTestCase):
tss = tsd[0]
self.assertIsInstance(tss, TimeSeriesSource)
def test_loadPleiades(self):
#load Pleiades data
# load Pleiades data
searchDir = DIR_PLEIADES
if not os.path.isdir(searchDir):
print('DIR_PLEIADES undefined. skip test.')
return
#files = file_search(searchDir, 'DIM*.xml', recursive=True)
# files = file_search(searchDir, 'DIM*.xml', recursive=True)
files = list(file_search(searchDir, '*.jp2', recursive=True))[0:3]
self.TS.addSources(files, runAsync=False)
self.assertEqual(len(files), len(self.TS))
def test_loadSentinel2(self):
#load Sentinel-2
# load Sentinel-2
searchDir = DIR_SENTINEL
if not os.path.isdir(searchDir):
print('DIR_SENTINEL undefined. skip test.')
......@@ -156,7 +149,7 @@ class TestFileFormatLoading(EOTSVTestCase):
files = list(file_search(searchDir, '*MSIL1C.xml', recursive=True))
self.TS.addSources(files, runAsync=False)
#self.assertRegexpMatches(self.stderr.getvalue().strip(), 'Unable to add:')
# self.assertRegexpMatches(self.stderr.getvalue().strip(), 'Unable to add:')
self.assertEqual(0, len(self.TS)) # do not add a containers
subdatasets = []
for file in files:
......
......@@ -17,19 +17,18 @@
***************************************************************************
"""
from eotimeseriesviewer.tests import start_app, testRasterFiles
import unittest
import tempfile
import os
import qgis.testing
import xmlrunner
from eotimeseriesviewer.labeling import *
from eotimeseriesviewer import DIR_REPO
from eotimeseriesviewer.mapcanvas import MapCanvas
from eotimeseriesviewer.tests import TestObjects, EOTSVTestCase
from eotimeseriesviewer.mapvisualization import MapView
from osgeo import ogr
from eotimeseriesviewer.tests import TestObjects, EOTSVTestCase
from qgis.core import QgsVectorLayer, QgsField, QgsEditorWidgetSetup, QgsProject, \
QgsFields, QgsEditorWidgetRegistry, QgsEditorWidgetWrapper
from qgis.gui import QgsDualView, QgsEditorConfigWidget, QgsMapLayerStyleManagerWidget, QgsMapCanvas, QgsGui
class TestLabeling(EOTSVTestCase):
......@@ -37,14 +36,14 @@ class TestLabeling(EOTSVTestCase):
def setUpClass(cls):
super().setUpClass()
print('## setUpClass')
#app = qgis.testing.start_app(cleanup=True)
# app = qgis.testing.start_app(cleanup=True)
import eotimeseriesviewer.labeling
print('## setUpClass - cleanup')
for store in eotimeseriesviewer.MAP_LAYER_STORES:
store.removeAllMapLayers()
print('## setUpClass - done')
def createVectorLayer(self)->QgsVectorLayer:
def createVectorLayer(self) -> QgsVectorLayer:
lyr = TestObjects.createVectorLayer()
self.assertIsInstance(lyr, QgsVectorLayer)
......@@ -83,20 +82,21 @@ class TestLabeling(EOTSVTestCase):
self.assertIsInstance(lyr, QgsVectorLayer)
tsd = ts[10]
#menu = model.menuForTSD(tsd)
#self.assertIsInstance(menu, QMenu)
# menu = model.menuForTSD(tsd)
# self.assertIsInstance(menu, QMenu)
canvas = MapCanvas()
canvas.setTSD(tsd)
canvas.setMapView(mv)
pos = QPoint(int(canvas.width()*0.5), int(canvas.height()*0.5))
pos = QPoint(int(canvas.width() * 0.5), int(canvas.height() * 0.5))
menu = canvas.contextMenu(pos)
self.assertIsInstance(menu, QMenu)
def findLabelAction(menu)->QAction:
def findLabelAction(menu) -> QAction:
for a in menu.actions():
if a.text().startswith('Quick Labels'):
return a
m = findLabelAction(menu).menu()
self.showGui(menu)
......@@ -126,7 +126,6 @@ class TestLabeling(EOTSVTestCase):
else:
self.fail('Unhandled QgsField typeName: {}'.format(field.typeName()))
def test_LabelShortcutEditorConfigWidget(self):
print('## test_LabelShortcutEditorConfigWidget')
vl = self.createVectorLayer()
......@@ -163,8 +162,6 @@ class TestLabeling(EOTSVTestCase):
editorWidgetWrapper = reg.create(EDITOR_WIDGET_REGISTRY_KEY, vl, i, setup.config(), None, parent)
self.assertIsInstance(editorWidgetWrapper, QgsEditorWidgetWrapper)
canvas = QgsMapCanvas(parent)
canvas.setVisible(False)
......@@ -173,16 +170,13 @@ class TestLabeling(EOTSVTestCase):
dv.init(vl, canvas) # , context=self.mAttributeEditorContext)
dv.setView(QgsDualView.AttributeTable)
panel = QgsMapLayerStyleManagerWidget(vl, canvas, parent)
parent.layout().addWidget(w)
parent.layout().addWidget(dv)
parent.layout().addWidget(panel)
#randomly click into table cells
# randomly click into table cells
vl.startEditing()
size = dv.size()
......@@ -190,19 +184,18 @@ class TestLabeling(EOTSVTestCase):
h = size.height()
from random import randint
for i in range(5):
print('Test mouse press {}'.format(i+1))
x = randint(0, w-1)
y = randint(0, h-1)
print('Test mouse press {}'.format(i + 1))
x = randint(0, w - 1)
y = randint(0, h - 1)
localPos = QPointF(x, y)
event = QMouseEvent(QEvent.MouseButtonPress, localPos, Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
dv.mousePressEvent(event)
vl.selectByIds([1, 2, 3])
ts = TestObjects.createTimeSeries()
tsd = ts[5]
if len(quickLabelLayers())> 0:
if len(quickLabelLayers()) > 0:
print('Found QuickLabelLayers:')
for l in quickLabelLayers():
print('{}={}'.format(l.name(), l.source()))
......@@ -248,7 +241,8 @@ class TestLabeling(EOTSVTestCase):
{CONFKEY_LABELTYPE: LabelShortcutType.DecimalYear}))
# set different types of classifications
from eotimeseriesviewer.externals.qps.classification.classificationscheme import EDITOR_WIDGET_REGISTRY_KEY as CS_KEY
from eotimeseriesviewer.externals.qps.classification.classificationscheme import \
EDITOR_WIDGET_REGISTRY_KEY as CS_KEY
from eotimeseriesviewer.externals.qps.classification.classificationscheme import classSchemeToConfig
vl.setEditorWidgetSetup(vl.fields().lookupField('class1l'),
QgsEditorWidgetSetup(CS_KEY, classSchemeToConfig(classScheme1)))
......@@ -257,11 +251,10 @@ class TestLabeling(EOTSVTestCase):
QgsEditorWidgetSetup(CS_KEY, classSchemeToConfig(classScheme1)))
vl.setEditorWidgetSetup(vl.fields().lookupField('class2l'),
QgsEditorWidgetSetup(CS_KEY, classSchemeToConfig(classScheme1)))
QgsEditorWidgetSetup(CS_KEY, classSchemeToConfig(classScheme1)))
vl.setEditorWidgetSetup(vl.fields().lookupField('class2n'),
QgsEditorWidgetSetup(CS_KEY, classSchemeToConfig(classScheme1)))
QgsEditorWidgetSetup(CS_KEY, classSchemeToConfig(classScheme1)))
return classScheme1, classScheme2
......@@ -280,7 +273,6 @@ class TestLabeling(EOTSVTestCase):
self.showGui(canvas)
def test_LabelingWidget2(self):
lyr = TestObjects.createVectorLayer()
lyr.setName('My Name')
......
......@@ -3,21 +3,19 @@ import os
import sys
import re
import xmlrunner
from qgis.core import *
from qgis.gui import *
from qgis.core import QgsVectorLayer
from qgis.gui import QgsSublayersDialog
from eotimeseriesviewer.tests import EOTSVTestCase
import unittest
class TestLayerProperties(EOTSVTestCase):
class TestLayerProperties(EOTSVTestCase):
def test_selectSubLayers(self):
from example import exampleGPKG
vl = QgsVectorLayer(exampleGPKG)
from eotimeseriesviewer.externals.qps.layerproperties import subLayerDefinitions
sublayerDefs = subLayerDefinitions(vl)
d = QgsSublayersDialog(QgsSublayersDialog.Ogr, "NAME")
d.populateLayerTable(sublayerDefs)
......@@ -28,4 +26,3 @@ class TestLayerProperties(EOTSVTestCase):
if __name__ == "__main__":
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'), buffer=False)
exit(0)
......@@ -148,12 +148,15 @@ class TestMain(EOTSVTestCase):
d = SaveAllMapsDialog()
self.assertEqual(d.fileType(), 'PNG')
pathTestOutput = tempfile.mkdtemp(prefix='EOTSTTestOutput')
dirTestOutput = self.createTestOutputDirectory() / 'test_screenshots'
os.makedirs(dirTestOutput, exist_ok=True)
pathTestOutput = dirTestOutput / 'canvas_shots.png'
TSV = EOTimeSeriesViewer()
paths = TestObjects.createMultiSourceTimeSeries()
TSV.addTimeSeriesImages(paths)
TSV.addTimeSeriesImages(paths, loadAsync=False)
self.assertTrue(len(TSV.timeSeries()) > 0)
TSV.exportMapsToImages(path=pathTestOutput)
self.showGui(TSV)
......
......@@ -29,6 +29,7 @@ from eotimeseriesviewer.tests import EOTSVTestCase
from eotimeseriesviewer.externals.qps.maptools import MapTools, MapToolCenter, \
FullExtentMapTool, PixelScaleExtentMapTool, QgsMapToolAddFeature, CursorLocationMapTool, QgsMapToolSelect
class TestMapTools(EOTSVTestCase):
"""Test that the plugin init is usable for QGIS.
......@@ -73,8 +74,6 @@ class TestMapTools(EOTSVTestCase):
self.assertIn(expectation, dict(metadata), message)
def test_TimeSeriesViewer(self):
from eotimeseriesviewer.main import EOTimeSeriesViewer
TSV = EOTimeSeriesViewer()
......@@ -102,11 +101,11 @@ class TestMapTools(EOTSVTestCase):
TSV.setMapTool(MapTools.CursorLocation)
self.assertIsInstance(TSV.mapCanvases()[0].mapTool(), CursorLocationMapTool)
#TSV.setMapTool(MapTools.SpectralProfile)
#self.assertIsInstance(TSV.mapCanvases()[0].mapTool(), SpectralProfileMapTool)
# TSV.setMapTool(MapTools.SpectralProfile)
# self.assertIsInstance(TSV.mapCanvases()[0].mapTool(), SpectralProfileMapTool)
#TSV.setMapTool(MapTools.TemporalProfile)
#self.assertIsInstance(TSV.mapCanvases()[0].mapTool(), TemporalProfileMapTool)
# TSV.setMapTool(MapTools.TemporalProfile)
# self.assertIsInstance(TSV.mapCanvases()[0].mapTool(), TemporalProfileMapTool)
TSV.setMapTool(MapTools.MoveToCenter)
self.assertIsInstance(TSV.mapCanvases()[0].mapTool(), MapToolCenter)
......
......@@ -21,8 +21,13 @@
from eotimeseriesviewer.tests import createTimeSeries, testRasterFiles, TestObjects, EOTSVTestCase
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.core import *
from qgis.gui import *
from qgis.core import QgsProject, QgsMapLayer, QgsRasterLayer, QgsVectorLayer, \
QgsRasterRenderer, QgsFeatureRenderer, \
QgsSingleBandGrayRenderer, QgsSingleBandPseudoColorRenderer, QgsMultiBandColorRenderer, \
QgsPalettedRasterRenderer, QgsSingleBandColorDataRenderer, QgsHillshadeRenderer, \
QgsRasterShader, \
QgsVirtualLayerDefinition
from qgis.gui import QgsFontButton
import unittest
import xmlrunner
from eotimeseriesviewer.utils import *
......@@ -31,10 +36,11 @@ from eotimeseriesviewer.mapcanvas import *
from eotimeseriesviewer.mapvisualization import *
from example.Images import Img_2014_05_07_LC82270652014127LGN00_BOA
from eotimeseriesviewer.main import EOTimeSeriesViewer
#from eotimeseriesviewer import initResources
#initResources()
# from eotimeseriesviewer import initResources
# initResources()
def getChildElements(node):
assert isinstance(node, QDomNode)
......@@ -43,7 +49,6 @@ def getChildElements(node):
def compareXML(element1, element2):
assert isinstance(element1, QDomNode)
assert isinstance(element2, QDomNode)
......@@ -60,7 +65,6 @@ def compareXML(element1, element2):
if len(elts1) == 0:
value1 = element1.nodeValue()
value2 = element2.nodeValue()
......