Commit 3459b151 authored by Martin Glatzle's avatar Martin Glatzle

Make interpolation work with len 1 arrays.

parent 745f1f71
...@@ -122,20 +122,22 @@ class Crefin(object): ...@@ -122,20 +122,22 @@ class Crefin(object):
if bounds_error and not a_bounds_error: if bounds_error and not a_bounds_error:
def f(aa, lam): def f(aa, lam):
r = _np.clip(aa, _np.amin(a), _np.amax(a)) r = _np.clip(aa, _np.amin(a), _np.amax(a))
rowind_unsorted = _np.argsort(r) n = rinterpolation(lam, r) + 1j*iinterpolation(lam, r)
colind_unsorted = _np.argsort(lam) if _np.prod(r.shape)*_np.prod(lam.shape) > 1:
return ( rowind_unsorted = _np.argsort(r)
rinterpolation(lam, r) colind_unsorted = _np.argsort(lam)
+ 1j*iinterpolation(lam, r))[ return n[rowind_unsorted][:, colind_unsorted]
rowind_unsorted][:, colind_unsorted] else:
return _np.atleast_2d(n)
else: else:
def f(a, lam): def f(a, lam):
rowind_unsorted = _np.argsort(lam) n = rinterpolation(lam, a) + 1j*iinterpolation(lam, a)
colind_unsorted = _np.argsort(r) if _np.prod(r.shape)*_np.prod(lam.shape) > 1:
return ( rowind_unsorted = _np.argsort(lam)
rinterpolation(lam, a) colind_unsorted = _np.argsort(r)
+ 1j*iinterpolation(lam, a))[ return n[rowind_unsorted][:, colind_unsorted]
rowind_unsorted][:, colind_unsorted] else:
return _np.atleast_2d(n)
return cls(f) return cls(f)
......
...@@ -52,6 +52,21 @@ class TestFromData(TestCase): ...@@ -52,6 +52,21 @@ class TestFromData(TestCase):
a = crefin.Crefin.fromData(c.a2, c.lam2, c.n2) a = crefin.Crefin.fromData(c.a2, c.lam2, c.n2)
return return
def test_single_element(self):
c = self.__class__
a = crefin.Crefin.fromData(c.a2, c.lam2, c.n2)
n = a(
np.array([1e-9])*u.micron,
np.array([8])*u.micron
)
self.assertTrue
return
def test_single_element_no_bounds(self):
c = self.__class__
a = crefin.Crefin.fromData(c.a2, c.lam2, c.n2)
return
def test_normal_no_bounds(self): def test_normal_no_bounds(self):
c = self.__class__ c = self.__class__
a = crefin.Crefin.fromData(c.a2, c.lam2, c.n2, a = crefin.Crefin.fromData(c.a2, c.lam2, c.n2,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment