miepython 3.0.5__py3-none-any.whl → 3.2.0__py3-none-any.whl

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.
miepython/__init__.py CHANGED
@@ -42,41 +42,79 @@ The scattering matrix
42
42
 
43
43
  mie.phase_matrix(m, x, mu)
44
44
 
45
+ Near-field calculations are provided by the ``miepython.field`` module::
46
+
47
+ from miepython.field import e_near, h_near, eh_near
48
+ from miepython.field import e_near_cartesian, h_near_cartesian, eh_near_cartesian
49
+ from miepython.field import e_far
50
+
51
+ Example near-field usage::
52
+
53
+ import numpy as np
54
+ from miepython.field import eh_near_cartesian
55
+
56
+ u = np.linspace(-1.5, 1.5, 101)
57
+ X, Z = np.meshgrid(u, u, indexing='xy')
58
+ E_xyz, H_xyz = eh_near_cartesian(
59
+ lambda0=1.0, d_sphere=1.0, m_sphere=1.5 + 0.0j, n_env=1.0,
60
+ x=X, y=np.zeros_like(X), z=Z
61
+ )
62
+
45
63
  """
46
64
 
47
- import os
48
-
49
- USE_JIT = os.environ.get("MIEPYTHON_USE_JIT", "0") == "1"
50
-
51
- if USE_JIT:
52
- # pull in the jit‐compiled backends under the "private" names core.py expects
53
- from .mie_jit import _an_bn_nb as an_bn
54
- from .mie_jit import _cn_dn_nb as cn_dn
55
- from .mie_jit import _single_sphere_nb as single_sphere
56
- from .mie_jit import _small_sphere_nb as small_sphere
57
- from .mie_jit import _small_conducting_sphere_nb as small_conducting_sphere
58
- from .mie_jit import _pi_tau_nb as _pi_tau
59
- from .mie_jit import _D_calc_nb as _D_calc
60
- from .mie_jit import _S1_S2_nb as _S1_S2
61
- from .mie_jit import _Lentz_Dn
62
- from .mie_jit import _D_upwards
63
- from .mie_jit import _D_downwards
64
- else:
65
- from .mie_nojit import _an_bn_py as an_bn
66
- from .mie_nojit import _cn_dn_py as cn_dn
67
- from .mie_nojit import _single_sphere_py as single_sphere
68
- from .mie_nojit import _small_sphere_py as small_sphere
69
- from .mie_nojit import _small_conducting_sphere_py as small_conducting_sphere
70
- from .mie_nojit import _pi_tau_py as _pi_tau
71
- from .mie_nojit import _D_calc_py as _D_calc
72
- from .mie_nojit import _S1_S2_py as _S1_S2
73
- from .mie_nojit import _Lentz_Dn
74
- from .mie_nojit import _D_upwards
75
- from .mie_nojit import _D_downwards
65
+ from ._backend import D_calc, USE_JIT, _D_downwards, _D_upwards, _Lentz_Dn, _S1_S2, an_bn, cn_dn, pi_tau
66
+ from ._backend import single_sphere, small_conducting_sphere, small_sphere
76
67
 
77
68
  from .core import efficiencies, intensities, i_par, i_per, i_unpolarized
78
69
  from .core import efficiencies_mx, S1_S2, phase_matrix, coefficients
79
70
 
71
+ _FIELD_IMPORT_ERROR = None
72
+
73
+
74
+ def _raise_field_import_error():
75
+ """Raise a consistent error when optional near-field dependencies are missing."""
76
+ raise ModuleNotFoundError(
77
+ "Near-field functions require the optional dependency 'scipy'. "
78
+ "Install miepython with SciPy support to use e_far/e_near/h_near/eh_near."
79
+ ) from _FIELD_IMPORT_ERROR
80
+
81
+
82
+ def _missing_field_function(name):
83
+ """Create a placeholder near-field function when SciPy is unavailable."""
84
+
85
+ def _missing(*_args, **_kwargs):
86
+ _raise_field_import_error()
87
+
88
+ _missing.__name__ = name
89
+ _missing.__qualname__ = name
90
+ _missing.__doc__ = f"{name} requires the optional dependency 'scipy'."
91
+ return _missing
92
+
93
+
94
+ try:
95
+ from . import field as _field
96
+ except ModuleNotFoundError as exc:
97
+ missing_module = str(getattr(exc, "name", "") or "")
98
+ if missing_module.startswith("scipy"):
99
+ _FIELD_IMPORT_ERROR = exc
100
+ e_far = _missing_field_function("e_far")
101
+ e_near = _missing_field_function("e_near")
102
+ h_near = _missing_field_function("h_near")
103
+ eh_near = _missing_field_function("eh_near")
104
+ e_near_cartesian = _missing_field_function("e_near_cartesian")
105
+ h_near_cartesian = _missing_field_function("h_near_cartesian")
106
+ eh_near_cartesian = _missing_field_function("eh_near_cartesian")
107
+ else:
108
+ raise
109
+ else:
110
+ e_far = _field.e_far
111
+ e_near = _field.e_near
112
+ h_near = _field.h_near
113
+ eh_near = _field.eh_near
114
+ e_near_cartesian = _field.e_near_cartesian
115
+ h_near_cartesian = _field.h_near_cartesian
116
+ eh_near_cartesian = _field.eh_near_cartesian
117
+
80
118
  # functions exposed to the user
81
119
  __all__ = (
82
120
  "intensities",
@@ -87,23 +125,31 @@ __all__ = (
87
125
  "coefficients",
88
126
  "efficiencies",
89
127
  "efficiencies_mx",
128
+ "e_far",
129
+ "e_near",
130
+ "h_near",
131
+ "eh_near",
132
+ "e_near_cartesian",
133
+ "h_near_cartesian",
134
+ "eh_near_cartesian",
90
135
  "an_bn",
91
136
  "cn_dn",
92
137
  "S1_S2",
93
138
  "single_sphere",
94
139
  "small_sphere",
95
140
  "small_conducting_sphere",
141
+ "USE_JIT",
142
+ "D_calc",
143
+ "pi_tau",
96
144
  "_S1_S2",
97
- "_D_calc",
98
- "_pi_tau",
99
145
  "_Lentz_Dn",
100
146
  "_D_upwards",
101
147
  "_D_downwards",
102
148
  )
103
149
 
104
- __version__ = "3.0.5"
150
+ __version__ = "3.2.0"
105
151
  __author__ = "Scott Prahl"
106
152
  __email__ = "scott.prahl@oit.edu"
107
- __copyright__ = "2017-26, Scott Prahl"
153
+ __copyright__ = "2017-2026, Scott Prahl"
108
154
  __license__ = "MIT"
109
155
  __url__ = "https://github.com/scottprahl/miepython.git"
miepython/_backend.py ADDED
@@ -0,0 +1,49 @@
1
+ """Select and expose the active low-level backend implementation.
2
+
3
+ This module centralizes JIT vs no-JIT backend selection so other modules can
4
+ import backend callables without importing ``miepython`` package root.
5
+ """
6
+
7
+ import os
8
+
9
+ USE_JIT = os.environ.get("MIEPYTHON_USE_JIT", "0") == "1"
10
+
11
+ if USE_JIT:
12
+ from .mie_jit import _D_calc_nb as D_calc
13
+ from .mie_jit import _D_downwards
14
+ from .mie_jit import _D_upwards
15
+ from .mie_jit import _Lentz_Dn
16
+ from .mie_jit import _S1_S2_nb as _S1_S2
17
+ from .mie_jit import _an_bn_nb as an_bn
18
+ from .mie_jit import _cn_dn_nb as cn_dn
19
+ from .mie_jit import _pi_tau_nb as pi_tau
20
+ from .mie_jit import _single_sphere_nb as single_sphere
21
+ from .mie_jit import _small_conducting_sphere_nb as small_conducting_sphere
22
+ from .mie_jit import _small_sphere_nb as small_sphere
23
+ else:
24
+ from .mie_nojit import _D_calc_py as D_calc
25
+ from .mie_nojit import _D_downwards
26
+ from .mie_nojit import _D_upwards
27
+ from .mie_nojit import _Lentz_Dn
28
+ from .mie_nojit import _S1_S2_py as _S1_S2
29
+ from .mie_nojit import _an_bn_py as an_bn
30
+ from .mie_nojit import _cn_dn_py as cn_dn
31
+ from .mie_nojit import _pi_tau_py as pi_tau
32
+ from .mie_nojit import _single_sphere_py as single_sphere
33
+ from .mie_nojit import _small_conducting_sphere_py as small_conducting_sphere
34
+ from .mie_nojit import _small_sphere_py as small_sphere
35
+
36
+ __all__ = (
37
+ "USE_JIT",
38
+ "D_calc",
39
+ "an_bn",
40
+ "cn_dn",
41
+ "pi_tau",
42
+ "single_sphere",
43
+ "small_sphere",
44
+ "small_conducting_sphere",
45
+ "_S1_S2",
46
+ "_Lentz_Dn",
47
+ "_D_upwards",
48
+ "_D_downwards",
49
+ )
miepython/core.py CHANGED
@@ -34,8 +34,7 @@ Normalized Mie scattering intensities for angles mu=cos(theta)::
34
34
  """
