Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue80 aryan, generation of processing algorithm *.rst files #1034

Merged
merged 17 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ per-file-ignores =
# QGS104 Use 'import qgis.PyQt.pyrcc_main' instead of 'import PyQt5.pyrcc_main'
# just not available in OSGeo4W installations
# script should run immediately which site.addsitedir(REPO) before other imports
scripts/*.py : E402
# scripts/*.py : E402
enmapbox/eo4qapps/geetimeseriesexplorerapp/*.py : F821
enmapbox/__main__.py: E402
enmapbox/gui/__init__.py: F401
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
python-version: "3.12"
- name: Run flake8
uses: julianwachholz/flake8-action@v2
with:
Expand Down
11 changes: 3 additions & 8 deletions enmapbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
import warnings

from osgeo import gdal

from qgis.PyQt.QtCore import QSettings
from qgis.PyQt.QtGui import QIcon
from qgis.core import Qgis, QgsApplication, QgsProcessingRegistry, QgsProcessingProvider, QgsProcessingAlgorithm
from qgis.core import Qgis, QgsApplication, QgsProcessingAlgorithm, QgsProcessingProvider, QgsProcessingRegistry
from qgis.gui import QgisInterface, QgsMapLayerConfigWidgetFactory

# provide shortcuts
Expand Down Expand Up @@ -96,7 +95,6 @@

ENMAP_BOX_KEY = 'EnMAP-Box'

_ENMAPBOX_PROCESSING_PROVIDER: QgsProcessingProvider = None
_ENMAPBOX_MAPLAYER_CONFIG_WIDGET_FACTORIES: typing.List[QgsMapLayerConfigWidgetFactory] = []

gdal.SetConfigOption('GDAL_VRT_ENABLE_PYTHON', 'YES')
Expand Down Expand Up @@ -262,13 +260,11 @@ def registerEnMAPBoxProcessingProvider():
assert isinstance(registry, QgsProcessingRegistry)
provider = registry.providerById(ID)
if not isinstance(provider, QgsProcessingProvider):
provider = EnMAPBoxProcessingProvider()
provider = EnMAPBoxProcessingProvider.instance()
registry.addProvider(provider)

assert isinstance(provider, EnMAPBoxProcessingProvider)
assert id(registry.providerById(ID)) == id(provider)
global _ENMAPBOX_PROCESSING_PROVIDER
_ENMAPBOX_PROCESSING_PROVIDER = provider

try:
existingAlgNames = [a.name() for a in registry.algorithms() if a.groupId() == provider.id()]
Expand All @@ -293,8 +289,7 @@ def unregisterEnMAPBoxProcessingProvider():
provider = registry.providerById(ID)

if isinstance(provider, EnMAPBoxProcessingProvider):
global _ENMAPBOX_PROCESSING_PROVIDER
_ENMAPBOX_PROCESSING_PROVIDER = None
EnMAPBoxProcessingProvider._ENMAPBOX_PROCESSING_PROVIDER = None
# this deletes the C++ object
registry.removeProvider(ID)

Expand Down
9 changes: 9 additions & 0 deletions enmapbox/algorithmprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ class EnMAPBoxProcessingProvider(QgsProcessingProvider):
It enhances the "standard" processing.core.AlgorithmProvider by functionality to add and remove GeoAlgorithms during runtime.
"""

_ENMAPBOX_PROCESSING_PROVIDER = None

@staticmethod
def instance() -> 'EnMAPBoxProcessingProvider':

if EnMAPBoxProcessingProvider._ENMAPBOX_PROCESSING_PROVIDER is None:
EnMAPBoxProcessingProvider._ENMAPBOX_PROCESSING_PROVIDER = EnMAPBoxProcessingProvider()
return EnMAPBoxProcessingProvider._ENMAPBOX_PROCESSING_PROVIDER

def __init__(self):
super(EnMAPBoxProcessingProvider, self).__init__()
# internal list of GeoAlgorithms. Is used on re-loads and can be manipulated
Expand Down
43 changes: 21 additions & 22 deletions enmapboxprocessing/enmapalgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@
from enum import Enum
from math import nan
from os import makedirs
from os.path import isabs, join, dirname, exists, splitext, abspath
from os.path import abspath, dirname, exists, isabs, join, splitext
from time import time
from typing import Any, Dict, Iterable, Optional, List, Tuple, TextIO
from typing import Any, Dict, Iterable, List, Optional, TextIO, Tuple

import numpy as np
from osgeo import gdal

import processing
from qgis.PyQt.QtCore import QVariant
from qgis.PyQt.QtGui import QIcon
from qgis.core import (Qgis, QgsCategorizedSymbolRenderer, QgsCoordinateReferenceSystem, QgsMapLayer,
QgsPalettedRasterRenderer, QgsProcessing, QgsProcessingAlgorithm, QgsProcessingContext,
QgsProcessingException, QgsProcessingFeedback, QgsProcessingOutputLayerDefinition,
QgsProcessingParameterBand, QgsProcessingParameterBoolean, QgsProcessingParameterCrs,
QgsProcessingParameterDefinition, QgsProcessingParameterEnum, QgsProcessingParameterExtent,
QgsProcessingParameterField, QgsProcessingParameterFile, QgsProcessingParameterFileDestination,
QgsProcessingParameterFolderDestination, QgsProcessingParameterMapLayer,
QgsProcessingParameterMatrix, QgsProcessingParameterMultipleLayers, QgsProcessingParameterNumber,
QgsProcessingParameterRange, QgsProcessingParameterRasterLayer, QgsProcessingParameterString,
QgsProcessingParameterVectorDestination, QgsProcessingParameterVectorLayer, QgsProcessingUtils,
QgsProject, QgsProperty, QgsRasterLayer, QgsRectangle, QgsVectorLayer)

from enmapbox.typeguard import typechecked
from enmapboxprocessing.driver import Driver
from enmapboxprocessing.glossary import injectGlossaryLinks
from enmapboxprocessing.parameter.processingparameterrasterdestination import ProcessingParameterRasterDestination
from enmapboxprocessing.processingfeedback import ProcessingFeedback
from enmapboxprocessing.typing import CreationOptions, GdalResamplingAlgorithm, ClassifierDump, \
TransformerDump, RegressorDump, ClustererDump
from enmapboxprocessing.typing import ClassifierDump, ClustererDump, CreationOptions, GdalResamplingAlgorithm, \
RegressorDump, TransformerDump
from enmapboxprocessing.utils import Utils
from qgis.PyQt.QtCore import QVariant
from qgis.PyQt.QtGui import QIcon
from qgis.core import (QgsProcessingAlgorithm, QgsProcessingParameterRasterLayer, QgsProcessingParameterVectorLayer,
QgsProcessingContext, QgsProcessingFeedback,
QgsRasterLayer, QgsVectorLayer, QgsProcessingParameterNumber, QgsProcessingParameterDefinition,
QgsProcessingParameterField, QgsProcessingParameterBoolean, QgsProcessingParameterEnum, Qgis,
QgsProcessingParameterString, QgsProcessingParameterBand, QgsCategorizedSymbolRenderer,
QgsPalettedRasterRenderer, QgsProcessingParameterMapLayer, QgsMapLayer,
QgsProcessingParameterExtent, QgsCoordinateReferenceSystem, QgsRectangle,
QgsProcessingParameterFileDestination, QgsProcessingParameterFile, QgsProcessingParameterRange,
QgsProcessingParameterCrs, QgsProcessingParameterVectorDestination, QgsProcessing,
QgsProcessingUtils, QgsProcessingParameterMultipleLayers, QgsProcessingException,
QgsProcessingParameterFolderDestination, QgsProject, QgsProcessingOutputLayerDefinition,
QgsProperty, QgsProcessingParameterMatrix)


class AlgorithmCanceledException(Exception):
Expand All @@ -42,8 +41,8 @@ class AlgorithmCanceledException(Exception):
class EnMAPProcessingAlgorithm(QgsProcessingAlgorithm):
O_RESAMPLE_ALG = 'NearestNeighbour Bilinear Cubic CubicSpline Lanczos Average Mode Min Q1 Med Q3 Max'.split()
NearestNeighbourResampleAlg, BilinearResampleAlg, CubicResampleAlg, CubicSplineResampleAlg, LanczosResampleAlg, \
AverageResampleAlg, ModeResampleAlg, MinResampleAlg, Q1ResampleAlg, MedResampleAlg, Q3ResampleAlg, \
MaxResampleAlg = range(12)
AverageResampleAlg, ModeResampleAlg, MinResampleAlg, Q1ResampleAlg, MedResampleAlg, Q3ResampleAlg, \
MaxResampleAlg = range(12)
O_DATA_TYPE = 'Byte Int16 UInt16 UInt32 Int32 Float32 Float64'.split()
Byte, Int16, UInt16, Int32, UInt32, Float32, Float64 = range(len(O_DATA_TYPE))
PickleFileFilter = 'Pickle files (*.pkl)'
Expand Down Expand Up @@ -1051,7 +1050,7 @@ class Group(Enum):
RasterProjections = 'Raster projections'
Regression = 'Regression'
Sampling = 'Sampling'
SpectralLibrary = 'Spectral library'
SpectralLibrary = 'Spectral Library'
SpectralResampling = 'Spectral resampling'
Testdata = 'Testdata'
Transformation = 'Transformation'
Expand Down
10 changes: 5 additions & 5 deletions scripts/EnFireMAP/sample_data.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from os import listdir, makedirs
from os.path import join, exists, dirname
from os.path import dirname, exists, join

from qgis.core import QgsVectorFileWriter, QgsVectorLayer

from enmapbox import initAll
from enmapbox.testing import start_app
from enmapboxprocessing.algorithm.samplerastervaluesalgorithm import SampleRasterValuesAlgorithm
from enmapboxprocessing.enmapalgorithm import EnMAPProcessingAlgorithm
from qgis.core import QgsVectorFileWriter, QgsVectorLayer

rootCube = r'D:\data\EnFireMap\cube'
tilingScheme = QgsVectorLayer(r'D:\data\EnFireMap\cube\shp\grid2.geojson')
Expand All @@ -21,9 +24,6 @@
locations = QgsVectorLayer(r'D:\data\EnFireMap\lib_points\lib_points.shp')
rootOutputSample = r'D:\data\EnFireMap\sample3'

from enmapbox import initAll
from enmapbox.testing import start_app

qgsApp = start_app()
initAll()

Expand Down
13 changes: 4 additions & 9 deletions scripts/create_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,24 @@
import pathlib
import re
import shutil
import site
import sys
import textwrap
import typing
import warnings
import markdown
from typing import Union

import docutils.core
from os.path import exists

from qgis.core import QgsUserProfileManager, QgsUserProfile, QgsFileUtils

site.addsitedir(pathlib.Path(__file__).parents[1]) # noqa

import markdown
import docutils.core
from qgis.core import QgsFileUtils, QgsUserProfile, QgsUserProfileManager
from qgis.testing import start_app

app = start_app()
import enmapbox
from enmapbox import DIR_REPO
from enmapbox.qgispluginsupport.qps.make.deploy import QGISMetadataFileWriter, userProfileManager
from enmapbox.qgispluginsupport.qps.utils import zipdir

app = start_app()
# consider default Git location on Windows systems to avoid creating a Start-Up Script
try:
import git
Expand Down
Loading
Loading