PyOptik 1.10.1__tar.gz → 1.10.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. {pyoptik-1.10.1 → pyoptik-1.10.6}/.github/workflows/deploy_documentation.yml +3 -0
  2. {pyoptik-1.10.1 → pyoptik-1.10.6}/PKG-INFO +2 -2
  3. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/_version.py +2 -2
  4. pyoptik-1.10.6/PyOptik/utils.py +45 -0
  5. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik.egg-info/PKG-INFO +2 -2
  6. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik.egg-info/SOURCES.txt +1 -1
  7. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik.egg-info/requires.txt +1 -1
  8. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/tabulated/plot_silver.py +0 -1
  9. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/source/conf.py +0 -1
  10. {pyoptik-1.10.1 → pyoptik-1.10.6}/pyproject.toml +1 -1
  11. pyoptik-1.10.6/tests/test_utils.py +166 -0
  12. pyoptik-1.10.1/PyOptik/utils.py +0 -45
  13. pyoptik-1.10.1/tests/test_utils.py +0 -168
  14. {pyoptik-1.10.1 → pyoptik-1.10.6}/.flake8 +0 -0
  15. {pyoptik-1.10.1 → pyoptik-1.10.6}/.github/dependabot.yml +0 -0
  16. {pyoptik-1.10.1 → pyoptik-1.10.6}/.github/workflows/deploy_PyPi.yml +0 -0
  17. {pyoptik-1.10.1 → pyoptik-1.10.6}/.github/workflows/deploy_anaconda.yml +0 -0
  18. {pyoptik-1.10.1 → pyoptik-1.10.6}/.github/workflows/deploy_coverage.yml +0 -0
  19. {pyoptik-1.10.1 → pyoptik-1.10.6}/.gitignore +0 -0
  20. {pyoptik-1.10.1 → pyoptik-1.10.6}/.readthedocs.yml +0 -0
  21. {pyoptik-1.10.1 → pyoptik-1.10.6}/LICENSE +0 -0
  22. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/__init__.py +0 -0
  23. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/__main__.py +0 -0
  24. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/__init__.py +0 -0
  25. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/BAF10.yml +0 -0
  26. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/BAK1.yml +0 -0
  27. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/FK51A.yml +0 -0
  28. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/LASF9.yml +0 -0
  29. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/SF10.yml +0 -0
  30. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/SF11.yml +0 -0
  31. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/SF5.yml +0 -0
  32. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/ZBLAN.yml +0 -0
  33. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/acetone.yml +0 -0
  34. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/acetylene.yml +0 -0
  35. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/air.yml +0 -0
  36. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/argon.yml +0 -0
  37. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/cellulose.yml +0 -0
  38. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/crown.yml +0 -0
  39. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/ethane.yml +0 -0
  40. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/ethanol.yml +0 -0
  41. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/ethylene.yml +0 -0
  42. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/flint.yml +0 -0
  43. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/fused_silica.yml +0 -0
  44. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/germanium.yml +0 -0
  45. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/glycerol.yml +0 -0
  46. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/lithium_niobate.yml +0 -0
  47. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/methane.yml +0 -0
  48. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/methanol.yml +0 -0
  49. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/polycarbonate.yml +0 -0
  50. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/polystyren.yml +0 -0
  51. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/polystyrene.yml +0 -0
  52. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/propanol.yml +0 -0
  53. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/pvc.yml +0 -0
  54. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/soda_lime_glass.yml +0 -0
  55. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/sellmeier/water.yml +0 -0
  56. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/BK7.yml +0 -0
  57. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/aluminium.yml +0 -0
  58. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/bismuth.yml +0 -0
  59. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/calcium.yml +0 -0
  60. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/chromium.yml +0 -0
  61. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/copper.yml +0 -0
  62. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/gold.yml +0 -0
  63. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/iron.yml +0 -0
  64. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/lead.yml +0 -0
  65. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/magnesium.yml +0 -0
  66. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/nickel.yml +0 -0
  67. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/paladium.yml +0 -0
  68. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/polyetylene.yml +0 -0
  69. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/pva.yml +0 -0
  70. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/rhodium.yml +0 -0
  71. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/silicon.yml +0 -0
  72. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/silver.yml +0 -0
  73. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/sodium.yml +0 -0
  74. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/tantalum.yml +0 -0
  75. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/titanium.yml +0 -0
  76. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/tungsten.yml +0 -0
  77. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/vanadium.yml +0 -0
  78. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/data/tabulated/zinc.yml +0 -0
  79. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/directories.py +0 -0
  80. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/libraries/__init__.py +0 -0
  81. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/libraries/classics.yml +0 -0
  82. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/libraries/dielectrics.yml +0 -0
  83. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/libraries/metals.yml +0 -0
  84. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/libraries/minimal.yml +0 -0
  85. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/libraries/organics.yml +0 -0
  86. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/libraries/others.yml +0 -0
  87. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/libraries/polymers.yml +0 -0
  88. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/libraries/repertoire.yml +0 -0
  89. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/material/__init__.py +0 -0
  90. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/material/base_class.py +0 -0
  91. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/material/sellmeier_class.py +0 -0
  92. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/material/tabulated_class.py +0 -0
  93. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/material_bank.py +0 -0
  94. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/material_type.py +0 -0
  95. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik/units.py +0 -0
  96. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik.egg-info/dependency_links.txt +0 -0
  97. {pyoptik-1.10.1 → pyoptik-1.10.6}/PyOptik.egg-info/top_level.txt +0 -0
  98. {pyoptik-1.10.1 → pyoptik-1.10.6}/README.rst +0 -0
  99. {pyoptik-1.10.1 → pyoptik-1.10.6}/development/dev_0.py +0 -0
  100. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/Makefile +0 -0
  101. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/README.rst +0 -0
  102. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/sellmeier/README.rst +0 -0
  103. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/sellmeier/plot_bk7.py +0 -0
  104. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/sellmeier/plot_silica.py +0 -0
  105. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/sellmeier/plot_water.py +0 -0
  106. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/tabulated/README.rst +0 -0
  107. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/tabulated/plot_sf5.py +0 -0
  108. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/utils/README.rst +0 -0
  109. /pyoptik-1.10.1/docs/examples/utils/build_library.py → /pyoptik-1.10.6/docs/examples/utils/__build_library.py +0 -0
  110. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/utils/__download_yml_file.py +0 -0
  111. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/utils/create_sellmeier_file.py +0 -0
  112. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/examples/utils/create_tabulated_file.py +0 -0
  113. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/images/example_bk7.png +0 -0
  114. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/images/logo.png +0 -0
  115. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/make.bat +0 -0
  116. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/source/_static/default.css +0 -0
  117. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/source/_static/thumbnail.png +0 -0
  118. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/source/code.rst +0 -0
  119. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/source/gallery/index.rst +0 -0
  120. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/source/index.rst +0 -0
  121. {pyoptik-1.10.1 → pyoptik-1.10.6}/docs/source/references.rst +0 -0
  122. {pyoptik-1.10.1 → pyoptik-1.10.6}/meta.yaml +0 -0
  123. {pyoptik-1.10.1 → pyoptik-1.10.6}/setup.cfg +0 -0
  124. {pyoptik-1.10.1 → pyoptik-1.10.6}/tests/__init__.py +0 -0
  125. {pyoptik-1.10.1 → pyoptik-1.10.6}/tests/test_sellmeier.py +0 -0
  126. {pyoptik-1.10.1 → pyoptik-1.10.6}/tests/test_tabulated.py +0 -0
  127. {pyoptik-1.10.1 → pyoptik-1.10.6}/tests/test_usual_material.py +0 -0
