class TG_IR - LeonSaal/TGA-FTIR-hyphenation-tool-kit GitHub Wiki
The TG_IR
class is the core of this project, that unites all the necessary funcionality.
A showcase can be found on the example page.
Index
1. Initialization
TG_IR(name, mode = 'construct', alias = 'load', profile = 'Otto', **kwargs) Initializes object with either TG or IR data or both. The functions reading TG and IR-data are designed to work with the output of distinct devices, namely the TGA/DSC 3+ thermobalance (Mettler Toledo) and Nicolet iS50 FTIR-spectrometer (Thermo Scientic). For other devices, the code has to be modified accordingly. Further information can be found on the page on adaption.
Parameters:
- name: str. Unique root name of measurement.
Optional:
- mode: {'construct', 'pickle'}. Default 'construct'. If 'construct', object is initialized with raw data from measurement. All files to be read must be within a subdirectory of the path supplied in
settings.ini
under dir_data. If 'pickle', object is de-serialized from pickle file. Is complementary to TG_IR.save(how = 'pickle').- alias: str. Default 'load'. Alias for measurement to show in plots. If default, tries to read alias from
Samplelog.xlsx
, except is the supplied name.- profile: str. Default 'Otto'. Defines the way to read TGA-Data from raw data. For further explanation visit adaption.
- **kwargs. Arguments to pass on to TG_IR.dry_weight(), that is being called during initialization.
2. Instance variables
- TG_IR.info: dict Contains information on the sample as well as characteristic masses or total released gases.
- name: str. See initialization.
- alias: str. See initialization.
- name: str. See initialization.
- initial_mass: float. Initial mass.
- reference_mass: str. Mass used to normalize data e.g. 'initial_mass'.
For IR data:
- gases
- TG_IR.tga: pandas.DataFrame
Contains TG-data in tabular form. Columns:
- time
- sample_temp
- mass
- TG_IR.ir: pandas.DataFrame
Contains IR-data in tabular form. Columns:
- time
- sample_temp
- gases
Calibration data:
- TG_IR.linreg: pandas.DataFrame. Contains characteristic values for the calibrated gases, such as 'slope' and 'intercept'.
- TG_IR.stats: pandas.DataFrame. Contains statistical parameters regarding the linear regression, such as LOD and LOQ. For more information visit the page on calibration
3. Methods
3.1 TG_IR.corr
Corrects raw data with data from reference measurement. For more information visit the page on the correction of raw data. From the corrected data, the drying point is derived and the total amount of released gases is calculated. TG_IR.info is expanded by the keywords:
- reference: str
For TG data:
- dry_mass: float. Dry mass of sample if how != None.
- dry_temp: float. Dry temperature of sample if how != None.
- dry_time: float. Dry time of sample in s if how != None.
- final_mass: float. Final mass of sample
- ml_'step': float. Mass loss for each step of the measurement, e.g. drying step and different method gases.
- rel_ml_'step': float. Relative mass loss for each step of the measurement, e.g. drying step and different method gases. See description of parameter 'ref_mass'.
For IR Data:
- area_'gas': float for each gas in IR Data If calibration data is supplied:
- mmol_'gas': float for each gas in IR Data
- mmol_'element': float for each element in gases in IR data
TG_IR.corr(self, reference = 'load', how_dry = 'H2O', plot = False, ref_mass = 'dry_mass', xlim = [None,None], ylim = [None,None])
Parameters:
- reference: str. Default 'load' Unique root name of reference measurement. If default, tries to read reference from
Samplelog.xlsx
.
Optional:
- how_dry: {'H2O', 'sample_mass', float, None}. default 'h2o'. Method to determine the dry point of the sample. If 'H2O', the dry point is derived from the water peak between 50 and 200 °C. Similar with 'mass', the dry point is derived from DTG. If a float is supplied, the value is interpreted as the dry temperature. If the sample is expected to be dry in the first place, None should be supplied.
- plot: boolean. default False. Show plots with data after and prior to correction as well as the determination of the dry point.
If True: Works only for dry mass determination.
- xlim: array-like. Default [None, None]. Set limits of x-Axis. None leaves limit unchanged.
- ylim: array-like. Default [None, None]. Set limits of primary y-Axis. None leaves limit unchanged.
- ref_mass: {'initial_mass', 'dry_mass', 'final_mass'}. default None. Reference mass to calculated the relative mass steps.
3.2 TG_IR.get_value
Get values from TG_IR.tga at certain points.
TG_IR.get_value(self,*values, which='sample_mass', at='sample_temp')
Parameters:
- values: iterable. values of 'at', where to get the values of 'which'
Optional:
- which: {'sample_mass','reference_temp','time','sample_temp'}. Default 'sample_mass'. Desired value
- at: {'sample_mass','reference_temp','time','sample_temp'}. Default 'sample_temp'. Reference value
3.3 TG_IR.dry_weight
Determines the dry_weight and mass steps of measurement. TG_IR.info is expanded by the keywords:
- dry_mass: float. Dry mass of sample if how != None.
- dry_temp: float. Dry temperature of sample if how != None.
- dry_time: float. Dry time of sample in s if how != None.
- final_mass: float. Final mass of sample
- ml_'step': float. Mass loss for each step of the measurement, e.g. drying step and different method gases.
- rel_ml_'step': float. Relative mass loss for each step of the measurement, e.g. drying step and different method gases. See description of parameter 'ref_mass'.
TG_IR.dry_weight(self,how_dry='H2O',plot=False,ref_mass='dry_mass',save=False,xlim=[None,None],ylim=[None,None])
Parameters:
Optional:
- how_dry: {'H2O', 'sample_mass', float, None}. default 'h2o'. Method to determine the dry point of the sample. If 'H2O', the dry point is derived from the water peak between 50 and 200 °C. Similar with 'mass', the dry point is derived from DTG. If a float is supplied, the value is interpreted as the dry temperature. If the sample is expected to be dry in the first place, None should be supplied.
- plot: boolean. default False. Show plots with data after and prior to correction as well as the determination of the dry point.
- ref_mass: {'initial_mass', 'dry_mass', 'final_mass'}. default None. Reference mass to calculated the relative mass steps.
If plot == True: Works only for dry mass determination.
- xlim: array-like. Default [None, None]. Set limits of x-Axis. None leaves limit unchanged.
- ylim: array-like. Default [None, None]. Set limits of primary y-Axis. None leaves limit unchanged.
3.4 TG_IR.plot
Different plotting options for TG, IR or combined data.
TG_IR.plot(self, which, save = False, x_axis = 'sample_temp', y_axis = 'orig', ylim = [None,None], xlim = [None,None], legend = False, gases = [])
Parameters:
- which: {'TG', 'IR', 'DIR', 'cumsum', 'heat_flow', 'IR_to_DTG'}. Plot to show. 'TG' for TG data, 'IR' for IR data, 'DIR' for first derivative of IR data, 'cumsum' for cumulative IR data, 'heat_flow' for heat_flow data and 'IR_to_DTG' for comparison of DTG with DTG reconstructed from IR data.
Optional:
- save: boolean. default False. Saving of Figure. Resolution can be modified in
settings.ini
in the section [plotting] under 'DPI'.- x_axis: {'sample_temp', 'time'}. Default 'sample_temp'. x-axis can be either sample temperature or measurement time.
- y_axis: {'orig', 'rel'}. Default 'orig'. y-axis can be either original ('orig') data in units of raw data or relative ('rel') values normalized on the reference mass. If which = 'IR', calibration is required.
- xlim: array-like. Default [None, None]. Set limits of x-Axis. None leaves limit unchanged.
- legend: boolean. Default True. Show legend. Only if which in ['TG', 'heatflow']
- ylim: array-like. Default [None, None]. Set limits of primary y-Axis. None leaves limit unchanged. Only if which in ['IR', 'DIR', 'cumsum', 'IR_to_DTG']
- gases: list. Default []. If default, show all gases in IR data. Else select subset of gases found in columns of TG_IR.ir.
3.5 TG_IR.fit
Perform deconvolution of IR data. For more information visit page on deconvolution.
TG_IR.fit(self, reference, T_max = None, T_max_tol = 50, plot = True, func = multi_gauss, y_axis = 'orig', save = True, presets = None, predef_tol = 0.01)
Parameters:
- reference: str. Acronym of reference found in first column of
Fitting_parameter.xlsx
. Used to define number and name of peaks to fit each gas as well as their initial center.
Optional:
- T_max: float or None. Default None. Upper boundary for temperature.
- T_max_tol: float. Default 50.
- plot: boolean. Default True. Show plot of deconvolution result.
- func: callable. Default multi_gauss. Model function to fit IR data. Default is sum of gaussian functions.
- y_axis: {'orig', 'rel'}. Default 'orig'. y-axis can be either original ('orig') data in units of raw data or relative ('rel') values in molar amounts, where calibration is required.
- save: boolean. Default True. Save results of fit in subdirectory of directory defined in
settings.ini
section [paths] under dir_fitting.- presets: dict. Default None. Presets for deconvolution of gases. If None, presets are loaded from 'Fitting_parameter.xlsx' (see Deconvolution) predef_tol: 0 < float < 1. Default 0.01. If groups are predefined from deconvolution results of other gases, this sets the tolerance in which they can deviate during deconvolution. E.g. if predef_tol = 0.01, the parameter can vary within 0.99 and 1.01 times the reference value.
3.6 TG_IR.save
Save content of object as serialized pickle file or in an excel spreadsheet. Either way, TG_IR.info is written in Samplelog.xlsx
.
TG_IR.save(self, how = 'pickle', overwrite = False)
Parameters:
Optional:
- how: {'pickle', 'excel'}. Default 'pickle'. File output. If 'pickle', file cannot be read by humans but can be easily de-serialized as a TG_IR object by specifying mode = 'pickle' during initialization. If 'excel', data is saved in an excel spreadsheet.
- overwrite: boolean. Default False. Overwrite data in
Samplelog.xlsx
with information from TG_IR.info.
3.7 TG_IR.calibrate
Calibrate IR by either loading provided data or recalibrating with TG and IR data from the decomposition of inorganic solids as described by Gabriela Hotová and Václav Slovák.
TG_IR.calibrate(plot = False, mode = 'load', method = 'max')
Parameters:
- mode: {'load', 'recalibrate'}. Default 'load'. Tries to load calibration data located under 'dir_calibration' in the
settings.ini
. If none is found, you should 'recalibrate' and follow the instructions.- plot: {boolean,'residual'}. Default False. If True and mode = 'load', show calibration straights. If mode = 'recalibrate', show integration limits. If 'residual', show straights and residual plots. If mode = 'recalibrate':
- method: {'max', 'co_oxi', 'iter'}. Default 'max'. Method to use for calibration.
- 'max': Assumes, that each of the supplied gases accounts solely for the mass loss of one decomposition step. Parallel release of other gases as well as side reactions are not considered.
- 'co_oxi': Assumes, that carbon monoxide is partly oxidized to carbon dioxide.
- 'iter': Accomdates for the parallel release of different gases during the same decomposition step and assumes, that the sum of released gases accounts for the mass loss during that decomposition step.
4. Functions that handle multiple instances
4.1 overview
Get tabular overview of objects in list.
overview(objs)
Parameters:
objs: list of TG_IR instances. List to get contents from.
4.2 plots
Overlay plots of different objects.
plots(TG_IR, plot, x_axis = 'sample_temp', y_axis = 'orig', ylim = [None, None], xlim = [None, None], gas = None, save = False,
legend = True, reference_mass = 'reference_mass')
Parameters:
- plot: {'TG', 'DTG', 'IR', 'heat_flow'}. Plot to show.
Optional:
- save: boolean. default False. Saving of Figure. Resolution can be modified in
settings.ini
in the section [plotting] under 'DPI'.- x_axis: {'sample_temp', 'time'}. Default 'sample_temp'. x-axis can be either sample temperature or measurement time.
- y_axis: {'orig', 'rel'}. Default 'orig'. y-axis can be either original ('orig') data in units of raw data or relative ('rel') values normalized on the reference mass. If which = 'IR', calibration is required.
- xlim: array-like. Default [None, None]. Set limits of x-Axis. None leaves limit unchanged.
- ylim: array-like. Default [None, None]. Set limits of primary y-Axis. None leaves limit unchanged.
- legend: boolean. Default True. Show legend.
- reference_mass: {'reference_mass', 'dry_mass', 'initial_mass', 'final_mass'}. Default 'reference_mass'. See y_axis
Only if plot = 'IR'
- gas: str. Default None. Gas to compare.
4.3 fits
Perform .fit operation on several objects and calculating statistical values for samples of same type.
fits(objs, reference, save = True, presets = None, **kwargs)
Parameters:
objs: list of TG_IR instances. Objects to perform fitting on.
- reference: str. Acronym of reference found in first column of
Fitting_parameter.xlsx
. Used to define number and name of peaks to fit each gas as well as their initial center.
Optional:
- save: boolean. Default True. Save results of fit in subdirectory of directory defined in
settings.ini
section [paths] under dir_fitting.- T_max: float or None. Default None. Upper boundary for temperature.
- plot: boolean. Default True. Show plot of deconvolution result.
- func: callable. Default multi_gauss. Model function to fit IR data. Default is sum of gaussian functions.
- y_axis: {'orig', 'rel'}. Default 'orig'. y-axis can be either original ('orig') data in units of raw data or relative ('rel') values in molar amounts, where calibration is required.
- presets: dict. Default None. Presets for deconvolution of gases. If None, presets are loaded from 'Fitting_parameter.xlsx' (see Deconvolution) predef_tol: 0 < float < 1. Default 0.01. If groups are predefined from deconvolution results of other gases, this sets the tolerance in which they can deviate during deconvolution. E.g. if predef_tol = 0.01, the parameter can vary within 0.99 and 1.01 times the reference value.
4.4 robustness
Testing robustness of fitting procedure by varying the fitting parameters center, center tolerance, initial height and HWHM as well as maximum HWHM.
robustness(objs, reference, T_max = None, save = True, var_T = 10, var_rel = 0.3, ylim = [0, None], **kwargs)
Parameters:
objs: list of TG_IR instances.
- reference: str. Acronym of reference found in first column of
Fitting_parameter.xlsx
. Used to define number and name of peaks to fit each gas as well as their initial center.
Optional:
- T_max: float. Default None. Upper limit of fitting range in °C.
- save: boolean. Default True. Save results of fit in subdirectory of directory defined in
settings.ini
section [paths] under dir_fitting.- var_T: flaot. Default 10. Amount of variance for center and tolerance center and maximum HWHM in °C.
- var_rel: float. Default 0.3. Amount of variance for initial height and HWHM relative to maximum height and HWHM.
- ylim: [float, float]. Default [0, None]. Set limits of primary y-Axis. None leaves limit unchanged.
- kwargs to pass onto fits() and consequently .fit()