RIXS Global-Fitting in Jupyter
Global Fitting of a series of spectra¶
In [1]:
Copied!
import pandas as pd
from spectrafit.plugins import notebook as nb
import pandas as pd from spectrafit.plugins import notebook as nb
In [2]:
Copied!
df = pd.read_csv(
"https://raw.githubusercontent.com/Anselmoo/spectrafit/1cda9e0d93f9d0536380075e75fac50459555b99/Examples/data_global.csv"
)
df = pd.read_csv( "https://raw.githubusercontent.com/Anselmoo/spectrafit/1cda9e0d93f9d0536380075e75fac50459555b99/Examples/data_global.csv" )
This example shows how to fit a series of spectra with a common model¶
To activate the global fitting routine, y_column
has to be defined to a list of column names and not a single column name. The list of column names will be selected for the fitting.
In [3]:
Copied!
spn = nb.SpectraFitNotebook(
df=df, x_column="energy", y_column=["y_1", "y_2", "y_3"], fname="example9_6"
)
spn = nb.SpectraFitNotebook( df=df, x_column="energy", y_column=["y_1", "y_2", "y_3"], fname="example9_6" )
Defining the model as a function of the parameters¶
The initial model
is defined as a function of the parameters as for 2D fitting.
In [4]:
Copied!
initial_model = [
{
"pseudovoigt": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 1},
"center": {"max": 2, "min": -2, "vary": True, "value": 0},
"fwhmg": {"max": 0.3, "min": 0.02, "vary": True, "value": 0.1},
"fwhml": {"max": 0.2, "min": 0.01, "vary": True, "value": 0.1},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 2.0, "min": 0, "vary": True, "value": 2},
"fwhmg": {"max": 0.3, "min": 0.02, "vary": True, "value": 0.1},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 3.5, "min": 1.5, "vary": True, "value": 2.5},
"fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.2},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 3.5, "min": 2, "vary": True, "value": 2.5},
"fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 4.5, "min": 3, "vary": True, "value": 2.5},
"fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 4.7, "min": 3.7, "vary": True, "value": 3.8},
"fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3},
}
},
]
spn.solver_model(initial_model=initial_model, show_plot=True, show_metric=False)
initial_model = [ { "pseudovoigt": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 1}, "center": {"max": 2, "min": -2, "vary": True, "value": 0}, "fwhmg": {"max": 0.3, "min": 0.02, "vary": True, "value": 0.1}, "fwhml": {"max": 0.2, "min": 0.01, "vary": True, "value": 0.1}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 2.0, "min": 0, "vary": True, "value": 2}, "fwhmg": {"max": 0.3, "min": 0.02, "vary": True, "value": 0.1}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 3.5, "min": 1.5, "vary": True, "value": 2.5}, "fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.2}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 3.5, "min": 2, "vary": True, "value": 2.5}, "fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 4.5, "min": 3, "vary": True, "value": 2.5}, "fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 4.7, "min": 3.7, "vary": True, "value": 3.8}, "fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3}, } }, ] spn.solver_model(initial_model=initial_model, show_plot=True, show_metric=False)
/home/runner/work/spectrafit/spectrafit/spectrafit/report.py:342: UserWarning: ## WARNING ######################### Uncertainties could not be estimated #################################### /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ######################################################################################## The parameter 'pseudovoigt_amplitude_1_1' is at its boundary and uncertainties cannot be estimated! ################################################################################################### /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING #################################################################################### The parameter 'pseudovoigt_fwhmg_1_1' is at its boundary and uncertainties cannot be estimated! ############################################################################################### /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING #################################################################################### The parameter 'pseudovoigt_fwhml_1_1' is at its boundary and uncertainties cannot be estimated! ############################################################################################### /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ################################################################################# The parameter 'gaussian_fwhmg_2_1' is at its boundary and uncertainties cannot be estimated! ############################################################################################ /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ################################################################################# The parameter 'gaussian_fwhmg_3_1' is at its boundary and uncertainties cannot be estimated! ############################################################################################ /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ################################################################################## The parameter 'gaussian_center_4_1' is at its boundary and uncertainties cannot be estimated! ############################################################################################# /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ################################################################################# The parameter 'gaussian_fwhmg_4_1' is at its boundary and uncertainties cannot be estimated! ############################################################################################ /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ################################################################################# The parameter 'gaussian_fwhmg_5_1' is at its boundary and uncertainties cannot be estimated! ############################################################################################ /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ################################################################################## The parameter 'gaussian_center_6_1' is at its boundary and uncertainties cannot be estimated! ############################################################################################# /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ################################################################################# The parameter 'gaussian_fwhmg_6_1' is at its boundary and uncertainties cannot be estimated! ############################################################################################ /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ######################################################################################## The parameter 'pseudovoigt_amplitude_1_2' is at its boundary and uncertainties cannot be estimated! ################################################################################################### /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ######################################################################################## The parameter 'pseudovoigt_amplitude_1_3' is at its boundary and uncertainties cannot be estimated! ###################################################################################################
Note:¶
Currently, the global fitting routine provides each spectrum as its own. This also allows to use other color schemes.