diff --git a/pyproject.toml b/pyproject.toml index 2179ca510..a826c8ef4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "SpectraFit" -version = "0.13.1" -description = "Fast fitting of 2D-Spectra with established routines" +version = "0.13.2" +description = "Fast fitting of 2D- and 3D-Spectra with established routines" readme = "README.md" authors = ["Anselm Hahn "] maintainers = ["Anselm Hahn "] diff --git a/spectrafit/__init__.py b/spectrafit/__init__.py index 947f4dae5..6a3ffa307 100644 --- a/spectrafit/__init__.py +++ b/spectrafit/__init__.py @@ -1,2 +1,2 @@ """SpectraFit, fast command line tool for fitting data.""" -__version__ = "0.13.1" +__version__ = "0.13.2" diff --git a/spectrafit/plugins/notebook.py b/spectrafit/plugins/notebook.py index dae8fc37f..7debdf149 100644 --- a/spectrafit/plugins/notebook.py +++ b/spectrafit/plugins/notebook.py @@ -703,6 +703,7 @@ class SpectraFitNotebook( df_fit: pd.DataFrame df_pre: pd.DataFrame = pd.DataFrame() df_metric: pd.DataFrame = pd.DataFrame() + df_peaks: pd.DataFrame = pd.DataFrame() initial_model: List[Dict[str, Dict[str, Dict[str, Any]]]] def __init__( @@ -993,6 +994,7 @@ def solver_model( show_plot: bool = True, show_metric: bool = True, show_df: bool = False, + show_peaks: bool = False, conf_interval: Union[bool, Dict[str, Any]] = False, bar_criteria: Optional[Union[str, List[str]]] = None, line_criteria: Optional[Union[str, List[str]]] = None, @@ -1008,6 +1010,7 @@ def solver_model( show_metric (bool, optional): Show the metric of the fit. Defaults to True. show_df (bool, optional): Show current fit results as dataframe. Defaults to False. + show_peaks (bool, optional): Show the peaks of fit. Defaults to False. conf_interval (Union[bool,Dict[str, Any]], optional): Bool or dictionary for the parameter with the parameter for calculating the confidence interval. Using `conf_interval=False` turns of the calculation of @@ -1052,6 +1055,7 @@ def solver_model( )(), )() self.update_metric + self.update_peaks if show_plot: self.plot_fit_df @@ -1063,6 +1067,37 @@ def solver_model( if show_df: self.interactive_display(df=self.df_fit) + if show_peaks: + self.interactive_display(df=self.df_peaks) + + @property + def update_peaks(self) -> None: + """Update the peaks dataframe as multi-column dataframe. + + The multi-column dataframe is used for the interactive display of the + peaks with initial, current (model), and best fit values. + """ + tuples = [] + _list = [] + for key_1, _dict in self.args["fit_insights"]["variables"].items(): + tuples.extend([(key_1, key_2) for key_2, val in _dict.items()]) + _list.extend([val for _, val in _dict.items()]) + + self.df_peaks = pd.concat( + [ + self.df_peaks, + pd.DataFrame( + pd.Series( + _list, + index=pd.MultiIndex.from_tuples( + tuples, names=["component", "parameter"] + ), + ) + ).T, + ], + ignore_index=True, + ) + @property def update_metric(self) -> None: """Update the metric dataframe.""" diff --git a/spectrafit/plugins/test/test_notebook.py b/spectrafit/plugins/test/test_notebook.py index f6b7b473f..8493fe8b9 100644 --- a/spectrafit/plugins/test/test_notebook.py +++ b/spectrafit/plugins/test/test_notebook.py @@ -494,6 +494,7 @@ def test_conv_1( show_plot=False, show_df=True, show_metric=True, + show_peaks=True, conf_interval=True, ) mock_show.assert_called_once() @@ -512,6 +513,7 @@ def test_conv_2( show_plot=False, show_df=True, show_metric=True, + show_peaks=True, conf_interval={}, ) diff --git a/spectrafit/report.py b/spectrafit/report.py index 1b572bc39..712ade62f 100644 --- a/spectrafit/report.py +++ b/spectrafit/report.py @@ -151,7 +151,7 @@ def __call__(self) -> Dict[Hashable, Any]: try: metric_dict[fnc.__name__].append(fnc(y_true, y_pred)) except ValueError as err: - print(f"ValueError: {err} for {fnc.__name__}!") + print(f"## Warning: {err} for {fnc.__name__}!") metric_dict[fnc.__name__].append(np.nan) return pd.DataFrame(metric_dict).T.to_dict(orient="split")