IndexError: list index out of range

523 views
Skip to first unread message

Tom Bell

unread,
Dec 16, 2021, 4:17:23 PM12/16/21
to QSWAT+
Hi,

When reading my land use and soils rasters, I get the following messages.  All of my rasters have the same coordinate system, number of rows and columns, bounding coordinates, and data type.  If I add the land use and soil rasters to my map outside of QSWAT+, they overlap the DEM perfectly without any errors so I am convinced that the coordinate systems of all three are identical including the ESPG code.

While looking at the SWAT+ forum I ran across this thread which might be related.  In this case the programmer had to made some changes to  the swatplus_datasets.sqlite.  Is this a known problem?

Tom

-----------------------------------------------------------------------------------------------------------------------------------

WARNING: only 0.0 percent of the watershed has defined landuse values.
 If this percentage is zero check your landuse map has the same projection as your DEM.

WARNING: only 0.0 percent of the watershed has defined soil values.
 If this percentage is zero check your soil map has the same projection as your DEM.

An error has occurred while executing Python code:

IndexError: list index out of range
Traceback (most recent call last):
  File "C:/PROGRA~1/QGIS3~1.16/apps/qgis-ltr/./python/plugins\QSWATPlus3_64\hrus.py", line 5223, in readFiles
    OK = self.CreateHRUs.generateBasins(self._dlg.progressBar, root)
  File "C:/PROGRA~1/QGIS3~1.16/apps/qgis-ltr/./python/plugins\QSWATPlus3_64\hrus.py", line 1046, in generateBasins
    self.writeTopoReport()
  File "C:/PROGRA~1/QGIS3~1.16/apps/qgis-ltr/./python/plugins\QSWATPlus3_64\hrus.py", line 2551, in writeTopoReport
    self.writeTopoReportSection(self.elevMap, fw, 'watershed')
  File "C:/PROGRA~1/QGIS3~1.16/apps/qgis-ltr/./python/plugins\QSWATPlus3_64\hrus.py", line 2579, in writeTopoReportSection
    (minimum, maximum, totalFreq, mean, stdDev) = self.analyseElevMap(mapp)
  File "C:/PROGRA~1/QGIS3~1.16/apps/qgis-ltr/./python/plugins\QSWATPlus3_64\hrus.py", line 2623, in analyseElevMap
    while mapp[minimum] == 0:
IndexError: list index out of range

Chris George

unread,
Dec 18, 2021, 8:47:59 AM12/18/21
to Tom Bell, QSWAT+
QGIS used to have a switch which allowed for on-the-fly reprojection to
be turned on or off, and I advised people to turn it off so it was
obvious if your soil or landuse map did not overlap with the DEM. In
current versions of QGIS it cannot be turned off, so you cannot see
visibly if there is an overlap. You should check by right clicking on
the layers panel entries for the DEM, landuse and soil maps, selecting
Properties, and looking at the CRS field in the Information tab.

It would be possible for QSWAT+ to do the on-the-fly reprojection of
each pixel in the DEM to find the corresponding pixel in each of the
landuse and soil maps, but allocating each DEM pixel to an HRU is
already the slowest calculation in QSWAT+, and projecting these maps in
advance is much more efficient.

Note that it is not necessary to align the numbers of rows and columns,
the bounding coordinates and data types of the landuse and soil maps
with the DEM, as these are simple calculations and are corrected on the
fly by QSWAT+ (though the code will run a little faster if the pixel
sizes and origins are aligned).

Regards,
Chris

