def test_opd_from_zernikes(): coeffs = [0,0.1, 0.4, 2, -0.3] opd = zernike.opd_from_zernikes(coeffs, npix=256) outcoeffs = zernike.opd_expand(opd, nterms=len(coeffs)) # only compare on indices 1-3 to avoid divide by zero on piston diffs = np.abs(np.asarray(coeffs[1:5]) - np.asarray(outcoeffs[1:5]))/np.asarray(coeffs[1:5]) max_diff = np.max(diffs ) assert max_diff < 2e-3, "recovered coefficients from opd_expand differ more than expected"
def test_opd_from_zernikes(): coeffs = [0, 0.1, 0.4, 2, -0.3] opd = zernike.opd_from_zernikes(coeffs, npix=256) outcoeffs = zernike.opd_expand(opd, nterms=len(coeffs)) diffs = np.abs(np.asarray(coeffs) - np.asarray(outcoeffs)) / np.asarray(coeffs) diffs[0] = 0 # ignore divide by zero on piston max_diff = np.max(diffs) assert max_diff < 2e-3, "recovered coefficients from opd_expand differ more than expected"
def test_opd_from_zernikes(): coeffs = [0,0.1, 0.4, 2, -0.3] opd = zernike.opd_from_zernikes(coeffs, npix=256) outcoeffs = zernike.opd_expand(opd, nterms=len(coeffs)) diffs = np.abs(np.asarray(coeffs) - np.asarray(outcoeffs))/np.asarray(coeffs) diffs[0] = 0 # ignore divide by zero on piston max_diff = np.max(diffs ) assert max_diff < 2e-3, "recovered coefficients from opd_expand differ more than expected"
def fitZernicke(wfr, mode='integrated', nterms=1250): nx, ny, nz = wfr.params.Mesh.nx, wfr.params.Mesh.ny, wfr.params.Mesh.nSlices aperture = create_circular_mask(nx, ny, r=nx // 2 - 2) if mode == 'integrated': ph = wfr.data.arrEhor[:, :, :, 1].sum(axis=2) #ii = wfr.get_intensity()[:,:,0] zc = zernike.opd_expand(ph, aperture=aperture, nterms=nterms) #rc = zernike.opd_from_zernikes(zc) return zc
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"
from matplotlib import pyplot as plt from poppy import zernike from model.src.coherent import construct_SA1_wavefront import numpy as np from wpg.wpg_uti_wf import calculate_fwhm wfr = construct_SA1_wavefront(1000, 1000, 12, 0.1) ii = wfr.get_intensity()[:,:,0] ph = wfr.get_phase()[:,:,0] aperture = np.ones(ii.shape) aperture[np.where(ii < ii.max()/10)] = 0 zc = zernike.opd_expand(ph, aperture = aperture) opd = zernike.opd_from_zernikes(zc) fig = plt.figure() ax1 = fig.add_subplot(111) ax1.bar(np.linspace(0,len(zc), len(zc)),zc) ax1.set_xticks(np.linspace(0+1,len(zc)+1, len(zc)+1)) ax1.set_xticklabels(labels = ["$Z_{}$".format(int(z)) for z in np.linspace(0+1,len(zc)+1, len(zc)+1)]) plt.show() for i in range(15): if i == 0: pass else: