optmat.gas.fitting#
Fit oscillator-strength models to the curated data.
A fit is specified by a configuration, data/gas/fits/<name>.toml, which names
the model: the resonance lines kept at their spectroscopic energies (NIST), each with a prior on its oscillator strength, and the number of effective oscillators that stand for the rest of the distribution (the higher Rydberg lines and the continuum), above a stated lowest energy;
optional priors on dipole sums (the static polarizability
S(-2), the Thomas-Reiche-Kuhn sumS(0));the datasets fitted, each with its options: a free scale (a dataset whose absolute level is less certain than its shape, like Mansfield & Peck’s helium), an extra relative uncertainty added in quadrature, and a wavelength window;
the datasets used only as validators.
The fit is a generalised least-squares problem in the polarizability (atomic units).
Each fitted value contributes (s_d alpha_model(omega) - alpha)/sigma, where s_d
is its dataset’s scale: 1, free, or constrained by the dataset’s stated systematic
uncertainty (a prior residual (s_d - 1)/sigma_sys). Line strengths enter as
(f - f_prior)/sigma_f. Effective strengths and energies are fitted as logarithms so
that they stay positive and above the lowest allowed energy.
The parameter covariance is (J^T J)^{-1} at the solution; when the reduced
chi-squared exceeds one it is also given scaled by it (the Birge ratio), and the
uncertainty band of the polarizability follows by linear propagation.
Module Attributes
Fit configurations, |
|
Vacuum wavelength of a one-hartree photon, nm (2 pi c / (E_h / hbar)). |
Functions
|
Serialise a fit result as JSON text. |
|
Fit a configuration's model to its data. |
|
Load a fit configuration. |
|
Return the fitted observations of a configuration. |
|
Return a fit result as a JSON-serialisable record. |
|
Compare the fit with its validator datasets. |
Classes
|
How one dataset enters a fit. |
|
A fit's specification. |
|
A fitted model with its uncertainty and statistics. |
|
A resonance line kept at its spectroscopic energy. |
|
The fitted values of one dataset, as polarizabilities in atomic units. |
- class optmat.gas.fitting.DatasetOptions(key, free_scale=False, extra_relative=0.0, range_nm=(0.0, inf), electric=False, infrared=True, correction_au=None, shape_relative=None, temperature=None)[source]#
Bases:
objectHow one dataset enters a fit.
- Attributes:
- keystr
source/dataset.- free_scalebool
Fit the dataset’s scale without a prior.
- extra_relativefloat
Relative uncertainty added in quadrature to every value.
- range_nmtuple of float
Vacuum-wavelength window of the values used, nm.
- electricbool
The values are electric polarizabilities (ab initio theory, dielectric measurements), compared with the model without its
chi_0. Cauchy moments are always electric.- infraredbool
The values include the vibrational (infrared) contribution, as measured refractivities and dielectric constants do; False for electronic theory. Only used when the model has infrared terms; Cauchy moments are always electronic.
- correction_autuple of float or None
(value, sigma)added to every value, atomic units, withsigmaadded in quadrature to its uncertainty: a term the values lack and the model includes, such as the zero-point vibrational average of a polarizability computed at the equilibrium geometry.- shape_relativefloat or None
With
free_scale: the relative uncertainty of the values’ shape, used in place of the stated one when that states the absolute level (which the free scale absorbs) and the register gives the shape’s own precision.- temperaturetuple of float or None
(measured_k, coefficient, sigma): the values were measured atmeasured_k(K), and the molecule’s zero-density polarizability changes bycoefficient(per K, relative; its uncertaintysigma) with temperature. The values are brought to the fit’sreference_temperatureby the factor1 + coefficient (T_ref - measured_k), andsigma |T_ref - measured_k|is added in quadrature to their relative uncertainty (TC-730).
- optmat.gas.fitting.FIT_DIRECTORY: Final = PosixPath('/home/docs/checkouts/optmat/checkouts/7/src/optmat/data/gas/fits')#
Fit configurations,
<name>.toml.
- class optmat.gas.fitting.FitConfig(name, gas, description, lines, effective, effective_min_energy, sum_priors, chi0, fitted, validators, range_nm, digest, starts=6, infrared=(), infrared_max_wavenumber=None, fixed=(), retardation=0.0, reference_temperature=None, absorption=None, band_nodes=None, rotational=(), windows=False, intervals_nm=(), gap_reasons=(), derived_sha256='')[source]#
Bases:
objectA fit’s specification.
- Attributes:
- namestr
The configuration’s file stem, and the fitted model’s name.
- gasGas
The species.
- descriptionstr
What the fit is for.
- linestuple of Line
The fixed-energy resonance lines.
- effectiveint
The number of effective oscillators.
- effective_min_energyfloat
The lowest energy an effective oscillator may take, hartree.
- sum_priorsdict of int to tuple of float
Priors
{k: (value, sigma)}on dipole sumsS(k), atomic units.- chi0float
The atom’s magnetic susceptibility, atomic units: the model’s refractive polarizability is its electric sum plus
chi0.- fittedtuple of DatasetOptions
The datasets fitted.
- validatorstuple of DatasetOptions
Datasets compared with the fit but not fitted (with their
electricflag).- range_nmtuple of float
The wavelength range over which the fitted model is declared valid, nm.
- digeststr
SHA-256 of the configuration file, recorded with the result.
- startsint
The number of starting points
fit()tries ([model] starts, default 6).- infraredtuple of tuple
Fixed vibrational terms
(label, strength, energy in hartree): the gas’s HITRAN bands (optmat.gas.infrared) up to[model] infrared_max_wavenumber; empty if that key is absent.- infrared_max_wavenumberfloat or None
The cutoff, cm^-1.
- fixedtuple of tuple
Fixed electronic terms
(label, strength, energy in hartree)from[[model.fixed]](a published distribution’s interval strengths above the measured range, say): always included, outside the fitted parameters.- reference_temperaturefloat or None
The temperature (K) the model’s polarizability refers to (
[model] reference_temperature_k): datasets with atemperatureoption are brought to it. None where no reference is declared (the atoms: their polarizability does not depend on temperature at the package’s accuracy).- retardationfloat
The coefficient
cof the retardation termc omega^2of the refractive polarizability ([model] retardation_au, atomic units, omega in hartree): added, likechi0, to refractive observations and not to electric ones or to moments. Known for helium only (TC-705); zero otherwise.- absorptionMeasuredAbsorption or None
A fixed measured-absorption term (
[model] absorption = true, fromdata/gas/absorption/<gas>.toml, smoothed to[model] absorption_fwhm_cmif given): its Kramers-Kronig polarizability is added to every prediction and its dipole sums to the sum priors.- band_nodesint or None
[model] band_nodes(OEP 3): the infrared terms are the derived rules of every band system (<gas>_band_rules.csv), at most this many nodes each, in place ofinfrared_max_wavenumber’s band poles.- rotationaltuple of tuple
The rotational system’s terms, with
band_nodes: a term class of its own, added to refractive observations and left out of electric ones and moments.- windowsbool
[model] windows = true: the model’s qualified intervals are the gas’s derived windows (<gas>_windows.csv), with each gap’s reason.- intervals_nmtuple of tuple of float
The qualified intervals, nm: the derived windows, or
range_nmalone.- gap_reasonstuple of str
The reason of each gap between two intervals.
- derived_sha256str
The SHA-256 of the derived tables the fit reads (
band_nodesorwindows); empty otherwise.
- absorption: MeasuredAbsorption | None = None#
- fitted: tuple[DatasetOptions, ...]#
- property fixed_terms: tuple[tuple[str, float, float], ...]#
Every term outside the fitted parameters: rotational, infrared, the rest.
- Returns:
- tuple of tuple
(label, strength, energy in hartree).
- validators: tuple[DatasetOptions, ...]#
- class optmat.gas.fitting.FitResult(config, model, parameters, covariance, scales=<factory>, chi2=0.0, dof=0, dataset_chi2=<factory>)[source]#
Bases:
objectA fitted model with its uncertainty and statistics.
- Attributes:
- configFitConfig
The fit’s configuration.
- modelOscillatorModel
The fitted model.
- parametersnumpy.ndarray
The fitted strengths (lines, then effective) and effective energies, hartree.
- covariancenumpy.ndarray
Their covariance, from
(J^T J)^{-1}(not scaled by the Birge ratio).- scalesdict of str to float
The fitted scale of each dataset (1 where not fitted).
- chi2float
Chi-squared of the data residuals at the solution.
- dofint
Degrees of freedom: data points minus parameters.
- dataset_chi2dict of str to tuple
(number of points, chi-squared)per dataset.
- covariance: Float[ndarray, 'q q']#
- model: OscillatorModel#
- parameters: Float[ndarray, 'q']#
- polarizability_sigma_au(omega, *, birge=True)[source]#
Return the one-sigma uncertainty of the fitted polarizability.
- Parameters:
- omeganumpy.ndarray
Photon energies, hartree.
- birgebool, optional
Scale the covariance by the reduced chi-squared when it exceeds one.
- Returns:
- numpy.ndarray
One-sigma uncertainty, atomic units.
- optmat.gas.fitting.HARTREE_NM: Final = 45.56335252767#
Vacuum wavelength of a one-hartree photon, nm (2 pi c / (E_h / hbar)).
- class optmat.gas.fitting.Line(label, wavelength_nm, f_prior, f_sigma)[source]#
Bases:
objectA resonance line kept at its spectroscopic energy.
- Attributes:
- labelstr
The transition.
- wavelength_nmfloat
Vacuum wavelength, nm.
- f_priorfloat
Prior oscillator strength.
- f_sigmafloat
Its standard uncertainty.
- class optmat.gas.fitting.Observation(key, omega, alpha, sigma, systematic, options, orders=None, harmonic=0, partner_delta=None, model_in_numerator=False)[source]#
Bases:
objectThe fitted values of one dataset, as polarizabilities in atomic units.
- Attributes:
- keystr
source/dataset.- omeganumpy.ndarray
Photon energies, hartree.
- alphanumpy.ndarray
Polarizabilities, atomic units.
- sigmanumpy.ndarray
One-sigma uncertainties, atomic units.
- systematicfloat or None
The dataset’s stated relative systematic uncertainty.
- optionsDatasetOptions
How the dataset enters the fit.
- ordersnumpy.ndarray or None
For Cauchy moments, the order
kof eachS(k)(thenalphaholds the sums andomegais unused); None for polarizabilities.- harmonicint
For a phase-matching density ratio, the harmonic (
omegais the fundamental,alphaholds the ratios); 0 otherwise.- partner_deltanumpy.ndarray or None
For a ratio, the partner gas’s
alpha(h omega) - alpha(omega)from its fixed model, atomic units.- model_in_numeratorbool
For a ratio, True if the fitted gas’s difference is the ratio’s numerator (
rho_partner / rho_fitted), False if its denominator.
- alpha: Float[ndarray, 'n']#
- omega: Float[ndarray, 'n']#
- options: DatasetOptions#
- sigma: Float[ndarray, 'n']#
- optmat.gas.fitting.dumps(result)[source]#
Serialise a fit result as JSON text.
- Parameters:
- resultFitResult
The result.
- Returns:
- str
Indented JSON.
- optmat.gas.fitting.fit(config, data=None, *, starts=None, start=None)[source]#
Fit a configuration’s model to its data.
Several starting points spread the effective oscillators over different energies; the solution with the lowest cost is kept.
- Parameters:
- configFitConfig
The fit.
- datasequence of Observation, optional
The observations; by default those the configuration names (
observations()).- startsint, optional
The number of spread starting points; by default the configuration’s.
- startFitResult, optional
A previous fit of the same model (for instance on more data), whose solution is tried first; with
starts=0the fit follows it to the nearest minimum.
- Returns:
- FitResult
The fitted model, its covariance and statistics.
- Raises:
- ValueError
If there is no starting point, or
starthas a different model layout.
- optmat.gas.fitting.load_config(name)[source]#
Load a fit configuration.
- Parameters:
- namestr or pathlib.Path
The configuration’s name (
data/gas/fits/<name>.toml) or path.
- Returns:
- FitConfig
The configuration.
- Raises:
- DataError
If the configuration is malformed or names an unknown dataset.
- optmat.gas.fitting.observations(config)[source]#
Return the fitted observations of a configuration.
- Parameters:
- configFitConfig
The fit.
- Returns:
- tuple of Observation
One per fitted dataset.
- optmat.gas.fitting.result_record(result)[source]#
Return a fit result as a JSON-serialisable record.
- Parameters:
- resultFitResult
The result.
- Returns:
- dict
The model’s terms, covariance, statistics and provenance.
- optmat.gas.fitting.validation(result)[source]#
Compare the fit with its validator datasets.
- Parameters:
- resultFitResult
The fit.
- Returns:
- dict
Per validator: the number of values, their chi-squared against the fit (where uncertainties are stated) and their mean relative deviation from it; or a note when the dataset’s quantity has no comparison yet. A validator may take a wavelength window (
range_nm); one that is also fitted, in another window, is compared at its fitted scale.