PyOptik 1.10.7__tar.gz → 1.11.0__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 (129) hide show
  1. {pyoptik-1.10.7 → pyoptik-1.11.0}/PKG-INFO +2 -3
  2. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/__init__.py +2 -0
  3. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/_version.py +2 -2
  4. pyoptik-1.11.0/PyOptik/data/sellmeier/BK7.yml +57 -0
  5. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/directories.py +8 -0
  6. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/libraries/classics.yml +4 -2
  7. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/libraries/dielectrics.yml +2 -1
  8. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/libraries/repertoire.yml +1 -2
  9. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/material/base_class.py +5 -5
  10. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/material/sellmeier_class.py +1 -1
  11. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/material/tabulated_class.py +1 -4
  12. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/material_bank.py +62 -52
  13. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/material_type.py +2 -0
  14. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/units.py +10 -6
  15. pyoptik-1.11.0/PyOptik/utils.py +97 -0
  16. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik.egg-info/PKG-INFO +2 -3
  17. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik.egg-info/SOURCES.txt +5 -30
  18. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/source/conf.py +1 -0
  19. {pyoptik-1.10.7 → pyoptik-1.11.0}/meta.yaml +3 -1
  20. {pyoptik-1.10.7 → pyoptik-1.11.0}/pyproject.toml +2 -2
  21. pyoptik-1.11.0/tests/test_base_material_decorator.py +38 -0
  22. pyoptik-1.11.0/tests/test_material_bank_extra.py +34 -0
  23. {pyoptik-1.10.7 → pyoptik-1.11.0}/tests/test_sellmeier.py +16 -1
  24. {pyoptik-1.10.7 → pyoptik-1.11.0}/tests/test_tabulated.py +1 -1
  25. {pyoptik-1.10.7 → pyoptik-1.11.0}/tests/test_usual_materials.py +3 -2
  26. {pyoptik-1.10.7 → pyoptik-1.11.0}/tests/test_utils.py +19 -21
  27. pyoptik-1.11.0/tests/test_utils_extra.py +41 -0
  28. pyoptik-1.10.7/PyOptik/data/sellmeier/BAF10.yml +0 -59
  29. pyoptik-1.10.7/PyOptik/data/sellmeier/FK51A.yml +0 -64
  30. pyoptik-1.10.7/PyOptik/data/sellmeier/LASF9.yml +0 -57
  31. pyoptik-1.10.7/PyOptik/data/sellmeier/SF10.yml +0 -56
  32. pyoptik-1.10.7/PyOptik/data/sellmeier/SF11.yml +0 -55
  33. pyoptik-1.10.7/PyOptik/data/sellmeier/acetylene.yml +0 -18
  34. pyoptik-1.10.7/PyOptik/data/sellmeier/cellulose.yml +0 -17
  35. pyoptik-1.10.7/PyOptik/data/sellmeier/ethane.yml +0 -20
  36. pyoptik-1.10.7/PyOptik/data/sellmeier/ethanol.yml +0 -16
  37. pyoptik-1.10.7/PyOptik/data/sellmeier/ethylene.yml +0 -18
  38. pyoptik-1.10.7/PyOptik/data/sellmeier/glycerol.yml +0 -16
  39. pyoptik-1.10.7/PyOptik/data/sellmeier/methane.yml +0 -18
  40. pyoptik-1.10.7/PyOptik/data/sellmeier/methanol.yml +0 -16
  41. pyoptik-1.10.7/PyOptik/data/sellmeier/polycarbonate.yml +0 -17
  42. pyoptik-1.10.7/PyOptik/data/sellmeier/polystyrene.yml +0 -17
  43. pyoptik-1.10.7/PyOptik/data/sellmeier/propanol.yml +0 -16
  44. pyoptik-1.10.7/PyOptik/data/sellmeier/pvc.yml +0 -16
  45. pyoptik-1.10.7/PyOptik/data/tabulated/BK7.yml +0 -862
  46. pyoptik-1.10.7/PyOptik/data/tabulated/bismuth.yml +0 -163
  47. pyoptik-1.10.7/PyOptik/data/tabulated/chromium.yml +0 -62
  48. pyoptik-1.10.7/PyOptik/data/tabulated/lead.yml +0 -163
  49. pyoptik-1.10.7/PyOptik/data/tabulated/magnesium.yml +0 -153
  50. pyoptik-1.10.7/PyOptik/data/tabulated/paladium.yml +0 -62
  51. pyoptik-1.10.7/PyOptik/data/tabulated/pva.yml +0 -635
  52. pyoptik-1.10.7/PyOptik/data/tabulated/rhodium.yml +0 -21
  53. pyoptik-1.10.7/PyOptik/data/tabulated/tantalum.yml +0 -163
  54. pyoptik-1.10.7/PyOptik/data/tabulated/titanium.yml +0 -62
  55. pyoptik-1.10.7/PyOptik/data/tabulated/tungsten.yml +0 -163
  56. pyoptik-1.10.7/PyOptik/data/tabulated/vanadium.yml +0 -62
  57. pyoptik-1.10.7/PyOptik/utils.py +0 -45
  58. {pyoptik-1.10.7 → pyoptik-1.11.0}/.flake8 +0 -0
  59. {pyoptik-1.10.7 → pyoptik-1.11.0}/.github/dependabot.yml +0 -0
  60. {pyoptik-1.10.7 → pyoptik-1.11.0}/.github/workflows/deploy_PyPi.yml +0 -0
  61. {pyoptik-1.10.7 → pyoptik-1.11.0}/.github/workflows/deploy_anaconda.yml +0 -0
  62. {pyoptik-1.10.7 → pyoptik-1.11.0}/.github/workflows/deploy_coverage.yml +0 -0
  63. {pyoptik-1.10.7 → pyoptik-1.11.0}/.github/workflows/deploy_documentation.yml +0 -0
  64. {pyoptik-1.10.7 → pyoptik-1.11.0}/.gitignore +0 -0
  65. {pyoptik-1.10.7 → pyoptik-1.11.0}/LICENSE +0 -0
  66. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/__main__.py +0 -0
  67. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/__init__.py +0 -0
  68. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/BAK1.yml +0 -0
  69. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/SF5.yml +0 -0
  70. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/ZBLAN.yml +0 -0
  71. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/acetone.yml +0 -0
  72. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/air.yml +0 -0
  73. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/argon.yml +0 -0
  74. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/crown.yml +0 -0
  75. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/flint.yml +0 -0
  76. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/fused_silica.yml +0 -0
  77. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/germanium.yml +0 -0
  78. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/lithium_niobate.yml +0 -0
  79. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/polystyren.yml +0 -0
  80. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/soda_lime_glass.yml +0 -0
  81. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/sellmeier/water.yml +0 -0
  82. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/aluminium.yml +0 -0
  83. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/calcium.yml +0 -0
  84. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/copper.yml +0 -0
  85. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/gold.yml +0 -0
  86. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/iron.yml +0 -0
  87. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/nickel.yml +0 -0
  88. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/polyetylene.yml +0 -0
  89. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/silicon.yml +0 -0
  90. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/silver.yml +0 -0
  91. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/sodium.yml +0 -0
  92. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/data/tabulated/zinc.yml +0 -0
  93. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/libraries/__init__.py +0 -0
  94. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/libraries/metals.yml +0 -0
  95. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/libraries/minimal.yml +0 -0
  96. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/libraries/organics.yml +0 -0
  97. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/libraries/others.yml +0 -0
  98. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/libraries/polymers.yml +0 -0
  99. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik/material/__init__.py +0 -0
  100. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik.egg-info/dependency_links.txt +0 -0
  101. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik.egg-info/requires.txt +0 -0
  102. {pyoptik-1.10.7 → pyoptik-1.11.0}/PyOptik.egg-info/top_level.txt +0 -0
  103. {pyoptik-1.10.7 → pyoptik-1.11.0}/README.rst +0 -0
  104. {pyoptik-1.10.7 → pyoptik-1.11.0}/development/dev_0.py +0 -0
  105. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/Makefile +0 -0
  106. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/README.rst +0 -0
  107. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/sellmeier/README.rst +0 -0
  108. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/sellmeier/plot_bk7.py +0 -0
  109. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/sellmeier/plot_silica.py +0 -0
  110. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/sellmeier/plot_water.py +0 -0
  111. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/tabulated/README.rst +0 -0
  112. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/tabulated/plot_sf5.py +0 -0
  113. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/tabulated/plot_silver.py +0 -0
  114. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/utils/README.rst +0 -0
  115. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/utils/__build_library.py +0 -0
  116. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/utils/__download_yml_file.py +0 -0
  117. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/utils/create_sellmeier_file.py +0 -0
  118. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/examples/utils/create_tabulated_file.py +0 -0
  119. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/images/example_bk7.png +0 -0
  120. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/images/logo.png +0 -0
  121. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/make.bat +0 -0
  122. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/source/_static/default.css +0 -0
  123. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/source/_static/thumbnail.png +0 -0
  124. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/source/code.rst +0 -0
  125. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/source/gallery/index.rst +0 -0
  126. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/source/index.rst +0 -0
  127. {pyoptik-1.10.7 → pyoptik-1.11.0}/docs/source/references.rst +0 -0
  128. {pyoptik-1.10.7 → pyoptik-1.11.0}/setup.cfg +0 -0
  129. {pyoptik-1.10.7 → pyoptik-1.11.0}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyOptik
3
- Version: 1.10.7
3
+ Version: 1.11.0
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
@@ -25,13 +25,12 @@ License: MIT License
25
25
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
26
  SOFTWARE.
27
27
 
28
- Keywords: refracive index,optics
28
+ Keywords: refractive index,optics
29
29
  Classifier: Programming Language :: Python
30
30
  Classifier: Programming Language :: Python :: 3
31
31
  Classifier: Programming Language :: Python :: Implementation :: CPython
32
32
  Classifier: Development Status :: 4 - Beta
33
33
  Classifier: Topic :: Scientific/Engineering :: Physics
34
- Classifier: License :: OSI Approved :: MIT License
35
34
  Classifier: Intended Audience :: Science/Research
36
35
  Requires-Python: >=3.10
37
36
  Description-Content-Type: text/x-rst
@@ -13,3 +13,5 @@ from .material import SellmeierMaterial
13
13
  from .material import base_class
14
14
 
15
15
  Material = MaterialBank # For retro-compatiibility
16
+
17
+ TIMEOUT = 10 # Default timeout for requests in seconds
@@ -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.7'
21
- __version_tuple__ = version_tuple = (1, 10, 7)
20
+ __version__ = version = '1.11.0'
21
+ __version_tuple__ = version_tuple = (1, 11, 0)
@@ -0,0 +1,57 @@
1
+ # this file is part of refractiveindex.info database
2
+ # refractiveindex.info database is in the public domain
3
+ # copyright and related rights waived via CC0 1.0
4
+
5
+ REFERENCES: |
6
+ <a href="https://refractiveindex.info/download/data/2017/schott_2017-01-20b.agf">SCHOTT Zemax catalog 2017-01-20b</a> (obtained from <a href="https://www.schott.com/en-us/products/optical-glass-p1000267/downloads/">http://www.schott.com</a>)<br>See also <a href="https://refractiveindex.info/download/data/2017/schott_2017-01-20.pdf">SCHOTT glass data sheets</a>
7
+ COMMENTS: |
8
+ suitable for precision molding
9
+ DATA:
10
+ - type: formula 2
11
+ wavelength_range: 0.31 2.5
12
+ coefficients: 0 1.18318503 0.00722141956 0.0871756426 0.0268216805 1.03133701 101.702362
13
+ - type: tabulated k
14
+ data: |
15
+ 0.310 3.8602E-06
16
+ 0.320 1.4536E-06
17
+ 0.334 3.3459E-07
18
+ 0.350 8.0850E-08
19
+ 0.365 3.1801E-08
20
+ 0.370 2.4996E-08
21
+ 0.380 1.7054E-08
22
+ 0.390 1.2477E-08
23
+ 0.400 1.0227E-08
24
+ 0.405 9.0558E-09
25
+ 0.420 8.0456E-09
26
+ 0.436 8.3521E-09
27
+ 0.460 7.3395E-09
28
+ 0.500 6.3790E-09
29
+ 0.546 5.2218E-09
30
+ 0.580 5.5469E-09
31
+ 0.620 5.9295E-09
32
+ 0.660 6.3120E-09
33
+ 0.700 6.6946E-09
34
+ 1.060 3.3758E-09
35
+ 1.530 1.0336E-07
36
+ 1.970 5.2286E-07
37
+ 2.325 2.6396E-06
38
+ 2.500 6.1794E-06
39
+ PROPERTIES:
40
+ nd: 1.5164
41
+ Vd: 64.06
42
+ glass_code: 516641.243
43
+ glass_status: standard
44
+ density:
45
+ - value: 2433
46
+ thermal_expansion:
47
+ - temperature_range: 243 343
48
+ value: 5.99e-06
49
+ - temperature_range: 293 573
50
+ value: 7.32e-06
51
+ dPgF: -0.0025
52
+ resistance:
53
+ climatic: 1.0
54
+ stain: 0.0
55
+ acid: 1.0
56
+ alkali: 2.3
57
+ phosphate: 2.3
@@ -1,6 +1,14 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ """Convenience paths used throughout the :mod:`PyOptik` package.
5
+
6
+ This module exposes commonly referenced directories such as the project
7
+ root, documentation and data folders. It is imported by other modules to
8
+ construct absolute paths in a centralised manner and therefore simplifies
9
+ file handling across the code base.
10
+ """
11
+
4
12
  from pathlib import Path
5
13
  import PyOptik
6
14
 
@@ -13,10 +13,11 @@ sellmeier:
13
13
  - argon
14
14
  - air
15
15
  - water
16
+ - acetone
17
+ - BK7
16
18
 
17
19
  tabulated:
18
20
  - silicon
19
- - BK7
20
21
  - silver
21
22
  - aluminium
22
23
  - gold
@@ -25,4 +26,5 @@ tabulated:
25
26
  - iron
26
27
  - sodium
27
28
  - nickel
28
- - zinc
29
+ - zinc
30
+ - polyetylene
@@ -15,7 +15,8 @@ sellmeier:
15
15
  - soda_lime_glass
16
16
  - crown
17
17
  - flint
18
+ - BK7
18
19
 
19
20
  tabulated:
20
- - BK7
21
+
21
22
  - silicon
@@ -13,12 +13,12 @@ sellmeier:
13
13
  lithium_niobate: https://refractiveindex.info/database/data/main/LiNbO3/nk/Zelmon-o.yml
14
14
  germanium: https://refractiveindex.info/database/data/main/Ge/nk/Icenogle.yml
15
15
 
16
+ BK7: https://refractiveindex.info/database/data/specs/schott/optical/P-BK7.yml
16
17
  soda_lime_glass: https://refractiveindex.info/database/data/glass/misc/soda-lime/nk/Rubin-clear.yml
17
18
  crown: https://refractiveindex.info/database/data/specs/schott/optical/K7.yml
18
19
  flint: https://refractiveindex.info/database/data/specs/schott/optical/F2.yml
19
20
  argon: https://refractiveindex.info/database/data/main/Ar/nk/Bideau-Mehu.yml
20
21
  air: https://refractiveindex.info/database/data/other/mixed%20gases/air/nk/Ciddor.yml
21
- water: https://refractiveindex.info/database/data/main/H2O/nk/Daimon-19.0C.yml
22
22
 
23
23
  ethanol: https://refractiveindex.info/database/data/organic/C2H6O%20-%20ethanol/nk/Rheims.yml
24
24
  methanol: https://refractiveindex.info/database/data/organic/CH4O%20-%20methanol/nk/El-Kashef.yml
@@ -38,7 +38,6 @@ tabulated:
38
38
  pva: https://refractiveindex.info/database/data/organic/(C2H3Cl)n%20-%20polyvinyl%20chloride/nk/Zhang.yml
39
39
  polyetylene: https://refractiveindex.info/database/data/organic/(C2H4)n%20-%20polyethylene/nk/Smith.yml
40
40
  silicon: https://refractiveindex.info/database/data/main/Si/nk/Aspnes.yml
41
- BK7: https://refractiveindex.info/database/data/glass/optical/BK7/nk/Lane.yml
42
41
  silver: https://refractiveindex.info/database/data/main/Ag/nk/Johnson.yml
43
42
  aluminium: https://refractiveindex.info/database/data/main/Al/nk/Rakic.yml
44
43
  gold: https://refractiveindex.info/database/data/main/Au/nk/Johnson.yml
@@ -64,23 +64,23 @@ class BaseMaterial:
64
64
  )
