Keywords: TRIOS, JSON, Python, Matplotlib, pandas, NumPy, SciPy
TB109
Abstract
This technical brief discusses how to carry out an enthalpy integration of differential scanning calorimetry data using Python® and associated libraries.
It will discuss the libraries that will be used for the integration, enthalpy reporting and visualization. It should be noted that when using Python and its associated libraries there are usually several approaches to the analysis. This note will describe one route but you are encouraged to investigate the other options.
Note: The TRIOS™ Software data file, exported JSON file, and the final Python scripts (JupyterLab format) used in this technical brief can be downloaded here. These files include explanations as to what is happening at each step. You are encouraged to modify or edit the code for your own needs.
Introduction
TA Instruments TRIOS Software instrument control and data analysis package offers numerous features for both routine and in-depth analysis of scientific data. However, you may sometimes need to generate uniform plot formats, overlay data from multiple sources, or apply advanced functions not available within TRIOS Software.
Previously, TRIOS Software could export data in formats such as plain text (ASCII), CSV, and Excel™ workbooks. TRIOS Software version 5.8 introduced the ability to export data as JavaScript™ Object Notation (JSON) files. JSON is a text-based, language-independent format that can be utilized in various programming and data-handling languages, and it is easily readable [1]. The JSON export follows a publicly available schema, ensuring consistent data structure and allowing code reuse across multiple samples run under the same procedure.
Python Library for JSON Files
Python has options for several libraries, allowing various tasks to be completed with relative ease. When working with scientific data there are several common (but not exclusive) libraries. These include Matplotlib [2] for data visualization, pandas [3] for data handling, and NumPy [4], SciPy [5], and LMfit [6] for numerical analysis and curve fitting. There are several integrated development environments available and you should select the one you are most comfortable with; options such as Jupyter® (Notebook or Lab) [7] or Visual Studio Code™ [8] (with appropriate plug-in) are generally the most flexible when working with scientific code.
Code Script Construction
When building scripts, you often will start building code and then realize that additional libraries or functions are required. If these are imported before running the script, then this will not be an issue. TA Instruments suggests, however, that, for ease of reading the final code, a consistent structure is maintained for the final version.
In the script discussed here, that final logical format will be presented in the script generation.
Script Requirements
To carry out the integration of heat flow data using a Python script, you will need to complete several steps.
- Import the required libraries to work with the data
- Load the datafile into a dataframe
- Define the lower and upper x-axis limits for the integration
- Define a baseline
- Carry out the integration between the baseline and the actual data
- Report the final analysis
Import the Required Libraries
The following libraries are required to carry out this integration:
- TADataKit from TA Instruments– Reading in the JSON file and creation of the initial dataframe. While working with a dataframe, the pandas library is not required since the TADataKit contains all the required functionality for this script implementation.
- NumPy and SciPy – Numerical analysis for the baseline (linear interpolation) and integration. It is worth noting that either can be used on its own to achieve the required final analysis, but each have their own strengths. NumPy is mainly focused on array manipulation and basic linear algebra whereas SciPy offers a broader spectrum of scientific tools, algorithms, and functions for a wide range of scientific options.
- MatplotLib.Pyplot – Visualization of the final data.
When importing the libraries it is common practice to import the specific areas required (for example, the “integrate” option within SciPy) rather than the complete library. It is also common practice to provide a shortened name for the operator; for example, importing NumPy as np. The Python code for the required library imports is:

Import the JSON File to a Dataframe
In this example, we are taking the measurement data from a polypropylene sample run under a heat-cool-reheat experiment. The full measurement method was:
- Equilibrate -50.00 °C
- Ramp 10.00 °C/min to 190.00 °C
- Isothermal 5.0 min
- Ramp 10.00 °C/min to -50.00 °C
- Isothermal 5.0 min
- Ramp 10.00 °C/min to 190.00 °C
However, for this integration we only require the second heat (step 6 above). The python code below takes the whole JSON file into a dataframe, and then creates a second dataframe (reheat_df) that only contains the reheat data:

Should you wish to, you can make an initial plot of the data. This allows definition of the temperature limits for the integration, although this may already be known from the original TRIOS file.
The basic plot code is:

This results in the plot shown in Figure 1, which displays the temperature range of interest (between 50 °C and 185 °C).

