Export Results
Saving Results¶
In general, there can be saved two types of data:
- DataFrames with information about data and fit
- All other data, such as fit results, covariance matrices, etc. plus
raw
andfit
as.lock
output file.
# Loading packages and default data
from spectrafit.plugins import notebook as nb
import pandas as pd
df = pd.read_csv(
"https://raw.githubusercontent.com/Anselmoo/spectrafit/main/Examples/data.csv"
)
Load the data into the notebook-plugin of SpectraFit
¶
In this particular name the default output name is example9_3.lock
and the default output directory is ./result.*
. The default output directory can be changed via the keyword fname
.
spn = nb.SpectraFitNotebook(
df=df, x_column="Energy", y_column="Noisy", fname="example9_3"
)
Define the fitting model without plotting the results¶
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.2},
"fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.2},
}
},
]
spn.solver_model(initial_model=initial_model, show_plot=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_fwhmg_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' 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' 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' 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' is at its boundary and uncertainties cannot be estimated! ########################################################################################## /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:358: UserWarning: ## WARNING ##################################################################################### The parameter 'gaussian_center_6' is at its initial value and uncertainties cannot be estimated! ################################################################################################ /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ################################################################################ The parameter 'gaussian_center_6' 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' is at its boundary and uncertainties cannot be estimated! ##########################################################################################
Saving the results as dataframes¶
Results of the dataframe can be saved as a .csv
file. The original, the final fitted, current used optional pre processed data can be saved as a .csv
file as well.
Currently, the following dataframes can be saved:
df_org
: The original datadf_act
: The actually used data, which can be different from the original data, if the optional pre processing is used.df_fit
: The fitted datadf_peaks
: The fit results of each peak component
spn.export_df_org
spn.export_df_act
spn.export_df_fit
spn.export_df_peaks
from pathlib import Path
list(Path(".").glob("*.csv"))
[PosixPath('peaks_example9_3.csv'), PosixPath('act_example9_3.csv'), PosixPath('org_example9_3.csv'), PosixPath('fit_example9_3.csv')]
Finally, the results can be stored in a .lock
file. This file contains all the information about the fit, the data, the model, the parameters, the covariance matrix, etc. The .lock
file can be loaded back into the SpectraFit
notebook-plugin via tomli
Showning peak components as a table¶
For each peak component, the following information can be shown:
spn.solver_model(initial_model=initial_model, show_plot=False, show_peaks=True)
/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_fwhmg_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' 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' 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' 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' is at its boundary and uncertainties cannot be estimated! ########################################################################################## /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:358: UserWarning: ## WARNING ##################################################################################### The parameter 'gaussian_center_6' is at its initial value and uncertainties cannot be estimated! ################################################################################################ /home/runner/work/spectrafit/spectrafit/spectrafit/report.py:366: UserWarning: ## WARNING ################################################################################ The parameter 'gaussian_center_6' 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' is at its boundary and uncertainties cannot be estimated! ##########################################################################################
component | pseudovoigt_amplitude_1 | pseudovoigt_center_1 | pseudovoigt_fwhmg_1 | pseudovoigt_fwhml_1 | gaussian_amplitude_2 | gaussian_center_2 | gaussian_fwhmg_2 | gaussian_amplitude_3 | gaussian_center_3 | gaussian_fwhmg_3 | gaussian_amplitude_4 | gaussian_center_4 | gaussian_fwhmg_4 | gaussian_amplitude_5 | gaussian_center_5 | gaussian_fwhmg_5 | gaussian_amplitude_6 | gaussian_center_6 | gaussian_fwhmg_6 | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
parameter | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value | init_value | model_value | best_value |
Loading ITables v2.2.3 from the internet... (need help?) |