65
65
 
66
66
  def ensure_units(func) -> Callable:
67
- """
68
- Decorator to ensure that the wavelength parameter has the correct units.
67
+ """Decorator ensuring the wavelength argument carries units.
69
68
 
70
69
  Parameters
71
70
  ----------
72
71
  func : Callable
73
- The function to wrap.
72
+ Function that expects a wavelength :class:`~PyOptik.units.Quantity`.
74
73
 
75
74
  Returns
76
75
  -------
77
76
  Callable
78
- The wrapped function that ensures wavelength is a Quantity in meters.
77
+ Wrapped version of ``func`` that accepts numerical wavelengths and
78
+ converts them to metre-based :class:`~PyOptik.units.Quantity` objects.
79
79
  """
80
80
  def wrapper(self, wavelength: Quantity = None, *args, **kwargs):
81
81
  if wavelength is None:
82
82
  if self.wavelength_bound is None:
83
- raise ValueError('Wavelenght must be provided for computation.')
83
+ raise ValueError('Wavelength must be provided for computation.')
84
84
  wavelength = numpy.linspace(self.wavelength_bound[0].magnitude, self.wavelength_bound[1].magnitude, 100) * self.wavelength_bound.units
85
85
 
86
86
  import PyOptik.units
@@ -133,7 +133,7 @@ class SellmeierMaterial(BaseMaterial):
133
133
  case 5: # Formula 5 computation (extended Sellmeier)
134
134
  n = 1 + self.coefficients[0]
135
135
  for (B, C) in zipped_coefficients:
136
- n = B * wavelength.to(micrometer).magnitude**C
136
+ n += B * wavelength.to(micrometer).magnitude**C
137
137
 
138
138
  case 6:
139
139
  n = 1 + self.coefficients[0]
@@ -74,6 +74,7 @@ class TabulatedMaterial(BaseMaterial):
74
74
  raise FileNotFoundError(f"YAML file {file_path} not found.")
75
75
 
76
76
  with file_path.with_suffix('.yml').open('r') as file:
77
+ print(file)
77
78
  parsed_yaml = yaml.safe_load(file)
78
79
 
79
80
  try:
@@ -134,10 +135,6 @@ class TabulatedMaterial(BaseMaterial):
134
135
  ----------
135
136
  wavelength : Optional[Quantity]
136
137
  The range of wavelengths to plot, in micrometers. If not provided, the entire tabulated wavelength range is used.
137
- title : str, optional
138
- Title of the plot.
139
- grid : bool, optional
140
- Whether to show grid lines on the plot.
141
138
 
142
139
  Raises
143
140
  ------
@@ -127,8 +127,7 @@ class _MaterialBank():
127
127
  cls.use_sellmeier = use_sellmeier
128
128
 
129
129
  def _list_materials(self, material_type: MaterialType) -> List[str]:
130
- """create_sellmeier_file
131
- Helper method to list materials of a specific type.
130
+ """Return available material names for a given type.
132
131
 
133
132
  Parameters
134
133
  ----------
@@ -182,8 +181,11 @@ class _MaterialBank():
182
181
  return self.sellmeier + self.tabulated
183
182
 
184
183
  def print_available(cls) -> None:
185
- """
186
- Prints out all the available Sellmeier and Tabulated materials in a tabulated format.
184
+ """Display all available materials in a table.
185
+
186
+ The method lists both Sellmeier and tabulated materials currently
187
+ stored in the local database and prints them in two columns using
188
+ :func:`tabulate.tabulate`.
187
189
  """
