PyTirCam-1.0: A Python Model to Manage Thermal Infrared Camera Data

: Thermal-infrared remote sensing is used to monitor and study hazardous volcanic phenomena. Thermal cameras are often used by monitoring centers and laboratories. A physical comprehension of their behavior is needed to perform quantitative measurements, which are strongly dependent on camera features and settings. This makes it possible to control the radiance measurements related to volcanic processes and, thus, to detect thermal anomalies, validate models, and extract source parameters. We review the theoretical background related to the camera behavior beside the main features a ﬀ ecting thermal measurements: Atmospheric transmission, object emissivity and reﬂectivity, camera characteristics, and external optics. We develop a Python package, PythTirCam-1.0, containing pyTirTran, a radiative transfer model based on the HITRAN database and the camera spectral response. This model is compared with the empirical algorithm implemented into a commercial camera. These two procedures are validated using a simple experiment involving pyTirConv, an algorithm developed to recover the radiometric thermal data from compressed images collected by monitoring centers. Python scripts corresponding to the described methods are provided as open-source code. This study can be applied to a wide variety of applications and, speciﬁcally, to di ﬀ erent volcanic processes, from earth and space.


Introduction
Remote sensing on ground and airborne platforms provides effective monitoring for volcanic eruptions, enabling the volcanic hazard assessment and risk management. Using portable thermal infrared cameras, the infrared thermography (IRT) method has been applied and tested for the first time at Kilauea (Hawaii) in U.S. [1,2] as well as Mt. Etna [3] and Stromboli [4] in Italy, i.e., among the most active volcanoes in the world. Today, its application represents a powerful tool to observe volcanic processes [5][6][7][8][9][10][11][12][13][14]. The IRT technique has an increasing significant role in a wide range of applications [15][16][17][18][19][20]. In particular, the use of thermal infrared (TIR) cameras in volcanic remote sensing makes it possible to automatically obtain qualitative and quantitative information, e.g., to measure temperature thresholds for surveillance purposes [21] and to study high-temperature volcanic features [22]. IRT enables the possibility to detect thermal anomalies and estimate useful key parameters for modelling volcanic phenomena, such as atmospheric properties, thermal precursors, ash and volcanic gas properties, and eruption source parameters [23][24][25][26]. For this reason, the development of innovative software techniques aims not only at the detection and quantification of Remote Sens. 2020, 12,4056 3 of 24 to each pixel. As a general application, this script can be used to recover data from 2D images with a colorbar. A similar functionality, written in Matlab, has been developed by the authors of [24].
The paper is organized as follows. In Section 2, we describe the application of the blackbody radiation theory to TIR cameras, focusing on the role of the sensor spectral response to convert radiance into brightness temperature and to consider spectral atmospheric emission and absorption by also including the presence of the camera external and internal optics. We conclude this section with a description of the methodology used to verify the camera algorithms and theoretical background and convert compressed images back to radiometric data. Sections 3 and 4 summarize the corresponding results and concluding remarks, respectively. In Section 4, we also list the main necessary assumptions needed by the camera algorithm to efficiently estimate the observed object brightness temperature. In this paper, we used the camera installed at Nicolosi station (Catania) to monitor Mt. Etna as a case study.

Materials and Methods
2.1. The Case Study, the TIR Sensors, and the Data Acquisition Procedure

Theoretical Background
Temperature measurements of a TIR camera are based on the theory of the radiance emitted by a blackbody (R BB ). In particular, the temperature estimated by a TIR camera typically depends not only on the measured radiation, but also on parameters such as the emissivity of the object, its distance from the device, the atmospheric radiative properties, and the camera itself (i.e., detector spectral response, Remote Sens. 2020, 12,4056 4 of 24 optical properties) [52,53]. In the following, we review the effect of these parameters on the measured brightness temperature, T obj , by introducing the radiance of the object R obj , the radiance reflected by the object R re f l , the radiance emitted by the atmosphere R atm , and the radiance measured by the device R obs . In addition, we show how the camera external optics can influence IR measurements.

Blackbody Radiation and Emissivity
In order to understand how a TIR camera converts measured radiance into brightness temperature, we need to briefly review the blackbody emission theory. The radiant flux density, or simply the radiant intensity, at all wavelengths and at temperature T from a blackbody surface with radiance R BB is M BB = πR BB = σT 4 , where σ is the Stefan-Boltzmann constant.
Indeed, given the Planck's law at wavelength λ (i.e., the spectral radiance of a blackbody), we obtain the radiance where dΩ is the solid angle and θ is the angle between the ray and the normal to the surface. This result holds for Lambertian surfaces, meaning that the radiation is isotropic (e.g., [5]). Real objects do not always behave as a blackbody. In fact, the radiation actually emitted, R obj , is a fraction of that emitted by a blackbody at the same temperature for a given wavelength through the emissivity, (λ) ≡ λ , i.e., R obj = ∞ 0 λ B(λ, T)dλ. Since some real objects, named greybodies, have a small emissivity variation over the different wavelengths, a constant value is used for the emissivity: R obj = R BB . In this approximation, the reflectivity of a completely opaque object is simply (1 − ). Thus, the radiation emitted and reflected by the object is R er = R obj + (1 − )R atm , where R atm is the radiance from the ambient atmosphere to the object. If all the surrounding ambient is at constant temperature T atm , we have

