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.layer_sequence property. #42

Merged
merged 1 commit into from
Jun 8, 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
19 changes: 19 additions & 0 deletions optika/materials/_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def thickness(self) -> u.Quantity | na.AbstractScalar:
def _thickness_plot(self) -> u.Quantity | na.AbstractScalar:
"""The thickness of the layer when plotted."""

@property
@abc.abstractmethod
def layer_sequence(self) -> LayerSequence:
"""
This object interpreted as an instance of :class:`LayerSequence`.
"""

@abc.abstractmethod
def transfer(
self,
Expand Down Expand Up @@ -180,6 +187,10 @@ def n(
else:
return self._chemical.n(wavelength)

@property
def layer_sequence(self) -> LayerSequence:
return LayerSequence([self])

def transfer(
self,
wavelength: u.Quantity | na.AbstractScalar,
Expand Down Expand Up @@ -382,6 +393,10 @@ def thickness(self) -> u.Quantity | na.AbstractScalar:
def _thickness_plot(self) -> u.Quantity | na.AbstractScalar:
return self.thickness

@property
def layer_sequence(self) -> LayerSequence:
return self

def transfer(
self,
wavelength: u.Quantity | na.AbstractScalar,
Expand Down Expand Up @@ -493,6 +508,10 @@ def thickness(self) -> u.Quantity | na.AbstractScalar:
def _thickness_plot(self) -> u.Quantity | na.AbstractScalar:
return LayerSequence(self.layers).thickness

@property
def layer_sequence(self) -> LayerSequence:
return LayerSequence(self.layers * self.num_periods)

def transfer(
self,
wavelength: u.Quantity | na.AbstractScalar,
Expand Down
9 changes: 9 additions & 0 deletions optika/materials/_tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def test_thickness(
result = a.thickness
assert np.all(result >= 0 * u.nm)

def test_layer_sequence(
self,
a: optika.materials.AbstractLayer,
):
result = a.layer_sequence
assert isinstance(result, optika.materials.LayerSequence)
for layer in result.layers:
assert isinstance(layer, optika.materials.AbstractLayer)

@pytest.mark.parametrize(
argnames="wavelength",
argvalues=[
Expand Down
Loading