optmat.solid.fitting#

Fitting a solid’s universal dispersion model to the curated data.

A fit starts from a published UDM formula of a source record (its newAD2 parameter file’s values) and frees a chosen set of its parameters. It adjusts them, by least squares, to curated n and k at their stated uncertainties:

  • n: refractive_index, or a refractive_index_deviation from a named formula, which the fit adds back to that formula; an index relative to room air (parameters.index_medium = "air") is taken to vacuum with the index of that air (TC-398);

  • k: extinction_coefficient, compared in log k, since k spans many decades;

  • offsets: each fitted n dataset may carry a free additive offset with a prior (its grade and temperature: silica grades differ by ~1e-5 in n, and dn/dT is ~1e-5 per kelvin);

  • priors: free parameters may carry priors.

The model stays causal, passive and sum-rule normalised whatever the parameters, so the fitted dielectric function is analytic like the published one. The configuration is data/solid/fits/<name>.toml; the result is stored as data/solid/models/fitted/<name>.json with its covariance (TC-322).

Module Attributes

FIT_DIRECTORY

The solid fit configurations.

Functions

dumps(result)

Serialise a fit result as JSON text.

fit(config)

Fit the configuration's free UDM parameters to its datasets.

load_config(name)

Load a solid fit configuration.

validation(result)

Compare the fitted model with each validator dataset.

Classes

DatasetOptions(key[, range_nm, sigma, ...])

How one curated dataset enters a fit.

FitConfig(name, material, description, ...)

A solid fit's configuration.

FitResult(config, attributes, values, ...)

A fitted model with its statistics.

class optmat.solid.fitting.DatasetOptions(key, range_nm=(0.0, inf), sigma=None, extra=0.0, offset_sigma=None, offset_group='', reference='', thermo_optic='', temperature_k=None)[source]#

Bases: object

How one curated dataset enters a fit.

Attributes:
keystr

source/dataset.

range_nmtuple of float

The vacuum-wavelength window used, nm.

sigmafloat or None

Uncertainty used where the dataset states none (n: absolute; k: relative).

extrafloat

Added in quadrature to every point’s uncertainty (same units as sigma).

offset_sigmafloat or None

The prior (one sigma) of a free additive offset in n; None for no offset.

offset_groupstr

Datasets naming the same group share one offset (a common reference level, such as whether a source’s n is relative to air); empty for the dataset’s own.

referencestr

For a refractive_index_deviation, the formula model it is relative to.

thermo_opticstr

A thermo_optic_coefficient dataset (source/dataset) that takes the values from their sample temperature to temperature_k, interpolated in wavelength; empty for none.

temperature_kfloat or None

The temperature the fit refers to, K, for thermo_optic.

extra: float = 0.0#
key: str#
offset_group: str = ''#
offset_sigma: float | None = None#
range_nm: tuple[float, float] = (0.0, inf)#
reference: str = ''#
sigma: float | None = None#
temperature_k: float | None = None#
thermo_optic: str = ''#
optmat.solid.fitting.FIT_DIRECTORY: Final = PosixPath('/home/docs/checkouts/optmat/checkouts/7/src/optmat/data/solid/fits')#

The solid fit configurations.

class optmat.solid.fitting.FitConfig(name, material, description, range_nm, start, free, scales=<factory>, added_attributes=(), added_values=<factory>, priors=<factory>, fitted=(), validators=(), digest='')[source]#

Bases: object

A solid fit’s configuration.

Attributes:
namestr

The configuration’s name (its file stem).

materialstr

The material’s id.

descriptionstr

What the fit is and why.

range_nmtuple of float

The range the fitted model supports, nm.

startstr

The starting UDM formula, <source>/<formula id> of a curated source whose formula holds a newAD2 parameter file’s values as its terms.

freetuple of str

The freed parameters, in newAD2’s names.

scalesdict of str to tuple of str

Groups of parameters multiplied by one fitted factor each (the OH bands of a grade, say), by the group’s name.

added_attributestuple of str

Terms added to the start model (loc=1 adds one Gaussian peak).

added_valuesdict of str to float

The added terms’ starting parameters.

priorsdict of str to tuple of float

Priors (value, sigma) on free parameters.

fitted, validatorstuple of DatasetOptions

The fitted datasets and the datasets only compared.

digeststr

The configuration file’s SHA-256.

added_attributes: tuple[str, ...] = ()#
added_values: Mapping[str, float]#
description: str#
digest: str = ''#
fitted: tuple[DatasetOptions, ...] = ()#
free: tuple[str, ...]#
material: str#
name: str#
priors: Mapping[str, tuple[float, float]]#
range_nm: tuple[float, float]#
scales: Mapping[str, tuple[str, ...]]#
start: str#
validators: tuple[DatasetOptions, ...] = ()#
class optmat.solid.fitting.FitResult(config, attributes, values, covariance, offsets, chi2, dof, dataset_chi2)[source]#

Bases: object

A fitted model with its statistics.

Attributes:
configFitConfig

The configuration.

attributestuple of str

The UDM’s attributes.

valuesdict of str to float

Every UDM parameter, fitted or fixed.

covariancenumpy.ndarray

The covariance of the free parameters, then of the group scales, then of the offsets (in their own units), Birge-scaled when the reduced chi-squared exceeds 1.

offsetsdict of str to float

The fitted n offset of each dataset that has one.

chi2float

The total chi-squared, priors included.

dofint

Degrees of freedom.

dataset_chi2dict of str to tuple

Points and chi-squared of each fitted dataset.

attributes: tuple[str, ...]#
chi2: float#
config: FitConfig#
covariance: Float[ndarray, 'p p']#
dataset_chi2: Mapping[str, tuple[int, float]]#
dof: int#
property model: UniversalDispersionModel#

The fitted UDM.

Returns:
UniversalDispersionModel

The model at the fitted parameters.

offsets: Mapping[str, float]#
values: Mapping[str, float]#
optmat.solid.fitting.dumps(result)[source]#

Serialise a fit result as JSON text.

Parameters:
resultFitResult

The result.

Returns:
str

Indented JSON: the full parameter set, the covariance of the free parameters, the statistics and the configuration’s digest.

optmat.solid.fitting.fit(config)[source]#

Fit the configuration’s free UDM parameters to its datasets.

Parameters:
configFitConfig

The configuration.

Returns:
FitResult

The fitted model, covariance and statistics.

optmat.solid.fitting.load_config(name)[source]#

Load a solid fit configuration.

Parameters:
namestr or pathlib.Path

The name (data/solid/fits/<name>.toml) or a path.

Returns:
FitConfig

The configuration.

Raises:
DataError

If it is malformed or names an unknown dataset.

optmat.solid.fitting.validation(result)[source]#

Compare the fitted model with each validator dataset.

Parameters:
resultFitResult

The fit.

Returns:
dict of str to dict

Per validator: the points, chi-squared and mean deviation (n: absolute; log k: relative).