def test_opd_expand(npix=512, input_coefficients=(0.1, 0.2, 0.3, 0.4, 0.5)): basis = zernike.zernike_basis(nterms=len(input_coefficients), npix=npix) for idx, coeff in enumerate(input_coefficients): basis[idx] *= coeff opd = basis.sum(axis=0) recovered_coeffs = zernike.opd_expand(opd, nterms=len(input_coefficients)) max_diff = np.max(np.abs(np.asarray(input_coefficients) - np.asarray(recovered_coeffs))) assert max_diff < 1e-3, "recovered coefficients from wf_expand more than 0.1% off" # Test the nonorthonormal version too # At a minimum, fitting with this variant version shouldn't be # worse than the regular one on a clear circular aperture. # We do the test in this same function for efficiency recovered_coeffs_v2 = zernike.opd_expand_nonorthonormal(opd, nterms=len(input_coefficients)) max_diff_v2 = np.max(np.abs(np.asarray(input_coefficients) - np.asarray(recovered_coeffs_v2))) assert max_diff_v2 < 1e-3, "recovered coefficients from wf_expand more than 0.1% off"
def test_opd_expand(npix=512, input_coefficients=(0.1, 0.2, 0.3, 0.4, 0.5)): basis = zernike.zernike_basis(nterms=len(input_coefficients), npix=npix) for idx, coeff in enumerate(input_coefficients): basis[idx] *= coeff opd = basis.sum(axis=0) recovered_coeffs = zernike.opd_expand(opd, nterms=len(input_coefficients)) max_diff = np.max(np.abs(np.asarray(input_coefficients) - np.asarray(recovered_coeffs))) assert max_diff < 1e-3, "recovered coefficients from wf_expand more than 0.1% off" # Test the nonorthonormal version too # At a minimum, fitting with this variant version shouldn't be # worse than the regular one on a clear circular aperture. # We do the test in this same function for efficiency recovered_coeffs_v2 = zernike.opd_expand_nonorthonormal(opd, nterms=len(input_coefficients)) max_diff_v2 = np.max(np.abs(np.asarray(input_coefficients) - np.asarray(recovered_coeffs_v2))) assert max_diff_v2 < 1e-3, "recovered coefficients from wf_expand more than 0.1% off"
def _get_coeff(self, opd, mask, basis, **kwargs): return zernike.opd_expand_nonorthonormal(opd, mask, basis=basis, **kwargs)