Camera Sensor Spectral Response
The sensor of a camera operates in a band of the electromagnetic spectrum with a wavelength dependent spectral response function, sr(λ). The spectral response describes the sensor sensitivity to optical radiation of different wavelengths. A typical spectral response of an IR detector is defined in the middle and long-wavelength infrared (MWIR and LWIR) bands (3-5 µm and 8-12 µm, respectively).
In Figure 1, we report R IR and R BB , beside the spectral response function that we used to obtain them. It is the typical spectral response of FLIR TIR camera sensors [23]. Its maximum value has been calibrated, as described in Section 2.3.
Remote Sens. 2020, 12, x 5 of 24 In Figure 1, we report and , beside the spectral response function that we used to obtain them. It is the typical spectral response of FLIR TIR camera sensors [23]. Its maximum value has been calibrated, as described in Section 2.3. The function ( ) is used by the camera to convert the received signal into brightness temperature. The inverse function ( ) can be used to convert the brightness temperature back to radiance. An analytical approximation of both functions is described in Section 2.3. These approximations can be adapted to any camera spectral response using pyTirTran. As a consequence, considering the contribution of each wavelength, the radiance emitted and reflected by the object and recorded by the camera is: This result holds neglecting the atmospheric absorption and emission. In the following, we discuss these effects.

Atmospheric Emission and Absorption
In the infrared wavelength, window absorption and emission are dominant, scattering can be neglected, and the local thermal equilibrium regime holds. Thus, atmospheric emission/absorption is described by the Schwarzschild's equation and the transmittance parameters. These parameters, and , are related to the atmosphere density and specific absorption coefficient through the optical depth. We need to introduce two transmittances because they slightly depend on the temperature of the object and of the atmosphere, respectively (for more details, see Appendix A). These parameters depend also on the optical depth, , of the atmosphere. A homogeneous atmosphere with density and specific absorption coefficient ( ) has where is the atmospheric thickness, i.e., the distance between the object and the camera (see Appendix A).
( ) depends on the atmospheric composition through the line-by-line absorption of each component, given by, e.g., the authors of [42]. Introducing atmospheric contributions, Equation (6) modifies accordingly to the Schwarzschild's equation as follows: Figure 1. (a) Spectral response function of the FLIR camera as used throughout this paper. Its maximum value has been fixed to 0.82 (see Section 2.3); (b) radiance emitted from a blackbody R BB (T) and received by the TIR camera R IR (T), as a function of temperature T.
The function R IR (T) is used by the camera to convert the received signal into brightness temperature. The inverse function T IR (R) can be used to convert the brightness temperature back to radiance. An analytical approximation of both functions is described in Section 2.3. These approximations can be adapted to any camera spectral response using pyTirTran.
As a consequence, considering the contribution of each wavelength, the radiance emitted and reflected by the object and recorded by the camera is: This result holds neglecting the atmospheric absorption and emission. In the following, we discuss these effects.

