Fitting Utility API

LMFIT supplement functions

mrsimulator.utils.spectral_fitting.make_LMFIT_params(sim: Simulator, processors: Optional[list] = None, include={})

Parse the Simulator and PostSimulator objects for a list of LMFIT parameters.

Parameters:
  • sim (Simulator) – Simulator object.

  • processors (list) – List of SignalProcessor objects. The order must match the order of methods within the simulator object.

  • include (set) – set of keywords from the method object to include as a fitting parameter. Default is {}.

The parameter name associated with the spin system within Simulator object is generated using the following nomenclature- sys_i_site_j_attribute1_attribute2 for attribute with signature sim.spin_systems[i].sites[j].attribute1.attribute2

Here, sys_i refers to the spin system at index i, site_j refers to the site at index j with in the :math:i^text{th} spin system, and attribute1 and attribute2 are the site attributes.

For examples:

sim.spin_systems[1].sites[0].isotropic_chemical_shift parametrizes to sys_1_site_0_isotropic_chemical_shift while sim.spin_systems[0].sites[1].quadrupolar.Cq to sys_0_site_1_quadrupolar_Cq.

Returns:

LMFIT Parameters object.

mrsimulator.utils.spectral_fitting.LMFIT_min_function(params: Parameters, sim: Simulator, processors: Optional[list] = None, sigma: Optional[list] = None)

The simulation routine to calculate the vector difference between simulation and experiment based on the parameters update.

Parameters:
  • params – Parameters object containing parameters for OLS minimization.

  • sim – Simulator object.

  • processors – A list of PostSimulator objects corresponding to the methods in the Simulator object.

  • sigma – A list of standard deviations corresponding to the experiments in the Simulator.methods attribute

Returns:

Array of the differences between the simulation and the experimental datasets.

mrsimulator.utils.spectral_fitting.bestfit(sim: Simulator, processors: Optional[list] = None)

Return a list of best fit spectrum ordered relative to the methods in the simulator object.

Parameters:
  • sim (Simulator) – The simulator object.

  • processors (list) – List of SignalProcessor objects ordered according to the methods in the simulator object.

mrsimulator.utils.spectral_fitting.residuals(sim: Simulator, processors: Optional[list] = None)

Return a list of residuals corresponding to the best fit spectrum. The list is based on the order of methods in the simulator object.

Parameters:
  • sim (Simulator) – The simulator object.

  • processors (list) – List of SignalProcessor objects ordered according to the methods in the simulator object.