188
190
  sellmeier_materials = cls.sellmeier
189
191
  tabulated_materials = cls.tabulated
@@ -226,7 +228,7 @@ class _MaterialBank():
226
228
  if material_type not in [MaterialType.SELLMEIER, MaterialType.TABULATED]:
227
229
  raise ValueError("Invalid material type. Please choose MaterialType.SELLMEIER or MaterialType.TABULATED.")
228
230
 
229
- return download_yml_file(filename=filename, url=url, location=material_type)
231
+ return download_yml_file(filename=filename, url=url, save_location=material_type)
230
232
 
231
233
  @classmethod
232
234
  def add_sellmeier_to_bank(cls, filename: str, url: str) -> None:
@@ -237,7 +239,7 @@ class _MaterialBank():
237
239
  return cls.add_material_to_bank(filename=filename, url=url, material_type=MaterialType.TABULATED)
238
240
 
239
241
  @classmethod
240
- def remove_item(cls, filename: str, location: Union[str, MaterialType] = 'any') -> None:
242
+ def remove_item(cls, filename: str, save_location: Union[str, MaterialType] = 'any') -> None:
241
243
  """
242
244
  Remove a file associated with a given element name from the specified location.
243
245
 
@@ -245,35 +247,35 @@ class _MaterialBank():
245
247
  ----------
246
248
  filename : str
247
249
  The name of the file to remove, without the '.yml' suffix.
248
- location : Union[str, MaterialType]
249
- The location to search for the file, either 'sellmeier', 'tabulated', 'any', or a MaterialType enum (default is 'any').
250
+ save_location : Union[str, MaterialType]
251
+ The save_location to search for the file, either 'sellmeier', 'tabulated', 'any', or a MaterialType enum (default is 'any').
250
252
 
251
253
  Raises
252
254
  ------
253
255
  FileNotFoundError
254
256
  If the specified file does not exist.
255
257
  ValueError
256
- If an invalid location is provided.
258
+ If an invalid save_location is provided.
257
259
  """
