From 3cdf25bb247cd5946653c2d2bcf999d59e63f8ea Mon Sep 17 00:00:00 2001 From: John Franklin Crenshaw <jfcrenshaw@gmail.com> Date: Thu, 18 Jan 2024 08:53:38 -0800 Subject: [PATCH] Streamlining zk4up and caches in instrument. --- python/lsst/ts/wep/instrument.py | 35 ++++++++++++++------------------ 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/python/lsst/ts/wep/instrument.py b/python/lsst/ts/wep/instrument.py index 3e95b4916..6b7783a1d 100644 --- a/python/lsst/ts/wep/instrument.py +++ b/python/lsst/ts/wep/instrument.py @@ -515,7 +515,6 @@ def _getIntrinsicZernikesCached( yAngle: float, band: Union[BandLabel, str], jmax: int, - return4Up: bool, ) -> np.ndarray: """Cached interior function for the getIntrinsicZernikes method. @@ -533,8 +532,6 @@ def _getIntrinsicZernikesCached( "{band}". jmax : int, optional The maximum Noll index of the intrinsic Zernikes. - return4Up : bool - Whether to only return the coefficients for Noll indices >= 4. Returns ------- @@ -563,11 +560,7 @@ def _getIntrinsicZernikesCached( # Multiply by wavelength to get Zernikes in meters zkIntrinsic *= self.wavelength[band] - if return4Up: - # Keep only Noll indices >= 4 - zkIntrinsic = zkIntrinsic[4:] - - return zkIntrinsic.copy() + return zkIntrinsic def getIntrinsicZernikes( self, @@ -601,9 +594,13 @@ def getIntrinsicZernikes( np.ndarray The Zernike coefficients in meters """ - return self._getIntrinsicZernikesCached( - xAngle, yAngle, band, jmax, return4Up - ).copy() + zk = self._getIntrinsicZernikesCached(xAngle, yAngle, band, jmax).copy() + + if return4Up: + # Keep only Noll indices >= 4 + zk = zk[4:] + + return zk @lru_cache(100) def _getOffAxisCoeffCached( @@ -613,7 +610,6 @@ def _getOffAxisCoeffCached( defocalType: DefocalType, band: Union[BandLabel, str], jmax: int, - return4Up: bool, ) -> np.ndarray: """Cached interior function for the getOffAxisCoeff method. @@ -634,8 +630,6 @@ def _getOffAxisCoeffCached( contains "{band}". jmax : int The maximum Noll index of the off-axis model Zernikes. - return4Up : bool - Whether to only return the coefficients for Noll indices >= 4. Returns ------- @@ -673,10 +667,6 @@ def _getOffAxisCoeffCached( # Multiply by wavelength to get Zernikes in meters zkIntrinsic *= self.wavelength[band] - if return4Up: - # Keep only Noll indices >= 4 - zkIntrinsic = zkIntrinsic[4:] - return zkIntrinsic def getOffAxisCoeff( @@ -715,15 +705,20 @@ def getOffAxisCoeff( np.ndarray The Zernike coefficients in meters, for Noll indices >= 4 """ - return self._getOffAxisCoeffCached( + zk = self._getOffAxisCoeffCached( xAngle, yAngle, defocalType, band, jmax, - return4Up, ).copy() + if return4Up: + # Keep only Noll indices >= 4 + zk = zk[4:] + + return zk + @property def maskParams(self) -> dict: """The mask parameter dictionary."""