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

Integrate docs pages from NSLS-II guide #136

Closed
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
32 changes: 32 additions & 0 deletions docs/pages/developers/refraction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# example/refraction.py

import numpy as np


def snell(theta_inc, n1, n2):
"""
Compute the refraction angle using Snell's Law.

See https://en.wikipedia.org/wiki/Snell%27s_law

Parameters
----------
theta_inc : float
Incident angle in radians.
n1, n2 : float
The refractive index of medium of origin and destination medium.

Returns
-------
theta : float
refraction angle

Examples
--------
A ray enters an air--water boundary at pi/4 radians (45 degrees).
Compute exit angle.

>>> snell(np.pi/4, 1.00, 1.33)
0.5605584137424605
"""
return np.arcsin(n1 / n2 * np.sin(theta_inc))
26 changes: 26 additions & 0 deletions docs/pages/developers/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# example/tests/test_examples.py

import numpy as np
from ..refraction import snell
# (The above is equivalent to `from example.refraction import snell`.
# Read on for why.)


def test_perpendicular():
# For any indexes, a ray normal to the surface should not bend.
# We'll try a couple different combinations of indexes....

actual = snell(0, 2.00, 3.00)
expected = 0
assert actual == expected

actual = snell(0, 3.00, 2.00)
expected = 0
assert actual == expected


def test_air_water():
n_air, n_water = 1.00, 1.33
actual = snell(np.pi/4, n_air, n_water)
expected = 0.5605584137424605
assert np.allclose(actual, expected)
Loading