unittest broken due to SpectralLibrary API changes

Issue #769 resolved
Andreas Janz created an issue

In enmapbox/externals/qps/speclib/core/spectrallibrary.SpectralLibrary class, in write methode, options keyword was removed.

Error
Traceback (most recent call last):
  File "D:\source\QGISPlugIns\enmap-box\enmapboxprocessing\test\algorithm\test_SpectralResamplingByResponseFunctionConvolutionAlgorithmBase.py", line 33, in test_fwhm
    result = self.runalg(alg, parameters)
  File "D:\miniconda\envs\qgis\Library\python\plugins\processing\core\Processing.py", line 174, in runAlgorithm
    ret, results = execute(alg, parameters, context, feedback, catch_exceptions=False)
  File "D:\miniconda\envs\qgis\Library\python\plugins\processing\gui\AlgorithmExecutor.py", line 71, in execute
    results, ok = alg.run(parameters, context, feedback, {}, False)
_core.QgsProcessingException: Traceback (most recent call last):
  File "D:\source\QGISPlugIns\enmap-box\site-packages\typeguard\__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
  File "D:\source\QGISPlugIns\enmap-box\enmapboxprocessing\algorithm\spectralresamplingbyresponsefunctionconvolutionalgorithmbase.py", line 180, in processAlgorithm
    library.write(filename + '.srf.gpkg', options=options)
TypeError: write() got an unexpected keyword argument 'options'

Comments (11)

  1. Andreas Janz reporter

    I guess I now have to use the SpectralLibraryUtils for creating a library. If you don’t have a code snippet right away, I will look at it after my holidays.

  2. Benjamin Jakimow

    @Andreas should now work again, based on QgsVectorLayerExporter

    You might use

    • SpectralLibrary.write(uri:str, settings:dict, feedback: QgsProcessingFeedback)
    • SpectralLibraryUtils.writeToSource(speclib:QgsVectorLayer,uri, settings:dict, feedback: QgsProcessingFeedback

    In any case it trys to recognize the matching format from a uri extension and use the corresponding SpectralLibraryIO:

    *.gpkg → GeoPackageSpectralLibraryIO(SpectralLibraryIO)

    *.sli → EnviSpectralLibraryIO(SpectralLibraryIO) (works fine in GUI but so far does not handle multi-profile fields)

    settings:dict will be filled with requirements of the specific SpectralLibraryIO.exportProfiles(...)implementation. E.g. in case of GPKG settings(options=<my options dict>) options is input for QgsVectorLayerExporter.

  3. Andreas Janz reporter

    As discussed, I just removed the options. Now I get another error when running the unittest:

    Traceback (most recent call last):
      File "D:\source\QGISPlugIns\enmap-box\enmapboxprocessing\test\algorithm\test_SpectralResamplingByResponseFunctionConvolutionAlgorithmBase.py", line 33, in test_fwhm
        result = self.runalg(alg, parameters)
      File "D:\miniconda\envs\qgis\Library\python\plugins\processing\core\Processing.py", line 174, in runAlgorithm
        ret, results = execute(alg, parameters, context, feedback, catch_exceptions=False)
      File "D:\miniconda\envs\qgis\Library\python\plugins\processing\gui\AlgorithmExecutor.py", line 71, in execute
        results, ok = alg.run(parameters, context, feedback, {}, False)
    _core.QgsProcessingException: Traceback (most recent call last):
      File "D:\source\QGISPlugIns\enmap-box\site-packages\typeguard\__init__.py", line 903, in wrapper
        retval = func(*args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapboxprocessing\algorithm\spectralresamplingbyresponsefunctionconvolutionalgorithmbase.py", line 178, in processAlgorithm
        library.write(filename + '.srf.gpkg')
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\externals\qps\speclib\core\spectrallibrary.py", line 1401, in write
        return SpectralLibraryUtils.writeToSource(self, uri, settings=settings, feedback=feedback)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\externals\qps\speclib\core\spectrallibrary.py", line 274, in writeToSource
        return SpectralLibraryIO.writeSpeclibToUri(speclib, uri, settings=settings, feedback=feedback)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\externals\qps\speclib\core\spectrallibraryio.py", line 323, in writeSpeclibToUri
        feedback=feedback)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\externals\qps\speclib\core\spectrallibraryio.py", line 461, in writeProfilesToUri
        create_files = IO.exportProfiles(_uri.as_posix(), _settings, profiles, feedback=feedback)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\externals\qps\speclib\io\geopackage.py", line 148, in exportProfiles
        if writer.errorCode() != Qgis.VectorExportResult.Success:
    AttributeError: type object 'Qgis' has no attribute 'VectorExportResult'
    

  4. Log in to comment