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.
In [1]:
Copied!
# 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"
)
# 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
.
In [2]:
Copied!
spn = nb.SpectraFitNotebook(df=df, x_column="Energy", y_column="Noisy", fname="example9_3")
spn = nb.SpectraFitNotebook(df=df, x_column="Energy", y_column="Noisy", fname="example9_3")
Define the fitting model without plotting the results¶
In [3]:
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., "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=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., "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=False)
## Warning: uncertainties could not 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.
In [4]:
Copied!
spn.export_df_org
spn.export_df_act
spn.export_df_fit
spn.export_df_org spn.export_df_act spn.export_df_fit
In [5]:
Copied!
from pathlib import Path
list(Path(".").glob("*.csv"))
from pathlib import Path list(Path(".").glob("*.csv"))
Out[5]:
[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