@@ -8,6 +8,9 @@ on:
8
8
  pull_request:
9
9
  branches: [ "master" ]
10
10
 
11
+ concurrency:
12
+ group: ${{ github.workflow }}-${{ github.ref }}
13
+ cancel-in-progress: true
11
14
 
12
15
  # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13
16
  permissions:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyOptik
3
- Version: 1.10.1
3
+ Version: 1.10.6
4
4
  Summary: A package for refractive index values.
5
5
  Author-email: Martin Poinsinet de Sivry-Houle <martin.poinsinet.de.sivry@gmail.com>
6
6
  License: MIT License
@@ -43,7 +43,7 @@ Requires-Dist: numpy
43
43
  Requires-Dist: matplotlib~=3.8
44
44
  Requires-Dist: requests~=2.31
45
45
  Requires-Dist: pyyaml~=6.0
46
- Requires-Dist: MPSPlots~=1.5.1
46
+ Requires-Dist: MPSPlots>=1.6
47
47
  Requires-Dist: tabulate~=0.9
48
48
  Provides-Extra: testing
49
49
  Requires-Dist: pytest<9.0,>=7.4; extra == "testing"
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '1.10.1'
21
- __version_tuple__ = version_tuple = (1, 10, 1)
20
+ __version__ = version = '1.10.6'
21
+ __version_tuple__ = version_tuple = (1, 10, 6)
@@ -0,0 +1,45 @@
1
+ from PyOptik.directories import sellmeier_data_path, tabulated_data_path
2
+ from PyOptik.material_type import MaterialType
3
+ import requests
4
+ import logging
5
+
6
+
7
+ logging.basicConfig(
8
+ level=logging.INFO,
9
+ format="%(asctime)s %(levelname)s %(message)s",
10
+ )
11
+
12
+ def download_yml_file(url: str, filename: str, location: MaterialType) -> None:
13
+ """
14
+ Downloads a .yml file from a specified URL and saves it locally.
15
+ """
16
+ match location:
17
+ case MaterialType.SELLMEIER:
18
+ file_path = sellmeier_data_path / f"{filename}.yml"
19
+ case MaterialType.TABULATED:
20
+ file_path = tabulated_data_path / f"{filename}.yml"
21
+ case _:
22
+ raise ValueError(f"Location [{location}] is invalid, it can be either MaterialType.SELLMEIER or MaterialType.TABULATED")
23
+
24
+
25
+ logging.info(f"Starting download of {url!r} → {file_path!s}")
26
+ try:
27
+ response = requests.get(url, timeout=10)
28
+ logging.info(f"Received response: HTTP {response.status_code}")
29
+ response.raise_for_status()
30
+
31
+ file_path.parent.mkdir(parents=True, exist_ok=True)
32
+
33
+ with open(file_path, "wb") as f:
34
+ f.write(response.content)
35
+ logging.info(f"File downloaded and saved to {file_path}")
36
+
37
+ except requests.exceptions.Timeout as e:
38
+ logging.error(f"Timeout after 10 s when fetching {url!r}: {e}")
39
+ raise
40
+ except requests.exceptions.HTTPError as e:
41
+ logging.error(f"HTTP error while fetching {url!r}: {e}")
42
+ raise
43
+ except Exception as e:
44
+ logging.error(f"Unexpected error: {e}")
45
+ raise
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyOptik
3
- Version: 1.10.1
3
+ Version: 1.10.6
4
4
  Summary: A package for refractive index values.