Create Required Functions
To carry out the integration, the lower and upper limits for the analysis first need to be defined. In general, these are temperature or time points in the analysis. In the python script, take the required temperatures (or times) and find the associated line in the dataframe that corresponds to those limits. A function is created to do this. The benefit of a function is they can be created once but used multiple times. The function is called with a required “target” and it returns the location in the data frame. The easiest approach to find this location is to work through the dataframe, subtracting the target value from the associated signal in the dataframe. When the value closest to zero is obtained (ignoring the sign) then the correct location is returned.
The function for this is shown below:

This function takes in two values. The first (series) is the dataframe signal we want to look at. The target is the value we are looking for. The function is then, row by row, subtracting the target from the series and just noting the absolute value (ignoring the sign). The index value (the row number) for the row where the value closest to zero is found is then returned.
A function for the integration of the data is also required. The function needs to take the start and end limits for the analysis and focuses on that range of data. When integrating data to measure the enthalpy change, the integration must be carried out against time. As such, the function focuses on the time and heat flow signals. The function is shown as:

In this case, the data input into the function is the dataframe of interest and the start and end is the lower and upper limits defined by the temperature limits. The function then defines an array of the data between those limits (called “peak”) and then also defines subset arrays for x and y, which are time and heat flow, respectively. The baseline being used here is a linear baseline and for this the NumPy Interpolate function can be used. This generates a straight-line equation (y = mx + c) and takes the first (0) and last (-1) points as the known values. The integration being used is a trapezoid integration of the heat flow value minus the baseline against the time axis. Since the x value is time in minutes and the enthalpy requires time in seconds, the resultant integration is being multiplied by 60. The function returns this single value, which is the enthalpy change in the material.
Bringing It All Together
At this point, all the code is generated to carry out the integration. The first analysis step is to find the line indices in the dataframe that corresponds to 50°C and 185°C, as follows:

Both variables (lower_limit and upper_limit) are calling the same “find_closest_index” function. This sets lower_limit to the line index value relating to 50°C and upper_limit to the line index value relating to 185°C.
The calculate_enthalpy function is then called, referencing the reheat_df dataframe and setting the index points for the analysis limits as the lower and upper limits found in the function above, as shown:

The function then returns the calculation to the variable “enthalpy”. Looking at the returned value, the enthalpy is reported as -109.9269 J/g, which is in good agreement with the TRIOS analysis over the same analysis limits, as shown in Figure 2.
The analysis can also be plotted. The use of Matplotlib.Pyplot has been discussed previously in technical briefs [9, 10] but additional options are shown here. The code being used is:

This generates a plot that is natively 10″ × 6″ and is using the “Temperature / °C” and the “Heat Flow (Normalized) / W/g” data columns from the reheat_df dataframe for the x and y axes, respectively. The fill option fills the space bounded by the “Heat Flow (Normalized) / W/g” data and by a straight-line interpolation between the same limits. The alpha value is the shading level used where 1.0 is the full color.
The enthalpy value is the plot title. The “f” comment is a format setting, so the comment {enthalpy:.2f} defines that the variable “enthalpy” is reported to 2 decimal places.
The final plot generated is shown in Figure 3.


Conclusions
This technical brief outlines the basic steps required to carry out an integration of the DSC data. It is important to note that when comparing data, it is a simple task to just enter the alternative file. The same code can then be run.
The linear integration is in good agreement with the same data analyzed in TRIOS Software.
References
- What is JSON
- Matplotlib — Visualization with Python
- pandas – Python Data Analysis Library
- NumPy
- SciPy
- Non-Linear Least-Squares Minimization and Curve-Fitting for Python — Non-Linear Least-Squares Minimization and Curve-Fitting for Python
- Project Jupyter | Home
- Visual Studio Code – Code Editing. Redefined
- P. Davies, “TB106: TRIOS and JSON Export: Basic Interaction with the Dataframe in Python,” TA Instruments, New Castle, DE.
- P. Davies, “TB107: TRIOS and JSON Export: Working With Matplotlib.Pyplot in Python,” TA Instruments, New Castle, DE.
Acknowledgement
For more information or to request a product quote, please visit www.tainstruments.com to locate your local sales office information.
This technical brief was written by Philip Davies, Principal Applications Scientist, TA Instruments.
Python is a registered mark of Python Software Foundation. Jupyter is a trademark of LF Charities, of which Project Jupyter is a part. Visual Studio Code and Excel are trademarks of Microsoft Corporation. JavaScript is a trademark of Oracle Corporation. pandas, Matplotlib, NumPy, SciPy are trademarks of NumFOCUS, Inc. TRIOS and TA Instruments are trademarks of Waters Technologies Corporation.
Click here to download the printable version of this application note.

