Skip to content

Commit d4862f8

Browse files
committed
fixing docs
1 parent 14f822e commit d4862f8

32 files changed

Lines changed: 416 additions & 406 deletions

PyMieSim/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
__version__ = version = '4.0.2'
3232
__version_tuple__ = version_tuple = (4, 0, 2)
3333

34-
__commit_id__ = commit_id = 'g541736f7a'
34+
__commit_id__ = commit_id = 'g14f822ec3'

PyMieSim/cpp/experiment/sets/properties_set/interface.h

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ void register_properties_set(py::module& module) {
1111
py::enum_<PropertyMode>(module, "PropertyMode")
1212
.value("Constant", PropertyMode::Constant)
1313
.value("Spectral", PropertyMode::Spectral)
14-
.export_values();
14+
.export_values()
15+
// .def_property_readonly(
16+
// "values",
17+
// [](const ScattererProperties &self) {
18+
// if (self.mode == PropertyMode::Constant)
19+
// return self.constant_values;
20+
21+
// return std::vector<complex128>{};
22+
// }
23+
// )
24+
;
1525

1626

1727
py::class_<ScattererProperties, std::shared_ptr<ScattererProperties>>(module, "ScattererProperties")
@@ -71,7 +81,17 @@ void register_properties_set(py::module& module) {
7181
return a.spectral_values == b.spectral_values;
7282
},
7383
py::is_operator()
74-
);
84+
)
85+
.def_property_readonly(
86+
"values",
87+
[](const ScattererProperties &self) {
88+
if (self.mode == PropertyMode::Constant)
89+
return py::cast(self.constant_values);
90+
91+
return py::cast(self.spectral_values);
92+
}
93+
)
94+
;
7595

7696

7797
py::class_<MediumProperties, std::shared_ptr<MediumProperties>>(module, "MediumProperties")
@@ -131,5 +151,15 @@ void register_properties_set(py::module& module) {
131151
return a.spectral_values == b.spectral_values;
132152
},
133153
py::is_operator()
134-
);
154+
)
155+
.def_property_readonly(
156+
"values",
157+
[](const ScattererProperties &self) {
158+
if (self.mode == PropertyMode::Constant)
159+
return py::cast(self.constant_values);
160+
161+
return py::cast(self.spectral_values);
162+
}
163+
)
164+
;
135165
}