5
5
  Author-email: Martin Poinsinet de Sivry-Houle <martin.poinsinet.de.sivry@gmail.com>
6
6
  License: MIT License
@@ -43,7 +43,7 @@ Requires-Dist: numpy
43
43
  Requires-Dist: matplotlib~=3.8
44
44
  Requires-Dist: requests~=2.31
45
45
  Requires-Dist: pyyaml~=6.0
46
- Requires-Dist: MPSPlots~=1.5.1
46
+ Requires-Dist: MPSPlots>=1.6
47
47
  Requires-Dist: tabulate~=0.9
48
48
  Provides-Extra: testing
49
49
  Requires-Dist: pytest<9.0,>=7.4; extra == "testing"
@@ -103,8 +103,8 @@ docs/examples/tabulated/README.rst
103
103
  docs/examples/tabulated/plot_sf5.py
104
104
  docs/examples/tabulated/plot_silver.py
105
105
  docs/examples/utils/README.rst
106
+ docs/examples/utils/__build_library.py
106
107
  docs/examples/utils/__download_yml_file.py
107
- docs/examples/utils/build_library.py
108
108
  docs/examples/utils/create_sellmeier_file.py
109
109
  docs/examples/utils/create_tabulated_file.py
110
110
  docs/images/example_bk7.png
