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

Add opticalsurface component and unit test #120

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 30 additions & 0 deletions architect/systems/optical/optical_surface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""An optical surface component."""

# external
import astropy.units as unit
import numpy as np

# project
from architect.systems import Component


class OpticalSurface(Component):
"""An optical surface is a component that can refract light."""

def __init__(self, medium_index=None):
super().__init__()
self.medium_index = medium_index

def angle_of_refraction(self, incident_angle: unit.deg, incident_index) -> unit.deg:
"""Get the angle of refraction for a given incident angle.

Ref: https://www.notion.so/utat-ss/Angle-of-Refraction-a4c5f3235ad941398137dd3560eec717

"""
assert self.medium_index is not None, "medium_index must be set."

angle_of_refraction = np.arcsin(
incident_index * np.sin(incident_angle) / self.medium_index
)

return angle_of_refraction.to(unit.deg)
35 changes: 35 additions & 0 deletions tests/test_systems/test_optical/test_OpticalSurface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Tests for OpticalSurface."""

# stdlib
import logging

# external
import astropy.units as unit

# project
from architect.systems.optical.optical_surface import OpticalSurface

LOG = logging.getLogger(__name__)


def test_init():
"""Test init method."""

component = OpticalSurface()
LOG.info(component)


def test_angle_of_refraction():
"""Test angle_of_refraction method."""

component = OpticalSurface(medium_index=1.5)

incident_angle = 45 * unit.deg
incident_index = 1.0
angle_of_refraction = component.angle_of_refraction(
incident_angle=incident_angle, incident_index=incident_index
)

LOG.info(angle_of_refraction)

assert angle_of_refraction.unit == unit.deg