Add maxsize limit to lru_cache
@@ -546,7 +546,7 @@ class WcsGeom(Geom):
else:
return int(self.npix[0][idx]), int(self.npix[1][idx])
- @lru_cache()
+ @lru_cache(maxsize=5)
def get_idx(self, idx=None, flat=False):
pix = self.get_pix(idx=idx, mode="center")
if flat:
@@ -573,7 +573,7 @@ class WcsGeom(Geom):
pix = np.meshgrid(*pix[::-1], indexing="ij")[::-1]
return pix
- @lru_cache()
+ @lru_cache(maxsize=5)
def get_pix(self, idx=None, mode="center"):
"""Get map pix coordinates from the geometry.
@@ -594,7 +594,7 @@ class WcsGeom(Geom):
_[~m] = INVALID_INDEX.float
return pix
- @lru_cache()
+ @lru_cache(maxsize=5)
def get_coord(self, idx=None, flat=False, mode="center", coordsys=None):
"""Get map coordinates from the geometry.
@@ -699,7 +699,7 @@ class WcsGeom(Geom):
idx = self.coord_to_idx(coords)
return np.all(np.stack([t != INVALID_INDEX.int for t in idx]), axis=0)
- @lru_cache()
+ @lru_cache(maxsize=5)
def to_image(self):
npix = (np.max(self._npix[0]), np.max(self._npix[1]))
cdelt = (np.max(self._cdelt[0]), np.max(self._cdelt[1]))
@@ -807,7 +807,7 @@ class WcsGeom(Geom):
axes=copy.deepcopy(self.axes),
)
- @lru_cache()
+ @lru_cache(maxsize=5)
def solid_angle(self):
"""Solid angle array (`~astropy.units.Quantity` in ``sr``).
@@ -845,7 +845,7 @@ class WcsGeom(Geom):
return u.Quantity(area_low_right + area_up_left, "sr", copy=False)
- @lru_cache()
+ @lru_cache(maxsize=5)
def bin_volume(self):
"""Bin volume (`~astropy.units.Quantity`)"""
bin_volume = self.to_image().solid_angle()