@@ -5,7 +5,7 @@ numpy
5
5
  matplotlib~=3.8
6
6
  requests~=2.31
7
7
  pyyaml~=6.0
8
- MPSPlots~=1.5.1
8
+ MPSPlots>=1.6
9
9
  tabulate~=0.9
10
10
 
11
11
  [dev]
@@ -9,7 +9,6 @@ This module demonstrates the usage of the PyOptik library to calculate and plot
9
9
  # %%
10
10
  import numpy
11
11
  from PyOptik import MaterialBank
12
- MaterialBank.build_library('metals')
13
12
 
14
13
  # Initialize the material with the Sellmeier model
15
14
  material = MaterialBank.silver
@@ -35,7 +35,6 @@ author = 'Martin Poinsinet de Sivry-Houle'
35
35
 
36
36
  extensions = [
37
37
  'sphinx.ext.mathjax',
38
- 'pyvista.ext.plot_directive',
39
38
  'sphinx_gallery.gen_gallery',
40
39
  'sphinx.ext.autodoc',
41
40
  'sphinx.ext.napoleon',
@@ -30,7 +30,7 @@ dependencies = [
30
30
  "matplotlib ~=3.8",
31
31
  "requests ~=2.31",
32
32
  "pyyaml ~=6.0",
33
- "MPSPlots ~=1.5.1",
33
+ "MPSPlots >=1.6",
34
34
  "tabulate ~=0.9",
35
35
  ]
36
36
 
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import pytest
5
+ # from PyOptik import MaterialBank, MaterialType
6
+ # from PyOptik.utils import download_yml_file
7
+
8
+ # MaterialBank.set_filter(use_sellmeier=True, use_tabulated=True)
9
+
10
+
11
+ # def test_main():
12
+ # MaterialBank.build_library('minimal', remove_previous=True)
13
+
14
+ # url_water = 'https://refractiveindex.info/database/data/main/H2O/nk/Daimon-19.0C.yml'
15
+
16
+ # def test_download_yml_files():
17
+ # """
18
+ # Test downloading YAML files to different locations. Ensures that files are
19
+ # correctly downloaded from a given URL to the specified directory.
20
+ # """
21
+ # download_yml_file(
22
+ # filename='test_tabulated',
23
+ # url=url_water,
24
+ # location=MaterialType.TABULATED
25
+ # )
26
+
27
+ # download_yml_file(
28
+ # filename='test_sellmeier',
29
+ # url=url_water,
30
+ # location=MaterialType.SELLMEIER
31
+ # )
32
+
33
+
34
+ # def test_add_custom():
35
+ # MaterialBank.add_tabulated_to_bank(
36
+ # filename='test_tabulated',
37
+ # url=url_water,
38
+ # )
39
+
40
+ # MaterialBank.add_sellmeier_to_bank(
41
+ # filename='test_sellmeier',
42
+ # url=url_water,
43
+ # )
44
+
45
+
46
+ # def test_fail_add_custom():
47
+ # with pytest.raises(ValueError):
48
+ # MaterialBank.add_material_to_bank(
49
+ # filename='test_tabulated',
50
+ # url=url_water,
51
+ # material_type='invalid_location'
52
+ # )
53
+
54
+
55
+ # def test_build_library():
56
+ # """
57
+ # Test the creation of the default library. Ensures that the default library
58
+ # is built without errors.
59
+ # """
60
+ # pass
61
+ # # MaterialBank.build_library('minimal', remove_previous=True)
62
+
63
+
64
+ # def test_remove_item():
65
+ # """
66
+ # Test the removal of an element from a library. Ensures that an element can
67
+ # be removed without errors.
68
+ # """
69
+ # with pytest.raises(ValueError):
70
+ # MaterialBank.remove_item(filename='test', location='invalid_location')
71
+
72
+ # download_yml_file(
73
+ # filename='test_sellmeier',
74
+ # url=url_water,
75
+ # location=MaterialType.SELLMEIER
76
+ # )
77
+
78
+ # MaterialBank.remove_item(filename='test_sellmeier', location=MaterialType.SELLMEIER)
79
+
80
+ # download_yml_file(
81
+ # filename='test_tabulated',
82
+ # url=url_water,
83
+ # location=MaterialType.TABULATED
84
+ # )
85
+
86
+ # MaterialBank.remove_item(filename='test_tabulated', location=MaterialType.TABULATED)
87
+
88
+ # download_yml_file(
89
+ # filename='test_sellmeier',
90
+ # url=url_water,
91
+ # location=MaterialType.SELLMEIER
92
+ # )
93
+
94
+ # MaterialBank.clean_data_files(regex='test*', location=MaterialType.SELLMEIER)
95
+
96
+ # download_yml_file(
97
+ # filename='test_tabulated',
98
+ # url=url_water,
99
+ # location=MaterialType.TABULATED
100
+ # )
101
+
102
+ # MaterialBank.clean_data_files(regex='test*', location=MaterialType.TABULATED)
103
+
104
+
105
+ # def test_create_custom_sellmeier_file():
106
+ # """
107
+ # Test the creation of a custom Sellmeier YAML file. Ensures that the file
108
+ # is created with the correct coefficients and formula type.
109
+ # """
110
+ # with pytest.raises(ValueError):
111
+ # MaterialBank.create_sellmeier_file(
112
+ # filename='test_sellmeier_file',
113
+ # coefficients=[0, 1, 2, 3, 4],
114
+ # formula_type=9,
115
+ # wavelength_range=[1, 1.2],
116
+ # comments='Dummy comment',
117
+ # specs='Random specs'
118
+ # )
119
+
120
+ # MaterialBank.test_sellmeier_file.compute_refractive_index(1.1e-6)
121
+
122
+
123
+ # def test_fail_with_wrong_formula_type():
124
+ # """
125
+ # Test the creation of a custom Sellmeier YAML file. Ensures that the file
126
+ # is created with the correct coefficients and formula type.
127
+ # """
128
+ # MaterialBank.create_sellmeier_file(
129
+ # filename='test_sellmeier_file',
130
+ # coefficients=[0, 10.6684293, 0.301516485, 0.0030434748, 1.13475115, 1.54133408, 1104],
131
+ # formula_type=2,
132
+ # wavelength_range=[1, 1.2],
133
+ # comments='Dummy comment',
134
+ # specs='Random specs'
135
+ # )
136
+
137
+ # MaterialBank.test_sellmeier_file.compute_refractive_index(1.1e-6)
138
+
139
+
140
+ # def test_create_custom_tabulated_file():
141
+ # """
142
+ # Test the creation of a custom tabulated YAML file. Ensures that the file
143
+ # is created with the correct tabulated data, reference, and comments.
144
+ # """
145
+ # MaterialBank.create_tabulated_file(
146
+ # filename="test_tabulated_file",
147
+ # data=[
148
+ # (0.1879, 0.94, 1.337),
149
+ # (0.1916, 0.95, 1.388),
150
+ # (0.1953, 0.97, 1.440)
151
+ # ],
152
+ # reference="Example of tabulated test file",
153
+ # comments="Room temperature"
154
+ # )
155
+
156
+
157
+ # def _test_download_yml_file_http_error_log(caplog):
158
+ # with pytest.raises(ValueError):
159
+ # download_yml_file(
160
+ # filename='example_download',
161
+ # url='__invalid_url__.com',
162
+ # location=MaterialType.SELLMEIER
163
+ # )
164
+
165
+ if __name__ == "__main__":
166
+ pytest.main(["-W error", "-s", __file__])
@@ -1,45 +0,0 @@
1
- import requests
2
- import logging
3
- from PyOptik.directories import sellmeier_data_path, tabulated_data_path
4
- from PyOptik.material_type import MaterialType
5
-
6
- def download_yml_file(url: str, filename: str, location: MaterialType) -> None:
7
- """
8
- Downloads a .yml file from a specified URL and saves it locally.
9
-
10
- Parameters
11
- ----------
12
- url : str
13
- The URL of the .yml file to download.
14
- save_path : str
15
- The local path where the .yml file should be saved.
16
-
17
- Raises
18
- ------
19
- HTTPError: If the download fails due to an HTTP error.
20
- """
21
- match location:
22
- case MaterialType.SELLMEIER:
23
- file_path = sellmeier_data_path / f"{filename}.yml"
24
- case MaterialType.TABULATED:
25
- file_path = tabulated_data_path / f"{filename}.yml"
26
- case _:
27
- raise ValueError(f"Location [{location}] is invalid, it can be either MaterialType.SELLMEIER or MaterialType.TABULATED")
28
-
29
- try:
30
- # Send a GET request to the URL
31
- response = requests.get(url)
32
- response.raise_for_status() # Raise an error for bad status codes
33
-
34
- # Save the content of the response as a file
35
- file_path.parent.mkdir(parents=True, exist_ok=True) # Create directories if they don't exist
36
-
37
- with open(file_path, 'wb') as file:
38
- file.write(response.content)
39
-
40
- logging.info(f"File downloaded and saved to {file_path}")
41
-
42
- except requests.exceptions.HTTPError as http_err:
43
- logging.warning(f"HTTP error occurred: {http_err}")
44
- except Exception as err:
45
- logging.error(f"An error occurred: {err}")
@@ -1,168 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- import pytest
5
- from PyOptik import MaterialBank, MaterialType
6
- from PyOptik.utils import download_yml_file
7
-
8
- MaterialBank.set_filter(use_sellmeier=True, use_tabulated=True)
9
-
10
-
11
- # def test_main():
12
- # MaterialBank.build_library('minimal', remove_previous=True)
13
-
14
- url_water = 'https://refractiveindex.info/database/data/main/H2O/nk/Daimon-19.0C.yml'
15
-
16
- def test_download_yml_files():
17
- """
18
- Test downloading YAML files to different locations. Ensures that files are
19
- correctly downloaded from a given URL to the specified directory.
20
- """
21
- download_yml_file(
22
- filename='test_tabulated',
23
- url=url_water,
24
- location=MaterialType.TABULATED
25
- )
26
-
27
- download_yml_file(
28
- filename='test_sellmeier',
29
- url=url_water,
30
- location=MaterialType.SELLMEIER
31
- )
32
-
33
-
34
- def test_add_custom():
35
- MaterialBank.add_tabulated_to_bank(
36
- filename='test_tabulated',
37
- url=url_water,
38
- )
39
-
40
- MaterialBank.add_sellmeier_to_bank(
41
- filename='test_sellmeier',
42
- url=url_water,
43
- )
44
-
45
-
46
- def test_fail_add_custom():
47
- with pytest.raises(ValueError):
48
- MaterialBank.add_material_to_bank(
49
- filename='test_tabulated',
50
- url=url_water,
51
- material_type='invalid_location'
52
- )
53
-
54
-
55
- def test_build_library():
56
- """
57
- Test the creation of the default library. Ensures that the default library
58
- is built without errors.
59
- """
60
- pass
61
- # MaterialBank.build_library('minimal', remove_previous=True)
62
-
63
-
64
- def test_remove_item():
65
- """
66
- Test the removal of an element from a library. Ensures that an element can
67
- be removed without errors.
68
- """
69
- with pytest.raises(ValueError):
70
- MaterialBank.remove_item(filename='test', location='invalid_location')
71
-
72
- download_yml_file(
73
- filename='test_sellmeier',
74
- url=url_water,
75
- location=MaterialType.SELLMEIER
76
- )
77
-
78
- MaterialBank.remove_item(filename='test_sellmeier', location=MaterialType.SELLMEIER)
79
-
80
- download_yml_file(
81
- filename='test_tabulated',
82
- url=url_water,
83
- location=MaterialType.TABULATED
84
- )
85
-
86
- MaterialBank.remove_item(filename='test_tabulated', location=MaterialType.TABULATED)
87
-
88
- download_yml_file(
89
- filename='test_sellmeier',
90
- url=url_water,
91
- location=MaterialType.SELLMEIER
92
- )
93
-
94
- MaterialBank.clean_data_files(regex='test*', location=MaterialType.SELLMEIER)
95
-
96
- download_yml_file(
97
- filename='test_tabulated',
98
- url=url_water,
99
- location=MaterialType.TABULATED
100
- )
101
-
102
- MaterialBank.clean_data_files(regex='test*', location=MaterialType.TABULATED)
103
-
104
-
105
- def test_create_custom_sellmeier_file():
106
- """
107
- Test the creation of a custom Sellmeier YAML file. Ensures that the file
108
- is created with the correct coefficients and formula type.
109
- """
110
- with pytest.raises(ValueError):
111
- MaterialBank.create_sellmeier_file(
112
- filename='test_sellmeier_file',
113
- coefficients=[0, 1, 2, 3, 4],
114
- formula_type=9,
115
- wavelength_range=[1, 1.2],
116
- comments='Dummy comment',
117
- specs='Random specs'
118
- )
119
-
120
- MaterialBank.test_sellmeier_file.compute_refractive_index(1.1e-6)
121
-
122
-
123
- def test_fail_with_wrong_formula_type():
124
- """
125
- Test the creation of a custom Sellmeier YAML file. Ensures that the file
126
- is created with the correct coefficients and formula type.
127
- """
128
- MaterialBank.create_sellmeier_file(
129
- filename='test_sellmeier_file',
130
- coefficients=[0, 10.6684293, 0.301516485, 0.0030434748, 1.13475115, 1.54133408, 1104],
131
- formula_type=2,
132
- wavelength_range=[1, 1.2],
133
- comments='Dummy comment',
134
- specs='Random specs'
135
- )
136
-
137
- MaterialBank.test_sellmeier_file.compute_refractive_index(1.1e-6)
138
-
139
-
140
- def test_create_custom_tabulated_file():
141
- """
142
- Test the creation of a custom tabulated YAML file. Ensures that the file
143
- is created with the correct tabulated data, reference, and comments.
144
- """
145
- MaterialBank.create_tabulated_file(
146
- filename="test_tabulated_file",
147
- data=[
148
- (0.1879, 0.94, 1.337),
149
- (0.1916, 0.95, 1.388),
150
- (0.1953, 0.97, 1.440)
151
- ],
152
- reference="Example of tabulated test file",
153
- comments="Room temperature"
154
- )
155
-
156
-
157
- def test_download_yml_file_http_error_log(caplog):
158
- download_yml_file(
159
- filename='example_download',
160
- url='__invalid_url__.com',
161
- location=MaterialType.SELLMEIER
162
- )
163
-
164
- assert 'An error occurred' in caplog.text, "Warning was not raised: {caplog.text}"
165
-
166
-
167
- if __name__ == "__main__":
168
- pytest.main(["-W error", __file__])
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes