Skip to content

Commit

Permalink
Add reflectance calculations.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKGrimes committed Oct 1, 2020
1 parent 480931a commit 9964f70
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

0.3.5 (2020-10-01)
------------------

* Add functions for calculating reflectance and transmission - useful for correcting for lack of AR coatings in
GRASP PO calculations of lens and dielectrics.

0.3.4 (2020-10-01)
------------------

Expand Down
41 changes: 41 additions & 0 deletions src/graspfile/analysis/reflectance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import numpy as np


def reflectance(n1, n2):
"""Calculate the amplitude reflection coefficient due to moving from media with index n1 to media with index n2.
Args:
n1 (float:): Refractive index of media 1.
n2 (float:): Refractive index of media 2.
Returns:
float: Reflection coefficient"""
return (n1 - n2) / (n1 + n2)


def transmittance(n1, n2):
"""Calculate the amplitude transmission coefficient due to moving from media with index n1 to media with index n2.
Args:
n1 (float:): Refractive index of media 1.
n2 (float:): Refractive index of media 2.
Returns:
float: Transmission coefficient"""
return np.sqrt(1.0 - ((n1 - n2) / (n1 + n2)) ** 2)


def total_transmittance(ns):
"""Calculate the total transmission coeffficient due to moving through media with listed indices. No interference
is included, making this calculation suitable for cascaded PO calculations in GRASP.
Args:
ns (list: of float:): List of refractive indices of media
Returns:
float: total transmittance."""
t = 1.0
for i in range(len(ns) - 1):
t *= transmittance(ns[i], ns[i + 1])

return t
35 changes: 35 additions & 0 deletions tests/test_analysis_reflectance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np
import pytest

from graspfile.analysis import reflectance


@pytest.fixture
def indices():
"""Return a list of refractive indices for testing."""
return [1.0, 3.0, 1.0, 3.0, 1.0]


def test_reflectance():
"""Test single reflectance value"""
r = reflectance.reflectance(1.0, 2.0)

assert pytest.approx(r) == (1.0 - 2.0)/(1.0 + 2.0)


def test_transmittance():
"""Test single transmittance value"""
t = reflectance.transmittance(1.0, 2.0)

assert pytest.approx(t) == np.sqrt(1.0 - ((1.0 - 2.0)/(1.0 + 2.0))**2)


def test_total_transmittance(indices):
"""Test cascaded transmittance value"""
t = reflectance.total_transmittance(indices)

t_test = 1.0
for i in range(len(indices)-1):
t_test *= reflectance.transmittance(indices[i], indices[i+1])

assert pytest.approx(t) == t_test

0 comments on commit 9964f70

Please sign in to comment.