Skip to content

Commit 68a00ce

Browse files
feat: ✨ Add Orca Gaussian distribution model and update documentation (#1886)
* feat: ✨ Add Orca Gaussian distribution model and update documentation * fix: 🧪 Update reference keys to include 'orcagaussian' and 'lorentzian' models * refactor: ♻️ Refactor code structure for improved readability and maintainability * fix: 🧪 Fix Orca Gaussian model and update tests for distribution models * chore: 📝 Update docstring to use raw string for core Gaussian calculation * fix: ✅ Add WidthAPI class for ORCA Gaussian model and update related tests * fix: 🧪 Update Orca Gaussian model to use 'width' parameter and adjust related tests * fix: 🧪 Update Gaussian model to use 'x_0' parameter and add tests for auto-parameter detection * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: ✅ Refactor test functions in TestDefineParametersAuto for improved type hints and readability * fix: ✅ Move Callable import under TYPE_CHECKING for improved clarity and organization * chore: 🐛 Refactor imports and update linting configurations - Consolidated multiple import statements into single lines for improved readability across various modules. - Updated the linting configuration in trunk.yaml to enable isort and disable black. - Removed unused imports and organized existing ones in several files to adhere to PEP 8 standards. - Enhanced code clarity and maintainability by restructuring import statements in the spectrafit package. * fix: ✅ Simplify Callable import logic for better readability --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 60ad302 commit 68a00ce

46 files changed

Lines changed: 4149 additions & 3948 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.trunk/trunk.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ runtimes:
1919
lint:
2020
disabled:
2121
- black
22-
- isort
2322
- markdown-table-prettify
2423
enabled:
25-
- markdown-table-prettify@3.6.0
24+
- isort@6.0.1
2625
- pre-commit-hooks@5.0.0:
2726
commands:
2827
- end-of-file-fixer

docs/doc/models.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ tags:
4343

4444
Bell-shaped curve widely used for modeling spectral peaks.
4545

46+
- :material-function-variant: **[Orca Gaussian Distribution](#orca-gaussian-distribution)**
47+
48+
Variant of Gaussian distribution with specific parameters.
49+
4650
- :material-function-variant: **[Lorentzian Distribution](#lorentzian-distribution)**
4751

4852
Distribution with wider tails than Gaussian, common in resonance phenomena.
@@ -155,6 +159,35 @@ Where:
155159
}
156160
```
157161

162+
### Orca Gaussian Distribution
163+
164+
The [Orca][1] Gaussian distribution is a variant of the Gaussian distribution, defined by its amplitude, center, and width:
165+
$$f(x) = \frac{A}{\sigma\sqrt{2\pi}} \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)$$
166+
167+
It is similar to the standard Gaussian distribution but uses a different notation for the amplitude with respect to the implementation in the [`orca_mapspc`][2].
168+
169+
Where:
170+
171+
- $A$ is the amplitude
172+
- $\mu$ is the center (mean)
173+
- $\sigma$ is related to the full width at half maximum (FWHM) by $\text{FWHM} = 2\sigma\sqrt{2\ln{2}}$
174+
175+
!!! example "ORCA Gaussian Model Parameters"
176+
177+
```json
178+
{
179+
"peaks": {
180+
"1": {
181+
"gaussian": {
182+
"amplitude": {"max": 2, "min": 0, "vary": true, "value": 1},
183+
"center": {"max": 2, "min": -2, "vary": true, "value": 0},
184+
"fwhmg": {"max": 0.5, "min": 0.02, "vary": true, "value": 0.1}
185+
}
186+
}
187+
}
188+
}
189+
```
190+
158191
### Lorentzian Distribution
159192

160193
The Lorentzian distribution, also known as the Cauchy distribution, is characterized by wider tails compared to the Gaussian distribution:
@@ -351,3 +384,6 @@ For calculating the models, a few math constants are needed, which are implement
351384
- [Fitting Documentation](fitting.md)
352385
- [API Reference](../api/modelling_api.md)
353386
- [Changelog](../changelog.md)
387+
388+
[1]: https://www.faccts.de/docs/orca/6.0/manual/#
389+
[2]: https://www.faccts.de/docs/orca/6.0/manual/contents/detailed/utilities.html

includes/abbreviations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
*[Normalization]: Scaling data to a common range or standard, often between 0 and 1 or based on a specific feature
7878
*[NumPy]: Fundamental package for scientific computing with Python
7979
*[Objective Function]: The function that an optimization algorithm seeks to minimize or maximize (e.g., sum of squared residuals in Least-Squares)
80+
*[ORCA]: A computational chemistry software package for quantum chemistry calculations
8081
*[Optimizer]: The algorithm (e.g., Levenberg-Marquardt, Nelder-Mead) used by the Minimizer to find the best-fit Parameters
8182
*[Overfitting]: Fitting a model too closely to the noise or random fluctuations in the data, rather than the underlying trend
8283
*[Pandas DataFrames]: Two-dimensional, size-mutable, and potentially heterogeneous tabular data structures in the Pandas Python library

spectrafit/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313

1414
import sys
1515
import warnings
16-
1716
from typing import Tuple
1817

1918
from typing_extensions import Literal
2019

21-
2220
PYTHON_END_OF_LIFE: Tuple[Literal[3], Literal[8]] = (3, 8)
2321

2422
if sys.version_info[:2] == PYTHON_END_OF_LIFE:

spectrafit/api/cmd_model.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44
from getpass import getuser
55
from hashlib import sha256
66
from socket import gethostname
7-
from typing import Any
8-
from typing import Dict
9-
from typing import List
10-
from typing import Optional
11-
from typing import Union
7+
from typing import Any, Dict, List, Optional, Union
128
from uuid import uuid4
139

14-
from pydantic import BaseModel
15-
from pydantic import Field
16-
from pydantic import HttpUrl
10+
from pydantic import BaseModel, Field, HttpUrl
1711
from pydantic.functional_validators import field_validator
12+
1813
from spectrafit import __version__
19-
from spectrafit.api.tools_model import AutopeakAPI
20-
from spectrafit.api.tools_model import DataPreProcessingAPI
21-
from spectrafit.api.tools_model import GlobalFittingAPI
14+
from spectrafit.api.tools_model import (
15+
AutopeakAPI,
16+
DataPreProcessingAPI,
17+
GlobalFittingAPI,
18+
)
2219

2320

2421
class DescriptionAPI(BaseModel):

spectrafit/api/file_model.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
"""Definition of the data file model."""
22

33
from pathlib import Path
4-
from typing import Callable
5-
from typing import List
6-
from typing import Optional
7-
from typing import Union
4+
from typing import Callable, List, Optional, Union
85

9-
from pydantic import BaseModel
10-
from pydantic import Field
6+
from pydantic import BaseModel, Field
117
from pydantic.functional_validators import field_validator
128

139

spectrafit/api/models_model.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
"""Reference model for the API of the models distributions."""
22

3-
from typing import Callable
4-
from typing import List
5-
from typing import Optional
6-
7-
from pydantic import BaseModel
8-
from pydantic import Field
3+
from typing import Callable, List, Optional
94

5+
from pydantic import BaseModel, Field
106

117
__description__ = "Lmfit expression for explicit dependencies."
128

@@ -99,6 +95,16 @@ class FwhmvAPI(BaseModel):
9995
expr: Optional[str] = Field(default=None, description=__description__)
10096

10197

98+
class WidthAPI(BaseModel):
99+
"""Definition of the Width of the ORCA Gaussian of the models distributions."""
100+
101+
max: Optional[float] = Field(default=None, description="Maximum width.")
102+
min: Optional[int] = Field(default=None, description="Minimum width.")
103+
vary: bool = Field(default=True, description="Vary the width.")
104+
value: Optional[float] = Field(default=None, description="Initial width value.")
105+
expr: Optional[str] = Field(default=None, description=__description__)
106+
107+
102108
class GammaAPI(BaseModel):
103109
"""Definition of the Gamma of the Voigt of the models distributions."""
104110

@@ -190,6 +196,14 @@ class GaussianAPI(BaseModel):
190196
fwhmg: FwhmgAPI = FwhmgAPI()
191197

192198

199+
class OrcaGaussianAPI(BaseModel):
200+
"""Definition of the ORCA Gaussian of the models distributions."""
201+
202+
amplitude: AmplitudeAPI = AmplitudeAPI()
203+
center: CenterAPI = CenterAPI()
204+
width: WidthAPI = WidthAPI()
205+
206+
193207
class LorentzianAPI(BaseModel):
194208
"""Definition of the Lorentzian of the models distributions."""
195209

@@ -371,6 +385,7 @@ class DistributionModelAPI(BaseModel):
371385
"""Definition of the models distributions."""
372386

373387
gaussian: GaussianAPI = GaussianAPI()
388+
orcagaussian: OrcaGaussianAPI = OrcaGaussianAPI()
374389
lorentzian: LorentzianAPI = LorentzianAPI()
375390
voigt: VoigtAPI = VoigtAPI()
376391
pseudovoigt: PseudovoigtAPI = PseudovoigtAPI()

spectrafit/api/notebook_model.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
"""Reference model for the API of the Jupyter Notebook interface."""
22

3-
from typing import List
4-
from typing import Optional
5-
from typing import Tuple
6-
from typing import Union
7-
8-
from _plotly_utils.colors.carto import Burg
9-
from _plotly_utils.colors.carto import Purp_r
10-
from _plotly_utils.colors.carto import Teal_r
3+
from typing import List, Optional, Tuple, Union
4+
5+
from _plotly_utils.colors.carto import Burg, Purp_r, Teal_r
116
from _plotly_utils.colors.qualitative import Plotly as PlotlyColors
12-
from pydantic import BaseModel
13-
from pydantic import Field
7+
from pydantic import BaseModel, Field
148
from pydantic.functional_validators import field_validator
159

1610

spectrafit/api/pptx_model.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@
22

33
import re
44
import tempfile
5-
65
from pathlib import Path
7-
from typing import Dict
8-
from typing import List
9-
from typing import Tuple
10-
from typing import Type
11-
from typing import Union
6+
from typing import Dict, List, Tuple, Type, Union
127

138
import pandas as pd
149
import pkg_resources
15-
1610
from matplotlib import pyplot as plt
1711
from pptx.util import Pt
18-
from pydantic import BaseModel
19-
from pydantic import ConfigDict
20-
from pydantic import Field
21-
from pydantic import field_validator
12+
from pydantic import BaseModel, ConfigDict, Field, field_validator
13+
2214
from spectrafit import __version__
2315
from spectrafit.plotting import PlotSpectra
2416

spectrafit/api/report_model.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
"""Reference model for the API of the Jupyter Notebook report."""
22

3-
from typing import Any
4-
from typing import Dict
5-
from typing import Hashable
6-
from typing import List
7-
from typing import Union
3+
from typing import Any, Dict, Hashable, List, Union
84

95
from dtale import __version__ as dtale_version
106
from emcee import __version__ as emcee_version
@@ -14,15 +10,14 @@
1410
from numpy import __version__ as numpy_version
1511
from pandas import __version__ as pandas_version
1612
from plotly import __version__ as plotly_version
17-
from pydantic import BaseModel
18-
from pydantic import ConfigDict
19-
from pydantic import Field
13+
from pydantic import BaseModel, ConfigDict, Field
2014
from pydantic import __version__ as pydantic_version
2115
from scipy import __version__ as scipy_version
2216
from sklearn import __version__ as sklearn_version
17+
from statsmodels import __version__ as statsmodels_version
18+
2319
from spectrafit.api.cmd_model import DescriptionAPI
2420
from spectrafit.api.tools_model import DataPreProcessingAPI
25-
from statsmodels import __version__ as statsmodels_version
2621

2722

2823
class CreditsAPI(BaseModel):

0 commit comments

Comments
 (0)