PyMieSim/cpp/experiment/sets/scatterer_set/interface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,8 @@ void register_scatterer_set(py::module& module) {
12961296
"get_mapping",
12971297
[ureg](const CoreShellSet& self) {
12981298
py::dict mapping;
1299-
mapping["scatterer:core_diameter"] = py::cast(self.core_diameter);
1300-
mapping["scatterer:shell_thickness"] = py::cast(self.shell_thickness);
1299+
mapping["scatterer:core_diameter"] = py::cast(self.core_diameter) * ureg.attr("meter");
1300+
mapping["scatterer:shell_thickness"] = py::cast(self.shell_thickness) * ureg.attr("meter");
13011301
mapping["scatterer:core_refractive_index"] = self.core_property;
13021302
mapping["scatterer:shell_refractive_index"] = self.shell_property;
13031303
mapping["scatterer:medium_refractive_index"] = self.medium_property;

PyMieSim/experiment/dataframe_subclass.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ def plot_standard(
213213
self,
214214
x: str,
215215
y: list[str] | None = None,
216-
legend_resolution: int | None = 4,
217-
x_tick_resolution: int | None = 4,
218-
y_tick_resolution: int | None = 4,
216+
legend_resolution: int | None = 1,
217+
x_tick_resolution: int | None = 1,
218+
y_tick_resolution: int | None = 1,
219219
**kwargs,
220220
):
221-
221+
y = [y] if isinstance(y, str) else y
222222
self._validate_column(x)
223223

224224
df = self.copy()
@@ -235,8 +235,6 @@ def plot_standard(
235235
and df[c].nunique(dropna=True) > 1
236236
]
237237

238-
print(parameters)
239-
240238
figure, ax = self._create_figure()
241239

242240
groups = df.groupby(parameters) if parameters else [(None, df)]
@@ -251,7 +249,6 @@ def plot_standard(
251249
)
252250

253251
for measure in y:
254-
255252
ax.plot(
256253
group[x].to_numpy(),
257254
group[measure].to_numpy(),

PyMieSim/experiment/setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from PyMieSim.experiment.detector import PhotodiodeSet, CoherentModeSet
1212
from PyMieSim.experiment.source import GaussianSet, PlaneWaveSet
1313
from PyMieSim.experiment.dataframe_subclass import PyMieSimDataFrame
14-
14+
from PyMieSim.experiment.source import PolarizationSet
1515
import PyMieSim
1616

1717

@@ -251,6 +251,12 @@ def _separate_units_and_values(self, mappings: Dict[str, Iterable]):
251251
# ----------------------------------------------------------
252252
# Scalar fallback
253253
# ----------------------------------------------------------
254+
255+
256+
if isinstance(param_values, PolarizationSet):
257+
values[key] = param_values
258+
continue
259+
254260
values[key] = [param_values]
255261

256262
return values, units
@@ -283,7 +289,6 @@ def _build_dataframe(self, measures: List[str], drop_unique_level: bool):
283289

284290
parameter_names = list(values.keys())
285291

286-
287292
mesh = np.meshgrid(*values.values(), indexing="ij")
288293

289294
flattened = [m.reshape(-1) for m in mesh]

docs/examples/experiment/coreshell/coreshell_Qback_vs_corediameter.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,28 @@
1111
import numpy
1212
from PyMieSim.units import ureg
1313

14-
from PyMieSim.experiment.scatterer import CoreShell
15-
from PyMieSim.experiment.source import Gaussian, PolarizationSet
14+
from PyMieSim.experiment.scatterer import CoreShellSet
15+
from PyMieSim.experiment.source import GaussianSet, PolarizationSet
1616
from PyMieSim.experiment import Setup
1717
from PyOptik import Material
1818

1919
polarization_set = PolarizationSet(
2020
angles=[0.0] * ureg.degree,
2121
)
2222

23-
source = Gaussian(
24-
wavelength=[800, 900, 1000]
25-
* ureg.nanometer, # Array of wavelengths: 800 nm, 900 nm, 1000 nm
26-
polarization=polarization_set, # Linear polarization angle in radians
27-
optical_power=1e-3 * ureg.watt, # 1 milliureg.watt
28-
numerical_aperture=0.2 * ureg.AU, # Numerical Aperture
23+
source = GaussianSet(
24+
wavelength=[800, 900, 1000] * ureg.nanometer,
25+
polarization=polarization_set,
26+
optical_power=[1e-3] * ureg.watt,
27+
numerical_aperture=[0.2] * ureg.AU,
2928
)
3029

31-
scatterer = CoreShell(
32-
core_diameter=numpy.geomspace(100, 600, 400)
33-
* ureg.nanometer, # Core diameters from 100 nm to 600 nm
34-
shell_thickness=800 * ureg.nanometer, # Shell width of 800 nm
35-
core_refractive_index=Material.silver, # Core material
36-
shell_refractive_index=Material.BK7, # Shell material
37-
medium_refractive_index=1 * ureg.RIU, # Surrounding medium's refractive index
30+
scatterer = CoreShellSet(
31+
core_diameter=numpy.geomspace(100, 600, 400) * ureg.nanometer,
32+
shell_thickness=[800] * ureg.nanometer,
33+
core_material=[Material.silver],
34+
shell_material=[Material.BK7],
35+
medium_material=[Material.water],
3836
source=source,
3937
)
4038

docs/examples/experiment/coreshell/coreshell_a1_vs_corediameter.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,31 @@
55
This example demonstrates how to compute and visualize the B1 scattering parameter as a function of core diameter for CoreShell scatterers using PyMieSim.
66
"""
77

8-
# %%
9-
# Importing the package dependencies: numpy, PyMieSim
108
import numpy as np
119
from PyMieSim.units import ureg
1210

13-
from PyMieSim.experiment.scatterer import CoreShell
14-
from PyMieSim.experiment.source import Gaussian, PolarizationSet
11+
from PyMieSim.experiment.scatterer import CoreShellSet
12+
from PyMieSim.experiment.source import GaussianSet, PolarizationSet
1513
from PyMieSim.experiment import Setup
1614
from PyOptik import Material
1715

1816
polarization_set = PolarizationSet(
1917
angles=[90.0] * ureg.degree,
2018
)
2119

22-
source = Gaussian(
23-
wavelength=800 * ureg.nanometer, # 800 nm
24-
polarization=polarization_set, # Linear polarization angle in radians
25-
optical_power=1e-3 * ureg.watt, # 1 milliureg.watt
26-
numerical_aperture=0.2 * ureg.AU, # Numerical Aperture
20+
source = GaussianSet(
21+
wavelength=[300] * ureg.nanometer,
22+
polarization=polarization_set,
23+
optical_power=[1e-3] * ureg.watt,
24+
numerical_aperture=[0.2] * ureg.AU,
2725
)
2826

29-
scatterer = CoreShell(
30-
core_diameter=np.geomspace(100, 600, 10) * ureg.nanometer, # Geometrically spaced core diameters
31-
shell_thickness=150 * ureg.nanometer, # Shell width of 800 nm
32-
core_refractive_index=[1.4] * ureg.RIU, # Refractive index of the core
33-
shell_refractive_index=[Material.BK7], # BK7 glass material for the shell
34-
medium_refractive_index=1 * ureg.RIU, # Refractive index of the surrounding medium
27+
scatterer = CoreShellSet(
28+
core_diameter=np.geomspace(100, 600, 100) * ureg.nanometer,
29+
shell_thickness=[150] * ureg.nanometer,
30+
core_refractive_index=[1.4] * ureg.RIU,
31+
shell_material=[Material.BK7],
32+
medium_refractive_index=[1] * ureg.RIU,
3533
source=source,
3634
)
3735

docs/examples/experiment/coreshell/coreshell_b1_vs_corediameter.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,31 @@
55
This example demonstrates how to compute and visualize the B1 scattering parameter as a function of core diameter for CoreShell scatterers using PyMieSim.
66
"""
77

8-
# %%
9-
# Importing the package dependencies: numpy, PyMieSim
108
import numpy as np
119
from PyMieSim.units import ureg
1210

13-
from PyMieSim.experiment.scatterer import CoreShell
14-
from PyMieSim.experiment.source import Gaussian, PolarizationSet
11+
from PyMieSim.experiment.scatterer import CoreShellSet
12+
from PyMieSim.experiment.source import GaussianSet, PolarizationSet
1513
from PyMieSim.experiment import Setup
1614
from PyOptik import Material
1715

1816
polarization_set = PolarizationSet(
1917
angles=[90.0] * ureg.degree,
2018
)
2119

22-
source = Gaussian(
23-
wavelength=800 * ureg.nanometer, # 800 nm
24-
polarization=polarization_set, # Linear polarization angle in radians
25-
optical_power=1e-3 * ureg.watt, # 1 milliureg.watt
26-
numerical_aperture=0.2 * ureg.AU, # Numerical Aperture
20+
source = GaussianSet(
21+
wavelength=[800] * ureg.nanometer,
22+
polarization=polarization_set,
23+
optical_power=[1e-3] * ureg.watt,
24+
numerical_aperture=[0.2] * ureg.AU,
2725
)
2826

29-
scatterer = CoreShell(
30-
core_diameter=np.geomspace(100, 3000, 500) * ureg.nanometer, # Geometrically spaced core diameters
31-
shell_thickness=800 * ureg.nanometer, # Shell width of 800 nm
32-
core_refractive_index=[1.3, 1.6] * ureg.RIU, # Refractive index of the core
33-
shell_refractive_index=Material.BK7, # BK7 glass material for the shell
34-
medium_refractive_index=1 * ureg.RIU, # Refractive index of the surrounding medium
27+
scatterer = CoreShellSet(
28+
core_diameter=np.geomspace(100, 3000, 500) * ureg.nanometer,
29+
shell_thickness=[800] * ureg.nanometer,
30+
core_refractive_index=[1.3, 1.6] * ureg.RIU,
31+
shell_material=[Material.BK7],
32+
medium_refractive_index=[1] * ureg.RIU,
3533
source=source,
3634
)
3735

docs/examples/experiment/coreshell/coreshell_coupling_vs_corediameter.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,41 @@
55
This example demonstrates how to compute and visualize the coupling efficiency as a function of core diameter for CoreShell scatterers using PyMieSim.
66
"""
77

8-
# %%
9-
# Importing the package dependencies: numpy, PyMieSim
108
import numpy
119
from PyMieSim.units import ureg
1210

13-
from PyMieSim.experiment.detector import Photodiode
14-
from PyMieSim.experiment.scatterer import CoreShell
15-
from PyMieSim.experiment.source import Gaussian, PolarizationSet
11+
from PyMieSim.experiment.detector import PhotodiodeSet
12+
from PyMieSim.experiment.scatterer import CoreShellSet
13+
from PyMieSim.experiment.source import GaussianSet, PolarizationSet
1614
from PyMieSim.experiment import Setup
1715
from PyOptik import Material
1816

1917
polarization_set = PolarizationSet(
2018
angles=[90.0] * ureg.degree,
2119
)
2220

23-
source = Gaussian(
24-
wavelength=1.2 * ureg.micrometer, # 1200 nm
25-
polarization=polarization_set, # Polarization angle in ureg.degrees
26-
optical_power=1e-3 * ureg.watt, # 1 milliureg.watt
27-
numerical_aperture=0.2 * ureg.AU, # Numerical Aperture
21+
source = GaussianSet(
22+
wavelength=[1.2] * ureg.micrometer,
23+
polarization=polarization_set,
24+
optical_power=[1e-3] * ureg.watt,
25+
numerical_aperture=[0.2] * ureg.AU,
2826
)
2927

30-
scatterer = CoreShell(
31-
core_diameter=numpy.geomspace(100, 600, 400)
32-
* ureg.nanometer, # Core diameters from 100 nm to 600 nm
33-
shell_thickness=800 * ureg.nanometer, # Shell width of 800 nm
34-
core_refractive_index=Material.silver, # Core material
35-
shell_refractive_index=Material.BK7, # Shell material
36-
medium_refractive_index=1 * ureg.RIU, # Surrounding medium's refractive index
28+
scatterer = CoreShellSet(
29+
core_diameter=numpy.geomspace(100, 600, 400) * ureg.nanometer,
30+
shell_thickness=[800] * ureg.nanometer,
31+
core_material=[Material.silver],
32+
shell_material=[Material.BK7],
33+
medium_refractive_index=[1] * ureg.RIU,
3734
source=source,
3835
)
3936

40-
detector = Photodiode(
41-
numerical_aperture=[0.1] * ureg.AU, # Numerical Apertures for the detector
42-
phi_offset=-180.0 * ureg.degree, # Phi offset in ureg.degrees
43-
gamma_offset=0.0 * ureg.degree, # Gamma offset in ureg.degrees
44-
sampling=600, # Number of sampling points
45-
polarization_filter=1 * ureg.degree,
37+
detector = PhotodiodeSet(
38+
numerical_aperture=[0.1] * ureg.AU,
39+
phi_offset=[-180.0] * ureg.degree,
40+
gamma_offset=[0.0] * ureg.degree,
41+
sampling=[600],
42+
polarization_filter=[1] * ureg.degree,
4643
)
4744

4845
experiment = Setup(scatterer=scatterer, source=source, detector=detector)

docs/examples/experiment/coreshell/coreshell_coupling_vs_na_cache.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,39 @@
1010
import numpy
1111
from PyMieSim.units import ureg
1212

13-
from PyMieSim.experiment.detector import Photodiode
14-
from PyMieSim.experiment.scatterer import CoreShell
15-
from PyMieSim.experiment.source import Gaussian, PolarizationSet
13+
from PyMieSim.experiment.detector import PhotodiodeSet
14+
from PyMieSim.experiment.scatterer import CoreShellSet
15+
from PyMieSim.experiment.source import GaussianSet, PolarizationSet
1616
from PyMieSim.experiment import Setup
1717
from PyOptik import Material
1818

1919
polarization_set = PolarizationSet(
2020
angles=[90.0] * ureg.degree,
2121
)
2222

23-
source = Gaussian(
24-
wavelength=1.2 * ureg.micrometer, # 1200 nm
25-
polarization=polarization_set, # Polarization angle in ureg.degrees
26-
optical_power=1e-3 * ureg.watt, # 1 milliureg.watt
27-
numerical_aperture=0.2 * ureg.AU, # Numerical Aperture
23+
source = GaussianSet(
24+
wavelength=[0.5] * ureg.micrometer,
25+
polarization=polarization_set,
26+
optical_power=[1e-3] * ureg.watt,
27+
numerical_aperture=[0.2] * ureg.AU,
2828
)
2929

30-
scatterer = CoreShell(
31-
core_diameter=[1000, 1250, 1500] * ureg.nanometer, # Core diameters from 100 nm to 600 nm
32-
shell_thickness=800 * ureg.nanometer, # Shell width of 800 nm
33-
core_refractive_index=Material.silver, # Core material
34-
shell_refractive_index=Material.BK7, # Shell material
35-
medium_refractive_index=1. * ureg.RIU, # Surrounding medium's refractive index
30+
scatterer = CoreShellSet(
31+
core_diameter=[1000, 1250, 1500] * ureg.nanometer,
32+
shell_thickness=[800] * ureg.nanometer,
33+
core_material=[Material.silver],
34+
shell_material=[Material.BK7],
35+
medium_refractive_index=[1.] * ureg.RIU,
3636
source=source,
3737
)
3838

39-
detector = Photodiode(
40-
numerical_aperture=[0.3] * ureg.AU, # Numerical Apertures for the detector
39+
detector = PhotodiodeSet(
40+
numerical_aperture=[0.3] * ureg.AU,
4141
cache_numerical_aperture=numpy.linspace(0.0, 0.2, 200) * ureg.AU,
42-
phi_offset=-180.0 * ureg.degree, # Phi offset in ureg.degrees
43-
gamma_offset=0.0 * ureg.degree, # Gamma offset in ureg.degrees
44-
sampling=4000, # Number of sampling points
45-
polarization_filter=1 * ureg.degree,
42+
phi_offset=[-180.0] * ureg.degree,
43+
gamma_offset=[0.0] * ureg.degree,
44+
sampling=[1000],
45+
polarization_filter=[1] * ureg.degree,
4646
)
4747

4848
experiment = Setup(scatterer=scatterer, source=source, detector=detector)

0 commit comments

Comments
 (0)