-1

I am using an existing script from github to calculate pixel temperatures from the flir camera. The original project can be found here https://github.com/Nervengift/read_thermal.py/blob/master/flir_image_extractor.py I am trying to automate the script to run for all images within a given folder. The script works for most files but I run into an issue from time to time which makes the script break. The official error I am getting is as such:

Traceback (most recent call last):
  File ".\flir_image_extractor.py", line 288, in <module>
    fie.process_image(args.input)
  File ".\flir_image_extractor.py", line 63, in process_image
    self.thermal_image_np = self.extract_thermal_image()
  File ".\flir_image_extractor.py", line 150, in extract_thermal_image
    thermal_np = raw2tempfunc(thermal_np)
  File "C:\Users\sai.peri\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\lib\function_base.py", line 2091, in __call__
    return self._vectorize_call(func=func, args=vargs)
  File "C:\Users\sai.peri\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\lib\function_base.py", line 2167, in _vectorize_call
    outputs = ufunc(*inputs)
  File ".\flir_image_extractor.py", line 149, in <lambda>
    PO=meta['PlanckO'], PR2=meta['PlanckR2']))
  File ".\flir_image_extractor.py", line 196, in raw2temp
    print("PB: {} LOG: {}".format(PB, log(PR1 / (PR2 * (raw_obj + PO)) + PF) - 273.15))
ValueError: math domain error

Following the trace I added variables to print out PB and the log function since these are what are used to calculate the temperature (The line to calculate temperature is as such temp_celcius = PB / log(PR1 / (PR2 * (raw_obj + PO)) + PF) - 273.15 I am working with averages so I can choose to ignore some pixels (although this will have effects on my results, though could be minor). I have printed out values of PB and LOG until the exception hits:

PB: 1428 LOG: -263.82261856683573
PB: 1428 LOG: -260.9464780172497
PB: 1428 LOG: -262.7915360578767
PB: 1428 LOG: -262.7915360578767
PB: 1428 LOG: -263.09963560725936
PB: 1428 LOG: -262.7915360578767
PB: 1428 LOG: -262.90511447579644
PB: 1428 LOG: -261.8717079609195

I am assuming the last entry is the last successful calculation and that on the next one it fails. What exactly is happening and how can I try to fix this to retain the actual legit value? I have tried reaching out to the owner of the project but with no luck. I would like to thank you in advance for your help.

EDIT: I have printed out the values of the variables that go into the log function. With these values I went to wolfram alpha and came up with the value of -273.39416898307 so the calculation then becomes 1428/-273.39416898307 = -5.223227 as the actual temperature value. I am not sure why I am getting this error because all of the prevous LOG functions have been negative with the -273 subtraction. The values used to cause the error and that I checked with wolfram are as such: PB: 1428 PR1: 17096.453 PR2: 0.062614508 raw_obj + PO: -1260325.936342655 PF: 1 with the equation:temp_celcius = PB / log(PR1 / (PR2 * (raw_obj + PO)) + PF) - 273.15

Sai Peri
  • 339
  • 1
  • 3
  • 17
  • could the argument of `log` have become `<= 0`? that would cause `log` to raise a `ValueError`. – hiro protagonist Sep 06 '19 at 19:38
  • I added an edit to find out the actual calculations with the variable values with wolframalpha. It seems that all of the log functions are becoming negative from my PB: LOG: output – Sai Peri Sep 06 '19 at 19:43

1 Answers1

0

It is the Python log() operation that generates this error. You will have to display all the variables you use when calling it to discover what happened.

But it is easy to reproduce:

In [2]: import math

In [3]: print math.log(0)
--------------------------------------------------------------------------- ValueError                                Traceback (most recent call last) <ipython-input-3-84ea89d877e8> in <module>()
----> 1 print math.log(0)

ValueError: math domain error

Remember that you do not need 0 exactly as you are dealing with floating number. Any "too small" value will create the same problem:

In [11]: print math.log(1e-1000)
--------------------------------------------------------------------------- ValueError                                Traceback (most recent call last) <ipython-input-11-7cab888e1f4d> in <module>()
----> 1 print math.log(1e-1000)

ValueError: math domain error

Any negative value will have the same consequence too.

With the values PB: 1428 PR1: 17096.453 PR2: 0.062614508 raw_obj + PO: -1260325.936342655 PF: 1, the log() is called with 0.783355249302 which provides -0.244168983072 as a result. So your problem is elsewhere.

Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
  • That is exactly what I was thinking, the issue has to be within that function itself for PB, PR, ...etc. Im stumped since you are getting a legit value for the log function so it should evaluate? – Sai Peri Sep 06 '19 at 20:42