From 31ddc9b59f1ef5c046e8a5792a27dd94fe1c1fdf Mon Sep 17 00:00:00 2001 From: Matthew Townson Date: Wed, 14 May 2025 11:06:30 +0100 Subject: [PATCH] Fix zoom issues and factorial error - Zoom issue due to interp2d deprecation - Factorial error from not forcing integer --- aotools/functions/zernike.py | 4 ++-- aotools/interpolation.py | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/aotools/functions/zernike.py b/aotools/functions/zernike.py index 20a2751..719fafa 100644 --- a/aotools/functions/zernike.py +++ b/aotools/functions/zernike.py @@ -91,8 +91,8 @@ def zernikeRadialFunc(n, m, r): R += numpy.array(r**(n - 2 * i) * (((-1)**(i)) * math.factorial(n - i)) / (math.factorial(i) * - math.factorial(0.5 * (n + m) - i) * - math.factorial(0.5 * (n - m) - i)), + math.factorial(int(0.5 * (n + m) - i)) * + math.factorial(int(0.5 * (n - m) - i))), dtype='float') return R diff --git a/aotools/interpolation.py b/aotools/interpolation.py index 02dc25f..b345289 100644 --- a/aotools/interpolation.py +++ b/aotools/interpolation.py @@ -35,12 +35,11 @@ def zoom(array, newSize, order=3): #If array is complex must do 2 interpolations if array.dtype==numpy.complex64 or array.dtype==numpy.complex128: - realInterpObj = interp2d( numpy.arange(array.shape[0]), - numpy.arange(array.shape[1]), array.real, copy=False, - kind=INTERP_KIND[order]) - imagInterpObj = interp2d( numpy.arange(array.shape[0]), - numpy.arange(array.shape[1]), array.imag, copy=False, - kind=INTERP_KIND[order]) + realInterpObj = RectBivariateSpline( numpy.arange(array.shape[0]), + numpy.arange(array.shape[1]), array.real, kx=order, ky=order) + imagInterpObj = RectBivariateSpline( numpy.arange(array.shape[0]), + numpy.arange(array.shape[1]), array.imag, + kx=order, ky=order) return (realInterpObj(coordsY,coordsX) + 1j*imagInterpObj(coordsY,coordsX)) @@ -48,9 +47,8 @@ def zoom(array, newSize, order=3): else: - interpObj = interp2d( numpy.arange(array.shape[0]), - numpy.arange(array.shape[1]), array, copy=False, - kind=INTERP_KIND[order]) + interpObj = RectBivariateSpline( numpy.arange(array.shape[0]), + numpy.arange(array.shape[1]), array, kx=order, ky=order) #return numpy.flipud(numpy.rot90(interpObj(coordsY,coordsX))) return interpObj(coordsY,coordsX)