Skip to content

Commit

Permalink
Added optika.surfaces module.
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie committed Sep 14, 2023
1 parent c97c8b5 commit 3360a66
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 3 deletions.
1 change: 1 addition & 0 deletions optika/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import materials
from . import apertures
from . import rulings
from . import surfaces
9 changes: 7 additions & 2 deletions optika/_tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ def test_plot(
for index in ax_normalized.ndindex():
assert ax_normalized[index].ndarray.has_data()

assert isinstance(result, na.AbstractScalar)
assert result.dtype == matplotlib.artist.Artist
if isinstance(result, dict):
for k in result:
assert isinstance(result[k], na.AbstractScalar)
assert result[k].dtype == matplotlib.artist.Artist
else:
assert isinstance(result, na.AbstractScalar)
assert result.dtype == matplotlib.artist.Artist
26 changes: 26 additions & 0 deletions optika/_tests/test_propagators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
import abc
import numpy as np
import optika.propagators
import optika.rays._tests.test_ray_vectors


class AbstractTestAbstractPropagator(
abc.ABC,
):
pass


class AbstractTestAbstractRayPropagator(
AbstractTestAbstractPropagator,
):
@pytest.mark.parametrize("rays", optika.rays._tests.test_ray_vectors.rays)
def test_propagate_rays(
self,
a: optika.propagators.AbstractRayPropagator,
rays: optika.rays.AbstractRayVectorArray,
):
result = a.propagate_rays(rays)

assert isinstance(result, optika.rays.AbstractRayVectorArray)
assert not np.all(result == rays)
63 changes: 63 additions & 0 deletions optika/_tests/test_surfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import pytest
import astropy.units as u
import named_arrays as na
import optika
from . import test_mixins
from . import test_plotting
from . import test_propagators


surfaces = [
optika.surfaces.Surface(),
optika.surfaces.Surface(
name="test_surface",
sag=optika.sags.SphericalSag(radius=1000 * u.mm),
material=optika.materials.Mirror(),
aperture=optika.apertures.RectangularAperture(half_width=10 * u.mm),
transformation=na.transformations.Cartesian3dTranslation(z=100 * u.mm),
),
]


class AbstractTestAbstractSurface(
test_plotting.AbstractTestPlottable,
test_mixins.AbstractTestTransformable,
test_propagators.AbstractTestAbstractRayPropagator,
):
def test_name(self, a: optika.surfaces.AbstractSurface):
if a.name is not None:
assert isinstance(a.name, str)

def test_sag(self, a: optika.surfaces.AbstractSurface):
assert isinstance(a.sag, optika.sags.AbstractSag)

def test_material(self, a: optika.surfaces.AbstractSurface):
assert isinstance(a.material, optika.materials.AbstractMaterial)

def test_aperture(self, a: optika.surfaces.AbstractSurface):
if a.aperture is not None:
assert isinstance(a.aperture, optika.apertures.AbstractAperture)

def test_aperture_mechanical(self, a: optika.surfaces.AbstractSurface):
if a.aperture_mechanical is not None:
assert isinstance(a.aperture_mechanical, optika.apertures.AbstractAperture)

def test_rulings(self, a: optika.surfaces.AbstractSurface):
if a.rulings is not None:
assert isinstance(a.rulings, optika.rulings.AbstractRulings)

def test_is_field_stop(self, a: optika.surfaces.AbstractSurface):
assert isinstance(a.is_field_stop, bool)

def test_is_pupil_stop(self, a: optika.surfaces.AbstractSurface):
assert isinstance(a.is_pupil_stop, bool)

def test_is_spectral_stop(self, a: optika.surfaces.AbstractSurface):
assert isinstance(a.is_spectral_stop, bool)


@pytest.mark.parametrize("a", surfaces)
class TestSurface(
AbstractTestAbstractSurface,
):
pass
2 changes: 1 addition & 1 deletion optika/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def plot(
transformation: None | na.transformations.AbstractTransformation = None,
components: None | tuple[str, ...] = None,
**kwargs,
) -> na.AbstractScalar:
) -> na.AbstractScalar | dict[str, na.AbstractScalar]:
"""
Plot the selected components onto the given axes.
Expand Down
35 changes: 35 additions & 0 deletions optika/propagators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import abc
import dataclasses
import optika

__all__ = [
"AbstractPropagator",
"AbstractRayPropagator",
]


@dataclasses.dataclass(eq=False, repr=False)
class AbstractPropagator(
abc.ABC,
):
pass


@dataclasses.dataclass(eq=False, repr=False)
class AbstractRayPropagator(
AbstractPropagator,
):
@abc.abstractmethod
def propagate_rays(
self,
rays: optika.rays.AbstractRayVectorArray,
) -> optika.rays.AbstractRayVectorArray:
"""
for the given input rays, calculate new rays based off of their
interation with this object
Parameters
----------
rays
a set of input rays that will interact with this object
"""
Loading

0 comments on commit 3360a66

Please sign in to comment.