258
- if isinstance(location, MaterialType):
259
- location = location.value
260
+ if isinstance(save_location, MaterialType):
261
+ save_location = save_location.value
260
262
 
261
- location = location.lower()
263
+ save_location = save_location.lower()
262
264
 
263
- if location not in ['any', 'sellmeier', 'tabulated']:
264
- raise ValueError("Invalid location. Please choose 'sellmeier', 'tabulated', or 'any'.")
265
+ if save_location not in ['any', 'sellmeier', 'tabulated']:
266
+ raise ValueError("Invalid save_location. Please choose 'sellmeier', 'tabulated', or 'any'.")
265
267
 
266
- if location in ['any', 'sellmeier']:
268
+ if save_location in ['any', 'sellmeier']:
267
269
  sellmeier_file = data_path / 'sellmeier' / f"{filename}.yml"
268
270
  if sellmeier_file.exists():
269
271
  sellmeier_file.unlink()
270
272
 
271
- if location in ['any', 'tabulated']:
273
+ if save_location in ['any', 'tabulated']:
272
274
  tabulated_file = data_path / 'tabulated' / f"{filename}.yml"
273
275
  if tabulated_file.exists():
274
276
  tabulated_file.unlink()
275
277
 
276
- def clean_data_files(self, regex: str, location: Union[str, MaterialType] = 'any') -> None:
278
+ def clean_data_files(self, regex: str, save_location: Union[str, MaterialType] = 'any') -> None:
277
279
  """
278
280
  Remove all files matching the given regex from the specified location.
279
281
 
@@ -289,13 +291,13 @@ class _MaterialBank():
289
291
  ValueError
290
292
  If an invalid location is provided.
291
293
  """
