Commit caf79b61 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

pulled qps updates


Signed-off-by: Benjamin Jakimow's avatarBenjamin Jakimow <benjamin.jakimow@geo.hu-berlin.de>
parent ec0b1531
......@@ -25,7 +25,6 @@
***************************************************************************
"""
import os
import collections
import numpy as np
......@@ -43,13 +42,13 @@ from .utils import *
from .models import *
from .classification.classificationscheme import ClassInfo, ClassificationScheme
class SourceValueSet(object):
def __init__(self, source, point:SpatialPoint):
def __init__(self, source, point: SpatialPoint):
assert isinstance(point, SpatialPoint)
self.source = source
self.point = point
def baseName(self):
return os.path.basename(self.source)
......@@ -58,7 +57,6 @@ class SourceValueSet(object):
class RasterValueSet(SourceValueSet):
class BandInfo(object):
def __init__(self, bandIndex, bandValue, bandName, classInfo=None):
assert bandIndex >= 0
......@@ -72,7 +70,6 @@ class RasterValueSet(SourceValueSet):
self.bandName = bandName
self.classInfo = classInfo
def __init__(self, source, point, pxPosition):
assert isinstance(pxPosition, QPoint)
super(RasterValueSet, self).__init__(source, point)
......@@ -80,6 +77,7 @@ class RasterValueSet(SourceValueSet):
self.noDataValue = None
self.bandValues = []
class VectorValueSet(SourceValueSet):
class FeatureInfo(object):
def __init__(self, fid):
......@@ -87,7 +85,7 @@ class VectorValueSet(SourceValueSet):
self.fid = fid
self.attributes = collections.OrderedDict()
def __init__(self, source, point:SpatialPoint):
def __init__(self, source, point: SpatialPoint):
super(VectorValueSet, self).__init__(source, point)
self.features = []
......@@ -189,7 +187,6 @@ class CursorLocationInfoModel(TreeModel):
n.setToolTip('Color selected from screen pixel')
n.setValues(bv.getRgb())
if isinstance(sourceValueSet, VectorValueSet):
if len(sourceValueSet.features) == 0:
return
......@@ -204,7 +201,6 @@ class CursorLocationInfoModel(TreeModel):
if 'point' in typeName:
root.setIcon(QIcon(r':/images/themes/default/mIconPointLayer.svg'))
for field in refFeature.fields():
assert isinstance(field, QgsField)
......@@ -346,7 +342,7 @@ class CursorLocationInfoDock(QDockWidget):
return (layerMode, layerType, rasterBands)
def loadCursorLocation(self, point:SpatialPoint, canvas:QgsMapCanvas):
def loadCursorLocation(self, point: SpatialPoint, canvas: QgsMapCanvas):
"""
:param point:
:param canvas:
......@@ -354,7 +350,7 @@ class CursorLocationInfoDock(QDockWidget):
"""
assert isinstance(canvas, QgsMapCanvas)
assert isinstance(point, SpatialPoint)
crs = canvas.mapSettings().destinationCrs()
self.setCursorLocation(point)
self.setCanvas(canvas)
self.reloadCursorLocation()
......@@ -416,7 +412,7 @@ class CursorLocationInfoDock(QDockWidget):
bandNumbers = renderer.usesBands()
elif rasterbands == 'ALL':
bandNumbers = list(range(1, l.bandCount()+1))
bandNumbers = list(range(1, l.bandCount() + 1))
else:
bandNumbers = [1]
......@@ -440,9 +436,8 @@ class CursorLocationInfoDock(QDockWidget):
classInfo = None
if isinstance(bandValue, (int, float)) \
and isinstance(classScheme, ClassificationScheme) \
and bandValue >= 0 \
and bandValue < len(classScheme):
and isinstance(classScheme, ClassificationScheme) \
and 0 <= bandValue < len(classScheme):
classInfo = classScheme[int(bandValue)]
info = RasterValueSet.BandInfo(b - 1, bandValue, l.bandName(b), classInfo=classInfo)
v.bandValues.append(info)
......@@ -478,7 +473,7 @@ class CursorLocationInfoDock(QDockWidget):
pass
def setCursorLocation(self, spatialPoint:SpatialPoint):
def setCursorLocation(self, spatialPoint: SpatialPoint):
"""
Set the cursor lcation to be loaded.
:param crs: QgsCoordinateReferenceSystem
......@@ -532,7 +527,6 @@ class CursorLocationInfoDock(QDockWidget):
self.btnCrs.setCrs(crs)
self.updateCursorLocationInfo()
def cursorLocation(self) -> SpatialPoint:
"""
Returns the last location that was set.
......@@ -543,13 +537,3 @@ class CursorLocationInfoDock(QDockWidget):
return None, None
class Resulthandler(QObject):
def __init__(self):
super(Resulthandler, self).__init__()
def onResult(self, *args):
print(args)
R = Resulthandler()
......@@ -44,7 +44,14 @@ import enum
import sip
import random
from qgis.core import *
from qgis.core import QgsMapLayer, QgsRasterLayer, QgsVectorLayer, QgsWkbTypes, QgsProcessingContext, \
QgsProcessingFeedback, QgsField, QgsFields, QgsApplication, QgsCoordinateReferenceSystem, QgsProject, \
QgsProcessingParameterNumber, QgsProcessingAlgorithm, QgsProcessingProvider, QgsPythonRunner, \
QgsFeatureStore, QgsProcessingParameterRasterDestination, QgsProcessingParameterRasterLayer, \
QgsProviderRegistry, QgsLayerTree, QgsLayerTreeModel, QgsLayerTreeRegistryBridge
from qgis.gui import *
from qgis.gui import QgsPluginManagerInterface, QgsLayerTreeMapCanvasBridge, QgsLayerTreeView, QgsMessageBar, \
QgsMapCanvas, QgsGui, QgisInterface
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
......@@ -91,6 +98,7 @@ class StartOptions(enum.IntFlag):
PrintProviders = 8
All = EditorWidgets | ProcessingFramework | PythonRunner | PrintProviders
def start_app(cleanup=True, options=StartOptions.Minimized, resources: list = []) -> QgsApplication:
if isinstance(QgsApplication.instance(), QgsApplication):
print('Found existing QgsApplication.instance()')
......@@ -363,8 +371,7 @@ class TestCase(qgis.testing.TestCase):
import gc
gc.collect()
def testOutputDirectory(self, name:str='test-outputs') -> pathlib.Path:
def testOutputDirectory(self, name: str = 'test-outputs') -> pathlib.Path:
"""
Returns the path to a test output directory
:return:
......@@ -478,7 +485,7 @@ class TestObjects():
n_bands = [nb if nb > 0 else cnb for nb in n_bands]
for nb in n_bands:
band_indices = np.linspace(0, cnb-1, num=nb, dtype=np.int16)
band_indices = np.linspace(0, cnb - 1, num=nb, dtype=np.int16)
i = 0
while i < n:
x = random.randint(0, coredata.shape[2] - 1)
......@@ -542,7 +549,11 @@ class TestObjects():
@staticmethod
def createRasterDataset(ns=10, nl=20, nb=1,
crs=None, gt=None,
eType: int = gdal.GDT_Int16, nc: int = 0, path: str = None) -> gdal.Dataset:
eType: int = gdal.GDT_Int16,
nc: int = 0,
path: str = None,
no_data_rectangle: int = 0,
no_data_value: typing.Union[int, float] = -9999) -> gdal.Dataset:
"""
Generates a gdal.Dataset of arbitrary size based on true data from a smaller EnMAP raster image
"""
......@@ -566,8 +577,15 @@ class TestObjects():
else:
path = '/vsimem/testImage.{}.tif'.format(str(uuid.uuid4()))
ds = drv.Create(path, ns, nl, bands=nb, eType=eType)
ds: gdal.Driver = drv.Create(path, ns, nl, bands=nb, eType=eType)
assert isinstance(ds, gdal.Dataset)
if no_data_rectangle > 0:
no_data_rectangle = min([no_data_rectangle, ns])
no_data_rectangle = min([no_data_rectangle, nl])
for b in range(ds.RasterCount):
band: gdal.Band = ds.GetRasterBand(b+1)
band.SetNoDataValue(no_data_value)
coredata, core_wl, core_wlu, core_gt, core_wkt = TestObjects.coreData()
dt_out = gdal_array.flip_code(eType)
......@@ -583,10 +601,9 @@ class TestObjects():
if nc > 0:
for b in range(nb):
band = ds.GetRasterBand(b + 1)
band: gdal.Band = ds.GetRasterBand(b + 1)
assert isinstance(band, gdal.Band)
nodata = band.GetNoDataValue()
array = np.empty((nl, ns), dtype=dt_out)
assert isinstance(array, np.ndarray)
......@@ -601,16 +618,18 @@ class TestObjects():
y0 += y1 + 1
band.SetCategoryNames(scheme.classNames())
band.SetColorTable(scheme.gdalColorTable())
if no_data_rectangle > 0:
array[0:no_data_rectangle, 0:no_data_rectangle] = no_data_value
band.WriteArray(array)
else:
# fill with test data
coredata = coredata.astype(dt_out)
cb, cl, cs = coredata.shape
if nb > coredata.shape[0]:
coreddata2 = np.empty((nb, cl, cs), dtype=dt_out)
coreddata2[0:cb, :, :] = coredata
# todo: increase the number of output bands by linear interpolation instead just repeated the last band
# todo: increase the number of output bands by linear interpolation instead just repeating the last band
for b in range(cb, nb):
coreddata2[b, :, :] = coredata[-1, :, :]
coredata = coreddata2
......@@ -625,6 +644,11 @@ class TestObjects():
yoff += ysize
xoff += xsize
if no_data_rectangle > 0:
arr = np.empty((nb, no_data_rectangle, no_data_rectangle), dtype=coredata.dtype)
arr.fill(no_data_value)
ds.WriteRaster(0, 0, no_data_rectangle, no_data_rectangle, arr.tobytes())
wl = []
if nb > cb:
wl.extend(core_wl.tolist())
......@@ -971,4 +995,3 @@ class QgsPythonRunnerMockup(QgsPythonRunner):
raise ex
return False
return True
......@@ -46,7 +46,7 @@ import datetime
from qgis.core import *
from qgis.core import QgsField, QgsVectorLayer, QgsRasterLayer, QgsRasterDataProvider, QgsMapLayer, QgsMapLayerStore, \
QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsRectangle, QgsPointXY, QgsProject, \
QgsMapLayerProxyModel, QgsRasterRenderer, QgsMessageOutput, QgsFeature, QgsTask
QgsMapLayerProxyModel, QgsRasterRenderer, QgsMessageOutput, QgsFeature, QgsTask, Qgis
from qgis.gui import *
from qgis.gui import QgisInterface, QgsDialog, QgsMessageViewer, QgsMapLayerComboBox, QgsMapCanvas
......@@ -282,69 +282,69 @@ class UnitLookup(object):
# so far this unit is unknown. Try to find the base unit
# store unit string in Lookup table for fast conversion into its base unit
# e.g. to convert string like "MiKrOMetErS" to "μm"
baseUnit = None
base_unit = None
if unit in UnitLookup.metric_units() + \
UnitLookup.date_units() + \
UnitLookup.time_units():
baseUnit = unit
base_unit = unit
elif re.search(r'^(Nanomet(er|re)s?)$', unit, re.I):
baseUnit = 'nm'
base_unit = 'nm'
elif re.search(r'^(Micromet(er|re)s?|um|μm)$', unit, re.I):
baseUnit = 'μm'
base_unit = 'μm'
elif re.search(r'^(Millimet(er|re)s?)$', unit, re.I):
baseUnit = 'mm'
base_unit = 'mm'
elif re.search(r'^(Centimet(er|re)s?)$', unit, re.I):
baseUnit = 'cm'
base_unit = 'cm'
elif re.search(r'^(Decimet(er|re)s?)$', unit, re.I):
baseUnit = 'dm'
base_unit = 'dm'
elif re.search(r'^(Met(er|re)s?)$', unit, re.I):
baseUnit = 'm'
base_unit = 'm'
elif re.search(r'^(Hectomet(er|re)s?)$', unit, re.I):
baseUnit = 'hm'
base_unit = 'hm'
elif re.search(r'^(Kilomet(er|re)s?)$', unit, re.I):
baseUnit = 'km'
base_unit = 'km'
# date units
elif re.search(r'(Date([_\- ]?Time)?([_\- ]?Group)?|DTG)$', unit, re.I):
baseUnit = 'DateTime'
base_unit = 'DateTime'
elif re.search(r'^(doy|Day[-_ ]?Of[-_ ]?Year?)$', unit, re.I):
baseUnit = 'DOY'
base_unit = 'DOY'
elif re.search(r'decimal[_\- ]?years?$', unit, re.I):
baseUnit = 'DecimalYear'
base_unit = 'DecimalYear'
elif re.search(r'decimal[_\- ]?years?\[356\]$', unit, re.I):
baseUnit = 'DecimalYear[365]'
base_unit = 'DecimalYear[365]'
elif re.search(r'decimal[_\- ]?years?\[366\]$', unit, re.I):
baseUnit = 'DecimalYear[366]'
base_unit = 'DecimalYear[366]'
elif re.search(r'^Years?$', unit, re.I):
baseUnit = 'Y'
base_unit = 'Y'
elif re.search(r'^Months?$', unit, re.I):
baseUnit = 'M'
base_unit = 'M'
elif re.search(r'^Weeks?$', unit, re.I):
baseUnit = 'W'
base_unit = 'W'
elif re.search(r'^Days?$', unit, re.I):
baseUnit = 'D'
base_unit = 'D'
elif re.search(r'^Hours?$', unit, re.I):
baseUnit = 'h'
base_unit = 'h'
elif re.search(r'^Minutes?$', unit, re.I):
baseUnit = 'm'
base_unit = 'm'
elif re.search(r'^Seconds?$', unit, re.I):
baseUnit = 's'
base_unit = 's'
elif re.search(r'^MilliSeconds?$', unit, re.I):
baseUnit = 'ms'
base_unit = 'ms'
elif re.search(r'^MicroSeconds?$', unit, re.I):
baseUnit = 'us'
base_unit = 'us'
elif re.search(r'^NanoSeconds?$', unit, re.I):
baseUnit = 'ns'
base_unit = 'ns'
elif re.search(r'^Picoseconds?$', unit, re.I):
baseUnit = 'ps'
base_unit = 'ps'
elif re.search(r'^Femtoseconds?$', unit, re.I):
baseUnit = 'fs'
base_unit = 'fs'
elif re.search(r'^Attoseconds?$', unit, re.I):
baseUnit = 'as'
base_unit = 'as'
if baseUnit:
UnitLookup.UNIT_LOOKUP[unit] = baseUnit
return baseUnit
if base_unit:
UnitLookup.UNIT_LOOKUP[unit] = base_unit
return base_unit
@staticmethod
def isMetricUnit(unit: str) -> bool:
......@@ -1155,13 +1155,15 @@ def check_package(name, package=None, stop_on_error=False):
return True
def as_py_value(value, datatype:Qgis.DataType):
def as_py_value(value, datatype: Qgis.DataType):
"""
Converts values into a corresponding python_typee
Converts values into a corresponding python_type
:param value:
:param datatype:
:return:
"""
if value in [None, QVariant()]:
return None
if datatype in [Qgis.Byte, Qgis.Int16, Qgis.Int32, Qgis.UInt16, Qgis.UInt32]:
return int(value)
elif datatype in [Qgis.Float32, Qgis.Float64, Qgis.CFloat32, Qgis.CFloat64]:
......@@ -1216,11 +1218,19 @@ def scanResources(path=':') -> typing.Iterator[str]:
def datetime64(value, dpy: int = None) -> np.datetime64:
"""
Converts an input value into a numpy.datetime64 value.
:param value:
:return:
:param value: the value to be converted into a numpy.datetime64 value
:param dpy: days per year. If `value` is a float, it is considered to be a decimal year value.
By default it is assumed that the year fraction is calculated on 366 year in leap years and 365
in none-leap year. However, dpy can be used to use any other number of days per year to convert
the fraction back into days.
:return: numpy.datetime64
"""
if isinstance(value, np.datetime64):
return value
elif isinstance(value, QDate):
return np.datetime64(value.toPyDate())
elif isinstance(value, QDateTime):
return np.datetime64(value.toPyDateTime())
elif isinstance(value, (str, datetime.date, datetime.datetime)):
return np.datetime64(value)
elif isinstance(value, int):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment