fitpy.dataset module

Datasets: units containing data and metadata.

The dataset is one key concept of the ASpecD framework and hence the FitPy package derived from it, consisting of the data as well as the corresponding metadata. Storing metadata in a structured way is a prerequisite for a semantic understanding within the routines. Furthermore, a history of every processing, analysis and annotation step is recorded as well, aiming at a maximum of reproducibility. This is part of how the ASpecD framework and therefore the FitPy package tries to support good scientific practice.

Therefore, each processing and analysis step of data should always be performed using the respective methods of a dataset, at least as long as it can be performed on a single dataset.

The reason for providing an own class for calculated datasets is to ensure a consistent handling of fit results and provide means for specialised plotters available in the fitpy.plotting module to check for their applicability.

class fitpy.dataset.CalculatedDataset[source]

Bases: aspecd.dataset.CalculatedDataset

Dataset containing results of fitting a model to data.

data

numeric data, residual, and axes

In contrast to other datasets, it contains the residual (difference between fitted model and original data) as well.

Type

Data

metadata

hierarchical key-value store of metadata

Type

CalculatedDatasetMetadata

class fitpy.dataset.CalculatedDatasetLHS[source]

Bases: fitpy.dataset.CalculatedDataset

Dataset containing results of fitting a model to data.

data

numeric data, residual, and axes

In contrast to other datasets, it contains the residual (difference between fitted model and original data) as well.

Type

Data

metadata

hierarchical key-value store of metadata

Type

CalculatedDatasetLHSMetadata

class fitpy.dataset.Data[source]

Bases: aspecd.dataset.Data

Unit containing numeric data, residual, and corresponding axes.

In contrast to the base class of the ASpecD framework, it contains the residual (difference between fitted model and original data) as well.

property residual

Residual (difference between fitted model and original data).

A residual need always to have the same shape as the corresponding data. If you try to set a residual not conforming to this condition, a ValueError will be raised.

class fitpy.dataset.CalculatedDatasetMetadata[source]

Bases: aspecd.metadata.CalculatedDatasetMetadata

Metadata for a dataset with calculated data.

This class contains the metadata for a dataset consisting of calculated data, i.e., CalculatedDataset.

Metadata can be converted to dict via aspecd.utils.ToDictMixin.to_dict(), e.g., for generating reports using templates and template engines.

calculation

Information on the calculation.

Contain, inter alia, the parameters of the calculation.

Type

aspecd.metadata.Calculation

model

Details of the model fitted to the data

Type

Model

data

Details of the data the model has been fitted to

Type

class:DataMetadata

result

Summary of results of fit

Type

Result

class fitpy.dataset.CalculatedDatasetLHSMetadata[source]

Bases: fitpy.dataset.CalculatedDatasetMetadata

Metadata for a dataset with calculated data.

This class contains the metadata for a dataset consisting of calculated data, i.e., CalculatedDataset.

Metadata can be converted to dict via aspecd.utils.ToDictMixin.to_dict(), e.g., for generating reports using templates and template engines.

calculation

Information on the calculation.

Contain, inter alia, the parameters of the calculation.

Type

aspecd.metadata.Calculation

model

Details of the model fitted to the data

Type

Model

data

Details of the data the model has been fitted to

Type

class:DataMetadata

result

Summary of results of fit

Type

Result

lhs

Details of the LHS and its full results for each sampling

Type

LHS

class fitpy.dataset.Model[source]

Bases: aspecd.metadata.Metadata

Metadata of a model fitted to data of a dataset.

Part of the metadata of a CalculatedDataset containing the data of the model fitted to the data of another (experimental) dataset.

type

Full class name (including package) of the respective model class

Type

str

parameters

All parameters of the model

Type

dict

from_model(model)[source]

Set attributes from aspecd.model.Model.

Parameters

model (aspecd.model.Model) – Model the attributes should be obtained from

class fitpy.dataset.DataMetadata[source]

Bases: aspecd.metadata.Metadata

Metadata of the data(set) a model has been fitted to.

Part of the metadata of a CalculatedDataset containing information of the (experimental) dataset the model has been fitted to.

id

(unique) identifier of the dataset (i.e., path, LOI, or else)

Type

str

label

Short description of the dataset

Can be set by the user, defaults to the value set as aspecd.dataset.Dataset.id by the importer.

Type

str

from_dataset(dataset)[source]

Set attributes from aspecd.dataset.Dataset.

Parameters

dataset (aspecd.dataset.Dataset) – Dataset the attributes should be obtained from

class fitpy.dataset.Result[source]

Bases: aspecd.metadata.Metadata

Metadata of results of fitting a model to data of a dataset.

Part of the metadata of a CalculatedDataset containing the data of the model fitted to the data of another (experimental) dataset.

While resembling the structure of the lmfit.minimizer.MinimizerResult class, this class tries to abstract away from the attributes in terms of their names and introduces more readable (and more lengthily) attribute names.

parameters

The best-fit parameters resulting from the fit.

Type

lmfit.parameter.Parameters

success

True if the fit succeeded, otherwise False.

Type

bool

error_bars

True if uncertainties were estimated, otherwise False.

Type

bool

n_function_evaluations

Number of function evaluations

Type

int

n_variables

Number of variables of the model

Type

int

degrees_of_freedom

Degrees of freedom

Type

int

chi_square

Chi-square value

For this value to be meaningful, the residual function needs to be scaled properly to the uncertainties in the data.

Type

float

reduced_chi_square

Reduced chi-square value

For this value to be meaningful, the residual function needs to be scaled properly to the uncertainties in the data.

Type

float

akaike_information_criterion

Akaike Information Criterion statistic

Type

float

bayesian_information_criterion

Bayesian Information Criterion statistic

Type

float

variable_names

Ordered list of variable parameter names used in the optimisation.

Type

list

covariance_matrix

Covariance matrix from minimisation.

Rows and columns correspond to variable_names

Type

numpy.ndarray

initial_values

List of initial values for variable parameters.

For the corresponding parameter names see variable_names.

Type

list

message

Message regarding the fit success.

Type

str

to_dict(remove_empty=False)[source]

Create dictionary containing public attributes of an object.

Parameters

remove_empty (bool) –

Whether to remove keys with empty values

Default: False

Returns

public_attributes – Ordered dictionary containing the public attributes of the object

The order of attribute definition is preserved

Return type

collections.OrderedDict

from_lmfit_minimizer_result(result)[source]

Set attributes from lmfit.minimizer.MinimizerResult.

Parameters

result (lmfit.minimizer.MinimizerResult) – Result of a minimisation using lmfit

class fitpy.dataset.LHS[source]

Bases: aspecd.metadata.Metadata

Metadata of the LHS and its full results for each sampling.

Part of the metadata of a CalculatedDatasetLHS containing the data of the model fitted to the data of another (experimental) dataset.

samples

Grid of the Latin Hypercube

Type

numpy.array

discrepancy

Discrepancy of the sample.

The discrepancy is a uniformity criterion used to assess the space filling of a number of samples in a hypercube. A discrepancy quantifies the distance between the continuous uniform distribution on a hypercube and the discrete uniform distribution on distinct sample points. (from scipy.stats.qmc.discrepancy())

Type

float

results

Results for each sample of the Latin Hypercube.

Each result is an instance of Result.

Type

list

from_lmfit_minimizer_results(results)[source]

Set attributes from lmfit.minimizer.MinimizerResult.

Parameters

results (list) –

List of results of a minimisation using lmfit

Each result is an instance of lmfit.minimizer.MinimizerResult and gets transferred to an instance of Result.