radis.tools.new_fitting module

Module for New RADIS Fitting Interface

This module is to conduct benchmarking process on spectra (LTE or Non-LTE) with temperatures (gas, vibrational, rotational, translational), mole fraction, cutoff, as well as other characteristics as fitting parameters.

This module is implemented into RADIS from the Fitting Benchmarking repository, as a 2022 GSOC project: https://github.com/TranHuuNhatHuy/RADIS-Spectrum-Fitting-Benchmark

This module aims to provide RADIS with a unified fitting interface which covers most of current fitting cases encountered from fellow scientists and researchers, while being simple and easy-to-use to RADIS newcomers, as you only need to input the parameters into pre-defined Dictionary objects in a simplified script, just as filling a form. This also serves as a bridge between RADIS codebase and a future fitting feature on RADIS App.

fit_spectrum(s_exp=None, fit_params=None, model=None, pipeline=None, bounds=None, input_file=None, verbose=True, show_plot=True, fit_kws={'max_nfev': 150, 'tol': 1e-15}) Spectrum | MinimizerResult | dict[source]

Fit an experimental spectrum (referred to as the “data spectrum”) with a modeled spectrum, and derive the fit results.

Parameters:
  • s_exp (Spectrum) – The experimental spectrum to be fitted.

  • fit_params (dict) – A dictionary containing fit parameters and their initial values.

  • model (dict) – A dictionary containing experimental conditions and additional convolutions for modeling the spectrum.

  • pipeline (dict) – A dictionary containing preference properties of the fitting process.

  • bounds (dict, optional) – A dictionary containing bounding ranges for the fit parameters. If not provided, default bounding ranges will be used.

  • input_file (str, optional) – The path to a JSON input file. If specified, all other input parameters will be discarded.

  • verbose (bool, optional) – If True, print details about each loop of the fitting process. Default is False.

  • show_plot (bool, optional) – If True, show the experimental spectrum before and after fitting. Default is True. Note that showing the plot will pause the runtime.

  • fit_kws (dict, optional) – Options to pass to the minimizer being used. See lmfit.minimizer.minimize.

Returns:

  • s_best (Spectrum) – The best fit results obtained as a spectrum.

  • best_fit (MinimizerResult) – The best fit results as output of LMFIT MinimizeResult.

  • log (dict) – A dictionary storing runtime log of the fitting process, including residual and fit values after each fitting loop, and total time elapsed.

Examples

Full list of examples can be found in the example gallery: https://radis.readthedocs.io/en

See also

fit_spectrum(), fit_legacy(), fitroom

get_conditions(input_conditions, verbose=True) dict | Parameters[source]

Get the ground-truth information by reading from input - either a JSON file or a dict parameter. Return a dict parameter containing fixed conditions for spectrum calculation, and an LMFIT.Parameters object containing fit parameters.

Parameters:

input_conditions (str or dict) – If str, the code assumes this is path to the JSON input file from the script calling it, for example:: “./test_dir/CO2_measured_spectrum_4-5um.json”, and then parses the JSON data as a dict. If dict, the code just simply parses the dict, yeah, that simple.

Other Parameters:

verbose (bool) – by default, True, print details about the fitting progress.

Examples

residual_LTE(params, conditions, s_data, sf, log, verbose)[source]

A cost function that calculates an LTE spectrum based on the initial conditions and values of fit parameters, then returning a scalar containing difference between experimental and data spectra.

Parameters:
  • params (LMFIT.Parameters) – basically a dict containing fit parameters that will be varied during the minimization.

  • conditions (dict) – a dict containing conditions (fixed parameters) for generating model spectra.

  • s_data (Spectrum) – data spectrum, loaded from the directory stated in JSON file.

  • sf (SpectrumFactory) – the SpectrumFactory object used for modeling spectra, generated before the minimize loop occurs.

  • log (list) – a Dictionary storing runtime log of the fitting process that are not quite covered by the Minimizer, including: residual and fit values after each fitting loop, and total time elapsed.

Other Parameters:

verbose (bool) – if True, will print out result of each fitting loop.

Returns:

residual – residuals of the two spectra, using RADIS’s get_residual().

Return type:

float

Examples

residual_NonLTE(params, conditions, s_data, sf, log, verbose)[source]

A cost function that calculates a non-LTE spectrum based on the initial conditions and values of fit parameters, then returning a scalar containing difference between experimental and data spectra.

Parameters:
  • params (LMFIT.Parameters) – basically a dict containing fit parameters that will be varied during the minimization.

  • conditions (dict) – a dict containing conditions (fixed parameters) for generating model spectra.

  • s_data (Spectrum) – data spectrum, loaded from the directory stated in JSON file.

  • sf (SpectrumFactory) – the SpectrumFactory object used for modeling spectra, generated before the minimize loop occurs.

  • log (list) – a Dictionary storing runtime log of the fitting process that are not quite covered by the Minimizer, including: residual and fit values after each fitting loop, and total time elapsed.

Other Parameters:

verbose (bool) – if True, will print out result of each fitting loop.

Returns:

residual – residuals of the two spectra, using RADIS’s get_residual().

Return type:

float

Examples

See also

residual_LTE(), Tvib12Tvib3Trot_NonLTEModel()

spectrum_refinement(s_data, conditions, verbose) Spectrum | dict[source]

Receive an experimental spectrum and further refine it according to the provided pipeline and ground-truths. Refinement process includes extracting the desired spectrum quantity, removing NaN values, and other additional convolutions. Finally, a refined Spectrum object is returned, along with the original condition as a Dictionary object.

Parameters:
  • s_data (Spectrum) – experimental spectrum loaded from the path given in input JSON file.

  • conditions (dict) – a Dictionary containing all ground-truth information, and also spectrum refinements or convolutions (desired spectrum quantity, normalization, etc.), as well as fitting process (max loop allowed, terminal tolerance, etc.).

Other Parameters:

verbose (bool) – by default, True, print details about the refinement progress.

Returns:

  • s_refined (Spectrum) – the refined spectrum.

  • conditions (dict) – the input conditions that might have been added fit_var (in case user didn’t).

Examples