Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
maintainers = ["Anselm Hahn <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion spectrafit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""SpectraFit, fast command line tool for fitting data."""
__version__ = "0.13.1"
__version__ = "0.13.2"
35 changes: 35 additions & 0 deletions spectrafit/plugins/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -1052,6 +1055,7 @@ def solver_model(
)(),
)()
self.update_metric
self.update_peaks
if show_plot:
self.plot_fit_df

Expand All @@ -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."""
Expand Down
2 changes: 2 additions & 0 deletions spectrafit/plugins/test/test_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -512,6 +513,7 @@ def test_conv_2(
show_plot=False,
show_df=True,
show_metric=True,
show_peaks=True,
conf_interval={},
)

Expand Down
2 changes: 1 addition & 1 deletion spectrafit/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down