-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
480931a
commit 9964f70
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |