Material Class
Each material is saved as an instance of the Material class. To make changes to a material or to update it with new data or new fits, it suffices to load the instance of Material class from the corresponding pkl file, and edit the attributes of that instance.
- class thermal_conductivity.material_class.Material(name, parent: str = None, fit_type='loglog', force_update: bool = False)[source]
A class to represent a material with thermal conductivity data and fits.
- name
Name of the material.
- Type:
str
- folder
Path to the material’s folder.
- Type:
str
- data_folder
Path to the folder containing raw data files.
- Type:
str
- plot_folder
Path to the folder for saving plots.
- Type:
str
- parent
Name of the parent material, if any.
- Type:
str
- fit_type
The function type used for fitting the data.
- Type:
function
- fits
List of Fit objects representing different fits applied to the data.
- Type:
list
- data_classes
Dictionary of DataSet objects for each data file.
- Type:
dict
- temp_range
Temperature range covered by the data.
- Type:
tuple
- raw_fit_params
Parameters from the initial fit to all included data.
- Type:
np.ndarray
- raw_fit_cov
Covariance matrix from the initial fit to all included data.
- Type:
np.ndarray
- room_temp_tuple
Tuple containing room temperature and corresponding conductivity, if available.
- Type:
tuple
- interpolate_function
Interpolation function for thermal conductivity based on fits.
- Type:
function
Initialize the Material class.
- Parameters:
name (str) – Name of the material.
parent (str, optional) – Name of the parent material. Defaults to None.
fit_type (function, optional) – The fitting function to use. Defaults to loglog_func.
force_update (bool, optional) – Whether to force update the material. Defaults to False.
- get_data()[source]
Get the data for the material.
- Returns:
A dictionary containing the data for the material. dict: A dictionary containing DataSet objects for each data file.
- Return type:
dict
- update_data()[source]
Update the data for the material.
- Returns:
A dictionary containing the updated data for the material. dict: A dictionary containing updated DataSet objects for each data file.
- Return type:
dict
- fit_data(n_param=None, p0=None, bounds=None)[source]
Fit the data for the material.
- Parameters:
n_param (int, optional) – The number of parameters for the fit. Defaults to 8.
p0 (array-like, optional) – Initial guess for the fit parameters. Defaults to None.
bounds (tuple, optional) – Bounds for the fit parameters. Defaults to None.
- Returns:
Optimal values for the fit parameters. pcov (np.ndarray): Covariance matrix of the fit parameters.
- Return type:
popt (np.ndarray)
- update_fit(new_fit_type, fit_index_to_replace: int, n_param=None)[source]
Use this function to change the default fit type for the material and refit the data. Be careful when doing this with a parent material as the parent material may have multiple fits that match the ‘data’ fit source and you may accidently update the wrong fit.
- Parameters:
new_fit_type (str) – The new fit type to use.
fit_index_to_replace (int) – The index of the fit in the material.fits list to replace with the new fit. Be careful to choose the correct index, especially if there are multiple fits with source “data”.
n_param (int, optional) – Number of parameters for the new fit. Defaults to None.
- Returns:
The updated Material object with the new fit.
- Return type:
self (Material)
- interpolate(preferred_fit: None)[source]
Interpolate the thermal conductivity data for the material. :param preferred_fit: A Fit object that should be preferred in the interpolation. Defaults to None. :type preferred_fit: Fit, optional
- Returns:
An interpolation function for the thermal conductivity data.
- Return type:
interp_func (function)
- add_fits(fit_name: str, source: str, fit_range: tuple, parameters: ndarray, parameter_covariance: ndarray, fit_type: str, fit_error: float = None, reference: str = None)[source]
Adds a new fit to the material. :param fit_name: Name of the fit (usually material + source). :type fit_name: str :param source: Source of the fit (e.g., “data”, “literature”). :type source: str :param fit_range: Temperature range over which the fit is valid. :type fit_range: tuple :param parameters: Parameters of the fit function. :type parameters: np.ndarray :param parameter_covariance: Covariance matrix of the fit parameters. :type parameter_covariance: np.ndarray :param fit_type: Type of fit function used. :type fit_type: str :param fit_error: Optional error metric for the fit. Defaults to None. :type fit_error: float, optional
Alternatively, a Fit object can be created externally and added to the material by appending to self.fits.
Fit Class
- class thermal_conductivity.material_class.Fit(material: str, source: str, range: tuple, parameters: ndarray, parameter_covariance: ndarray, fit_type=None, fit_error: float = None, reference: str = None)[source]
A class to represent a fit applied to the data.
- material
Name of the material.
- Type:
str
- source
Source of the fit (e.g., “data”, “literature”).
- Type:
str
- name
Name of the fit (usually material + source).
- Type:
str
- range
Temperature range over which the fit is valid.
- Type:
tuple
- parameters
Parameters of the fit function.
- Type:
np.ndarray
- parameter_covariance
Covariance matrix of the fit parameters.
- Type:
np.ndarray
- fit_type
Type of fit function used.
- Type:
str
- fit_error
Optional error metric for the fit.
- Type:
float
- reference
Reference for the fit.
- Type:
str
- function()[source]
Returns the function type used for the fit as a callable. E.g. Fit.function()(x, *params) will evaluate the fit function at x.
- calc_tc(T: Unit('K'))[source]
Calculate the thermal conductivity at a specific temperature. :param T: Temperature at which to calculate thermal conductivity. :type T: u.K
- Returns:
Thermal conductivity at temperature T.
- Return type:
k (u.W/m/K)
Uses astropy units to ensure correct unit handling.
- evaluate(T)[source]
Evaluate the fit function at a specific temperature without astropy units. :param T: Temperature at which to evaluate the fit function. :type T: float
- Returns:
Thermal conductivity at temperature T.
- Return type:
k (float)
- tc_integral(T1: Unit('K'), T2: Unit('K'))[source]
Calculate the integral of the thermal conductivity over a temperature range. :param T1: Lower temperature limit. :type T1: u.K :param T2: Upper temperature limit. :type T2: u.K
- Returns:
The integral of thermal conductivity from T1 to T2. error (float): Estimated error of the integral.
- Return type:
integral (u.W/m)
Uses astropy units to ensure correct unit handling.
DataSet Class
- class material_class.DataSet(name: str, data: ndarray, ref_string: str)[source]
A class to represent a dataset from a CSV file. .. attribute:: name
Name of the dataset (usually the filename).
- type:
str
- data
The data array with temperature and property values.
- Type:
np.ndarray
- include
Whether to include this dataset in fits.
- Type:
bool