TUFLOW-Support / QGIS-TUFLOW-Plugin

TUFLOW related QGIS Plugins
9 stars 7 forks source link

Error loading specific 2D Map Results on Linux #23

Closed ZedeN1 closed 3 years ago

ZedeN1 commented 3 years ago

I keep getting an error loading in specific 2D map results, available on Google Drive. The layer gets added to Layer's panel but not TUFLOW Viewer. I am still able to view the results and change times/ datasets using QGIS in-built styling / properties but not through the viewer.

Same results files open fine on Windows. Other model result files get opened without any issues on Windows and Linux.

This is using TUFLOW Viewer v3.1.1 directly from QGIS repository.

The same issue also happens on a different Linux machine running same TUFLOW Viewer but QGIS 3.10 LTR

An error has occurred while executing Python code: 

RuntimeError: dictionary keys changed during iteration 
Traceback (most recent call last):
  File "/home/pavel/.local/share/QGIS/QGIS3/profiles/default/python/plugins/tuflow/tuflowqgis_tuviewer/tuflowqgis_tumenufunctions.py", line 81, in load2dResults
    loaded = self.tuView.tuResults.importResults('mesh', inFileNames[0])
  File "/home/pavel/.local/share/QGIS/QGIS3/profiles/default/python/plugins/tuflow/tuflowqgis_tuviewer/tuflowqgis_turesults.py", line 75, in importResults
    result = self.tuResults2D.importResults(inFileNames)
  File "/home/pavel/.local/share/QGIS/QGIS3/profiles/default/python/plugins/tuflow/tuflowqgis_tuviewer/tuflowqgis_turesults2d.py", line 101, in importResults
    index = self.getResultMetaData(name, mLayer, ext)
  File "/home/pavel/.local/share/QGIS/QGIS3/profiles/default/python/plugins/tuflow/tuflowqgis_tuviewer/tuflowqgis_turesults2d.py", line 370, in getResultMetaData
    self.alignFirstTimestepValues()
  File "/home/pavel/.local/share/QGIS/QGIS3/profiles/default/python/plugins/tuflow/tuflowqgis_tuviewer/tuflowqgis_turesults2d.py", line 908, in alignFirstTimestepValues
    for i in results[result][resultType]['times']:
RuntimeError: dictionary keys changed during iteration

Python version: 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0] 
QGIS version: 3.14.0-Pi Pi, 9f7028fd23 
pavel@blackwater:~$ lsb_release -a
LSB Version:    core-11.1.0ubuntu2-noarch:printing-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal
pavel@blackwater:~$ uname -a
Linux blackwater 5.4.0-39-generic #43-Ubuntu SMP Fri Jun 19 10:28:31 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
QGIS version
3.14.0-Pi
QGIS code revision
9f7028fd23
Compiled against Qt
5.12.8
Running against Qt
5.12.8
Compiled against GDAL/OGR
3.0.4
Running against GDAL/OGR
3.0.4
Compiled against GEOS
3.8.0-CAPI-1.13.1
Running against GEOS
3.8.0-CAPI-1.13.1 
Compiled against SQLite
3.31.1
Running against SQLite
3.31.1
PostgreSQL Client Version
12.2 (Ubuntu 12.2-4)
SpatiaLite Version
4.3.0a
QWT Version
6.1.4
QScintilla2 Version
2.11.2
Compiled against PROJ
6.3.1
Running against PROJ
Rel. 6.3.0, January 1st, 2020
OS Version
Ubuntu 20.04 LTS
Active python plugins
DigitizingTools; 
Coordtransform; 
crayfish; 
QuickOSM; 
ImportPhotos; 
nominatim; 
quick_map_services; 
processing_r; 
LAStools; 
profiletool; 
QPackage; 
DataPlotly; 
valuetool; 
tuflow; 
SwapVectorDirection; 
processing; 
db_manager; 
MetaSearch
ZedeN1 commented 3 years ago

Quick google search suggested the following changes in tuflowqgis_turesults2d.py.

(change line 908 and remove following indent. Seems to work but I have no idea what I am doing!)

            if firstTime is not None:
                if firstTime == 0:
                    continue  # move onto next result dataset
                else:  # find time 0 values and change to firstTime
                    for resultType in results[result]:
                        #if '_ts' not in resultType and '_lp' not in resultType:
                        if TuResults.isMapOutputType(resultType):
                            if len(results[result][resultType]['times']) == 1:
                                for i in [x for x in results[result][resultType]['times'] if x == 0]:
                                    timeKey = '{0:.6f}'.format(firstTime)
                                    dataType = results[result][resultType]['times'][i][1]
                                    meshIndex = results[result][resultType]['times'][i][2]
                                    results[result][resultType]['times'][timeKey] = (firstTime, dataType, meshIndex)
                                    del results[result][resultType]['times'][i]

                                    # also delete from dicts
                                    a = sorted([x for x in self.tuView.tuResults.time2date.keys()])
                                    if a[0] != firstTime:
                                        del self.tuView.tuResults.time2date[a[0]]

                                        a = sorted([x for x in self.tuView.tuResults.timekey2date.keys()])
                                        del self.tuView.tuResults.timekey2date[a[0]]

                                        a = sorted([x for x in self.tuView.tuResults.timekey2time.keys()])
                                        del self.tuView.tuResults.timekey2time[a[0]]

                                        a = sorted([x for x in self.tuView.tuResults.date2time.keys()])
                                        del self.tuView.tuResults.date2time[a[0]]

                                        a = sorted([x for x in self.tuView.tuResults.date2timekey.keys()])
                                        del self.tuView.tuResults.date2timekey[a[0]]
TUFLOW-Support commented 3 years ago

Hi, thanks for letting us know. I think I already fixed this one (locally). I did something similar and iterated through a copy of the dictionary keys. I was able to load the example datasets you provided.

I'll upload a copy of the latest plugin (it has a bunch of fixes if you're using QGIS 3.14).