Integrated fitting workflow (pesfit.fitter)
¶
-
class
pesfit.fitter.
DistributedFitter
(xdata, ydata, drange=None, model=None, modelkwds={}, **kwds)¶ Parallelized fitting of line spectra in a photoemission data patch.
-
_single_fit
(model, pars, xvals, yspec, n, include_vary, prefixes, varkeys, others, pref_exclude, **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', pref_exclude=[], include_vary=True, pbar=False, ret=False, **kwds)¶ Parallel pointwise spectrum 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.
- para_kwds: dic | {}
Additional keyword arguments for the work scheduler.
- scheduler: str | ‘processes’
Scheduler for parallelization (‘processes’ or ‘threads’, which can fail).
- backend: str | ‘multiprocessing’
Backend for executing the parallelization (‘dask’, ‘concurrent’, ‘multiprocessing’, ‘parmap’, ‘async’). Input ‘singles’ for sequential operation.
- ret: bool | False
Option for returning the fitting outcome.
- **kwds: keyword arguments
- nfitter: int |
self.nfitter
Number of spectra for fitting.
- num_workers: int |
n_cpu
Number of workers to use for the parallelization.
- chunksize: int | integer from nfitter/num_worker
Number of tasks assigned to each worker (needs to be >=1).
- nfitter: int |
-
save_data
(fdir='./', fname='', ftype='h5', keyname='fitres', orient='dict', **kwds)¶ Save the fitting outcome to a file.
-
set_inits
(inits_dict=None, band_inits=None, offset=0)¶ Set initialization for all constituent fitters. Parameters see
set_inits()
method inpesfit.fitter.PatchFitter
class.
-
-
class
pesfit.fitter.
InteractiveFitter
(x, data, size, coarse_step, fine_step=1)¶ Interactively conducting spectrum fitting at anchor points individually
-
extract
(ncomp, compstr='center')¶ Extract fitting parameters.
-
fit
(model, inits, pars=None, view_result=True, **kwds)¶ Manually fit for a single spectrum.
-
keep
(fit_result, index=None)¶ Keep or replace the specified fit result.
-
next_task
(indices=None)¶ Progress to the next task.
-
restart
()¶ Restart counting the indices.
-
view
(data)¶ View the outcome of current fitting.
-
-
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). The default shape is that the last dimension is energy.
- model: instance of
lmfit.model.Model
orpesfit.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.
Parameters
- shape: list/tuple
Shape of the data to convert to.
- orient: str | ‘dict’
Customization of the key-value pairs (see
pandas.DataFrame.to_dict
).
-
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
. Executesself.load()
withattrname=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
. Executesself.load()
withattrname=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], pref_exclude=['bg_'], include_vary=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()
.
- nspec: int |
-
set_inits
(inits_dict=None, xdata=None, band_inits=None, drange=None, offset=0)¶ 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).
- offset: numeric | 0
Global (energy) offset for the band positions.
-
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.
- params: instance of
-
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, flatten=False, legend=True, ret=False, lgkwds={'fontsize': 15, 'frameon': 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).
- flatten: bool | False
Option to flatten the data (in case multidimensional).
- legend: bool | True
Option to include legend in the figure.
- ret: bool | False
Option to return figure and axis objects.
- lgkwds: dict | {‘frameon’:False, ‘fontsize’:15}
Keyword arguments for figure legend.
- **kwds: keyword arguments
- figsize: list/tuple | [8, 5]
Default size of the figure.
- xlabel, ylabel: str, str | None, None
Axis labels.
- lfs: numeric | 15
Font size of the axis labels.
- fitres: instance of
-
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
orpesfit.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, fit_attr='chisqr', thresh=0.85, cbfit=None, rounds=None, rcount=0, method='leastsq', **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
orpesfit.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.
- thresh: numeric | 0.8
Threshold of the chi-squared to judge quality of fit.
- cbfit: instance of
lmfit.model.ModelResult
| None Current best fitting result.
- rounds: int | None
Total number of rounds in applying random shifts.
- rcount: int | 0
Round counter.
- **kwds: keyword arguments
Extra keywords passed to the
Model.fit()
method.
- fitres: instance of
-
pesfit.fitter.
restruct_fit_result
(fpath, shape, pref='lp', ncomp=10, parname='center')¶ Restructure the outcome into the desired format.
Parameters
- file: str
File path.
- shape: list/tuple
Shape of reconstructed parameter matrix.
- pref: str | ‘lp’
Prefix of the line profile.
- ncomp: int | 10
Number of components.
- parname: str | ‘çenter’
Namestring of the parameter.
-
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.
- params: