Skip to content

Commit

Permalink
Add missing background level to comparisons of fits with object conti…
Browse files Browse the repository at this point in the history
…nuum model, eliminating a 30-count discrepancy. Reduce tolerances accordingly (with a few counts of leeway).
  • Loading branch information
jehturner committed Apr 14, 2021
1 parent 4b11d05 commit a09b4b3
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions gempy/library/tests/test_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def setup_class(self):
Gaussian1D(amplitude=1., mean=15.8, stddev=2.)(slit))

# A continuum level makes for a more stable comparison of fit vs data:
sky = sky_model(wav.value) + 30.
self.bglev = 30.
sky = sky_model(wav.value) + self.bglev

data = obj + sky

Expand Down Expand Up @@ -122,7 +123,7 @@ def test_chebyshev_def_ax_quartic(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5,
plot=debug).evaluate()

assert_allclose(fit_vals, self.obj, atol=40., rtol=0.025)
assert_allclose(fit_vals, self.obj + self.bglev, atol=15., rtol=0.015)

def test_chebyshev_ax1_quartic_grow2(self):
"""
Expand All @@ -136,7 +137,7 @@ def test_chebyshev_ax1_quartic_grow2(self):
sigma_lower=3.7, sigma_upper=3.7, niter=5, grow=2,
plot=debug).evaluate()

assert_allclose(fit_vals, self.obj, atol=40., rtol=0.02)
assert_allclose(fit_vals, self.obj + self.bglev, atol=15., rtol=0.015)

def test_chebyshev_single_quartic(self):
"""
Expand All @@ -148,7 +149,8 @@ def test_chebyshev_single_quartic(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5,
plot=debug).evaluate()

assert_allclose(fit_vals, self.obj[16], atol=30., rtol=0.02)
assert_allclose(fit_vals, self.obj[16] + self.bglev, atol=5.,
rtol=0.015)

def test_chebyshev_1_model_def_ax_quartic(self):
"""
Expand All @@ -160,10 +162,8 @@ def test_chebyshev_1_model_def_ax_quartic(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5,
plot=debug).evaluate()

# This should work, but currently fails because fit_1D is returning
# a result with shape (140, 1) from (1, 140) inputs.

assert_allclose(fit_vals, self.obj[16:17], atol=30., rtol=0.02)
assert_allclose(fit_vals, self.obj[16:17] + self.bglev, atol=5.,
rtol=0.015)

def test_chebyshev_1_model_ax0_lin(self):
"""
Expand Down Expand Up @@ -240,7 +240,7 @@ def test_cubic_spline_def_ax_ord3(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5, grow=1,
plot=debug).evaluate()

assert_allclose(fit_vals, self.obj, atol=40., rtol=0.02)
assert_allclose(fit_vals, self.obj + self.bglev, atol=20., rtol=0.01)

def test_legendre_ax1_quartic(self):
"""
Expand All @@ -252,7 +252,7 @@ def test_legendre_ax1_quartic(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5,
plot=debug).evaluate()

assert_allclose(fit_vals, self.obj, atol=40., rtol=0.02)
assert_allclose(fit_vals, self.obj + self.bglev, atol=20., rtol=0.01)

def test_chebyshev_def_ax_quartic_masked(self):
"""
Expand All @@ -264,7 +264,7 @@ def test_chebyshev_def_ax_quartic_masked(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5, plot=debug)
fit_vals = fit1d.evaluate()

assert_allclose(fit_vals, self.obj, atol=40., rtol=0.02)
assert_allclose(fit_vals, self.obj + self.bglev, atol=20., rtol=0.01)

# Ensure that masked input values have been passed through to the
# output mask by the fitter:
Expand All @@ -285,7 +285,7 @@ def test_cubic_spline_def_ax_ord3_masked(self):
plot=debug)
fit_vals = fit1d.evaluate()

assert_allclose(fit_vals, self.obj, atol=40., rtol=0.02)
assert_allclose(fit_vals, self.obj + self.bglev, atol=20., rtol=0.01)

# Ensure that masked input values have been passed through to the
# output mask by the fitter:
Expand All @@ -309,7 +309,8 @@ def setup_class(self):
x_stddev=2.1, y_stddev=1.9)(x, y))

# A continuum level makes for a more stable comparison of fit vs data:
sky = sky_model(wav) + 30.
self.bglev = 30.
sky = sky_model(wav) + self.bglev

data = obj + sky

Expand All @@ -332,7 +333,7 @@ def test_chebyshev_ax0_quartic(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5,
plot=debug).evaluate()

assert_allclose(fit_vals, self.obj, atol=45., rtol=0.015)
assert_allclose(fit_vals, self.obj + self.bglev, atol=20., rtol=0.01)

def test_chebyshev_def_ax_quartic(self):
"""
Expand All @@ -350,7 +351,7 @@ def test_chebyshev_def_ax_quartic(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5,
plot=debug).evaluate()

assert_allclose(fit_vals, self.obj.T, atol=45., rtol=0.015)
assert_allclose(fit_vals, self.obj.T + self.bglev, atol=20., rtol=0.01)

def test_cubic_spline_ax0_ord3(self):
"""
Expand All @@ -363,7 +364,7 @@ def test_cubic_spline_ax0_ord3(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5,
plot=debug).evaluate()

assert_allclose(fit_vals, self.obj, atol=45., rtol=0.015)
assert_allclose(fit_vals, self.obj + self.bglev, atol=20., rtol=0.01)

def test_cubic_spline_def_ax_ord3(self):
"""
Expand All @@ -376,7 +377,7 @@ def test_cubic_spline_def_ax_ord3(self):
sigma_lower=2.5, sigma_upper=2.5, niter=5,
plot=debug).evaluate()

assert_allclose(fit_vals, self.obj.T, atol=45., rtol=0.015)
assert_allclose(fit_vals, self.obj.T + self.bglev, atol=20., rtol=0.01)

def test_cubic_spline_ax1_ord3_grow1(self):
"""
Expand All @@ -390,8 +391,8 @@ def test_cubic_spline_ax1_ord3_grow1(self):
sigma_lower=3.5, sigma_upper=3.5, niter=5, grow=1,
plot=debug).evaluate()

assert_allclose(fit_vals, np.rollaxis(self.obj, 0, 2),
atol=45., rtol=0.015)
assert_allclose(fit_vals, np.rollaxis(self.obj, 0, 2) + self.bglev,
atol=20., rtol=0.01)


class TestFit1DNewPoints:
Expand Down

0 comments on commit a09b4b3

Please sign in to comment.