def fitting(Z,n,remain3D=False,remain2D=False,barchart=False,interferogram=False,removepiston=True): """ ------------------------------------------------ fitting(Z,n) Fitting an aberration to several orthonormal Zernike polynomials. Return: n-th Zernike coefficients for a fitting surface aberration Zernike coefficients barchart Remaining aberration Fiting surface plot Input: Z: A surface or aberration matrix measure from inteferometer or something else. n: How many order of Zernike Polynomials you want to fit reamin(default==Flase): show the surface after remove fitting aberrations. removepiston: if remove piston, default = True ------------------------------------------------ """ fitlist = [] l = len(Z) x2 = __np__.linspace(-1, 1, l) y2 = __np__.linspace(-1, 1, l) [X2,Y2] = __np__.meshgrid(x2,y2) r = __np__.sqrt(X2**2 + Y2**2) u = __np__.arctan2(Y2, X2) for i in range(n): C = [0]*i+[1]+[0]*(37-i-1) ZF = __zernikepolar__(C,r,u) for i in range(l): for j in range(l): if x2[i]**2+y2[j]**2>1: ZF[i][j]=0 a = sum(sum(Z*ZF))*2*2/l/l/__np__.pi fitlist.append(round(a,3)) l1 = len(fitlist) fitlist = fitlist+[0]*(37-l1) Z_new = Z - __zernikepolar__(fitlist,r,u) for i in range(l): for j in range(l): if x2[i]**2+y2[j]**2>1: Z_new[i][j]=0 #plot bar chart of zernike if barchart == True: fitlist1 = fitlist[0:n] index = __np__.arange(n) fig = __plt__.figure(figsize=(9, 6), dpi=80) xticklist = [] width = 0.6 for i in index: xticklist.append('Z'+str(i+1)) barfigure = __plt__.bar(index, fitlist1, width,color = '#2E9AFE',edgecolor = '#2E9AFE') __plt__.xticks( index+width/2, xticklist ) __plt__.xlabel('Zernike Polynomials',fontsize=18) __plt__.ylabel('Coefficient',fontsize=18) __plt__.title('Fitting Zernike Polynomials Coefficient',fontsize=18) __plt__.show() else: pass if remain3D == True: fig = __plt__.figure(figsize=(12, 8), dpi=80) ax = fig.gca(projection='3d') surf = ax.plot_surface(X2, Y2, Z_new, rstride=1, cstride=1, cmap=__cm__.RdYlGn, linewidth=0, antialiased=False, alpha = 0.6) v = max(abs(Z.max()),abs(Z.min())) ax.set_zlim(-v, v) ax.zaxis.set_major_locator(__LinearLocator__(10)) ax.zaxis.set_major_formatter(__FormatStrFormatter__('%.02f')) cset = ax.contourf(X2, Y2, Z_new, zdir='z', offset=-v, cmap=__cm__.RdYlGn) fig.colorbar(surf, shrink=1, aspect=30) __plt__.title('Remaining Aberration',fontsize=18) p2v = round(__tools__.peak2valley(Z_new),5) rms1 = round(__tools__.rms(Z_new),5) label_new = "P-V: "+str(p2v)+"\n"+"RMS: "+str(rms1) ax.text2D(0.02, 0.1,label_new, transform=ax.transAxes) __plt__.show() else: pass if remain2D == True: fig = __plt__.figure(figsize=(9, 6), dpi=80) ax = fig.gca() im = __plt__.pcolormesh(X2, Y2, Z_new, cmap=__cm__.RdYlGn) __plt__.colorbar() __plt__.title('Remaining Aberration',fontsize=18) ax.set_aspect('equal', 'datalim') __plt__.show() else: pass if interferogram == True: zernike_coefficient = Coefficient(fitlist) __interferometer__.twyman_green(zernike_coefficient) else: pass if removepiston == True: fitlist[0] = 0 else: pass C = Coefficient(fitlist) #output zernike Coefficient class __tools__.zernikeprint(fitlist) return fitlist,C
def twyman_green(self,lambda_1=632,PR=1): __interferometer__.twyman_green(self,lambda_1=lambda_1,PR=PR)
def fitting(Z, n, remain3D=False, remain2D=False, barchart=False, interferogram=False, removepiston=True): """ ------------------------------------------------ fitting(Z,n) Fitting an aberration to several orthonormal Zernike polynomials. Return: n-th Zernike coefficients for a fitting surface aberration Zernike coefficients barchart Remaining aberration Fiting surface plot Input: Z: A surface or aberration matrix measure from inteferometer or something else. n: How many order of Zernike Polynomials you want to fit reamin(default==Flase): show the surface after remove fitting aberrations. removepiston: if remove piston, default = True ------------------------------------------------ """ fitlist = [] l = len(Z) x2 = __np__.linspace(-1, 1, l) y2 = __np__.linspace(-1, 1, l) [X2, Y2] = __np__.meshgrid(x2, y2) r = __np__.sqrt(X2**2 + Y2**2) u = __np__.arctan2(Y2, X2) for i in range(n): C = [0] * i + [1] + [0] * (37 - i - 1) ZF = __zernikepolar__(C, r, u) for i in range(l): for j in range(l): if x2[i]**2 + y2[j]**2 > 1: ZF[i][j] = 0 a = sum(sum(Z * ZF)) * 2 * 2 / l / l / __np__.pi fitlist.append(round(a, 3)) l1 = len(fitlist) fitlist = fitlist + [0] * (37 - l1) Z_new = Z - __zernikepolar__(fitlist, r, u) for i in range(l): for j in range(l): if x2[i]**2 + y2[j]**2 > 1: Z_new[i][j] = 0 #plot bar chart of zernike if barchart == True: fitlist1 = fitlist[0:n] index = __np__.arange(n) fig = __plt__.figure(figsize=(9, 6), dpi=80) xticklist = [] width = 0.6 for i in index: xticklist.append('Z' + str(i + 1)) barfigure = __plt__.bar(index, fitlist1, width, color='#2E9AFE', edgecolor='#2E9AFE') __plt__.xticks(index + width / 2, xticklist) __plt__.xlabel('Zernike Polynomials', fontsize=18) __plt__.ylabel('Coefficient', fontsize=18) __plt__.title('Fitting Zernike Polynomials Coefficient', fontsize=18) __plt__.show() else: pass if remain3D == True: fig = __plt__.figure(figsize=(12, 8), dpi=80) ax = fig.gca(projection='3d') surf = ax.plot_surface(X2, Y2, Z_new, rstride=1, cstride=1, cmap=__cm__.RdYlGn, linewidth=0, antialiased=False, alpha=0.6) v = max(abs(Z.max()), abs(Z.min())) ax.set_zlim(-v, v) ax.zaxis.set_major_locator(__LinearLocator__(10)) ax.zaxis.set_major_formatter(__FormatStrFormatter__('%.02f')) cset = ax.contourf(X2, Y2, Z_new, zdir='z', offset=-v, cmap=__cm__.RdYlGn) fig.colorbar(surf, shrink=1, aspect=30) __plt__.title('Remaining Aberration', fontsize=18) p2v = round(__tools__.peak2valley(Z_new), 5) rms1 = round(__tools__.rms(Z_new), 5) label_new = "P-V: " + str(p2v) + "\n" + "RMS: " + str(rms1) ax.text2D(0.02, 0.1, label_new, transform=ax.transAxes) __plt__.show() else: pass if remain2D == True: fig = __plt__.figure(figsize=(9, 6), dpi=80) ax = fig.gca() im = __plt__.pcolormesh(X2, Y2, Z_new, cmap=__cm__.RdYlGn) __plt__.colorbar() __plt__.title('Remaining Aberration', fontsize=18) ax.set_aspect('equal', 'datalim') __plt__.show() else: pass if interferogram == True: zernike_coefficient = Coefficient(fitlist) __interferometer__.twyman_green(zernike_coefficient) else: pass if removepiston == True: fitlist[0] = 0 else: pass C = Coefficient(fitlist) #output zernike Coefficient class __tools__.zernikeprint(fitlist) return fitlist, C
def twyman_green(self, lambda_1=632, PR=1): __interferometer__.twyman_green(self, lambda_1=lambda_1, PR=PR)
def twyman_green(self, lambda_1=632, PR=1): fig = __interferometer__.twyman_green(self, lambda_1=lambda_1, PR=PR) return fig
def twyman_green(self,lambda_1=632,PR=1): fig = __interferometer__.twyman_green(self,lambda_1=lambda_1,PR=PR) return fig