ExtractMultiValuesToPoints Fails in standalone script

370
4
07-29-2021 05:01 PM
GabrielMarcus_C
New Contributor III

I'm running AGP 2.8.0 with the default python environment. 

I can execute the same script fine through the toolbox, but if I schedule it for a later time, or run it in the IDE it fails with the error below. 

Error Info:
ERROR 160326: The table already exists.
Failed to execute (ExtractMultiValuesToPoints).

When I look this error up, under the Solution it says "There is no documented solution at this time."

I have env.overwriteOutput=True, but I also go through and check for the field names that are generated and delete them before I get to this step in the script. 

 

0 Kudos
4 Replies
DavidPike
MVP Frequent Contributor

Are you able to share your script? I think that's the only way forward.

0 Kudos
GabrielMarcus_C
New Contributor III
import arcpy, os
from arcpy.ia import *
from arcpy.sa import *
from arcpy import env
import pandas as pd
import sys
import traceback
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")


#####
#####   Script Variables
#####
#####



aprx = arcpy.mp.ArcGISProject(r"C:\Users\Devel\Aug2021Wx\Aug2021Wx.aprx")
adm = r"C:\Geodata\Locations.gdb"
cLocs = os.path.join(adm, "Locations2021")
NDFDOutConus = r"C:\ndfd\degrib\output\conus"

wspd = os.path.join(NDFDOutConus,"wspd.nc")
wgust = os.path.join(NDFDOutConus,"wgust.nc")
snow = os.path.join(NDFDOutConus,"snow.nc")
rain = os.path.join(NDFDOutConus,"qpf.nc")
ice = os.path.join(NDFDOutConus,"iceaccum.nc")
mint = os.path.join(NDFDOutConus,"mint.nc")
maxt = os.path.join(NDFDOutConus,"maxt.nc")
apt = os.path.join(NDFDOutConus,"apt.nc")

locFile = cLocs.split("\\")[-1]

aprxMap = aprx.listMaps("Map")[0]
env.workspace = r"C:\Users\Devel\Aug2021Wx"
arcpy.env.overwriteOutput = True

def exec():
    # wind Speed
    out_multidimensional_raster_wspd = arcpy.ia.AggregateMultidimensionalRaster(wspd, "StdTime", "MAXIMUM",                                                                         "WindSpd_10_HTGL", "ALL", '', None, '',                                                                              None, '', "DATA")
    out_multidimensional_raster_wspd.save("wspd_Aggregate.crf")
    arcpy.AddMessage("Loaded and saved windspeed")
    # wind gusts
    out_multidimensional_raster_wgust = arcpy.ia.AggregateMultidimensionalRaster(wgust, "StdTime", "MAXIMUM",
                                                                                 "WindGust_10_HTGL", "ALL", '', None,
                                                                                 '', None, '', "DATA")
    out_multidimensional_raster_wgust.save("wgust_Aggregate.crf")
    arcpy.AddMessage("Loaded and saved windgusts")
    # Snow
    out_multidimensional_raster_snow = arcpy.ia.AggregateMultidimensionalRaster(snow, "StdTime", "SUM", "SnowAmt_SFC",
                                                                                "ALL", '', None, '', None, '', "DATA")
    out_multidimensional_raster_snow.save( "snow_Aggregate.crf")
    arcpy.AddMessage("Loaded and saved snow")
    # Rain
    out_multidimensional_raster_qpf = arcpy.ia.AggregateMultidimensionalRaster(rain, "StdTime", "SUM", "QPF_SFC", "ALL",
                                                                               '', None, '', None, '', "DATA")
    out_multidimensional_raster_qpf.save( "qpf_Aggregate.crf")
    arcpy.AddMessage("Loaded and saved QPF")
    # Ice
    out_multidimensional_raster_ice = arcpy.ia.AggregateMultidimensionalRaster(ice, "StdTime", "SUM", "IceAccum_SFC",
                                                                               "ALL", '', None, '', None, '', "DATA")
    out_multidimensional_raster_ice.save( "iceaccum_Aggregate.crf")
    arcpy.AddMessage("Loaded and saved ice")
    # Min Temp
    out_multidimensional_raster_mint = arcpy.ia.AggregateMultidimensionalRaster(mint, "StdTime", "MINIMUM",
                                                                                "MinT_2_HTGL", "ALL", '', None, '',
                                                                                None, '', "DATA")
    out_multidimensional_raster_mint.save( "mint_Aggregate.crf")
    arcpy.AddMessage("Loaded and saved Min T")
    # Max Temp
    out_multidimensional_raster_maxt = arcpy.ia.AggregateMultidimensionalRaster(maxt, "StdTime", "MAXIMUM",
                                                                                "MaxT_2_HTGL", "ALL", '', None, '',
                                                                                None, '', "DATA")
    out_multidimensional_raster_maxt.save( "maxt_Aggregate.crf")
    arcpy.AddMessage("Loaded and saved Max T")

    out_multidimensional_raster_apt = arcpy.ia.AggregateMultidimensionalRaster(apt, "StdTime", "MAXIMUM",
                                                                                "ApparentT_2_HTGL", "ALL", '', None, '',
                                                                                None, '', "DATA")
    out_multidimensional_raster_apt.save("apt_Aggregate.crf")
    arcpy.AddMessage("Loaded and saved apt")



def extractFields():

    inRasterList =  [["wspd_Aggregate.crf", "WindSpeed"],
                    ["wgust_Aggregate.crf", "WindGust"],
                    ["snow_Aggregate.crf", "Snow"],
                    ["qpf_Aggregate.crf", "QPF"],
                    ["iceaccum_Aggregate.crf", "Ice"],
                    ["mint_Aggregate.crf", "minT"],
                    ["maxT_Aggregate.crf", "maxT"],
                    ["apt_Aggregate.crf", "apt"]]

    arcpy.AddMessage("Dropping old fields...")
    # checking to see if the weather value fields are already in the table
    dropFields = []
    field_names = [f.name for f in arcpy.ListFields(cLocs)]
    for d in field_names:
        if d in ["WindSpeed", "WindGust", "Snow", "QPF", "Ice", "minT", "maxT","apt"]:
            dropFields.append(d)
            arcpy.AddMessage("Found {}".format(d))

    if len(dropFields) > 0:
        arcpy.DeleteField_management(cLocs, dropFields)

    arcpy.AddMessage("Multi Values to Points...")
    for m in aprxMap.listLayers(locFile + "*"):
        if m.supports("DEFINITIONQUERY"):
            m.definitionQuery = ""
            m.definitionQuery = "CTRY = 'US'"
    try:
        arcpy.env.extent = "MINOF"
        arcpy.sa.ExtractMultiValuesToPoints(cLocs, inRasterList, "NONE")
        arcpy.AddMessage("Successfully completed!")

    except Exception as e:
        e = sys.exc_info()[1]
        arcpy.AddError(e.args[0])
        print(e.args[0])
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]

    finally:
        for m in aprxMap.listLayers(locFile + "*"):
            if m.supports("DEFINITIONQUERY"):
                m.definitionQuery = ""

        arcpy.CheckInExtension("Spatial")

if __name__ == "__main__":
    exec()
    extractFields()
0 Kudos
GabrielMarcus_C
New Contributor III

I'm running the same script from the toolbox and scheduling it to run. It just fails on the scheduled attempts. I initially thought that it was something with paths not being fully written out, but I don't think that's the case. 

A few things:

  • I don't use concurrent licensing, so checking in/out the spatial license should have no effect
  • The NetCDF files are from the tkdegrib program produced by the National Weather Service. I download the data before running the script. 
  • The point file is just points, not multipoint. Definition query is set to just the US and then to nothing. 

Thanks!

0 Kudos
YuWang1
Esri Contributor

Hello. Thank you so much for your post about Extract Multivalues to Point. I am a Product Engineer on the Spatial Analyst team. We'd like to reproduce this issue and then try to solve it. Is it possible for us to get a copy of the data you used in this process?

0 Kudos