clophfit.fitting.data_structures#
Core data structures in clophfit.
Classes:#
DataArray: Represents matched x, y, and optional w arrays.
Dataset: Extends dict to store DataArray as key-value pairs, with optional support for pH-specific datasets.
Classes#
Represent matched x, y, and optional w (weight) arrays. |
|
A dictionary-like container for storing DataArray. |
|
A very small common interface for all minimizers / backends. |
|
Result container of a fitting procedure. |
|
A dataclass representing the results of both svd and bands fits. |
Module Contents#
- class clophfit.fitting.data_structures.DataArray#
Represent matched x, y, and optional w (weight) arrays.
- Parameters:
xc (ArrayF) – x at creation.
yc (ArrayF) – y at creation.
x_errc (ArrayF, optional) – x_err at creation.
y_errc (ArrayF, optional) – y_err at creation.
- property mask: clophfit.clophfit_types.ArrayMask#
Mask.
- Return type:
clophfit.clophfit_types.ArrayMask
- property x: clophfit.clophfit_types.ArrayF#
Masked x.
- Return type:
clophfit.clophfit_types.ArrayF
- property y: clophfit.clophfit_types.ArrayF#
Masked y.
- Return type:
clophfit.clophfit_types.ArrayF
- property y_err: clophfit.clophfit_types.ArrayF#
Masked y_err.
- Return type:
clophfit.clophfit_types.ArrayF
- property x_err: clophfit.clophfit_types.ArrayF#
Masked x_err.
- Return type:
clophfit.clophfit_types.ArrayF
- class clophfit.fitting.data_structures.Dataset(data, *, is_ph=False)#
Bases:
collections.UserDict[str,DataArray]A dictionary-like container for storing DataArray.
- Parameters:
data (dict[str, DataArray]) – Maps keys to DataArray instances.
is_ph (bool)
- is_ph: bool = False#
Indicates whether x values represent pH. Default is False.
- classmethod from_da(da, *, is_ph=False)#
Alternative constructor to create Dataset from a list of DataArray.
- apply_mask(combined_mask)#
Correctly distribute and apply the combined mask across all DataArrays.
- Parameters:
combined_mask (ArrayMask) – Boolean array where True keeps the data point, and False masks it out.
- Raises:
ValueError – If the length of the combined_mask does not match the total number of data points.
- Return type:
None
- copy(keys=None)#
Return a copy of the Dataset.
If keys are provided, only data associated with those keys are copied.
- Parameters:
keys (list[str] | set[str] | None, optional) – List of keys to include in the copied dataset. If None (default), copies all data.
- Returns:
A copy of the dataset.
- Return type:
- Raises:
KeyError – If a provided key does not exist in the Dataset.
- clean_data(n_params)#
Remove too small datasets.
- Parameters:
n_params (int)
- Return type:
None
- concatenate_data()#
Concatenate x, y, x_err, and y_err across all datasets.
Optimized version with pre-allocation for better memory efficiency.
- Return type:
tuple[clophfit.clophfit_types.ArrayF, clophfit.clophfit_types.ArrayF, clophfit.clophfit_types.ArrayF, clophfit.clophfit_types.ArrayF]
- export(filep)#
Export this dataset into a csv file.
- Parameters:
filep (str | pathlib.Path)
- Return type:
None
- plot(*, title=None, ax=None)#
Plot the dataset with error bars.
- Parameters:
title (str | None) – Plot title.
ax (Axes | None) – Axes to plot on. If None, creates a new figure.
- Returns:
The figure containing the plot.
- Return type:
Figure
- class clophfit.fitting.data_structures.MiniProtocol#
Bases:
ProtocolA very small common interface for all minimizers / backends.
- class clophfit.fitting.data_structures.FitResult[MiniType: MiniProtocol]#
Result container of a fitting procedure.
- figure: matplotlib.figure.Figure | None = None#
Matplotlib figure visualizing the fit, if generated.
- result: lmfit.minimizer.MinimizerResult | _Result | None = None#
Backend-agnostic fit result exposing a .params attribute along with residual, redchi, and success fields (as in lmfit). For lmfit this is a MinimizerResult.
- mini: MiniType | None = None#
The primary backend object (e.g., lmfit.Minimizer, scipy.odr.Output, or az.InferenceData for PyMC).
- dataset: Dataset | None = None#
Dataset used for the fit (typically a deep copy of the input dataset).
- pprint()#
Provide a brief summary of the fit, focusing on the K value.
- Return type:
str
- is_valid()#
Whether figure, result, and minimizer exist.
- Return type:
bool
- class clophfit.fitting.data_structures.SpectraGlobResults#
A dataclass representing the results of both svd and bands fits.
- svd: FitResult[lmfit.minimizer.Minimizer] | None = None#
The FitResult object representing the outcome of the concatenated svd fit, or None if the svd fit was not performed.