Skip to content

Commit

Permalink
enh: introduce UnsupportedModelParametersError to detect bad model pa…
Browse files Browse the repository at this point in the history
…ramters for the rytov-sc model
  • Loading branch information
paulmueller committed Sep 13, 2019
1 parent 09cb19a commit 8f7d512
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -1,3 +1,6 @@
0.5.4
- enh: introduce UnsupportedModelParametersError to detect bad model
paramters for the rytov-sc model
0.5.3
- fix: also guess initial values for image method if edge detection
is ill-defined (RadiusExceedsImageSizeError)
Expand Down
3 changes: 3 additions & 0 deletions qpsphere/models/excpt.py
@@ -0,0 +1,3 @@
class UnsupportedModelParametersError(BaseException):
"""Used when a specific model cannot handle input parameters"""
pass
10 changes: 10 additions & 0 deletions qpsphere/models/mod_rytov_sc.py
@@ -1,6 +1,11 @@
import numpy as np

from . import mod_rytov
from .excpt import UnsupportedModelParametersError


class RefractiveIndexLowerThanMediumError(UnsupportedModelParametersError):
pass


#: correction parameters (see :func:`correct_rytov_output`)
Expand Down Expand Up @@ -43,6 +48,11 @@ def correct_rytov_sc_input(radius_sc, sphere_index_sc, medium_index,
"""
params = get_params(radius_sampling)

if sphere_index_sc < medium_index:
raise RefractiveIndexLowerThanMediumError(
"The object refractive index {} is ".format(sphere_index_sc)
+ "lower than that of the medium {} ".format(medium_index)
+ "which is not supported by the rytov-sc model.")
# sage script:
# var('sphere_index, sphere_index_sc, na, nb, medium_index')
# x = sphere_index / medium_index - 1
Expand Down
18 changes: 17 additions & 1 deletion tests/test_rytov_sc.py
@@ -1,6 +1,6 @@
import numpy as np

from qpsphere.models import mod_rytov_sc, mod_rytov
from qpsphere.models import excpt, mod_rytov_sc, mod_rytov


def test_parameter_inversion():
Expand Down Expand Up @@ -46,6 +46,22 @@ def test_basic():
assert np.all(qpi.pha == qpi_sc.pha)


def test_unsupported_parameters():
kwargs = dict(grid_size=(20, 20),
center=(9.5, 9.5),
radius=5e-6,
sphere_index=1.330,
medium_index=1.333,
wavelength=550e-9,
pixel_size=1e-6)
try:
mod_rytov_sc.rytov_sc(**kwargs)
except excpt.UnsupportedModelParametersError:
pass
else:
assert False, "Sphere index lower than medium should error out"


if __name__ == "__main__":
# Run all tests
loc = locals()
Expand Down

0 comments on commit 8f7d512

Please sign in to comment.