Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optika.materials.AbstractLayer.n() method. #50

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion optika/materials/_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ class AbstractLayer(
of homogeneous layers.
"""

@abc.abstractmethod
def n(
self,
wavelength: u.Quantity | na.AbstractScalar,
) -> na.AbstractScalar:
"""
The index of refraction on the left side of the layer.

Parameters
----------
wavelength
The wavelength of the incident light in vacuum
"""

@property
@abc.abstractmethod
def thickness(self) -> u.Quantity | na.AbstractScalar:
Expand Down Expand Up @@ -179,7 +193,7 @@ def n(
wavelength: u.Quantity | na.AbstractScalar,
) -> float | na.AbstractScalar:
"""
The complex index of refraction of this layer.
The complex index of refraction of this entire layer.
"""
if self.chemical is None:
return 1
Expand Down Expand Up @@ -384,6 +398,12 @@ class LayerSequence(AbstractLayerSequence):
layers: Sequence[AbstractLayer] = dataclasses.MISSING
"""A sequence of layers."""

def n(
self,
wavelength: u.Quantity | na.AbstractScalar,
) -> na.AbstractScalar:
return self.layers[0].n(wavelength)

@property
def thickness(self) -> u.Quantity | na.AbstractScalar:
result = 0 * u.nm
Expand Down Expand Up @@ -508,6 +528,12 @@ class PeriodicLayerSequence(AbstractLayerSequence):
num_periods: int = dataclasses.MISSING
"""The number of times to repeat the layer sequence."""

def n(
self,
wavelength: u.Quantity | na.AbstractScalar,
) -> na.AbstractScalar:
return self.layers[0].n(wavelength)

@property
def thickness(self) -> u.Quantity | na.AbstractScalar:
return self.num_periods * LayerSequence(self.layers).thickness
Expand Down
10 changes: 10 additions & 0 deletions optika/materials/_tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ class AbstractTestAbstractLayer(
optika._tests.test_mixins.AbstractTestPrintable,
):

@pytest.mark.parametrize("wavelength", [100 * u.AA])
def test_n(
self,
a: optika.materials.AbstractLayer,
wavelength: u.Quantity | na.AbstractScalar,
):
result = a.n(wavelength)
assert np.all(np.real(result) >= 0)
assert np.all(np.imag(result) >= 0)

def test_thickness(
self,
a: optika.materials.AbstractLayer,
Expand Down
Loading