Calling Arc Hydro Tools in Python in ArcGIS Pro?

5363
20
03-02-2018 02:51 PM
JohnGaiot
Occasional Contributor

Hello,

I am testing some python scripts created originally in ArcGIS 10.3.1/10.5.1 which utilize the ArcHydroTools module. I have installed the latest Arc Hydro package in ArcGIS Pro, but it still doesn't recognize this module. I get the following error when trying to import the module:

" ModuleNotFoundError: No module named 'ArcHydroTools' "

Is this functionality not yet available? Or should I be doing something else?

I tried scouring the documentation but it all relates to ArcGIS desktop not Pro. Not that I could find anyway!

Thanks in advance,

John

0 Kudos
20 Replies
JohnGaiot
Occasional Contributor

Hi Stuart,

It took me a while trying to find where Arc Hydro installs itself. The MSI installer does not tell you where it will install, and explorer does not search the "Program Files" folder for some weird 'security' reason (I tried typing "ArcHydro" as my search parameter from the C drive and only files I created referencing Arc Hydro or files I opened recently came up). So through manual sleuthing, I found Arc Hydro 'Pro' installs here:

C:\Program Files\ArcGIS\Pro\Resources\ArcToolBox\Scripts\ArcHydro (or likely it will install wherever you chose to install ArcGIS Pro)

I then proceeded to follow your suggestion, and it seems the AH install was smart enough to do that part for me. There was already a archydropython.pth file located in said "site-packages" folder with the path above already in it.

Let me clarify, the individual tools within the Arc_Hydro_Toolbox_Pro.tbx do run okay on their own. It's when I try calling the functions through ArcPy it bails with the following message (my script is called "2. Create EFD**" just in case you're wondering what that means):

Start Time: March 12, 2018 4:18:23 PM
Running script CreateEFD...
Failed script 2. Create EFD** ...
 Traceback (most recent call last):
  File "Z:\GI\ProvincialMapping\Tools\Python\MNRF_TerrainProcessing-JG-2017-08-09\TerrainScripts\Step C.2. Create EFD - master.py", line 38, in <module>
    import ArcHydroTools
ModuleNotFoundError: No module named 'ArcHydroTools'
 Failed to execute (CreateEFD).
Failed at March 12, 2018 4:18:24 PM (Elapsed Time: 0.59 seconds)
0 Kudos
V_StuartFoote
MVP Frequent Contributor

Hmm, do your ArcHydro  snippets run run with Pro's integrated Python window?  Using the Load Code context in the Python prompt...

The Python window—ArcPy Get Started | ArcGIS Desktop

That way you should be able to tell if it is incomplete environment, or a syntax error.

0 Kudos
JohnGaiot
Occasional Contributor

I tried manually typing in the import command in the Python window, which works with the standard modules. But when I try "import ArcHydroTools", I get the same "No module named.." error. Either the name of the module for calling Arc Hydro has changed or is nonexistent / not available for this version of the tools. We have automated much of our data processing with rather complicated scripts which would not be easily translatable to the Model Builder environment. Nor would I want to do that when I can just stick with ArcGIS Desktop..

0 Kudos
deleted-user-yIALGElyA_K9
New Contributor III

John, did you ever find a solution for this? I too am in a similar situation. We have a whole AH workflow that has been streamlined with a python script. Calling the ArcHydro module returns the same error for me. It's a shame if this would be the reason we couldn't use Pro for these processes... Any suggestions would be greatly appreciated. Thanks!

JohnGaiot
Occasional Contributor

Hi Jacob. There are several reasons why we decided not to take the jump to Pro.. this being one of them. But I imagine the Arc Hydro team is getting close to a viable update (I would keep track of their main thread for this). They're not totally to blame though. As an 'old school' programmer, I've always exercised the concept of 'backwards compatibility' when versioning software or you run the risk of upsetting or alienating your user base (and I sort of see the Arc Hydro team as part of this 'user base' even though they are affiliated with ESRI). In Pro, the decision not to support traditional simple geometric networks (forcing folks towards the more complex Utility Network model instead) and dropping the ability to view read only fields on toolbox forms are a couple things that have really irked me personally. I've raised these issues as well, but they are not seen as priority which is unfortunate. But the main reason is we've built a lot of Python tools for specialized auto processing of large datasets and producing informed status updates/error reporting which Arc Hydro alone lacks.. so for us to needlessly rework the entire workflow (which works perfectly fine otherwise) just makes it not worth our while to port over to Pro. For the foreseeable future, we're sticking with ArcGIS Desktop for surface water related processes, and may also explore open source alternatives (Whitebox is a promising contender for handling LiDAR big data in surface water applications).

deleted-user-yIALGElyA_K9
New Contributor III

Thank you, John, for getting back to me so quickly. I really appreciate it. When you say, "keep track of their main thread for this," which thread are you referring to?

I hear what you are saying. A lot is being asked of the community in the "big switch." I will say, and I imagine you'll agree to a certain extent, that ESRi has been surprisingly responsive to the requests of users (with regards to Pro). I do not have the technical background to understand why calling these tools (like any other tools) should be a difficult request to accommodate. 

All the best,

Jacob

0 Kudos
JohnGaiot
Occasional Contributor

Sorry Jacob.. I may have not responded directly to you.. see below or my comment earlier today on this thread.

JohnGaiot
Occasional Contributor

Here you go:

https://community.esri.com/thread/105831-arc-hydro-installation-versions-and-documentation

Yes you're right.. they are responsive when it comes to infrastructure, cartographic and online type applications. Their user base is large and some 'niche' users are left struggling, but we'll have to adapt one way or another eventually.

Cheers,

John

ChristineDartiguenave
Esri Contributor

We are still in the process of moving Arc Hydro Tools to Pro.

The best way to call the tools in pro is to use "import archydro" which is available with the most recent setups. You can try to type it in the Python window in Pro.

Another way is to import each script. The issue with this method is for tools that have the same name in the core product (e.g. flowdirection or flowaccumulation). You may end up importing the core tool instead of the arc hydro tools.

You can look in the tools to see how we are calling other tools (mainly calling the scripts for now) but eventually we will use import archydro.

As a side note, the core is working on a tracing network (hydro network) that will allow performing the hydro network analyses in Pro. it should be available early next year. 

Christine 

TheodoreBarnhart
New Contributor

Could you provide an example of how to correctly call a archydro tool from a Python 3 script? For example, I'd like to call StreamDefinition from a script, would I import it as:

from archydro.streamdefinition import StreamDefinition‍

The only way I can see to then execute the tool is via

params = ("facPath", "threshold")
StreamDefinition.execute(params, None)‍‍‍

I haven't been able to get that to work, is there another way? 

0 Kudos