Atmospheric Emission and Absorption
In the infrared wavelength, window absorption and emission are dominant, scattering can be neglected, and the local thermal equilibrium regime holds. Thus, atmospheric emission/absorption is described by the Schwarzschild's equation and the transmittance parameters. These parameters, τ obj and τ atm , are related to the atmosphere density and specific absorption coefficient through the optical depth. We need to introduce two transmittances because they slightly depend on the temperature of the object and of the atmosphere, respectively (for more details, see Appendix A). These parameters depend also on the optical depth, δ, of the atmosphere. A homogeneous atmosphere with density ρ atm and specific absorption coefficient A atm (λ) has Remote Sens. 2020, 12, 4056 where d is the atmospheric thickness, i.e., the distance between the object and the camera (see Appendix A). A atm (λ) depends on the atmospheric composition through the line-by-line absorption of each component, given by, e.g., the authors of [42]. Introducing atmospheric contributions, Equation (6) modifies accordingly to the Schwarzschild's equation as follows: where τ obj R obj is the radiance of the object attenuated by the atmosphere, τ atm R atm is the reflected radiance attenuated by the atmosphere, and (1 − τ atm )R atm is the atmospheric emission (for more details see Appendix A).
In the standard use of the TIR camera, we want to use Equation (8) to obtain R obj , and thus: from R obs , for prescribed , δ, and T atm . However, Equation (8) is not invertible as long as τ obj depends from T obj . The transmittances are defined from the previous equations and can be considered equal in the approximation T obj ≈ T atm : i.e., we are disregarding that the spectral emission of the object changes with its temperature, influencing how the atmosphere absorbs. This approximation leads to a maximum discrepancy τ obj τ atm − 1 = 5% with 50% humidity, up to 10 km of distance, up to T obj = 500 • C (this can be checked using pyTirTran). Using Equation (10), Equation (8) becomes easily invertible and R obj can be calculated from R obs : This is the strategy used by the FLIR TIR camera to obtain R obj from R obs [52,53]. When the temperature difference between the atmosphere and the observed object is relatively small or when the object distance is limited, this approximation works very well. However, as discussed in the following and in Section 3.1, the atmospheric transmittance is sensitive to temperature when distance increases, e.g., in the window T atm = [0, 15] • C, with 50% of humidity, it varies by a factor 6% and 13% at 1 km and 10 km of distance, respectively. As pointed out before, this variability becomes even more important for larger temperature contrasts and leads to significant measurement error when observing far and hot objects. This is the typical condition in geophysical applications. The quantification of these effects can be done using pyTirTran. When they are not negligible, Equation (8) should be used to relax the approximation used in Equation (10). The former should be inverted with a higher computational cost to reconstruct the radiance emitted by the observed object.
In this section, we have described how to recover the observed radiance by filtering out the camera atmospheric corrections. This analysis can be used to implement a more accurate inversion algorithm fed by commercial camera measurements.

Effect of a Protective Germanium Lens on IR Measurements
The implementation of protective IR windows is commonly used not only for safety standards (e.g., for inspecting live equipment) but also to prevent the degradation of the camera lens. In fact, the surveillance monitoring centers use a protective case provided of a Germanium (Ge) lens to cover the camera from the environment. Studies related to the influence of IR windows on IR measurements can be found in technical publications such as [54][55][56][57]. The Ge widow is designed to operate in the LWIR band, and it is recommended as window material due to its good transmission and, consequently, low emissivity and reflection (see Figure 2a). The technical documentation related to the Ge spectral transmittance has been provided by Electro Optical Technologies [58]. Nevertheless, its effect on the measurements should be considered to obtain accurate data when it is placed between the target object and the camera. In this case, a calibration of the camera with the Ge window should be done to account for its transmittance. Moreover, the radiance emitted and reflected should be added in the total radiance received by the TIR camera. Defining the effective External Optics (EO) transmittance τ ext , emissivity ext , and reflectivity ρ ext , Equation (11) should be modified as: where R ext = R IR (T ext ) and R cam = R IR (T cam ) are the emitted and reflected radiance defined through the EO temperature, T ext , and their reflected temperature, T cam , respectively. This is the effective equation used by the camera, where the temperature dependence of all the EO parameters is disregarded. However, the EO transmittance depends on the wavelength and its effective value depends on the camera spectral response and on measurement conditions, as we quantify in Equation (14).
Remote Sens. 2020, 12, x 7 of 24 equation used by the camera, where the temperature dependence of all the EO parameters is disregarded. However, the EO transmittance depends on the wavelength and its effective value depends on the camera spectral response and on measurement conditions, as we quantify in Equation (14). The EO spectral transmittance, ( ), should be considered in Equation (11) beside the camera spectral response to correctly account for its wavelength dependence. In particular, Equation (5) should be modified as follows: To get , all the radiances transmitted by the EO should be calculated with Equation (13): Equation (12) can be obtained from Equation (14) under the following approximation for the effective transmittance ( ): This equation enables the evaluation of from the EO spectral transmittance ( ), taking into account the camera spectral response. The Python scripts enclosed with the paper provide this functionality. We can see here that, in principle, the effective transmittance of the EO should depend on the brightness temperature. In Figure 2b, its variation in the window = [0,500] °C is shown. With the camera settings described here, we obtained = 0.860 ± 0.004 as an effective constant value. Thus, the EO transmittance can be considered constant and Equation (12) can be used within a relative error equal to 0.5%. Using the energy conservation condition + + = 1 and the additional approximation ≈ , Equation (12) simplifies to: The EO spectral transmittance, st(λ), should be considered in Equation (11) beside the camera spectral response to correctly account for its wavelength dependence. In particular, Equation (5) should be modified as follows: To get R obs , all the radiances transmitted by the EO should be calculated with Equation (13): Equation (12) can be obtained from Equation (14) under the following approximation for the effective transmittance τ ext (T): This equation enables the evaluation of τ ext from the EO spectral transmittance st(λ), taking into account the camera spectral response. The Python scripts enclosed with the paper provide this functionality. We can see here that, in principle, the effective transmittance of the EO should depend Remote Sens. 2020, 12, 4056 8 of 24 on the brightness temperature. In Figure 2b, its variation in the window T = [0, 500] • C is shown. With the camera settings described here, we obtained τ ext = 0.860 ± 0.004 as an effective constant value. Thus, the EO transmittance can be considered constant and Equation (12) can be used within a relative error equal to 0.5%. Using the energy conservation condition ext + ρ ext + τ ext = 1 and the additional approximation T ext ≈ T cam , Equation (12) simplifies to: In the sections that follow and in pyTirTran, we use Equation (16).

