def biconic_grad(test_vector): """ Computation of biconic gradient equals explicit calculation """ coordinate_system = LocalCoordinates.p(name="root") radiusx = 100.0 radiusy = 120.0 conic_constantx = -0.5 conic_constanty = -1.7 cx = 1./radiusx cy = 1./radiusy alpha2 = 1e-3 alpha4 = -1e-6 alpha6 = 1e-8 beta2 = 0.1 beta4 = -0.6 beta6 = 0.2 maxradiusx = (math.sqrt(1./((1+conic_constantx)*cx**2)) if conic_constantx > -1 else abs(radiusx)) maxradiusy = (math.sqrt(1./((1+conic_constanty)*cy**2)) if conic_constanty > -1 else abs(radiusy)) maxradius = min([maxradiusx, maxradiusy]) # choose minimal radius values = (2*test_vector - 1)*maxradius x = values[0] y = values[1] shape = Biconic.p(coordinate_system, curvx=cx, curvy=cy, ccx=conic_constantx, ccy=conic_constanty, coefficients=[(alpha2, beta2), (alpha4, beta4), (alpha6, beta6)]) gradient = shape.getGrad(x, y) comparison = np.zeros_like(gradient) comparison[2, :] = 1. comparison[0, :] = ( -alpha2*(-2*beta2*x + 2*x) - alpha4*(-4*beta4*x + 4*x)*(-beta4*(x**2 - y**2) + x**2 + y**2) - alpha6*(-6*beta6*x + 6*x)*(-beta6*(x**2 - y**2) + x**2 + y**2)**2 - cx**2*x*(conic_constantx + 1)*(cx*x**2 + cy*y**2)/((np.sqrt(-cx**2*x**2*(conic_constantx + 1) - cy**2*y**2*(conic_constanty + 1) + 1) + 1)**2*np.sqrt(-cx**2*x**2*(conic_constantx + 1) - cy**2*y**2*(conic_constanty + 1) + 1)) - 2*cx*x/(np.sqrt(-cx**2*x**2*(conic_constantx + 1) - cy**2*y**2*(conic_constanty + 1) + 1) + 1)) comparison[1, :] = ( -alpha2*(2*beta2*y + 2*y) - alpha4*(4*beta4*y + 4*y)*(-beta4*(x**2 - y**2) + x**2 + y**2) - alpha6*(6*beta6*y + 6*y)*(-beta6*(x**2 - y**2) + x**2 + y**2)**2 - cy**2*y*(conic_constanty + 1)*(cx*x**2 + cy*y**2)/((np.sqrt(-cx**2*x**2*(conic_constantx + 1) - cy**2*y**2*(conic_constanty + 1) + 1) + 1)**2*np.sqrt(-cx**2*x**2*(conic_constantx + 1) - cy**2*y**2*(conic_constanty + 1) + 1)) - 2*cy*y/(np.sqrt(-cx**2*x**2*(conic_constantx + 1) - cy**2*y**2*(conic_constanty + 1) + 1) + 1) ) assert np.allclose(gradient, comparison)
def biconic_sag(test_vector): """ Computation of biconic sag equals explicit calculation """ coordinate_system = LocalCoordinates.p(name="root") radiusx = 100.0 radiusy = 120.0 conic_constantx = -0.5 conic_constanty = -1.7 cx = 1. / radiusx cy = 1. / radiusy alpha2 = 1e-3 alpha4 = -1e-6 alpha6 = 1e-8 beta2 = 0.1 beta4 = -0.6 beta6 = 0.2 maxradiusx = (math.sqrt(1. / ((1 + conic_constantx) * cx**2)) if conic_constantx > -1 else abs(radiusx)) maxradiusy = (math.sqrt(1. / ((1 + conic_constanty) * cy**2)) if conic_constanty > -1 else abs(radiusy)) maxradius = min([maxradiusx, maxradiusy]) # choose minimal radius values = (2 * test_vector - 1) * maxradius x_coordinate = values[0] y_coordinate = values[1] shape = Biconic.p(coordinate_system, curvx=cx, curvy=cy, ccx=conic_constantx, ccy=conic_constanty, coefficients=[(alpha2, beta2), (alpha4, beta4), (alpha6, beta6)]) sag = shape.getSag(x_coordinate, y_coordinate) # comparison with explicitly entered formula comparison = ( (cx * x_coordinate**2 + cy * y_coordinate**2) / (1. + np.sqrt(1. - (1. + conic_constantx) * cx**2 * x_coordinate**2 - (1. + conic_constanty) * cy**2 * y_coordinate**2)) + alpha2 * (x_coordinate**2 + y_coordinate**2 - beta2 * (x_coordinate**2 - y_coordinate**2)) + alpha4 * (x_coordinate**2 + y_coordinate**2 - beta4 * (x_coordinate**2 - y_coordinate**2))**2 + alpha6 * (x_coordinate**2 + y_coordinate**2 - beta6 * (x_coordinate**2 - y_coordinate**2))**3) assert np.allclose(sag, comparison)
tiltThenDecenter=False), refname=lc0.name) lcimage = s.addLocalCoordinateSystem(LocalCoordinates.p( name="image", decy=-30.892, decz=43.083, tiltx=-si * 50.668 * degree, tiltThenDecenter=False), refname=lc0.name) objsurf = Surface.p(lc0) D1surf = Surface.p(lcD1) S1surf = Surface.p(lcS1, shape=Biconic.p(lcS1, curvy=si * 1. / 108.187, curvx=si * 1. / 73.105, coefficients=[(0., 0.), (-si * 5.542e-7, -0.08), (-si * 8.176e-11, -1.379)]), aperture=CircularAperture.p(lcS1, maxradius=40.0)) D1Psurf = Surface.p(lcD1prime) D2surf = Surface.p(lcD2) S2surf = Surface.p(lcS2, shape=Biconic.p(lcS2, curvy=si * 1. / 69.871, curvx=si * 1. / 60.374, ccy=-0.1368, ccx=-0.123, coefficients=[(0., 0.), (si * 7.233e-11, 29.075), (si * 4.529e-12, -2.085)]), aperture=CircularAperture.p(lcS2, maxradius=40.0))