On 12/16/2021 4:08 PM, Tom Bell wrote:
> Hi,
>
> When reading my land use and soils rasters, I get the following
> messages.  All of my rasters have the same coordinate system, number of
> rows and columns, bounding coordinates, and data type.  If I add the
> land use and soil rasters to my map outside of QSWAT+, they overlap the
> DEM perfectly without any errors so I am convinced that the coordinate
> systems of all three are identical including the ESPG code.
>
> While looking at the SWAT+ forum I ran across this thread
> <https://groups.google.com/g/swatplus/c/SfmM5h_-KhE/m/ZtaU8weNAAAJ>
> --
> You received this message because you are subscribed to the Google
> Groups "QSWAT+" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to qswatplus+...@googlegroups.com
> <mailto:qswatplus+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/qswatplus/492e37ff-9dfc-4733-8236-10b148fb2db4n%40googlegroups.com
> <https://groups.google.com/d/msgid/qswatplus/492e37ff-9dfc-4733-8236-10b148fb2db4n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Jean Yves N'GUESSAN

unread,
Dec 21, 2021, 8:32:27 AM12/21/21
to Chris George, Tom Bell, QSWAT+
Thanks Chris!

I did check the DEM and land use/land cover and soil maps SCRs and they match but the problem persists in QSWAT+.
I am attaching the screenshots. I don't know where the error is anymore.

Regards.

N’GUESSAN Konan Jean-Yves

00225 07-475-55-026 / 01-028-25-949

Doctorant en Agro-Hydrologie / PhD Student in Agro-Hydrology

Laboratoire des Sciences et Technologies de l’Environnement / Laboratory of Environmental Science and Technology

UNIVERSITE JEAN LOROUGNON GUEDE, DALOA-COTE D’IVOIRE



To unsubscribe from this group and stop receiving emails from it, send an email to qswatplus+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qswatplus/fc21dc3e-9b87-5a21-082b-212dc4cc2b97%40mcmaster.ca.
Capture d’écran 2021-12-21 120546.png
Capture d’écran 2021-12-21 120616.png
Capture d’écran 2021-12-21 120638.png

Tom Bell

unread,
Dec 21, 2021, 8:32:27 AM12/21/21
to QSWAT+
Hi Chris,

Thanks for addressing the problem.

I loaded each raster into a separate blank QGIS project and copied and pasted the CRS for each one below.  Each one has the same CRS when they are read into my SWAT project.

RSR_DEM              CRS     EPSG:3726 - NAD83(NSRS2007) / UTM zone 19N - Projected
RSR_SSURGO       CRS     EPSG:3726 - NAD83(NSRS2007) / UTM zone 19N - Projected
RSR_LU                  CRS     EPSG:3726 - NAD83(NSRS2007) / UTM zone 19N - Projected

The alignment of the rows and columns, bounding coordinates, and data types was done in desperation because nothing else I tried was working.

I forgot to mention that the "Writing topographic report" task shows a completed progress bar but the report is never actually completed (wait cursor still spinning) even after leaving it overnight.

I understand that this could be a heavy lift if the resolution of the input rasters is high.  Their dimensions are 1900x2550.  More than half of the LU raster has no data cells (-99999).  Am I right to assume that QSWAT+ would clip these rasters to the watershed boundary before any calculations took place? 

Regards
Tom

Tom Bell

unread,
Dec 22, 2021, 8:04:11 AM12/22/21
to QSWAT+
Hi Jean-Yves,

I am glad you have confirmed that your DEMs are also in the same coordinate system.  It seems to indicate that our problems are not SWAT model specific.  It is most likely some error in the code somewhere.  I looked at the last calls before the error and since I am not familiar with the code saw nothing obvious.  I did not see where the final error message was called however which makes any help on my part impossible.

Tom

Richard Heal

unread,
Dec 26, 2021, 7:40:55 PM12/26/21
to QSWAT+
Hi all

Interested in this conversation as I too am having an issue with zero land use and soil.  My rasters are all in the same CRS etc.  I have a few comments/questions/points that may help:

1. Are you trying to add lakes to the watershed?  I am looking at whether this step of the process (adding lakes via a shapefile) causes the issue.  Maybe to do with merging small subbasins?  CRS not set correctly?
2. When I add the landuse and soil rasters I update the symbology (it does not automatically classify them) and I set the NoData value to zero for each - again not sure if this is the case but is part of a set of processes I have done that has managed to get it to work (sometimes)
3. I also set the project home folder, CRS and remove any transformations from QGIS Options.
4. I manually set the CRS of the lakes shapefile after it has been added.
5. Be careful merging small subbasins - I think this may throw the system when adding lakes.

I use rasters at lower resolution to go through the model building before trying it with 10m x 10m rasters - just for the sake of speed of processing.  Usually I have no errors on the "delineate watershed" stage but if the numbers do not appear on the subbasins the next stage - Create HRUs - does not seem to work.

Sorry that this all seems a bit like a "black box".  There are so many combinations to try out and I often settle on a set that work.

Best

Richard

Tom Bell

unread,
Dec 29, 2021, 9:37:49 AM12/29/21
to QSWAT+

Hi Richard,

Thanks for weighing in on this. but I'm sorry for you to have joined our small club.  In answer to your questions:

1.  I have five lakes identified as 3 wetlands and 2 lakes.  The CRS for all inputs, (shapefiles and rasters) are identical.

2.  I had not noticed that both the SSURGO and Landuse rasters had not been classified and symbolized.  I just did that and it does not make any difference.  I expected symbolization would occur when they had been successfully read and new rasters clipped to the watershed boundary were generated.
 
My no-data is set to -99999.  The SSURGO raster does not have any missing data.  The landuse raster does.  

I created two dummy rasters.  I set the first one so that all cells had a value of 1.  I set the second one so that all values were 2.  When I loaded and read them, I still got the same Index error.

3. I haven't tried this but since I have confirmed and reconfirmed the CRS of all layers, I don't see the point of disabling the transforms option.  Could be wrong here.

4. I confirmed that the CRS of the lakes file is identical to all other layers so no need to reset it.

5. I did not automatically merge small sub-basins since they were already not so small.  I did check the attributes table of the sub-basin shapefile to confirm that there were no small ones that I had not noticed.

My two lakes are small and I only see the sub-basin number appear when I zoom in.  They are both there.

Perhaps three is the magic number of users with the same problem for someone more knowledgeable than us to help out.

Cheers
Tom

Richard Heal

unread,
Jan 3, 2022, 10:32:15 AM1/3/22
to QSWAT+
Thanks Tom

Sorry I could not help.  I have found that the land use and soil rasters when clipped appear in the table of contents but the symbology is not classified.  I do this to check overlap.  Also, I find the NoData value does not always mirror that of the original hence I change this before proceeding.

I seem to be able to get the process to work (well I think it does as I have not taken the models further yet) if I do not merge sub-basins.  For me this seems to mess things up and results in the map at the end of the watershed process not having the subbasins numbered.

I assume the Robit example that comes with the software works?

Best wishes for the New Year!

Richard

Tom Bell

unread,
Jan 6, 2022, 7:04:06 AM1/6/22
to QSWAT+
I found the problem.  I found this on page 25 of the manual.

Floodplain maps created by QSWAT+ need to be recreated after rerunning delineation because they are based on the channel network, which is likely to change when delineation is rerun with different parameters or with changed inlets or outlets.

I don't recall changing any of my outlets or rerunning the delineation but I have been playing with this part of the program over and over and it is possible.  In any case, after several tries I was able to re-run the inversion to create a new floodplain map.  At least in my case, I kept getting cryptic errors when re-running it until I removed the invflood0_10 tif AND deleted it from the directory. QSWAT did not want to overwrite it for some reason even when it had been removed from the project.

Once I had a fresh inversion flood plain map, all necessary rasters were read and I was able to finally create the HRUs.  My take away is not get lost in the the error messages since none of the errors I got pointed to the actual problem.  Trial and error saved the day unless you are counting lost hours without a clue.
Reply all
Reply to author
Forward
0 new messages