35
35
 
36
36
  import numpy as np
37
- from miepython import an_bn, cn_dn, single_sphere, _S1_S2
38
-
37
+ from ._backend import _S1_S2, an_bn, cn_dn, single_sphere
39
38
 
40
39
  # not really needed but included for clarity
41
40
  __all__ = (
@@ -382,7 +381,7 @@ def i_per(m, x, mu, norm="albedo", n_pole=0):
382
381
  This function calculates the angular distribution of the scattered intensity from a sphere
383
382
  for incident light with its electric field vector perpendicular to the scattering plane
384
383
  (the plane defined by the incident direction and the scattered direction).
385
- This corresponds to the |S₁(θ)|² term in Mie theory.
384
+ This corresponds to the :math:`|S₁(θ)|²` term in Mie theory.
386
385
 
387
386
  The result is normalized according to the specified method. The normalization affects
388
387
  the total integrated intensity over 4π steradians. Accepted normalization options include:
@@ -411,7 +410,7 @@ def i_par(m, x, mu, norm="albedo", n_pole=0):
411
410
  This function calculates the angular distribution of the scattered intensity from a sphere
412
411
  for incident light with its electric field vector parallel to the scattering plane
413
412
  (the plane defined by the incident direction and the scattered direction).
414
- This corresponds to the |S₂(θ)|² term in Mie theory.
413
+ This corresponds to the :math:`|S₂(θ)|²` term in Mie theory.
415
414
 
416
415
  The result is normalized according to the specified method. The normalization affects
417
416
  the total integrated intensity over 4π steradians. Accepted normalization options include: