6

I have written a python script that does some euclidean allocation. For that I use arcpy.gp.EucAllocation_sa() method. Now, my python script takes 30-40% extra time than spatial analyst euclidean allocation tool.

    arcpy.gp.EucAllocation_sa(in_raster_name, out_allocation_raster_name, "", "", cellSize, "VALUE", out_distance_raster_name, "")

Question:

Is there any process that help me to improve the running time of this method? Is there any environment setting issue?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Emi
  • 2,405
  • 2
  • 22
  • 40
  • 1
    By any chance, are you running in a Python IDE? Many Python IDEs' debuggers actually slow down the execution of Python code. – Jason Scheirer Oct 02 '12 at 04:46
  • I am using windows default command prompt and c# process to run the python file – Emi Oct 02 '12 at 04:58
  • 1
    How big is the dataset you're working with? – om_henners Oct 02 '12 at 05:16
  • uncompressed size of the raster data set is: 10.51 MB – Emi Oct 02 '12 at 10:29
  • I had even stranger issue - my analysis ran perfectly using GUI, but never managed to push it through scripting. – radek Oct 02 '12 at 11:18
  • 30-40% extra time is really painful. In fact, using model builder one of my colleagues, made a tool, where this process took 3-4 sec only(after running the tool 10-15 times. at first it took 2 minutes approximately). But by spatial analysis euclidean allocation tool takes 1 min 5 seconds approximately. I just did not find any logic about the huge variation of time :( – Emi Oct 03 '12 at 03:05

1 Answers1

6

I know where I work, simply typing 'import arcpy' into IDLE or a python command line will take 1-2 minutes. I'm not sure everything that goes on behind the scenes, but I imagine it has a lot of code/libraries to load and it has to check your license. When you run the tool inside of Arc, whether through the Arc python command line or the arc toolbox, or model builder, ArcGIS is already loaded, so that overhead is not there.

Does your C# process run the python script multiple times? If so, there is overhead in importing the arcpy libraries when using python outside of ArcGIS, so if you are running the script multiple times I would imagine you would incur that additional overhead multiple times.

MWrenn
  • 1,508
  • 8
  • 13
  • My c# process runs the python script once. Is there any way to improve the running time or shortening the overhead? – Emi Dec 10 '12 at 03:07
  • 1
    How much extra time are you taking in actual minutes/hours? The overhead I'm taking about should be a flat 1-2 minutes at most on top of the normal running time. – MWrenn Dec 11 '12 at 19:38
  • Don't you think 1-2 minutes extra time for a 1-1.5 minutes process, a huge time? – Emi Dec 13 '12 at 06:53
  • I would guess that your next step then is to look into speeding up your ArcGIS start time if that 1-2 minutes is unacceptable. here's a previous question I found related to getting Arc to start quicker http://gis.stackexchange.com/questions/20437/arcmap-arccatalog-very-slow-to-open-on-a-new-laptop-with-ample-resources – MWrenn Dec 13 '12 at 16:19