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=False) Union[Spectrum, MinimizerResult, dict][source]¶

Fit an experimental spectrum (from here referred as “data spectrum”) with a modeled one, then derive the fit results. Data spectrum is loaded from the path stated in the JSON file, while model spectrum is generated based on the conditions stated in the JSON file, too.

Parameters
  • s_exp (Spectrum) – a Spectrum object, containing the experimental spectrum.

  • fit_params (dict) – a dict object, containing fit parameters and their initial values.

  • bounds (dict) – a dict object, optional, containing bounding ranges of those fit parameters. If not stated, all fit parameters will receive default bounding ranges.

  • model (dict) – a dict object, containing experimental conditions and some additional convolutions for modeling the spectrum.

  • pipeline (dict) – a dict object, containing some preference properties of fitting process.

  • input_file (str) – path to the JSON input file from the script calling it, by default, None. If this parameter is defined, it means user uses JSON file for inputing everything, and so will discard all other input parameters. For example:: “./test_dir/CO2_measured_spectrum_4-5um.json”

Other Parameters

verbose (bool) – print details about each loop of the fitting process. By default, False.

Returns

  • s_best (Spectrum) – visualization of the best fit results obtained, as a spectrum.

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

  • log (dict) – 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.

get_conditions(input_conditions, verbose=True) Union[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.

Returns

  • conditions (dict) – Dictionary object containing all ground-truth information.

  • params (Parameters) – LMFIT.Parameters object that contains fit parameters.

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

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

spectrum_refinement(s_data, conditions, verbose=True) Union[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).