Integrated fitting workflow (pesfit.fitter) — pesfit 0.5.2 documentation

# Integrated fitting workflow `(pesfit.fitter)`

class `pesfit.fitter.` `ParallelPatchFitter`(xdata=None, ydata=None, model=None, modelkwds={}, **kwds)

  Parallelized fitting of line spectra in a photoemission data patch.

  `_single_fit`(model, pars, xvals, yspec, n, prefixes, varkeys, others, **kwds)

    Fit a single line spectrum with custom initializaton.

  property `nspec`

    Number of line spectra.

  `parallel_fit`(varkeys=['value', 'vary'], other_initvals=[True], para_kwds={}, scheduler='processes', backend='multiprocessing', ret=False, **kwds)

    Parallel pointwise spectrum fitting of the data patch.

    Parameters

    varkeys: list/tuple | [‘value’, ‘vary’] other_initvals: list/tuple | [True] para_kwds: dic | {} scheduler: str | ‘processes’ backend: str | ‘multiprocessing’ ret: bool | False **kwds: keyword arguments

  `save_data`(fdir='./', fname='', ftype='h5', keyname='fitres', orient='dict', **kwds)

    Save the fitting outcome to a file.

  `set_inits`(inits_dict=None, xdata=None, band_inits=None, drange=None)

    Set initialization for all constituent fitters.

class `pesfit.fitter.` `PatchFitter`(xdata=None, ydata=None, model=None, modelkwds={}, **kwds)

  Class for fitting a patch of photoemission band mapping data.

  Parameters

  xdata: 1D array

    Energy coordinates for photoemission line spectrum fitting.

  ydata: numpy array

    Photoemission spectral data for fitting (2D or 3D).

  model: instance of `lmfit.model.Model` or `pesfit.lineshape.MultipeakModel`

    Existing universal lineshape model for fitting (all spectra).

  peaks: dict | {‘Voigt’:2}

    Specification of constituent single-peak lineshape model.

  background: str | ‘None’

    Specification of approximation function for approximating the signal background.

  `fit_to_dict`(shape, orient='dict')

    Restructure the fitting outcome to dictionary.

  `load`(attrname='', fdir='', fname='', ftype='h5', **kwds)

    Generic load function including attribute assignment.

    Parameters

    attrname: str | ‘’

      Attribute name to be assigned to.

    fdir, fname: str, str | ‘’, ‘’

      Directory and name for file to load. The ull path is the string combination of the two).

    ftype: str | ‘h5’

      File type to load.

    **kwds: keywords argument

      Additional arguments for `pesfit.fitter.load_file()`.

  `load_band_inits`(**kwds)

    Load band energy initialization as `self.band_inits`. Executes `self.load()` with `attrname=band_inits`.

  `load_fitting`(fdir='./', fname='', ftype='h5', **kwds)

    Load fitting outcome (for visualization).

  `load_spec_data`(**kwds)

    Load line spectrum data patch as `self.ydata`. Executes `self.load()` with `attrname=ydata`.

  property `nspec`

    Total number of line spectra.

  `save_data`(fdir='./', fname='', ftype='h5', keyname='fitres', orient='dict', **kwds)

    Save the fitting outcome to a file.

  `sequential_fit`(varkeys=['value', 'vary'], other_initvals=[True], pbar=False, pbenv='notebook', **kwds)

    Sequential line fitting of the data patch.

    Parameters

    varkeys: list/tuple | [‘value’, ‘vary’]

      Collection of parameter keys to set (‘value’, ‘min’, ‘max’, ‘vary’).

    other_initvals: list/tuple | [True]

      Initialization values for spectrum-dependent variables. Supply a list/tuple of size 1 or the same size as the number of spectra.

    pbar: bool | False

      Option to show a progress bar.

    pbenv: str | ‘notebook’

      Progress bar environment (‘notebook’ for Jupyter notebook or ‘classic’ for command line).

    **kwds: keywords arguments
      nspec: int | `self.nspec`

        Number of spectra for fitting.

      additional arguments:

        See `pesfit.fitter.pointwise_fitting()`.

  `set_inits`(inits_dict=None, xdata=None, band_inits=None, drange=None)

    Set the persistent part of initialization parameters.

    Parameters

    inits_dict: dict | None

      Initialization parameters and constraints persistent throughout the fitting process.

    xdata: 1D array | None

      Calibrated energies for the energy axis

    band_inits: numpy array | None

      Initialization for the band energy values.

    drange: slice object | None

      Slice object corresponding to the energy range to select (None or slice(None, None) means selecting all values).

  `view`(fit_result=None, fit_df=None, xaxis=None, **kwds)

    Visualize selected fitting results.

`pesfit.fitter.` `init_generator`(params=None, parname='center', varkeys=['value'], **kwds)

  Dictionary generator for initial fitting conditions.

  Parameters

  params: instance of `lmfit.parameter.Parameters`

    Existing model parameters.

  parname: str | ‘center’

    Name of the parameter.

  varkeys: list/tuple | [‘value’]

    Keyword specified for the parameter (‘value’, ‘min’, ‘max’, ‘vary’).

  **kwds: keyword arguments
    lpnames: list/tuple | None

      Collection of namestrings (or prefixes) for lineshapes.

    parvals: list/tuple | None

      Collection of values for parameters.

`pesfit.fitter.` `load_file`(fdir='./', fname='', ftype='h5', parts=None, **kwds)

  Load whole file or parts of the file.