292
- if isinstance(location, MaterialType):
293
- location = location.value
294
+ if isinstance(save_location, MaterialType):
295
+ save_location = save_location.value
294
296
 
295
- location = location.lower()
297
+ save_location = save_location.lower()
296
298
 
297
- if location not in ['any', 'sellmeier', 'tabulated']:
298
- raise ValueError("Invalid location. Please choose 'sellmeier', 'tabulated', or 'any'.")
299
+ if save_location not in ['any', 'sellmeier', 'tabulated']:
300
+ raise ValueError("Invalid save_location. Please choose 'sellmeier', 'tabulated', or 'any'.")
299
301
 
300
302
  # Compile the regex pattern
301
303
  pattern = re.compile(regex)
@@ -308,11 +310,11 @@ class _MaterialBank():
308
310
  file.unlink()
309
311
 
310
312
  # Remove files from the sellmeier location if specified
311
- if location in ['any', 'sellmeier']:
313
+ if save_location in ['any', 'sellmeier']:
312
314
  remove_matching_files(data_path / 'sellmeier')
313
315
 
314
316
  # Remove files from the tabulated location if specified
315
- if location in ['any', 'tabulated']:
317
+ if save_location in ['any', 'tabulated']:
316
318
  remove_matching_files(data_path / 'tabulated')
317
319
 
318
320
  def build_library(self, library: Union[str, List[str]] = 'classics', remove_previous: bool = False) -> None:
@@ -341,8 +343,8 @@ class _MaterialBank():
341
343
  # Remove previous files if the flag is set
342
344
  if remove_previous:
343
345
  logging.info("Removing previous files from the library.")
344
- self.clean_data_files(regex=".*", location="sellmeier") # Remove all sellmeier files
345
- self.clean_data_files(regex=".*", location="tabulated") # Remove all tabulated files
346
+ self.clean_data_files(regex=".*", save_location="sellmeier") # Remove all sellmeier files
347
+ self.clean_data_files(regex=".*", save_location="tabulated") # Remove all tabulated files
346
348
 
347
349
  for lib in libraries_to_download:
348
350
  file_path = libraries_path / lib
@@ -353,13 +355,13 @@ class _MaterialBank():
353
355
  if data_dict.get('sellmeier', False):
354
356
  for element_name in data_dict['sellmeier']:
355
357
  url = repertoire_dict['sellmeier'][element_name]
356
- download_yml_file(url=url, filename=element_name, location=MaterialType.SELLMEIER)
358
+ download_yml_file(url=url, filename=element_name, save_location=MaterialType.SELLMEIER)
357
359
 
358
360
  # Download new files for tabulated
359
361
  if data_dict.get('tabulated', False):
360
362
  for element_name in data_dict['tabulated']:
361
363
  url = repertoire_dict['tabulated'][element_name]
362
- download_yml_file(url=url, filename=element_name, location=MaterialType.TABULATED)
364
+ download_yml_file(url=url, filename=element_name, save_location=MaterialType.TABULATED)
363
365
 
