I am not a strong Python programmer, and do not know the proper way to tackle a problem I have run into. I am attempting to replicate a process defined by others and cannot deviate from that process. I am calculating values for a field in an attribute table (Field5) which is derived from other fields in the table using a given formula.
Here is a simplified version of the formula:
Field5 = math.log(!Field1! / !Field2!) + math.log(!Field3! / !Field4!)
In cases where Field1 = 0 or Field3 =0 an error is produced, since the natural log of 0 is undefined. In these instances the dataset I am replicating has assigned a value of "0" to that term in the expression. For instance, if Field1 was equal to zero then math.log(!Field1! / !Field2!) was assigned a value of "0". Similarly, if Field3 had a value of 0, then
math.log(!Field3! / !Field4!) was assigned a value of "0". Using the ArcGIS Pro Calculate Field tool, is there a Python script that will allow me to calculate values for this field using the correct formula and then specify that a value of "0" should be assigned in these instances? Something like "If math.log(!Field1! / !Field2!) is undefined, then assign a value of zero", or "If math.log(!Field1! / !Field2!) = math.log(0 / !Field2!), then assign a value of 0". Putting in the formula without such conditions results in the following:
ERROR 000539: Traceback (most recent call last):
File "<expression>", line 1, in <module>
ValueError: math domain error
I am using
ArcGIS Pro 3.0.3. Thank you for your help!