Effect of the Internal Optics
The effects of the TIR camera optics are equivalent to those due to the EO. Defining cam , ρ cam , τ cam , the optical properties of the camera lenses can be combined with those of the EO. The two optical parts can be treated as one element with equivalent parameters opt , ρ opt , τ opt . Disregarding the effect of the atmosphere between the lenses (as done in the previous section), but including multiple reflections, those parameters are: Thus, when both the external and internal optics (IO) transmittance is known, both effects can be considered in Equation (16) using τ ext → τ opt .
On the contrary, when no information on the IO spectral transmittance are given, their effect can be left in the effective spectral response. This can be done at the first order in (1 − τ).
Under this approximation, τ opt ≈ τ ext τ cam . Moreover, defining the IO spectral transmittance sc(λ), Equation (5) is modified as follows: and, as obtained for the EO in Equation (15): With these ingredients, Equation (16) becomes: The additional approximation (1 − τ cam ) (1 − τ ext ) holds when the IO optics have a higher quality than the EO, and Equation (22) becomes equivalent to Equation (16) with R → R . Thus, it is possible to consider the IO together with the camera sensibility in a compact way using an effective spectral response: This is what we have done in the following of the paper, where sr(λ), given in Figure 1, implicitly includes the IO spectral transmittance. The method is also validated with the camera radiometric data in the following section, where the camera effective spectral response is used to perform the radiance and brightness temperature conversion used by the TIR camera.

Radiance and Brighness Temperature Conversion Used by the FLIR Camera
The properties of the TIR camera sensor (and IO) have to be considered in the conversion of radiance into temperature and vice versa. Following the theoretical background described above, we used a fitting procedure to relate analytically these two quantities.
Since the Stefan-Boltzmann formula is a fourth-order degree in terms of temperature (see Section 2.2, Equation (4)), we approximated R IR (T), defined in Equation (5), by fitting the theoretical radiance as a fourth-degree polynomial: R f it (T) = 4 i=0 a R,i T i . Meanwhile, for the inverse function T IR (R), our fitting procedure consisted of the combination of a power law and a linear function of the radiance, i.e., T f it = a T,0 + a T,1 R + a T,2 R a T,3 . These parameters were calculated using a two-step procedure. We started by assuming that the camera sensor has a perfect efficiency, with the maximum value of sr(λ) equal to 1. In this way, we were able, once the temperature range was defined, to approximate Equation (5) and its inverse with R f it and T f it , respectively. The values of the fitting coefficients were obtained for two different temperature ranges, corresponding to those used by the camera (see Table 1). However, the camera sensor should have some dissipation, and thus, we had to calibrate the maximum value of the spectral response, sr max , using radiometric data. We extracted these data, say R exp and T exp , from a radiometric image recorded by a FLIR A40 M camera monitoring Mt. Etna from Nicolosi station on 16th November 2006. We used ResearchIR software to export R exp and T exp [53] along a high-contrast line in the image. Then, we tuned sr max to the value, optimizing the difference between R exp and R f it T exp . For both temperature ranges, we obtained sr max = 0.82 ± 0.01. Since R f it depends on the camera optical properties through sr(λ), this procedure enabled the quantification of the uncertainty due to the camera spectral response (and IO transmittance) shown in Figure 1. Table 1. Fit coefficient values of R f it and T f it for two different temperature ranges beside relative error with respect to Equation (5), and the maximum value of the spectral response, sr max . It is worth noting that the value of the exponent of the fitting function T f it , approximating the inverse function T IR = R −1 IR (T), was a T,3 ≈ 1/4 in accordance with the inverse of the Stefan-Boltzmann law, see Table 1. Moreover, the discrepancy between the numerical fit of the inverse function and the given temperature had an average relative error smaller than 4·10 −4 .

Experimental Procedure with the FLIR A40 M Camera
In this subsection, we briefly describe the experimental procedure carried out with a FLIR A40 M camera, the same installed at INGV-OE Nicolosi station. We performed a small experiment to compare the theoretical and empirical atmospheric adjustments described in the previous sections with that used by our camera. The simplicity of the experiment did not allow us to perfectly control the temperature of the observed objects. However, we took temperature measurements every few seconds, keeping the camera-target position fixed while changing the camera settings. This allowed us to keep object temperature variations within the measurement error. In particular, a hot (a PC battery charger) and a cold object (a plastic ice pack) were considered as references to verify the influence of the camera settings. Figure 3 shows the setup used for the measurements. In the following, we report the settings related to the ENT camera: • It is worth noting that the maximum configurable distance of this camera is 3.047 km.