`pesfit.fitter.` `model_generator`(peaks={'Voigt': 2}, background='None', **kwds)

  Simple multiband lineshape model generator with semantic parsing.

  Parameters

  peaks: dict | {‘Voigt’:2}

    Peak profile specified in a dictionary. All possible models see `lmfit.models`.

  background: str | ‘None’

    Background model name. All possible models see `lmfit.models`.

  **kwds: keyword arguments

    Additional keyword arguments for `pesfit.lineshape.MultipeakModel` class.

  Return

  model: instance of `pesfit.lineshape.MultipeakModel`

    Lineshape model created from the specified components.

`pesfit.fitter.` `plot_bandpath`(paths, ksymbols, erange=[], evals=None, path_inds=[], koverline=True, klines=False, ret=False, **kwds)

  Plot momentum-energy map from a segment of the band mapping data.

  Parameters

  paths: numpy array

    Momentum diagram data.

  ksymbols: list of strings

    Symbols of the high-symmetry points.

  erange: list | []

    Bounds of the electron energy, [lower, upper].

  evals: numpy array | None

    Energy values.

  path_inds: list | []

    Locations of the high-symmetry points along the momentum direction.

  koverline: bool | True

    Option to display momentum symbols with an overline.

  klines: bool | False

    Option to draw vertical lines at the specified high-symmetry points.

  ret: bool | False

    Option to return the graphical elements.

  **kwds: keyword arguments
    figsize: list/tuple | [10, 6]

      Default size of the figure.

`pesfit.fitter.` `plot_fit_result`(fitres, x, plot_components=True, downsamp=1, ret=False, **kwds)

  Plot the fitting outcomes.

  Parameters

  fitres: instance of `lmfit.model.ModelResult`

    Fitting result from the lmfit routine.

  x: numpy array

    Horizontal-axis values of the lineshape model.

  plot_components: bool | True

    Option to plot components of the multipeak lineshape.

  downsamp: int | 1

    Level of downsampling of the data (1 means no downsampling).

  **kwds: keyword arguments
    figsize: list/tuple | [8, 5]

      Default size of the figure.

`pesfit.fitter.` `pointwise_fitting`(xdata, ydata, model=None, peaks=None, background='None', params=None, inits=None, ynorm=True, method='leastsq', jitter_init=False, ret='result', modelkwds={}, **kwds)

  Pointwise fitting of a multiband line profile.

  Parameters

  xdata, ydata: 1D array, 1D array

    x and y axis data.

  model: instance of `lmfit.model.Model` or `pesfit.lineshape.MultipeakModel` | None

    A lineshape model for the fitting task.

  peaks, background: dict, str | None, ‘None’

    Details see identical arguments for `pesfit.fitter.model_generator()`

  params: instance of `lmfit.paramter.Parameters` | None

    Parameters of the model.

  inits: dict/list | None

    Fitting initial values and constraints (format see `pesfit.fitter.varsetter()`).

  ynorm: bool | True

    Option to normalize each trace by its maximum before fitting.

  method: str | ‘leastsq’

    Optimization method of choice (complete list see https://lmfit.github.io/lmfit-py/fitting.html).

  jitter_init: bool | False

    Option to introduct random perturbations (jittering) to the peak position in fitting. The values of jittering is supplied in `shifts`.

  ret: str | ‘result’

    Specification of return values.

    `'result'`: returns the fitting result

    `'all'`: returns the fitting result and evaluated lineshape components.

  **kwds: keyword arguments
    shifts: list/tuple/numpy array | np.arange(0.1, 1.1, 0.1)

      The choices of random shifts to apply to the peak position initialization (energy in eV unit). The shifts are only operational when `jitter_init=True`.

    other arguments

      See details in `pesfit.fitter.random_varshift()`.

`pesfit.fitter.` `print_fit_result`(params, printout=False, fpath='', mode='a', **kwds)

  Pretty-print the fitting outcome.

`pesfit.fitter.` `random_varshift`(fitres, model, params, shifts=[], yvals=None, xvals=None, parnames=[], verbose=True, **kwds)

  Recursively apply a random shift value to certain key variables to get a better fit. Execution of the function terminates when either (1) the fitting results are sufficiently good (measured by its chi-squared metric) or (2) the trials exhaust all choices of shift parameters.

  Parameters

  fitres: instance of `lmfit.model.ModelResult`

    Current fitting result.

  model: instance of `lmfit.model.Model` or `pesfit.lineshape.MultipeakModel`

    Lineshape model.

  params: instance of `lmfit.parameter.Parameters`

    Lineshape model parameters.

  shifts: list/tuple/array | []

    Different random shifts to apply to the initial conditions.

  xvals, yvals: numpy array, numpy array | None, None

    Horizontal and vertical axis values for the lineshape fitting.

  parnames: list | []

    List of names of the parameters to update initial conditions.

  verbose: bool | True

    Option for printout of the chi-squared value.

  **kwds: keyword arguments

    Extra keywords passed to the `Model.fit()` method.

`pesfit.fitter.` `varsetter`(params, inits={}, ret=False)

  Function to set the parameter constrains in multiparameter fitting.

  Parameters

  params: `lmfit.parameter.Parameter` or other subclass of dict

    Parameter dictionary.

  init: dict | {}

    Initialization value dictionary.

  ret: bool | False

    Option for returning outcome.