364
366
  def create_sellmeier_file(
365
367
  self,
@@ -370,25 +372,29 @@ class _MaterialBank():
370
372
  reference: Optional[str] = None,
371
373
  comments: Optional[str] = None,
372
374
  specs: Optional[dict] = None) -> None:
373
- """
374
- Creates a YAML file with custom Sellmeier coefficients in the correct format.
375
+ """Create a custom Sellmeier material definition.
375
376
 
376
377
  Parameters
377
378
  ----------
378
379
  filename : str
379
- The name of the file to create (without the extension).
380
+ Name of the output file without extension.
380
381
  formula_type : int
381
- The type of Sellmeier formula.
382
- coefficients : list[float]
383
- A list of coefficients for the Sellmeier equation.
384
- wavelength_range : Tuple[float, float]
385
- The range of wavelengths, in micrometers.
386
- reference : str
387
- A reference for the material data.
388
- comments : Optional[str]
389
- Additional comments about the material.
390
- specs : Optional[dict]
391
- Additional specifications, such as temperature and whether the wavelength is in a vacuum.
382
+ Identifier of the Sellmeier formula to use.
383
+ coefficients : list[float]
384
+ Coefficients of the selected Sellmeier equation.
385
+ wavelength_range : tuple[float, float], optional
386
+ Minimum and maximum wavelength in micrometers.
387
+ reference : str, optional
388
+ Reference or citation for the data.
389
+ comments : str, optional
390
+ Additional comments stored in the file.
391
+ specs : dict, optional
392
+ Extra specifications such as temperature or vacuum information.
393
+
394
+ Notes
395
+ -----
396
+ The YAML file is written to ``data/sellmeier`` within the package
397
+ directory.
392
398
  """
393
399
  reference = 'None' if reference is None else reference
394
400
 
@@ -428,19 +434,23 @@ class _MaterialBank():
428
434
  data: List[Tuple[float, float, float]],
429
435
  reference: Optional[str] = None,
430
436
  comments: Optional[str] = None) -> None:
431
- """
432
- Creates a YAML file with tabulated nk data in the correct format.
437
+ """Create a tabulated ``n``/``k`` material definition.
433
438
 
434
439
  Parameters
435
440
  ----------
436
- filename : str)
437
- The name of the file to create (without the extension).
438
- data : List[Tuple[float, float, float]])
439
- The tabulated nk data.
440
- reference : Optional[str])
441
- A reference for the material data.
442
- comments : Optional[str])
443
- Additional comments about the material.
441
+ filename : str
442
+ Name of the output file without extension.
443
+ data : list[tuple[float, float, float]]
444
+ Sequence of ``(wavelength, n, k)`` tuples.
445
+ reference : str, optional
446
+ Reference or citation for the data.
447
+ comments : str, optional
448
+ Additional comments stored in the file.
449
+
450
+ Notes
451
+ -----
452
+ The YAML file is written to ``data/tabulated`` within the package
453
+ directory.
444
454
  """
445
455
  reference = 'None' if reference is None else reference
446
456
 
@@ -5,5 +5,7 @@ from enum import Enum
5
5
 
6
6
 
7
7
  class MaterialType(Enum):
8
+ """Enumeration of material data representations."""
9
+
8
10
  SELLMEIER = "sellmeier"
9
11
  TABULATED = "tabulated"
@@ -14,15 +14,19 @@ SCALES = ['nano', 'micro', 'milli', '', 'kilo', 'mega']
14
14
 
15
15
 
16
16
  def initialize_registry(ureg: Optional[pint.UnitRegistry] = None) -> None:
17
- """
18
- Initialize and set up a unit registry. This function also leaks
19
- the units into the global namespace for easy access throughout
20
- the module.
17
+ """Initialise the unit registry used by :mod:`PyOptik`.
21
18
 
22
19
  Parameters
23
20
  ----------
