Skip to content

Commit

Permalink
Formula dispersion (#122)
Browse files Browse the repository at this point in the history
* Adds draft for formula dispersion init function

* Adds working diel-func formula dispersion

* Adds FormulaIndex dispersion

* Adds formula dispersion represenation test

* Adds nexus dispersive material load function

* Adds grammar file to manifest

* Clean unit check for formula dispersion

* Removes unecessary code

* Regenerate requirements

* Adds nexus dispersive material testing files

* Dispersions remodelling

* Correctly add dispersions via *args

* Adds quoting for fitting install in README

* Adds converter functions between index and dielectric dispersions

* Adds index based adding and fixes rii

* Re-enable index based nexus file

* Adds parametrization for adding tests

* Adds nexus dispersion tests

* Fix parameter order in custom sellmeier (#127)

* Update discord link

* Update discord badge

* Adds absolute delta range

* Adds support for 0,360 delta range

* Return self in `as_delta_range`

* Adds tests

* Fix parameter order in custom sellmeier

Fixes #126

* Fix documentation

---------

Co-authored-by: domna <[email protected]>

---------

Co-authored-by: Marius Müller <[email protected]>
  • Loading branch information
domna and MarJMue authored Apr 15, 2023
1 parent 98b61f4 commit 5b9d41b
Show file tree
Hide file tree
Showing 37 changed files with 1,331 additions and 1,132 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
recursive-include src/elli/database/refractiveindexinfo-database *.yml
recursive-include src/elli/database/refractiveindexinfo-database *.yml
include src/elli/formula_parser/dispersion_function_grammer.lark
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ the folder to install it in development mode:
```sh
git clone https://github.com/PyEllips/pyElli
cd pyElli
pip install -e .[fitting]
pip install -e ".[fitting]"
```

## Acknowledgements
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ dependencies = [
"h5py",
"pyyaml",
"importlib-resources",
"rapidfuzz"
"rapidfuzz",
"lark>=1.1.5",
"pint",
]

[project.optional-dependencies]
Expand Down
29 changes: 27 additions & 2 deletions requirements/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
#
# pip-compile --extra=fitting --extra=testing --generate-hashes --output-file=requirements/dev-requirements.txt pyproject.toml requirements/fitting-requirements.txt
#
Expand Down Expand Up @@ -292,6 +292,12 @@ h5py==3.7.0 \
# via
# -r requirements/fitting-requirements.txt
# pyElli (pyproject.toml)
importlib-metadata==6.0.0 \
--hash=sha256:7efb448ec9a5e313a57655d35aa54cd3e01b7e1fbcf72dce1bf06119420f5bad \
--hash=sha256:e354bedeb60efa6affdcc8ae121b73544a7aa74156d047311948f6d711cd378d
# via
# -r requirements/fitting-requirements.txt
# nbconvert
importlib-resources==5.10.0 \
--hash=sha256:c01b1b94210d9849f286b86bb51bcea7cd56dde0600d8db721d7b81330711668 \
--hash=sha256:ee17ec648f85480d523596ce49eae8ead87d5631ae1551f913c0100b5edd3437
Expand Down Expand Up @@ -451,6 +457,12 @@ kiwisolver==1.4.4 \
# via
# -r requirements/fitting-requirements.txt
# matplotlib
lark==1.1.5 \
--hash=sha256:4b534eae1f9af5b4ea000bea95776350befe1981658eea3820a01c37e504bb4d \
--hash=sha256:8476f9903e93fbde4f6c327f74d79e9b4bd0ed9294c5dfa3164ab8c581b5de2a
# via
# -r requirements/fitting-requirements.txt
# pyElli (pyproject.toml)
lmfit==1.0.3 \
--hash=sha256:d067c3ea501f035af5d3c079e6e6e35dc3cc1ac7d439429a425b0aeb5a7858a2
# via
Expand Down Expand Up @@ -828,6 +840,12 @@ pillow==9.3.0 \
# via
# -r requirements/fitting-requirements.txt
# matplotlib
pint==0.20.1 \
--hash=sha256:387cf04078dc7dfe4a708033baad54ab61d82ab06c4ee3d4922b1e45d5626067 \
--hash=sha256:68afe65665542ee3ec99f69f043b1d39bfe7c6d61b786940157138fd08b838fb
# via
# -r requirements/fitting-requirements.txt
# pyElli (pyproject.toml)
plotly==5.10.0 \
--hash=sha256:4d36d9859b7a153b273562deeed8c292587a472eb1fd57cd4158ec89d9defadb \
--hash=sha256:989b13825cc974390aa0169479485d9257d37848a47bc63957251f8e1a7046ba
Expand Down Expand Up @@ -1382,3 +1400,10 @@ widgetsnbextension==3.6.1 \
# via
# -r requirements/fitting-requirements.txt
# ipywidgets
zipp==3.15.0 \
--hash=sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b \
--hash=sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556
# via
# -r requirements/fitting-requirements.txt
# importlib-metadata
# importlib-resources
27 changes: 25 additions & 2 deletions requirements/fitting-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
#
# pip-compile --extra=fitting --generate-hashes --output-file=requirements/fitting-requirements.txt pyproject.toml requirements/requirements.txt
#
Expand Down Expand Up @@ -202,6 +202,10 @@ h5py==3.7.0 \
# via
# -r requirements/requirements.txt
# pyElli (pyproject.toml)
importlib-metadata==6.0.0 \
--hash=sha256:7efb448ec9a5e313a57655d35aa54cd3e01b7e1fbcf72dce1bf06119420f5bad \
--hash=sha256:e354bedeb60efa6affdcc8ae121b73544a7aa74156d047311948f6d711cd378d
# via nbconvert
importlib-resources==5.10.0 \
--hash=sha256:c01b1b94210d9849f286b86bb51bcea7cd56dde0600d8db721d7b81330711668 \
--hash=sha256:ee17ec648f85480d523596ce49eae8ead87d5631ae1551f913c0100b5edd3437
Expand Down Expand Up @@ -338,6 +342,12 @@ kiwisolver==1.4.4 \
--hash=sha256:f8ad8285b01b0d4695102546b342b493b3ccc6781fc28c8c6a1bb63e95d22f09 \
--hash=sha256:f9f39e2f049db33a908319cf46624a569b36983c7c78318e9726a4cb8923b26c
# via matplotlib
lark==1.1.5 \
--hash=sha256:4b534eae1f9af5b4ea000bea95776350befe1981658eea3820a01c37e504bb4d \
--hash=sha256:8476f9903e93fbde4f6c327f74d79e9b4bd0ed9294c5dfa3164ab8c581b5de2a
# via
# -r requirements/requirements.txt
# pyElli (pyproject.toml)
lmfit==1.0.3 \
--hash=sha256:d067c3ea501f035af5d3c079e6e6e35dc3cc1ac7d439429a425b0aeb5a7858a2
# via pyElli (pyproject.toml)
Expand Down Expand Up @@ -679,6 +689,12 @@ pillow==9.3.0 \
--hash=sha256:ebf2029c1f464c59b8bdbe5143c79fa2045a581ac53679733d3a91d400ff9efb \
--hash=sha256:f1ff2ee69f10f13a9596480335f406dd1f70c3650349e2be67ca3139280cade0
# via matplotlib
pint==0.20.1 \
--hash=sha256:387cf04078dc7dfe4a708033baad54ab61d82ab06c4ee3d4922b1e45d5626067 \
--hash=sha256:68afe65665542ee3ec99f69f043b1d39bfe7c6d61b786940157138fd08b838fb
# via
# -r requirements/requirements.txt
# pyElli (pyproject.toml)
plotly==5.10.0 \
--hash=sha256:4d36d9859b7a153b273562deeed8c292587a472eb1fd57cd4158ec89d9defadb \
--hash=sha256:989b13825cc974390aa0169479485d9257d37848a47bc63957251f8e1a7046ba
Expand Down Expand Up @@ -1126,3 +1142,10 @@ widgetsnbextension==3.6.1 \
--hash=sha256:954e0faefdd414e4e013f17dbc7fd86f24cf1d243a3ac85d5f0fc2c2d2b50c66 \
--hash=sha256:9c84ae64c2893c7cbe2eaafc7505221a795c27d68938454034ac487319a75b10
# via ipywidgets
zipp==3.15.0 \
--hash=sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b \
--hash=sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556
# via
# -r requirements/requirements.txt
# importlib-metadata
# importlib-resources
16 changes: 14 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
#
# pip-compile --generate-hashes --output-file=requirements/requirements.txt pyproject.toml
#
Expand Down Expand Up @@ -30,6 +30,10 @@ importlib-resources==5.10.0 \
--hash=sha256:c01b1b94210d9849f286b86bb51bcea7cd56dde0600d8db721d7b81330711668 \
--hash=sha256:ee17ec648f85480d523596ce49eae8ead87d5631ae1551f913c0100b5edd3437
# via pyElli (pyproject.toml)
lark==1.1.5 \
--hash=sha256:4b534eae1f9af5b4ea000bea95776350befe1981658eea3820a01c37e504bb4d \
--hash=sha256:8476f9903e93fbde4f6c327f74d79e9b4bd0ed9294c5dfa3164ab8c581b5de2a
# via pyElli (pyproject.toml)
numpy==1.23.2 \
--hash=sha256:17e5226674f6ea79e14e3b91bfbc153fdf3ac13f5cc54ee7bc8fdbe820a32da0 \
--hash=sha256:2bd879d3ca4b6f39b7770829f73278b7c5e248c91d538aab1e506c628353e47f \
Expand Down Expand Up @@ -87,6 +91,10 @@ pandas==1.4.4 \
--hash=sha256:e7cc960959be28d064faefc0cb2aef854d46b827c004ebea7e79b5497ed83e7d \
--hash=sha256:ee6f1848148ed3204235967613b0a32be2d77f214e9623f554511047705c1e04
# via pyElli (pyproject.toml)
pint==0.20.1 \
--hash=sha256:387cf04078dc7dfe4a708033baad54ab61d82ab06c4ee3d4922b1e45d5626067 \
--hash=sha256:68afe65665542ee3ec99f69f043b1d39bfe7c6d61b786940157138fd08b838fb
# via pyElli (pyproject.toml)
python-dateutil==2.8.2 \
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9
Expand Down Expand Up @@ -270,3 +278,7 @@ six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
# via python-dateutil
zipp==3.15.0 \
--hash=sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b \
--hash=sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556
# via importlib-resources
23 changes: 21 additions & 2 deletions src/elli/database/refractive_index_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
SellmeierCustomExponent,
Table,
)
from ..dispersions.base_dispersion import Dispersion, DispersionSum
from ..dispersions.base_dispersion import (
Dispersion,
DispersionSum,
IndexDispersion,
IndexDispersionSum,
)
from ..materials import IsotropicMaterial

WavelengthFilterType = Union[
Expand Down Expand Up @@ -282,7 +287,9 @@ def get_mat(self, book: str, page: str) -> IsotropicMaterial:
"""
return IsotropicMaterial(self.load_dispersion(book, page))

def load_dispersion(self, book: str, page: str) -> Dispersion:
def load_dispersion(
self, book: str, page: str
) -> Union[Dispersion, IndexDispersion]:
"""Load a dispersion from the refractive index database.
Selection by material and source identifiers.
Expand All @@ -307,6 +314,7 @@ def load_dispersion(self, book: str, page: str) -> Dispersion:
)

dispersion_list = []
contains_index_dispersion = False

for dispersion_relation in yml_file["DATA"]:
if dispersion_relation["type"] == "tabulated nk":
Expand All @@ -319,6 +327,7 @@ def load_dispersion(self, book: str, page: str) -> Dispersion:
df.set_index("Wavelength", inplace=True)

dispersion = Table(lbda=df.index, n=df["n"] + 1j * df["k"])
contains_index_dispersion = True

elif dispersion_relation["type"] == "tabulated n":
df = pd.read_table(
Expand All @@ -330,6 +339,7 @@ def load_dispersion(self, book: str, page: str) -> Dispersion:
df.set_index("Wavelength", inplace=True)

dispersion = Table(lbda=df.index, n=df["n"])
contains_index_dispersion = True

elif dispersion_relation["type"] == "tabulated k":
df = pd.read_table(
Expand All @@ -341,6 +351,7 @@ def load_dispersion(self, book: str, page: str) -> Dispersion:
df.set_index("Wavelength", inplace=True)

dispersion = Table(lbda=df.index, n=0 + 1j * df["k"])
contains_index_dispersion = True

elif dispersion_relation["type"] == "formula 1":
coeffs = list(
Expand Down Expand Up @@ -415,6 +426,7 @@ def load_dispersion(self, book: str, page: str) -> Dispersion:
cauchy.add(f_i / 1e3**e_i, e_i)

dispersion = cauchy
contains_index_dispersion = True

else:
raise ValueError("Unimplemented Format.")
Expand All @@ -423,6 +435,13 @@ def load_dispersion(self, book: str, page: str) -> Dispersion:

if len(dispersion_list) == 1:
return dispersion_list[0]

if contains_index_dispersion:
for i, dispersion in enumerate(dispersion_list):
if not isinstance(dispersion, IndexDispersion):
dispersion_list[i] = dispersion.as_index()

return IndexDispersionSum(*dispersion_list)
return DispersionSum(*dispersion_list)

def get_reference(self, book: str, page: str) -> str:
Expand Down
1 change: 1 addition & 0 deletions src/elli/dispersions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
from .tauc_lorentz import TaucLorentz
from .cody_lorentz import CodyLorentz
from .pseudo_dielectric import PseudoDielectricFunction
from .formula import Formula, FormulaIndex
Loading

0 comments on commit 5b9d41b

Please sign in to comment.