Script seems to function differently when run as part of a geoprocessing service

Discussion created by melissatalley on Nov 8, 2011
I have a model which in the incorporates a python script. Everything in my model works perfectly when I run it in the desktop environment. When I run the model as a geoprocessing service everything works, but my results are strange.

Basically my model takes user input that selects a county, calculates a field on that row. Then exports that field with all the rows as a text file. This is the input parameter for my script. My script performs matrix algebra on that row, then exports the results as a text file called product. This is the output parameter of my script. My model takes that text file, makes it into a dbf and joins it back to the original shapefile. Something is going wrong somewhere though when run as a service because the values seem to get joined back to the wrong rows, even though they get joined to the correct rows when run in the desktop environment.

I'm not sure if the problem is in my script, but I was wondering if it had something to do with not using the arcgis server scratchworkspace in my script as I do in the model?

from __future__ import with_statement 
from numpy import *
import arcpy
import time
import sys, string, os, arcgisscripting, shutil
gp = arcgisscripting.create(9.3)
from arcpy import env

tablePath = gp.GetParameterAsText(0)

#Load durbin.txt file
durbin= loadtxt("C:\\inetpub\\wwwroot\\REIS\\assets\\durbin_edit.txt")
print durbin
print"durbin loaded"
#load all columns except the first column which is the poly ids for the counties
print durbin_cut
print"durbin columns selected"
#Load output of model, which includes 2 columns for x and y, impossible not to include
delta= loadtxt (tablePath)
print delta
print "delta loaded"
#Select only results column, exclude x and y coordinate columns from output
delta_cut = delta[:, 2:]
print delta_cut
print "column selected"
#Multiply using matrix algebra durbin_cut by delta_cut
product= dot(durbin_cut,delta_cut)
print product
print "calculated"

#Get current time for file names
print date1

#make a text file from array with header and product
dateproduct=date1 + "_product.txt"
print dateproduct
textfilename= "C:\Users\WinSSHD_VirtualUsers\Downloads\WebGIS project\Counties00_08_web\scratch\out" + dateproduct
print textfilename

product.tofile (textfilename, sep='\n', format="%e")
print "file created"
#open text file
with open(textfilename, "r+") as f:
     old = # read everything in the file # rewind
     f.write("value\n" + old) # write the new line before everything

print "all done"

#Set output parameter
arcpy.SetParameterAsText(1, textfilename)

Any insight would be greatly appreciated!