Select to view content in your preferred language

laharz

4064
13
Jump to solution
03-21-2018 02:23 PM
charlesmoser
Occasional Contributor

Wondering if somebody can help me with some errors generated by the LaHarz model.  I am trying to run the Laharz Distal Zones standalone python tool.  It was created by a USGS developer and it is supposed to work with ArcGIS 10.X.  There are four required inputs: 1) filled DEM, 2) text file of volumes (integers), separated by commas 3) a text file of XY coordinates and 4) a string denoting a prefix for output grids.  Below is the message in Geoprocessing Results.  The full python script will be attached.

Executing: laharzdistalzones.py C:\Users\cmoser\Downloads\laharz_py_example\mtrain_example fill mtrwest_ C:\Users\cmoser\Downloads\laharz_py_example\mtrain_example\laharz_textfiles\volumesrockfall.txt C:\Users\cmoser\Downloads\laharz_py_example\mtrain_example\point_textfiles_for_ArcMap\points.txt Rock_Avalanche
Start Time: Wed Mar 21 17:19:08 2018
Running script laharzdistalzones.py...
Parsing user inputs:
Running Laharz_py
_________ Input Values _________
Input Surface Raster Is:fill
Volume textfile :C:\Users\cmoser\Downloads\laharz_py_example\mtrain_example\laharz_textfiles\volumesrockfall.txt
Starting coordinates file :C:\Users\cmoser\Downloads\laharz_py_example\mtrain_example\point_textfiles_for_ArcMap\points.txt
Drainage identifier :mtrwest_
Rock Avalanche Selected
_________ Paths on Disk _________
full path fill :C:\Users\cmoser\Downloads\laharz_py_example\mtrain_example\fill
full path dir :C:\Users\cmoser\Downloads\laharz_py_example\mtrain_example\dir
full path flac :C:\Users\cmoser\Downloads\laharz_py_example\mtrain_example\flac
full path str :C:\Users\cmoser\Downloads\laharz_py_example\mtrain_example\str
_________ Creating DEM Array _________
_________ Get NumPyArray Dimensions _________
Shape is: (986, 1251) (rows, colums)
Number of rows is: 986
Number of columns is: 1251
_________ Set Window Boundaries _________
wXmin (TOP): 0
wXmax (BOTTOM): 985
wYmin (LEFT): 0
wYmax (RIGHT): 1250
_________ Convert Textfiles to Arrays _________
Volume List is: [1000.0, 3000.0, 10000.0, 300000.0]
Points entered: [[587737.0, 5204869.0], [579305.0, 5196801.0], [577930.0, 5191581.0]]
Cross Section Area List is: [20.0, 42.0, 93.0, 896.0]
Planimetric Area List is: [2000.0, 4160.0, 9283.0, 89628.0]
_________ Creating startpts_g _________
Failed script laharzdistalzones.py...

Traceback (most recent call last):
File "D:\Programs\ArcGIS\Desktop10.4\ArcToolbox\Toolboxes\laharz_py_example\laharz_py\distal_inundation.py", line 1621, in <module>
main(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6])
File "D:\Programs\ArcGIS\Desktop10.4\ArcToolbox\Toolboxes\laharz_py_example\laharz_py\distal_inundation.py", line 1169, in main
tmpStartPoints = ExtractByPoints(Input_surface_raster,startCoordsList,"INSIDE")
File "d:\programs\arcgis\desktop10.4\arcpy\arcpy\sa\Functions.py", line 1409, in ExtractByPoints
extraction_area)
File "d:\programs\arcgis\desktop10.4\arcpy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
File "d:\programs\arcgis\desktop10.4\arcpy\arcpy\sa\Functions.py", line 1405, in Wrapper
return _wrapToolRaster(u"ExtractByPoints_sa", unicode(result.getOutput(0)))
AttributeError: 'unicode' object has no attribute 'getOutput'

Failed to execute (laharzdistalzones.py).
Failed ta Wed Mar 21 17:19:09 2018 (Elapsed Time: 1.06 seconds)

0 Kudos
13 Replies
charlesmoser
Occasional Contributor

Eureka!  I found it!  the problem really was the call to the ExtractByPoints method.  I finally decided to paste the ExtractByPoints tool into ModelBuilder, ran my data, then exported the model to Python.  I discovered that the call to ExtractByPoints is way different than in the USGS code:

Here is the USGS Code:

tmpStartPoints = ExtractByPoints(Input_surface_raster,"'587737 5204869';'579305 5196801';'577930 5191581'","INSIDE")

Here is the code that works from ModelBuilder:

tmpStartPoints = arcpy.gp.ExtractByPoints_sa(Input_surface_raster, "'587737 5204869';'579305 5196801';'577930 5191581'", "INSIDE")

I have to add, Dan Patterson, who responded earlier, asked about import statements.  To be fair to the original author of the code, he did include the import statement, from arcpy.sa import *.  So why does the code not work for me unless I spell out the full call to the method?  I have no idea if it's a Python version issue.  I am using Python 2.7.  I should get my coworker to try the tool and see whether or not he gets the same error, using the original code.  Maybe there is something screwy with my environment.  At any rate, I am very happy that the tool works for me now.

Thanks to everybody who responded to this post!

0 Kudos
DanPatterson_Retired
MVP Emeritus

by chance did their script do a 

from arcpy.sa import *

charlesmoser
Occasional Contributor

Here are the import statements in the original code:

import sys, string, os, arcpy, math, time

from arcpy import env

from arcpy.sa import *

from math import *

And the code checks out the Spatial Analyst extension. I wonder why I had to explicitly state the full object to get the tool to work.

I have tried it back and forth several times and believe me the tool works like a charm when I state the full object and method, arcpy.gp.ExtractByPoints_sa.

I have Python 2.7. I don’t know if that has anything to do with it.

0 Kudos
DanPatterson_Retired
MVP Emeritus

This ... from arcpy.sa import *  ...

should never be done in my opinion, even though the help documentation shows it as correct.

importing as you did is best, but I am surprised that it failed if you used their import method.

It might be for that version of arcpy with python 2.7

0 Kudos