Hi all,
I am using geostatistical methods for generating interpolated surfaces. I want to have something like stopwatch which can measure performance.I would like to have a customized tool through arcsdk which can synchronize with arcmap when I perform geostatistical method. The tool should record the internal time at execution of the geostatistical method such as IDW and display the elapsed time when the process completes.
Solved! Go to Solution.
If I do a manual IDW interpolation (Spatial Analyst Tools\Interpolation\IDW) it does appear in the Result window and I can copy the Python Snippet:
Result from clipboard:
# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script # The following inputs are layers or table views: "points03" arcpy.gp.Idw_sa("points03", "IDWval", "C:/Users/xbakker/Documents/ArcGIS/Default.gdb/Idw_points031", "4,21920391999947E-04", "2", "VARIABLE 12", "")
You can also scroll down on the Help page and get some more detailed Python examples:
If you use a ArcGIS tool from a toolbox, the messages will contain information about the elapsed time:
Messages
Executing: CostDistance Water SlopeSetNull C:\Forum\Pasture\gdb\Pasture.gdb\CostWater2 # #
Start Time: Thu Jan 08 22:33:20 2015
Succeeded at Thu Jan 08 22:33:45 2015 (Elapsed Time: 24,92 seconds)
Would that be enough?
If you would use python to program a process you can simply determine the moment the process started and the moment the process ended and determine the elapsed time (datetime.timedelta)
For exact measurement in Python, you can execute code multiple times and obtains stats, using the timeit module.
26.6. timeit — Measure execution time of small code snippets — Python 2.7.9 documentation
Thanks for the information provided by you.
However , I tried through ArcGIS toolbox which does not show the elapsed time for the geostatistical processes such as IDW, GPI. I have to perform the interpolation process around 800 times , so do I need to run the python script provided by you every often?
If you plan is to run the tool 800 times, you will want to script this. Don't do something 800 manual when with little effort it can be scripted A very easy start is to perform the IDW manually and in the Results windows, right click on the IDW result and select Copy Python Snippet from the context sensitive menu. This will give you the python syntax of the IDW interpolation. Based on that you can start scripting (changing dataset, IDW settings, etc).
If you want some help with it, just explain what you would like to do with the 800 interpolations (how they differ from each other).
I have to perform diffrent interpolation methods and by changing few parameters on three data sets.Almost there are 189 combinations. And the interpolation method does not show any result in the result window. So how to copy as python snippet?
If I do a manual IDW interpolation (Spatial Analyst Tools\Interpolation\IDW) it does appear in the Result window and I can copy the Python Snippet:
Result from clipboard:
# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script # The following inputs are layers or table views: "points03" arcpy.gp.Idw_sa("points03", "IDWval", "C:/Users/xbakker/Documents/ArcGIS/Default.gdb/Idw_points031", "4,21920391999947E-04", "2", "VARIABLE 12", "")
You can also scroll down on the Help page and get some more detailed Python examples:
I have done this in the past for python scripts using a combination of function decorators and a timing function.
Basically, the timer is placed in a function wrapper that captures information about the script name, function name and execution time. This information is stored in an array until the writePerformance function is called to write the data out to a file.
#xyzGlobals.py import time import inspect #Performance Information timings = [] def recordPerformance(func): def wrapper(*arg): t1 = time.clock() res = func(*arg) t2 = time.clock() timings.append('%s, %s, %0.2f' % (getFilename(func) , func.func_name, (t2-t1))) return res return wrapper def getFilename(func): try: return inspect.getfile(func) except Exception, e: return '' def writePerformance(path): f = open(path, 'w') f.write('Filename, Function, Seconds\n') for t in timings: f.write('{0}\n'.format(t)) f.close()
Then you can use python function decorators to call the timer:
@xyzGlobals.recordPerformance def makeBasinTable(self): """Make the basin tables """ src = self.__getDataSource('Basins') if src != None: task = BasinCalc(self.log, self.cleanup) task.setDataSource(src) task.calcStatistics(self.aoi_obj)
When your script has completed call the xyzGlobals.writePerformance function to write the performance data to a file.
Please note that this code was used for a project undertaken several years ago and hasn't been used recently. However, you should be able to update parts of it as required. You would also need to modify the writePerformance function to print information to ArcMap output instead of a file.