@@ -721,17 +721,40 @@ def gradY(self):
721
721
newCoef /= self .R_outer
722
722
return Zernike (newCoef , R_outer = self .R_outer , R_inner = self .R_inner )
723
723
724
- def __call__ (self , x , y ):
724
+ def __call__ (self , x , y , robust = False ):
725
725
"""Evaluate this Zernike polynomial series at Cartesian coordinates x and y.
726
726
Synonym for `evalCartesian`.
727
727
728
+ Parameters:
729
+ x: x-coordinate of evaluation points. Can be list-like.
730
+ y: y-coordinate of evaluation points. Can be list-like.
731
+ robust: If True, use a more robust method for evaluating the polynomial.
732
+ This can sometimes be slower, but is usually more accurate,
733
+ especially for large Noll indices. [default: False]
734
+ Returns:
735
+ Series evaluations as numpy array.
736
+ """
737
+ if robust :
738
+ return self .evalCartesianRobust (x , y )
739
+ return self .evalCartesian (x , y )
740
+
741
+ def evalCartesianRobust (self , x , y ):
742
+ """Evaluate this Zernike polynomial series at Cartesian coordinates x and y using a more
743
+ robust method than the default `evalCartesian`.
744
+
728
745
Parameters:
729
746
x: x-coordinate of evaluation points. Can be list-like.
730
747
y: y-coordinate of evaluation points. Can be list-like.
748
+
731
749
Returns:
732
750
Series evaluations as numpy array.
733
751
"""
734
- return self .evalCartesian (x , y )
752
+ x = np .asarray (x )
753
+ y = np .asarray (y )
754
+ rho = (x + 1j * y ) / self .R_outer
755
+ rhosq = np .abs (rho )** 2
756
+ ar = _noll_coef_array (len (self .coef )- 1 , self .R_inner / self .R_outer ).dot (self .coef [1 :])
757
+ return horner2d (rhosq , rho , ar ).real
735
758
736
759
def evalCartesian (self , x , y ):
737
760
"""Evaluate this Zernike polynomial series at Cartesian coordinates x and y.
@@ -743,7 +766,8 @@ def evalCartesian(self, x, y):
743
766
Returns:
744
767
Series evaluations as numpy array.
745
768
"""
746
- return horner2d (x , y , self ._coef_array_xy , dtype = float )
769
+ ar = self ._coef_array_xy
770
+ return horner2d (x , y , ar , dtype = float )
747
771
748
772
def evalPolar (self , rho , theta ):
749
773
"""Evaluate this Zernike polynomial series at polar coordinates rho and theta.
0 commit comments