Skip to content

Commit

Permalink
Wrote test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcrenshaw committed Dec 5, 2024
1 parent c9f36bb commit b305211
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions tests/estimation/test_danish.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,45 +50,46 @@ def testGoodLstsqKwargs(self):
self.assertEqual(hist["lstsqResult"]["nfev"], 1)

def testAccuracy(self):
# Create estimator
dan = DanishAlgorithm()
danBin = DanishAlgorithm(binning=2)

# Try several different random seeds
for seed in [12345, 23451, 34512, 45123, 51234]:
# Get the test data
zkTrue, intra, extra = forwardModelPair(seed=seed)

# Compute shape of binned images
shapex, shapey = intra.image.shape
binned_shapex = shapex // 2
binned_shapey = shapey // 2

# Ensure odd
if binned_shapex % 2 == 0:
binned_shapex -= 1
if binned_shapey % 2 == 0:
binned_shapey -= 1
binned_shape = (binned_shapex, binned_shapey)

# Test estimation with pairs and single donuts:
for images in [[intra, extra], [intra], [extra]]:
# Estimate Zernikes (in meters)
zkEst = dan.estimateZk(*images)

# Check that results are fairly accurate
self.assertLess(np.sqrt(np.sum((zkEst - zkTrue) ** 2)), 0.35e-6)

# Test with binning
zkEst = danBin.estimateZk(*images, saveHistory=True)
self.assertLess(np.sqrt(np.sum((zkEst - zkTrue) ** 2)), 0.35e-6)

# Test that we binned the images.
if "intra" in danBin.history:
self.assertEqual(
danBin.history["intra"]["image"].shape, binned_shape
)
if "extra" in danBin.history:
self.assertEqual(
danBin.history["extra"]["image"].shape, binned_shape
)
for jointFitPair in [True, False]:
# Create estimator
dan = DanishAlgorithm(jointFitPair=jointFitPair)
danBin = DanishAlgorithm(binning=2, jointFitPair=jointFitPair)

# Try several different random seeds
for seed in [12345, 23451, 34512, 45123]:
# Get the test data
zkTrue, intra, extra = forwardModelPair(seed=seed)

# Compute shape of binned images
shapex, shapey = intra.image.shape
binned_shapex = shapex // 2
binned_shapey = shapey // 2

# Ensure odd
if binned_shapex % 2 == 0:
binned_shapex -= 1
if binned_shapey % 2 == 0:
binned_shapey -= 1
binned_shape = (binned_shapex, binned_shapey)

# Test estimation with pairs and single donuts:
for images in [[intra, extra], [intra], [extra]]:
# Estimate Zernikes (in meters)
zkEst = dan.estimateZk(*images)

# Check that results are fairly accurate
self.assertLess(np.sqrt(np.sum((zkEst - zkTrue) ** 2)), 0.35e-6)

# Test with binning
zkEst = danBin.estimateZk(*images, saveHistory=True)
self.assertLess(np.sqrt(np.sum((zkEst - zkTrue) ** 2)), 0.35e-6)

# Test that we binned the images.
if "intra" in danBin.history:
self.assertEqual(
danBin.history["intra"]["image"].shape, binned_shape
)
if "extra" in danBin.history:
self.assertEqual(
danBin.history["extra"]["image"].shape, binned_shape
)

0 comments on commit b305211

Please sign in to comment.