Riverscapes / riverscapes-tools

Open-source Python 3.0 tools for the Riverscapes organization
https://tools.riverscapes.net/
GNU General Public License v3.0
11 stars 12 forks source link

RSContext Error When HUC2 feature class DOES exist #988

Closed philipbaileynar closed 3 months ago

philipbaileynar commented 3 months ago

PR #936 introduced a minor bug when cleaning NHD data. It seems related to whether the NHD data include the HUC2 feature class or not. @KellyMWhitehead wrote some code to handle missing HUC2 feature class and this pathway works. However, when the HUC2 feature class DOES exist the code throws an indexing error.

Working Code

When running RSContext for HUC 1601010101 the code passes and works. Note that the layer variable is None and so the code proceeds down the new code that @KellyMWhitehead wrote within the else pathway.

Failing Code

When running RSContext for HUC 1204020205 the code fails. layer is valid and line 43 is run. The code then errors on line 73 because layer is a pointer to an individual layer and not a list of layers.

https://github.com/Riverscapes/riverscapes-tools/blob/5050aa025497c2add0f01b8803f40ac8b3ceeccf/lib/commons/rscommons/clean_nhd_data.py#L41-L74

Error Information

From @r-k-g run:

RS_CONTEXT_CHANNEL_TAUDEM Production Rowan Job    1204020205    FAILED    2048    16384    0:00:00.055226    2024-08-13T17:46:06.893Z    2024-08-13T17:47:02.119Z    https://us-west-2.console.aws.amazon.com/cloudwatch/home?region=us-west-2#logsV2:log-groups/log-group/CybercastorLogs_production/log-events/ecs$252FCybercastorEngine_riverscapesTools_production$252FriverscapesTools$252F2d865b02cb314f7a81d4cb10599287dc     b77ddf3c-f665-49af-98a2-197ae4d28924    3180f0c9-6869-4f20-a055-6b083e51c09c
Failed (Previously IndexError, still IndexError)
File "/usr/local/src/riverscapes-tools/packages/rscontext/rscontext/rs_context.py", line 240, in rs_context
nhd, filegdb, huc_name, _nhd_url = clean_nhd_data(
File "/usr/local/src/riverscapes-tools/lib/commons/rscommons/clean_nhd_data.py", line 73, in clean_nhd_data
huc_name = layer[0].GetField('name')
File "/usr/lib/python3/dist-packages/osgeo/ogr.py", line 2784, in __getitem__; raise IndexError
KellyMWhitehead commented 3 months ago

The huc 10 does not seem to exist for this huc (1204020205). Might be an edge case where the NHD is missing along texas (this huc is listed as East Galveston Bay). The thing to do here is probably provide a useful message and exit gracefully...

philipbaileynar commented 3 months ago
  1. Really? When we were debugging the layer object returned on line 42 was valid. It was not null.
  2. Is this one of those WDB version inconsistency issues?