Description of Python Scripts
The PyTirCam-1.0 project was divided into the following folders: • PyTirCam-1.0/pyTirTran: A transmission and conversion algorithm based on the spectral properties of atmospheric gases and of the TIR camera. • PyTirCam-1.0/jpgToTIR: An algorithm based on Python PIL library to recover the radiometric thermal data from compressed images.
The two folders contain the input data, the functions defined throughout this paper, and the scripts used to retrieve the presented results, as a practical tutorial of the PyTirCam-1.0 usage.
The folder contains: • The required input and functions to run PyTirTran.py: 1. input.py is the input file of pyTirTran.py. The required inputs are (symbols used in the script are reported in brackets): Temperature range in K (Tmin and Tmax), length of the temperature linear space (len_T), CO2 bulk density (rhoCO2), maximum value of the camera spectral response (SpR_max), minimum and maximum wavelength of the spectral response defined as a step function (lambda_min, lambda_max), the camera-object distance (L), external optics transmittance (tauext), and the local path of the H2O and CO2 absorption We show the results of this methodology in Section 3.4.

Description of Python Scripts
The PyTirCam-1.0 project was divided into the following folders: • PyTirCam-1.0/pyTirTran: A transmission and conversion algorithm based on the spectral properties of atmospheric gases and of the TIR camera. • PyTirCam-1.0/jpgToTIR: An algorithm based on Python PIL library to recover the radiometric thermal data from compressed images.
The two folders contain the input data, the functions defined throughout this paper, and the scripts used to retrieve the presented results, as a practical tutorial of the PyTirCam-1.0 usage.
The folder contains:

•
The required input and functions to run PyTirTran.py: input.py is the input file of pyTirTran.py. The required inputs are (symbols used in the script are reported in brackets): Temperature range in K (Tmin and Tmax), length of the temperature linear space (len_T), CO 2 bulk density (rhoCO2), maximum value of the camera spectral response (SpR_max), minimum and maximum wavelength of the spectral response defined as a step function (lambda_min, lambda_max), the camera-object distance (L), external optics transmittance (tauext), and the local path of the H 2 O and CO 2 absorption coefficient data, beside the camera spectral response data (fileIn_*). 2.
functions/__init__.py is the file containing: Fit, the function to perform curve fittings and provide optimal parameters; T_func, the function approximating T IR (R) as a combination of linear and power laws (see Section 2.3 and Table 1); ps, the saturation pressure of water; rhow and rhowThC, the water vapor bulk density (as in Equations (A3) and (A6), respectively); Planck and RIR, the Planck function and the Stefan-Boltzmann law corrected with the camera spectral response (Equations (1) and (5), respectively); Step, the spectral response as a step function (Section 3.1); tauA and tauThC, the atmospheric transmittances (Equations (10) and (A5), respectively); Rtot, the total radiance received by the camera sensor (Equation (16)).
• pyTirTran.py is the Python script to be executed. The script can be run to: 1.
Use the spectral response of the camera or defined as step function by choosing the flag step = False or True, respectively.
• plot_technote.py is a Python script to show the plots given in Figures 5 and 6. To use the script for different data, it is necessary to modify the input file, i.e., the path of the new spectralData folder and insert the new input values and ranges according to the new data in input.py. To add new gas components, it is sufficient to pass longer arrays to the rhoA function. In particular, the bulk density and the specific absorption coefficient data of each new gas component are needed. In addition, it is possible to obtain the results reported on Tables 2-4 for a new experiment by changing the experimental data in the corresponding part of pyTirTran.py. Table 2. Settings and measurements for the hot object observations. The selected measurement scale is between 0 • C and 500 • C. T f lir , T SpR , and T ThC are the observed, the theoretically corrected and the empirically corrected brightness temperatures, respectively.

Measurement
Group As shown by the authors of [31], we obtained a wide variability of the transmission coefficients depending on the adopted model. At short distances, SpR provided smaller transmittances than ThC when % 0.5. On the other hand, SpR absorbed less than ThC when % 0.5. It is worth noting that SpR and ThC gave similar results in the case % = 0.5 and = 15 °C. At long distances, SpR absorbed more than ThC in cold conditions (Figure 6a), but it did the opposite when = 15 °C (Figure 6b). SpRS absorbed always less than ThC. This comparison shows how the atmospheric transmittance is sensitive to the spectral response of the camera. At short distances, SpR behaved much similarly to ThC than SpRS did. Moreover, ThC was somehow between SpR and SpRS. We can thus conclude that, at short distances, the spectral response used in Equation (10) can have a significant role in determining the discrepancies between ThC and SpR obtained in this and in the previous subsection. On the other hand, the fact that the maximum allowed distance in the camera settings is 3 km may indicate that ThC cannot be safely used at greater distances. Unfortunately, we cannot directly evaluate the accuracy of either ThC or SpR transmission models because they strongly depend not only on the optical properties of the  Table 3. Settings and measurements for the cold object observations. The selected measurement scale is between −10 • C and 60 • C. M1, M2, M3 refer to three different points on the target object. T f lir , T SpR , and T ThC are the observed, the theoretically corrected, and the empirically corrected brightness temperatures, respectively.

Measurement
Group  This comparison shows how the atmospheric transmittance is sensitive to the spectral response of the camera. At short distances, SpR behaved much similarly to ThC than SpRS did. Moreover, ThC was somehow between SpR and SpRS. We can thus conclude that, at short distances, the spectral response used in Equation (10) can have a significant role in determining the discrepancies between ThC and SpR obtained in this and in the previous subsection. On the other hand, the fact that the maximum allowed distance in the camera settings is 3 km may indicate that ThC cannot be safely used at greater distances. Unfortunately, we cannot directly evaluate the accuracy of either ThC or SpR transmission models because they strongly depend not only on the optical properties of the atmosphere, but also on the particular spectral response of the camera. In Section 3.3, we analyze a simple experiment to directly test the TIR camera measurements.
At distance = 10 km, the above results were compared with LOWTRAN, a Low-Resolution Transmittance open-source code [45,46], to provide further comparison with a widely used atmospheric transmittance model. The code enables the evaluation of the spectral transmittance of a horizonal portion of atmosphere. Setting the same compositions and parameters used in this section, we obtained the results reported in Figure 7.  Table 4. Settings and measurements for the cold object observations. The selected measurement scale is between −10 • C and 60 • C. Each measurement group M1, M2, M3 corresponds to a different observation point. T f lir , T SpR , and T ThC are the observed, the theoretically corrected, and the empirically corrected brightness temperatures, respectively.

Measurement
Group The folder contains: • The required input and functions to run PyTirConv.py: finds the colorbar index corresponding to the closest color (by means of the Euclidean distance); analyticBar, defines a specific analytical colorbar; fromJpgToBar, finds the colorbar directly from the image; and fromJpgToArray, extract the temperature values from the compressed image.
• pyTirConv.py is the Python script to be executed. The script can be run to: It is possible to apply the script for other images by modifying the input.py file according to the new image coordinates. It is worth nothing that the script can be applied to any 2D colormap when the variable showed is quantified with a colorbar.

Atmospheric Transmittance Models Comparison
The method used to describe atmospheric transmission can significantly affect the thermal measurements. Significantly different atmospheric transmittance coefficients can be obtained in the LWIR band by changing the algorithm used by TIR cameras, using different transmission models, or empirical tables [31].
We compared the expression of the transmittance given by Equation (10) and that used by FLIR for ThermaCAM-PM-595-LW in the wavelength window [7.5, 13] µm, described by the authors of [31] (see Equation (A5), Appendix B). Equation (10) was calculated using sr(λ), either as in Figure 1a or as a step function defined as equal to 1 for λ ∈ [7.5, 13] µm and 0 elsewhere. We refer to the model used by ThermaCAM-PM-595-LW as ThC, to Equation (10) with sr(λ) of Figure 1a as SpR, and to Equation (10) with a step function as SpRS. Figure 5 compares SpR and SpRS with ThC at short distances (d < 1 km). It shows the atmospheric transmittance with respect to the camera-to-object distance as a function of T atm , with relative humidity ω % = 0.5; and as a function of ω % with T atm = 15 • C. Figure 6 shows the atmospheric transmission up to 10 km for the cases ω % = 0.5 and T atm = 0, 15 • C, obtained with ThC, SpR and SpRS. Data can be reproduced using pyTirTran.
As shown by the authors of [31], we obtained a wide variability of the transmission coefficients depending on the adopted model. At short distances, SpR provided smaller transmittances than ThC when ω % ≤ 0.5. On the other hand, SpR absorbed less than ThC when ω % > 0.5. It is worth noting that SpR and ThC gave similar results in the case ω % = 0.5 and T atm = 15 • C. At long distances, SpR absorbed more than ThC in cold conditions (Figure 6a), but it did the opposite when T atm = 15 • C (Figure 6b). SpRS absorbed always less than ThC. This comparison shows how the atmospheric transmittance is sensitive to the spectral response of the camera. At short distances, SpR behaved much similarly to ThC than SpRS did. Moreover, ThC was somehow between SpR and SpRS. We can thus conclude that, at short distances, the spectral response used in Equation (10) can have a significant role in determining the discrepancies between ThC and SpR obtained in this and in the previous subsection. On the other hand, the fact that the maximum allowed distance in the camera settings is 3 km may indicate that ThC cannot be safely used at greater distances. Unfortunately, we cannot directly evaluate the accuracy of either ThC or SpR transmission models because they strongly depend not only on the optical properties of the atmosphere, but also on the particular spectral response of the camera. In Section 3.3, we analyze a simple experiment to directly test the TIR camera measurements.
At distance d = 10 km, the above results were compared with LOWTRAN, a Low-Resolution Transmittance open-source code [45,46], to provide further comparison with a widely used atmospheric transmittance model. The code enables the evaluation of the spectral transmittance of a horizonal portion of atmosphere. Setting the same compositions and parameters used in this section, we obtained the results reported in Figure 7.  (7) (blue). The transmittances given in legend were calculated using FLIR typical spectral response (SpR, Equation (10)).
Whereas the comparison of LOWTRAN with the high-resolution HITRAN spectral transmittance that we used in SpR was very good at 0 °C, the atmospheric transmittance calculated with the former model was smaller at 15 °C. The main sources of discrepancy were the spectral resolution and water self-line-broadening [60]. The latter effect was small to negligible except for water vapor at bottom of the Earth's atmosphere [44]. In this case, to provide agreement with experimental results, the water vapor continuum has been formulated in literature by empirically broadening the collisional Lorentz shape of water absorption lines [61]. This effect can be considered in pyTirTran by substituting the HITRAN water cross section with the smoother water continuum. This functionality will be provided in future developments.

Effect of the Atmospheric and External Optics Corrections on High Temperature Measurements
Here, we want to show how the atmospheric and external optics corrections affect the brightness temperature data as the contrast between the object and the atmospheric temperature changes. In Figure 8, we show each of these effects, when an object with = 0.98 was at 1 km and 10 km of distance, in an atmosphere at 20 °C with 40% relative humidity, and = 0.86. Since Equation (16) is linear with respect to radiances, the relationship between and is quasilinear, and we can focus on the maximum temperature contrast ( = 500 °C) to highlight the weight of each effect.
In the case defined above, the effect of the external optics is comparable with the effect of 1 km of atmosphere because = 0.82. In particular, when = 500 °C, we obtained = 447 °C and 435 °C, respectively. Combining the two effects at 1 km of distance, we obtained = 395 °C.
Moving to 10 km of distance, the increasing atmospheric optical thickness led to = 0.54 , corresponding to = 303 °C and 333 °C, respectively, with and without external optics. These numbers quantified the influence of the two main effects affecting the observed brightness  (7) (blue). The transmittances given in legend were calculated using FLIR typical spectral response (SpR, Equation (10)).
Whereas the comparison of LOWTRAN with the high-resolution HITRAN spectral transmittance that we used in SpR was very good at 0 • C, the atmospheric transmittance calculated with the former model was smaller at 15 • C. The main sources of discrepancy were the spectral resolution and water self-line-broadening [60]. The latter effect was small to negligible except for water vapor at bottom of the Earth's atmosphere [44]. In this case, to provide agreement with experimental results, the water vapor continuum has been formulated in literature by empirically broadening the collisional Lorentz shape of water absorption lines [61]. This effect can be considered in pyTirTran by substituting the HITRAN water cross section with the smoother water continuum. This functionality will be provided in future developments.

Effect of the Atmospheric and External Optics Corrections on High Temperature Measurements
Here, we want to show how the atmospheric and external optics corrections affect the brightness temperature data as the contrast between the object and the atmospheric temperature changes. In Figure 8, we show each of these effects, when an object with = 0.98 was at 1 km and 10 km of distance, in an atmosphere at 20 • C with 40% relative humidity, and τ ext = 0.86. Since Equation (16) is linear with respect to radiances, the relationship between T obj and T obs is quasilinear, and we can focus on the maximum temperature contrast (T obj = 500 • C) to highlight the weight of each effect. In the case defined above, the effect of the external optics is comparable with the effect of 1 km of atmosphere because τ atm = 0.82. In particular, when T obj = 500 • C, we obtained T obs = 447 • C and 435 • C, respectively. Combining the two effects at 1 km of distance, we obtained T obs = 395 • C. Moving to 10 km of distance, the increasing atmospheric optical thickness led to τ atm = 0.54, corresponding to T obs = 303 • C and 333 • C, respectively, with and without external optics. These numbers quantified the influence of the two main effects affecting the observed brightness temperature, highlighting the crucial importance of the correction algorithms needed to retrieve the object temperature. It is worth noting that, in practical monitoring applications, external optics are subject to corrosion due to atmospheric particulate, aerosols, and some gases, such as CO2, SO2, HCl, and HF. This aspect is particularly critical in the monitoring of volcanoes, which also have the presence of ash and sulfur. In the worst cases, it is necessary to replace the external optics every few months. The degradation of the transmission coefficient over time will be investigated in future studies.

