<?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: Model Builder and Python : Boolean in Calculting Field box in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/model-builder-and-python-boolean-in-calculting/m-p/1115094#M62933</link>
    <description>&lt;P&gt;Hey Mag&lt;/P&gt;&lt;P&gt;You have to add the the other fields that you want to use to your Function definition. Your def should be more like this&lt;/P&gt;&lt;P&gt;def calcul(Euval, GdVal,SmVal)&lt;/P&gt;&lt;P&gt;...rest of your code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and to use the function you could use calcul(!Eu_Eu!,!Gd!,!Sm!)&lt;/P&gt;&lt;P&gt;Bonne chance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Nov 2021 22:38:58 GMT</pubDate>
    <dc:creator>DominicRobergeIADOT</dc:creator>
    <dc:date>2021-11-08T22:38:58Z</dc:date>
    <item>
      <title>Model Builder and Python : Boolean in Calculting Field box</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-and-python-boolean-in-calculting/m-p/1115071#M62932</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I built a Model Builder tool that performs a number of operations on a FGDB feature class that contains geochemical analyzes. I want to calculate a geochemical index called Eu/Eu * on the basis of the contents of europium (Eu), samarium (Sm) and gadolinium (Gd), according to the following formula: Eu/Eu * = (Eu/0.058)/math.sqrt((Sm/0.153) * (Gd/0.2055)).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;To note : &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;•&amp;nbsp; Values below a detection limit are negative. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;•&amp;nbsp; For a same element, this detection threshold varies depending on the analysis method. For example, for platinum Pt, it is -0.1 and -70. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;•&amp;nbsp; Since the square root (in the equation) of a negative value does not exist, then my Model Builder tool crashes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mag_Geol2016_0-1636407921990.png" style="width: 377px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/27017iCCDD726368C940A4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Mag_Geol2016_0-1636407921990.png" alt="Mag_Geol2016_0-1636407921990.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;This is why I tried to introduce a small boolean python script in the "Calculate Field" box (figure below), so that if one of the 3 elements is negative, then it must then put zero in the Eu_Eu field created previously (Float type). Otherwise (i.e. actually all 3 are positive) it calculates the above formula.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;def calcul(Eu_Eu):&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!Eu!&amp;lt;=0 or !Gd!&amp;lt;=0 or !Sm!&amp;lt;=0):&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (!Eu!/0.058)/math.sqrt((!Sm!/0.153)*(!Gd!/0.2055))&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;The problem is that, besides not really knowing if my script is correct (I'm just a beginner...), it puts me error 000989 (figure below) according to which there would be a problem with the syntax, which I unfortunately cannot locate. To my knowledge, field names should be placed between two exclamation points in a Python script, right? I say that because by putting "‘ ", the error disappears, but the calculation still crashes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mag_Geol2016_1-1636408299050.png" style="width: 641px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/27018i4590B15FA42200D3/image-dimensions/641x250?v=v2" width="641" height="250" role="button" title="Mag_Geol2016_1-1636408299050.png" alt="Mag_Geol2016_1-1636408299050.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mag_Geol2016_2-1636408318112.png" style="width: 629px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/27019iC3035AF4F5626303/image-dimensions/629x517?v=v2" width="629" height="517" role="button" title="Mag_Geol2016_2-1636408318112.png" alt="Mag_Geol2016_2-1636408318112.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mag_Geol2016_3-1636408336677.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/27020i7A778D13D3ABD62A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mag_Geol2016_3-1636408336677.png" alt="Mag_Geol2016_3-1636408336677.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Thank you in advance for your precious help!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 22:03:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-and-python-boolean-in-calculting/m-p/1115071#M62932</guid>
      <dc:creator>Mag_Geol2016</dc:creator>
      <dc:date>2021-11-08T22:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder and Python : Boolean in Calculting Field box</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-and-python-boolean-in-calculting/m-p/1115094#M62933</link>
      <description>&lt;P&gt;Hey Mag&lt;/P&gt;&lt;P&gt;You have to add the the other fields that you want to use to your Function definition. Your def should be more like this&lt;/P&gt;&lt;P&gt;def calcul(Euval, GdVal,SmVal)&lt;/P&gt;&lt;P&gt;...rest of your code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and to use the function you could use calcul(!Eu_Eu!,!Gd!,!Sm!)&lt;/P&gt;&lt;P&gt;Bonne chance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 22:38:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-and-python-boolean-in-calculting/m-p/1115094#M62933</guid>
      <dc:creator>DominicRobergeIADOT</dc:creator>
      <dc:date>2021-11-08T22:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder and Python : Boolean in Calculting Field box</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-and-python-boolean-in-calculting/m-p/1115170#M62934</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/366436"&gt;@DominicRobergeIADOT&lt;/a&gt;&amp;nbsp; is absolutely right, the Python variables are used locally (unlike labeling expressions). I'd add that a more Pythonic approach is to beg for forgiveness instead of asking for permission. If the calculation throws an error for any reason, you'll get zero return to your Calculate Field results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# expression
calcu(!Eu!, !Gd!, !Sm!)

# bloc du code
def calcu(Eu, Gd,  Sm):
    try:
        return  Eu / 0.058 / math.sqrt((Sm / 0.053) * Gd / 0.2055)
    except:
        return 0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 05:20:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-and-python-boolean-in-calculting/m-p/1115170#M62934</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-11-09T05:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder and Python : Boolean in Calculting Field box</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-and-python-boolean-in-calculting/m-p/1115329#M62937</link>
      <description>&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Thank you so much to both of you for your rapid reply and solutions! My problem is now resolved. I finally adopted the second method.&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 09 Nov 2021 17:38:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-and-python-boolean-in-calculting/m-p/1115329#M62937</guid>
      <dc:creator>Mag_Geol2016</dc:creator>
      <dc:date>2021-11-09T17:38:10Z</dc:date>
    </item>
  </channel>
</rss>