24
- ureg: Optional[pint.UnitRegistry]
25
- A UnitRegistry object to use. If None, the default PintType.ureg will be used.
21
+ ureg : Optional[pint.UnitRegistry], optional
22
+ A preconfigured :class:`~pint.UnitRegistry` instance. When ``None`` (the
23
+ default) a new registry is created and configured.
24
+
25
+ Notes
26
+ -----
27
+ The registry is configured for matplotlib integration and a number of unit
28
+ shortcuts (``nano``/``micro``/``milli``/... ``meter``) as well as commonly
29
+ used units are leaked into the module's global namespace for convenience.
26
30
  """
27
31
 
28
32
  # If no unit registry is provided, use the default
@@ -0,0 +1,97 @@
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
+ from pathlib import Path
6
+ import PyOptik
7
+ import time
8
+
9
+ logging.basicConfig(
10
+ level=logging.INFO,
11
+ format="%(asctime)s %(levelname)s %(message)s",
12
+ )
13
+
14
+ def download_yml_file(
15
+ url: str,
16
+ filename: str,
17
+ save_location: MaterialType,
18
+ max_retries: int = 5,
19
+ retry_delay: float = 2.0,
20
+ backoff_factor: float = 2.0,
21
+ ) -> None:
22
+ """
23
+ Download a YAML material file from the given URL and save it locally.
24
+
25
+ If the file already exists, the function will skip downloading.
26
+ Retries are performed on connection or timeout errors.
27
+
28
+ Parameters
29
+ ----------
30
+ url : str
31
+ Direct link to the YAML file to download.
32
+ filename : str
33
+ File name to save (without .yml extension).
34
+ save_location : MaterialType
35
+ The target material type (SELLMEIER or TABULATED).
36
+ max_retries : int, optional
37
+ Maximum number of retry attempts (default is 3).
38
+ retry_delay : float, optional
39
+ Delay (in seconds) between retries (default is 2.0).
40
+ backoff_factor : float, optional
41
+ Multiplier applied to delay after each failed attempt (default is 2.0).
42
+
43
+ Raises
44
+ ------
45
+ ValueError
46
+ If an invalid MaterialType is passed.
47
+ requests.exceptions.RequestException
48
+ For non-retriable HTTP or connection errors.
49
+ """
50
+ # Determine save save_location
51
+ if save_location == MaterialType.SELLMEIER:
52
+ file_path: Path = sellmeier_data_path / f"{filename}.yml"
53
+ elif save_location == MaterialType.TABULATED:
54
+ file_path: Path = tabulated_data_path / f"{filename}.yml"
55
+ else:
56
+ raise ValueError(f"Invalid save_location: {save_location}. Must be SELLMEIER or TABULATED.")
57
+
58
+ # Skip if already downloaded
59
+ if file_path.exists():
60
+ logging.info(f"File already exists: {file_path}. Skipping download.")
61
+ return
62
+
63
+ # Create directory if needed
64
+ file_path.parent.mkdir(parents=True, exist_ok=True)
65
+
66
+ # Retry logic
67
+ attempt = 0
68
+ delay = retry_delay
69
+
70
+ while attempt < max_retries:
71
+ attempt += 1
72
+ try:
73
+ logging.info(f"Attempt {attempt} of {max_retries}: downloading {url}")
74
+ response = requests.get(url, timeout=PyOptik.TIMEOUT)
75
+ response.raise_for_status()
76
+
77
+ with open(file_path, "wb") as f:
78
+ f.write(response.content)
79
+
80
+ logging.info(f"Successfully downloaded and saved to: {file_path}")
81
+ return
82
+
83
+ except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e:
84
+ logging.warning(f"Download attempt {attempt} failed due to network error: {e}")
85
+ if attempt < max_retries:
86
+ logging.info(f"Retrying in {delay:.1f} seconds...")
87
+ time.sleep(delay)
88
+ delay *= backoff_factor
89
+ else:
90
+ logging.error(f"Exceeded maximum retries for {url}")
91
+ raise
92
+ except requests.exceptions.HTTPError as e:
93
+ logging.error(f"HTTP error while downloading {url}: {e}")
94
+ raise
95
+ except Exception as e:
96
+ logging.error(f"Unexpected error while saving {url} to {file_path}: {e}")
97
+ raise
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyOptik
3
- Version: 1.10.7
3
+ Version: 1.11.0
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
@@ -25,13 +25,12 @@ License: MIT License
25
25
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
26
  SOFTWARE.
27
27
 
28
- Keywords: refracive index,optics
28
+ Keywords: refractive index,optics
29
29
  Classifier: Programming Language :: Python
30
30
  Classifier: Programming Language :: Python :: 3
31
31
  Classifier: Programming Language :: Python :: Implementation :: CPython
32
32
  Classifier: Development Status :: 4 - Beta
33
33
  Classifier: Topic :: Scientific/Engineering :: Physics
34
- Classifier: License :: OSI Approved :: MIT License
35
34
  Classifier: Intended Audience :: Science/Research
36
35
  Requires-Python: >=3.10
37
36
  Description-Content-Type: text/x-rst