Skip to content

Commit 6fadeb6

Browse files
committed
Use dataclasses to store fitting settings and outputs rather than loads of parameters. ODR fitting not quite working at present.
1 parent 33e881a commit 6fadeb6

File tree

4 files changed

+184
-215
lines changed

4 files changed

+184
-215
lines changed

Stoner/analysis/fitting/classes.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"""Classes to support data fitting."""
33

44
from copy import deepcopy as copy
5+
from dataclasses import dataclass, field
56
from inspect import getfullargspec, isclass
7+
from typing import Union, Optional
68

79
import lmfit as lmfit_mod
810
import numpy as np
@@ -165,7 +167,7 @@ def wrapper(beta, x, y, sigma, *args):
165167
self.minimize_func = wrapper
166168

167169

168-
class _curve_fit_result:
170+
class _Curve_Fit_Result:
169171
"""Represent a result from fitting using :py:func:`scipy.optimize.curve_fit`
170172
as a class to make handling easier.
171173
"""
@@ -203,6 +205,7 @@ def __init__(self, popt=None, pcov=None, infodict=None, mesg=None, ier=None):
203205
self._residual_vals = None
204206
self.chisq = None
205207
self.nfree = None
208+
self.f_name = None
206209
self._infodict = infodict
207210
if infodict:
208211
for k in infodict:
@@ -377,6 +380,22 @@ def add_metadata(self, datafile):
377380
return datafile
378381

379382

383+
@dataclass
384+
class _Curve_Fit_Output:
385+
"""Dataclass for gathering together information about the output from a curve fitting operation."""
386+
387+
prefix: str = ""
388+
columns: AttributeStore = field(default_factory=dict)
389+
result: Union[bool, str, None] = None
390+
replace: bool = False
391+
header: Optional[str] = None
392+
residuals: bool = False
393+
asrow: bool = False
394+
output: str = "row"
395+
scale_covar: bool = True
396+
nan_policy: str = "raise"
397+
398+
380399
def _prep_lmfit_model(model, kargs):
381400
"""Prepare an lmfit model instance.
382401

0 commit comments

Comments
 (0)