def test_absolute_ratio_benchmark(): # Mostly sanity to check that Analytical functions don't have typos # or syntax errors n = 501 r_max = 50 for symmetric in [True, False]: for Backend, options in [(StepAnalytical, dict(A0=10.0, r1=6.0, r2=14.0, ratio_valid_step=1.0)), (GaussianAnalytical, dict(sigma=2))]: ref = Backend(n, r_max, symmetric=symmetric, **options) ratio = absolute_ratio_benchmark(ref, ref.func) backend_name = type(ref).__name__ assert_allclose_msg( ratio.mean(), 1.0, "Sanity test, sym={}: {}: ratio == 1.0".format( symmetric, backend_name)) assert_allclose_msg( ratio.std(), 0.0, "Sanity test, sym={}: {}: std == 0.0".format( symmetric, backend_name))
def test_fabel_hansenlaw_transform_gaussian(): """Check fabel_hansenlaw with a Gaussian function""" n = 1001 r_max = 501 # more points better fit ref = GaussianAnalytical(n, r_max, symmetric=False, sigma=200) recon = fabel_hansenlaw_transform(ref.func, ref.dr) ratio = absolute_ratio_benchmark(ref, recon, kind='direct') assert_allclose(ratio, 1.0, rtol=7e-2, atol=0)
def test_iabel_hansenlaw_gaussian(): """Check iabel_hansenlaw with a Gaussian function""" n = 1001 # better with a larger number of points r_max = 501 ref = GaussianAnalytical(n, r_max, symmetric=True, sigma=200) tr = np.tile(ref.abel[None, :], (n, 1)) # make a 2D array from 1D recon = iabel_hansenlaw(tr, ref.dr) recon1d = recon[n // 2 + n % 2] # centre row ratio = absolute_ratio_benchmark(ref, recon1d) assert_allclose(ratio, 1.0, rtol=1e-1, atol=0)
def test_forward_direct_gaussian(): """Check fabel_direct with a Gaussian""" if not cython_ext: raise SkipTest n = 51 r_max = 25 ref = GaussianAnalytical(n, r_max, symmetric=False, sigma=10) recon = fabel_direct(ref.func, dr=ref.dr) ratio = absolute_ratio_benchmark(ref, recon, kind='direct') assert_allclose(ratio, 1.0, rtol=7e-2, atol=0)
def test_iabel_hansenlaw_gaussian(): """Check iabel_hansenlaw with a Gaussian function""" n = 1001 # better with a larger number of points r_max = 501 ref = GaussianAnalytical(n, r_max, symmetric=True, sigma=200) tr = np.tile(ref.abel[None, :], (n, 1)) # make a 2D array from 1D recon = iabel_hansenlaw(tr, ref.dr) recon1d = recon[n//2 + n%2] # centre row ratio = absolute_ratio_benchmark(ref, recon1d) assert_allclose(ratio, 1.0, rtol=1e-1, atol=0)
def test_three_point_step_ratio(): """Check a gaussian solution for three_point""" n = 51 r_max = 25 ref = GaussianAnalytical(n, r_max, symmetric=True, sigma=10) tr = np.tile(ref.abel[None, :], (n, 1)) # make a 2D array from 1D recon = iabel_three_point(tr, 25, basis_dir=None, verbose=False) recon1d = recon[n // 2 + n % 2] ratio = absolute_ratio_benchmark(ref, recon1d) assert_allclose(ratio, 1.0, rtol=3e-2, atol=0)
def test_basex_step_ratio_asym(): """Check a gaussian solution for asymmetric BASEX""" n = 51 r_max = 25 ref = GaussianAnalytical(n, r_max, symmetric=True, sigma=10) tr = np.tile(ref.abel[None, :], (n, 1)) # make a 2D array from 1D bs = get_bs_basex_cached_asym(n, n, basis_dir=None, verbose=False) recon = basex_transform_asym(tr, *bs) recon1d = recon[n // 2 + n % 2] ratio = absolute_ratio_benchmark(ref, recon1d) assert_allclose(ratio, 1.0, rtol=3e-2, atol=0)
def test_hansenlaw_gaussian(): """Check a gaussian solution for HansenLaw""" n = 51 r_max = 25 ref = GaussianAnalytical(n, r_max, symmetric=True, sigma=10) tr = np.tile(ref.abel[None, :], (n, 1)) # make a 2D array from 1D recon = iabel_hansenlaw(tr, calc_speeds=False, verbose=False) recon1d = recon[n // 2 + n % 2] ratio = absolute_ratio_benchmark(ref, recon1d) # this only passes with a relative tolerance of 0.35, someone would # need to look into it. assert_allclose(ratio, 1.0, rtol=0.35, atol=0)
def test_three_point_step_ratio(): """Check a gaussian solution for three_point""" n = 51 r_max = 25 ref = abel.tools.analytical.GaussianAnalytical(n, r_max, symmetric=True, sigma=10) tr = np.tile(ref.abel[None, :], (n, 1)) # make a 2D array from 1D recon = abel.three_point.three_point(tr, 25, basis_dir=None, direction='inverse',verbose=False) recon1d = recon[n//2 + n%2] ratio = absolute_ratio_benchmark(ref, recon1d) assert_allclose( ratio , 1.0, rtol=3e-2, atol=0)
def test_absolute_ratio_benchmark(): # Mostly sanity to check that Analytical functions don't have typos # or syntax errors n = 501 r_max = 50 for symmetric in [True, False]: for Backend, options in [(StepAnalytical, dict(A0=10.0, r1=6.0, r2=14.0, ratio_valid_step=1.0)), (GaussianAnalytical, dict(sigma=2))]: ref = Backend(n, r_max, symmetric=symmetric, **options) ratio = absolute_ratio_benchmark(ref, ref.func) backend_name = type(ref).__name__ assert_allclose_msg(ratio.mean(), 1.0, "Sanity test, sym={}: {}: ratio == 1.0".format(symmetric, backend_name)) assert_allclose_msg(ratio.std(), 0.0, "Sanity test, sym={}: {}: std == 0.0".format(symmetric, backend_name))