<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Adding Function to Field Calculator fails in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/adding-function-to-field-calculator-fails/m-p/519500#M17236</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;by the looks of the script, it is designed to run as a tool from within Arctoolbox, within Arcmap, since there are a number of parameters that need to be provided, which aren't being provided from within the field calculator.&amp;nbsp; Check the documentation that you got with the toolset if you have it&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 29 Jul 2011 12:56:31 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2011-07-29T12:56:31Z</dc:date>
    <item>
      <title>Adding Function to Field Calculator fails</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/adding-function-to-field-calculator-fails/m-p/519499#M17235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm new to the forum, so: Hello Everybody!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to add a def function to ArcGIS Desktops Field Calculator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code of the def written in python is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import math
import numpy
from arcpy import env
from numpy import *

pointshape = arcpy.GetParameterAsText (0)
raster = arcpy.GetParameterAsText (1)
solar_azimuth = arcpy.GetParameterAsText (2)
solar_height = arcpy.GetParameterAsText (3)
tilt = arcpy.GetParameterAsText (4)
output_raster = arcpy.GetParameterAsText (5)

def calculate_angles(ET_ANGLE):
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Calculating IN-Vector

&amp;nbsp;&amp;nbsp;&amp;nbsp; phi_in = math.radians(180 - solar_azimuth)
&amp;nbsp;&amp;nbsp;&amp;nbsp; theta_in&amp;nbsp; = math.radians(90 - solar_height)

&amp;nbsp;&amp;nbsp;&amp;nbsp; r = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; x = -(r * math.sin(theta_in) * math.cos(phi_in))
&amp;nbsp;&amp;nbsp;&amp;nbsp; y = -(r * math.sin(theta_in) * math.sin(phi_in))
&amp;nbsp;&amp;nbsp;&amp;nbsp; z = -(r * math.cos(theta_in))

&amp;nbsp;&amp;nbsp;&amp;nbsp; VSonneIn = numpy.matrix([&lt;X&gt;, &lt;Y&gt;, &lt;Z&gt;])


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Calculating Module-Vector

&amp;nbsp;&amp;nbsp;&amp;nbsp; phi_modul = math.radians(180 - ET_ANGLE)
&amp;nbsp;&amp;nbsp;&amp;nbsp; theta_modul = math.radians(tilt)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # r = 1 from above
&amp;nbsp;&amp;nbsp;&amp;nbsp; u = r * math.sin(theta_modul) * math.cos(phi_modul)
&amp;nbsp;&amp;nbsp;&amp;nbsp; v = r * math.sin(theta_modul) * math.sin(phi_modul)
&amp;nbsp;&amp;nbsp;&amp;nbsp; w = r * math.cos(theta_modul)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Defining Transformation-Matrix

&amp;nbsp;&amp;nbsp;&amp;nbsp; MReflexion = numpy.matrix([[1-2*u*u, -2*u*v, -2*u*w],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [-2*u*v, 1-2*v*v, -2*v*w],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [-2*u*w, -2*v*w, 1-2*w*w]])

&amp;nbsp;&amp;nbsp;&amp;nbsp; VSonneOut = MReflexion * VSonneIn

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Calculating OUT-Angles

&amp;nbsp;&amp;nbsp;&amp;nbsp; theta_out = math.degrees(math.acos(VSonneOut[2]/(math.sqrt(VSonneOut[0]*VSonneOut[0]+VSonneOut[1]*VSonneOut[1]+VSonneOut[2]*VSonneOut[2]))))

&amp;nbsp;&amp;nbsp;&amp;nbsp; VERT1 = (90 - theta_out)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return VERT1


&amp;nbsp;&amp;nbsp;&amp;nbsp; if (VSonneOut[0] &amp;gt; 0):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phi_out = math.degrees(math.atan(VSonneOut[1]/VSonneOut[0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (VSonneOut[0] == 0):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phi_out = math.degrees(numpy.sign(VSonneOut[1])*(math.pi/2))
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (VSonneOut[1] &amp;gt;= 0):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phi_out = math.degrees(math.atan(VSonneOut[1]/VSonneOut[0])+math.pi)
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phi_out = math.degrees(math.atan(VSonneOut[1]/VSonneOut[0])-math.pi)

&amp;nbsp;&amp;nbsp;&amp;nbsp; AZIMUTH1 = (180 - phi_out)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return AZIMUTH1&lt;/Z&gt;&lt;/Y&gt;&lt;/X&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The expression I use in the Field Calculator is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;calculate_angles(!ET_ANGLE!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now my problem is, that this def doesn't work. The Error message I get is not defined.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-&amp;gt; &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (CalculateField).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any Idea how to debug this or how to get it to work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not getting it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:33:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/adding-function-to-field-calculator-fails/m-p/519499#M17235</guid>
      <dc:creator>PinoHegi</dc:creator>
      <dc:date>2021-12-12T16:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Function to Field Calculator fails</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/adding-function-to-field-calculator-fails/m-p/519500#M17236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;by the looks of the script, it is designed to run as a tool from within Arctoolbox, within Arcmap, since there are a number of parameters that need to be provided, which aren't being provided from within the field calculator.&amp;nbsp; Check the documentation that you got with the toolset if you have it&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jul 2011 12:56:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/adding-function-to-field-calculator-fails/m-p/519500#M17236</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2011-07-29T12:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Function to Field Calculator fails</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/adding-function-to-field-calculator-fails/m-p/519501#M17237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;by the looks of the script, it is designed to run as a tool from within Arctoolbox, within Arcmap&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That's right.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;there are a number of parameters that need to be provided, which aren't being provided from within the field calculator&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you please name some of them? I don't know to which you are referring to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;the documentation that you got with the toolset&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With 'Toolset' you mean the 'Field Calculator'? I Don't have a documentation for the Toolset the script should run in, because I've created it by my own.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your Help so far!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Aug 2011 12:32:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/adding-function-to-field-calculator-fails/m-p/519501#M17237</guid>
      <dc:creator>PinoHegi</dc:creator>
      <dc:date>2011-08-03T12:32:27Z</dc:date>
    </item>
  </channel>
</rss>