Comparison between Experimental Data and Theoretical Atmospheric Correction
In this section, we experimentally checked how the camera settings influenced the acquired brightness temperature of an object kept at an approximately constant temperature and position with respect to the camera. We changed the following setting parameters: Distance 0 m or 3047 m; relative humidity 0% or 40%; emissivity 0.98 or 1; atmospheric and reflected temperature 20 °C or 40 °C. The results are reported in Tables 2-4. There, was the temperature given by the camera; was the temperature corrected using Equations (9), (10), and (16); and was the temperature corrected using the empirical algorithm ThC in Equation (A5). When = 0 and = 1, we should have had = 1 and = . When 0 or < 1 in the camera settings, the measured temperature changed. Our aim was to verify that was approximately not influenced by the camera settings, meaning that our theoretical atmospheric correction worked similarly to that implemented in the device.
The thermal data measured on the hot object showed that varied from 48.5 °C to 39 °C when moved from 3047 m to 0 m (see Table 2 for more details). when 0 because the camera was trying to correct for the presence of approximately 3 km of colder atmosphere. Our theoretical atmospheric correction kept = 40.1 ± 1.1 °C, while the camera algorithm gave = 39.1 ± 0.7 °C.
In Table 3, the measurements on the cold object were performed by changing the sole parameter . They were divided in three groups: M1, M2, and M3. Similar to the hot object observations, a variation in the TIR measurements was obtained by changing from 0 m to 3047 m and by keeping It is worth noting that, in practical monitoring applications, external optics are subject to corrosion due to atmospheric particulate, aerosols, and some gases, such as CO 2 , SO 2 , HCl, and HF. This aspect is particularly critical in the monitoring of volcanoes, which also have the presence of ash and sulfur. In the worst cases, it is necessary to replace the external optics every few months. The degradation of the transmission coefficient over time will be investigated in future studies.

Comparison between Experimental Data and Theoretical Atmospheric Correction
In this section, we experimentally checked how the camera settings influenced the acquired brightness temperature of an object kept at an approximately constant temperature and position with respect to the camera. We changed the following setting parameters: Distance 0 m or 3047 m; relative humidity 0% or 40%; emissivity 0.98 or 1; atmospheric and reflected temperature 20 • C or 40 • C. The results are reported in Tables 2-4. There, T f lir was the temperature given by the camera; T SpR was the temperature corrected using Equations (9), (10), and (16); and T ThC was the temperature corrected using the empirical algorithm ThC in Equation (A5). When d = 0 and = 1, we should have had τ = 1 and T SpR = T f lir . When d > 0 or < 1 in the camera settings, the measured temperature T f lir changed. Our aim was to verify that T SpR was approximately not influenced by the camera settings, meaning that our theoretical atmospheric correction worked similarly to that implemented in the device.
The thermal data measured on the hot object showed that T f lir varied from 48.5 • C to 39 • C when d moved from 3047 m to 0 m (see Table 2 for more details). T f lir > T SpR when d > 0 because the camera was trying to correct for the presence of approximately 3 km of colder atmosphere. Our theoretical atmospheric correction kept T SpR = 40.1 ± 1.1 • C, while the camera algorithm gave T ThC = 39.1 ± 0.7 • C.
In Table 3, the measurements on the cold object were performed by changing the sole parameter d. They were divided in three groups: M1, M2, and M3. Similar to the hot object observations, a variation in the TIR measurements was obtained by changing d from 0 m to 3047 m and by keeping the other parameters constant. In this case, we obtained T SpR = −1.9 ± 2.0, 3.5 ± 0.9, 4.3 ± 0.5 • C, respectively, for M1, M2, and M3. The camera algorithm gave T ThC = −1.0 ± 2.9, 4.2 ± 0.1, 5.0 ± 0.2 • C, respectively. The first group showed a larger error because its second measurement was off-range.
We verified that our theoretical atmospheric correction is able to keep T SpR constant within an error of 1.1 • C. We verified also that the empirical atmospheric correction, Equation (A5), keeps T ThC constant within an error of 0.7 • C.
In our simple experiment, the algorithm ThC worked as expected and could be used to understand how the camera atmospheric correction works. However, the algorithm used by the camera was empirical, implicitly depended on the particular camera spectral response, and has been tested only up to 3 km. For these reasons, we also tested a theoretical atmospheric correction based directly on the specific spectral absorption coefficients of air and water. We found that this algorithm worked coherently to that implemented in the camera with a slight increase in the relative error. This fact does not necessarily mean that the empirical algorithm computed the atmospheric transmission coefficient in a more accurate way. Instead, we can only conclude that the camera actually used an algorithm that was more similar (if not exactly the same) to the empirical one. Both the theoretical and empirical algorithms behaved similarly within an error of approximately 1 • C. Figure 9. Absolute error between temperature data measured by the camera and those obtained using the conversion procedure described in Section 2.5 and implemented in pyTirConv.