Python + GME (Spatial Ecology) + Subprocess.call

1122
6
09-04-2013 12:04 AM
SvenJunghans
New Contributor
I am attempting to run GME functions using python using "subprocess.call".  But every time I receive a Windows error message (see attached image). Apparently the log file cannot be found (incorrect path). I was wondering if this is because of the double forward slash (see red circle in attached image). Is this really the cause of the error? If yes, then how can this be fixed?

I will post the code I am using:

import subprocess as subp
subp.call(r'C:\Program Files\SpatialEcology\GME\SEGME.exe -c run(in=\"H:\GME\testing\text_commands\exportcsv.txt\");')


The text file contains the following:
export.csv(in="H:\GME\testing\data\test4csv.shp", out="H:\GME\testing\text_commands\output\exportcsv.csv");
Tags (2)
0 Kudos
6 Replies
ZacharyHart
Occasional Contributor III
Hey Sven, I've run into the exact same problem.

I'm trying to wrap up the GME commands in Python and have actually had some good success. Now that I understand the proper way to pass the correct syntax, i was able to execute from the Python shell. Now i'm attempting to roll my script in a model in ArcGIS and this is where I'm hitting the same error. Let me look at your error message more closely, and I'll also report back any other findings or observations that come along.

Yes I have the // as well, but I'm not sure why that's getting pushed to GME.

EDIT:

Sven, curious, are you executing this in a python shell, or as a script added to arctoolbox?

My original test scripts executed just fine in the the python shell, but when executed from ArcMap, that's when the error occurs.

Trying to sort out as many variables as we can.
0 Kudos
SvenJunghans
New Contributor
Hi,

Yesterday I spent some more time on attempting to resolve this problem. I noticed the error only occurs when executing the python script from within ArcMap (or ArcCatalog). When using the shell there is no error and it seems to work fine (as you mentioned already).

The path leads to an .htm log file (name seems to contain date and time). This file contains general information about GME and says whether the execution of the GME function was successful or not.
path: "C:\Users\sjunghans\AppData\Local\Temp\arc35A\SpatialEcology\20130903_153332\Log_20130903_153332.htm"

It seems to be possible to modify the GME config file ("C:\Program Files\SpatialEcology\GME\SEGME.exe.config") to change the way GME creates or interacts with the log file. But when looking at the code it's not obvious to me what to modify.

When the error pops up and I close it, then the GME function executes as it should.

Reinstalling python, GME or R didn't fix the problem.

My ultimate goal is to create a tool (python script or model builder) which executes a sequence of functions from both GME and ArcGIS (without the need to close an error window...).
0 Kudos
ZacharyHart
Occasional Contributor III
Sven, similar experience all the way around. I tried to modify the config file, but if you look at what it says:

!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>--


So Un-commenting it enables some kind of logging (I haven't seen anything in any available documentation about this). I think this is all related to VB debugging anyway.

I have an email out to Hawthorne (with the offer to pay for service), but haven't heard anything back. My concern is that this is a bug related to how GME decides to write a temp location when run within ArcMap. Note that every ArcMap session writes a 'arcABC1' type temp folder.

GME does not write any entries to your registry, so there's nothing to modify in there.

I also have a post on the GIS Stack Exchange regarding this.

Too bad, I have a fair amount of time in just getting the correct syntax to pass from Python to GME and was getting excited about the sampling tools. I had gone down the path of trying to leverage the fishnet tool for my workflow, but sadly, it does not support rotation (its true). The GME option here would be perfect.
0 Kudos
SvenJunghans
New Contributor
Hi Zachary,

Thanks for your input.

When having the arguments of the subprocess call in a list:
subprocess.call([r'F:\Program Files\SpatialEcology\GME\SEGME.exe -c run(in=\"F:\GME Test\text command\download_image.txt\");']);

Then I receive a Runtime Error message instead of the error window. It looks like this:
Runtime error 
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "C:\Python27\Lib\subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\Lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\Lib\subprocess.py", line 893, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

Now perhaps this additional information can help with the debugging?
EDIT: Or is this some other error which is unrelated? (maybe wrong syntax for list?)

Please tell me if you get any feedback from Hawthorne (or stackexchange).

Thanks.
0 Kudos
ZacharyHart
Occasional Contributor III
I'm going to go with a syntax error on that....I'll keep you posted for sure. Let me know if you have any success, or observations of any kind. I'm not sure this is an R problem, but i've thought about rolling back to an earlier version to test. Not many options at this point.

I forgot to mention:

Here is but one observation I forgot to share. When the GUI is launched, and you get the error, clear/ 'OK' through that, and then you see that your command has not been submitted to the 'output' tab in GME. If I then use the 'save' command manually, my process executes.
0 Kudos
AlisonMontgomery
New Contributor
Hello,

I've run into the same issue. Typically, with the scripts I wrote that integrate GME and Arc via Python, Arc and GME don't always play nice and I have a feeling the Arc software runs something that GME has a tough time handling. However, when I have had that pop-up appear, when I click ok, typically my scripts run, albeit on the 2nd or 3rd try.

I did get a reply from the GME creator, and that was his best guess, that a temp toolbox is set up and GME gets a little confused. I also know the GME creator is switching everything to R so that he won't have to rely on the Arc libraries taht would cause this. Already GME doesn't work with 10.2, or least I had an issue with it.

I created the scripts and use them in ArcToolbox, but they definitely run best when run directly via a Python IDE (I use PythonWin), and then are ok through ArcCatalog, and all the inputs have to be out of the map document if I run them in ArcMap. However, they do seem to work, though it varies from tool to tool, depending on if it solely uses and algorithm in GME, or if it needs the Arc libraries.

So not much insight, but hope this helps!

Alison
0 Kudos