0

I'm trying to make a python script tool that extracts the values from a NetCDF raster to each data point from a time enabled shapefile at the correct time. My NetCDF raster consists of monthly sea surface temperature (SST) averages and I also have a plastic debris point shapefile that has been time enabled with time step interval of one month. I have checked with Time Slider that both the raster and the shapefile values change through time correctly.

Can someone please help me figure out why I keep getting an error with this script:

mxd = arcpy.mapping.MapDocument('SST.mxd')
df = arcpy.mapping.ListDataFrames(mxd)[0]
rasterLayerName = "SST"
rasterLayer = arcpy.mapping.ListLayers(mxd, rasterLayerName, df)[0]
plasticLayerName = "Plastic"
plasticLayer = arcpy.mapping.ListLayers(mxd, plasticLayerName, df)[0]
df.time.currentTime = df.time.startTime
while df.time.currentTime <= df.time.endTime:
   uniqueName = "Plastic_" + df.time.currentTime.strftime("%Y_%m")
   outPointFeatures = "U:/gis/" + uniqueName
   arcpy.sa.ExtractValuesToPoints(plasticLayer, rasterLayer,
         outPointFeatures, "NONE", "VALUE_ONLY")
df.time.currentTime += df.time.timeStepInterval

Here is the error:

Runtime error
  Traceback (most recent call last):
   File "<string>", line 6, in <module>
   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py", line 1311, in ExtractValuesToPoints
     add_attributes)
   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Utils.py", line 47, in swapper
     result = wrapper(*args, **kwargs)
   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py", line 1304, in wrapper
     add_attributes)
   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda>
     return lambda *args: val(*gp_fixargs(args, True))
 ExecuteError: ERROR 001143: Background server threw an exception.

I'm using ArcGIS Desktop 10.1 and Python 2.7 on Windows 7.

  • Could it be that the output is to be a featureclass and you have not provided a path or an environment setting to put the file in? – user681 Jun 23 '14 at 18:04
1

It appears as though you have background geoprocessing for your script enabled. Disable background geoprocessing for this tool and try running it again.

Additionally, you are introducing an infinite loop in your script. Change your while loop to include the df.time.currentTime += df.time.timeStepInterval snippet:

while df.time.currentTime <= df.time.endTime:
   uniqueName = "Plastic_" + df.time.currentTime.strftime("%Y_%m")
   outPointFeatures = "U:/gis/" + uniqueName
   arcpy.sa.ExtractValuesToPoints(plasticLayer, rasterLayer,
                                  outPointFeatures, "NONE", "VALUE_ONLY")
   df.time.currentTime += df.time.timeStepInterval
  • I don't get errors any more but now I discovered a new problem - all shapefile values (from all time step intervals) ended up getting assigned raster layer values just from the first time step interval. So somehow the stepping through time loop only worked for the point shapefile but not for the NetCDF raster layer, even though both are time enabled and share the same time step interval. Any ideas what might be going wrong? – Dily Jun 23 '14 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.