Thursday, September 27, 2012

Using Map() or Apply_async() For Multiprocessing


With the release of this new python article on the ArcGIS blogs.  I find it increasingly harder to find concrete/simple explanations of important functions that help make life easier for processing data in ArcGIS.
Though the crux of this article is to give guidance to when or when not to use multiprocessing with ArcGIS, it does use a variation on a method of multiprocessing different than I prefer.  So I decided to investigate the differences between map() and apply_async() on the Pool object.
Pool.apply_async() is also like Python's built-in apply(), except that the call returns immediately instead of waiting for the result. An ApplyResult object is returned. You call its get() method to retrieve the result of the function call. The get() method blocks until the function is completed. Apply_async() does not preserve the order of the results meaning that the codes return results will not be a 1:1 correlation between when it was called and when it finished.  In addition, apply_async() allows coders to call multiple functions instead of a single function.
Pool.map() is like the Python's built-in map() function.  Pool.map() applies the same function to many arguments. The results are returned in an order corresponding to the order of the arguments.

When it comes right down to it, you basically need to find the right tool for the right job.

Here are some resources to help you along.

Enjoy

Monday, September 24, 2012

Delete Rows Using the UpdateCursor - arcpy.da

The arcpy.da.UpdateCursor() provides the method to alter and update field values.  This quick post will show you how to delete a row.

All you need to do is specify the fields, here I take the default of * and the feature class.  You can reduce the number of rows by passing a query as well.

Code Sample Run From Python Window:

with da.UpdateCursor(r'C:\temp\scratch.gdb\floodsub', "*") as urows:
...     for row in urows:
...         urows.deleteRow()
...         break


This little sample just erases the first row in the feature class.  The 'with' statement automatically closes the cursor object, so it does not have to be manually deleted.  This ensures the locks are removed on success or on failure.

Enjoy

Friday, September 21, 2012

Uninstalling Time!

The funny things you see when upgrading versions of software:

Installers always were lousy estimators of time, but this one was way off!!!! I guess I need two cups of coffee for this one.

Enjoy

Friday, September 7, 2012

Article on 3rd Party Modules

The Esri python team wrote another good article on 3rd party modules, which is a good read for anyone who is new to python.

The article can be found here.

Enjoy