Coverage for python / lsst / cell_coadds / _stitched_aperture_correction.py: 56%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-15 00:10 +0000

1# This file is part of cell_coadds. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22from __future__ import annotations 

23 

24import logging 

25from collections.abc import Iterable, Mapping 

26from typing import overload 

27 

28import numpy as np 

29 

30import lsst.geom as geom 

31from lsst.skymap import Index2D 

32 

33from ._uniform_grid import UniformGrid 

34 

35__all__ = ("StitchedApertureCorrection",) 

36 

37logger = logging.getLogger(__name__) 

38 

39 

40class StitchedApertureCorrection: 

41 """A class that quacks like BoundedField and defined on a grid piecewise. 

42 

43 Parameters 

44 ---------- 

45 ugrid : `~lsst.cell_coadds.UniformGrid` 

46 The uniform grid that defines the bounding boxes for each piece. 

47 gc : `Mapping[Index2D, float]` 

48 The grid container that holds the values for each cell. 

49 """ 

50 

51 def __init__(self, ugrid: UniformGrid, gc: Mapping[Index2D, float]): 

52 self.ugrid = ugrid 

53 self.gc = gc 

54 

55 @overload 

56 def evaluate(self, x: geom.Point2D | geom.Point2I, y: None) -> float: ... # noqa: E704 56 ↛ exitline 56 didn't return from function 'evaluate' because

57 

58 @overload 

59 def evaluate(self, x: Iterable[float], y: Iterable[float]) -> np.ndarray: ... # noqa: E704 59 ↛ exitline 59 didn't return from function 'evaluate' because

60 

61 def evaluate(self, x, y=None): # type: ignore 

62 """Evaluate the BoundedField at a given point on the image. 

63 

64 Parameters 

65 ---------- 

66 x : `~lsst.geom.Point2D` or `~lsst.geom.Point2I`, or `Iterable[float]` 

67 The point at which to evaluate the BoundedField, or an iterable of 

68 x-coordinates. 

69 y : `Iterable[float]`, optional 

70 The y-coordinates of the points at which to evaluate the aperture 

71 correction. 

72 If `None`, `x` is assumed to be a single point. 

73 

74 Returns 

75 ------- 

76 value: `float`, or `numpy.ndarray` 

77 The value of the BoundedField at the specified point. 

78 """ 

79 if y is None: 

80 eval_point = geom.Point2I(x) 

81 idx = self.ugrid.index(eval_point) 

82 try: 

83 return self.gc[idx] 

84 except KeyError: 

85 logger.info("No aperture correction found for %s", idx) 

86 return 1.0 

87 

88 else: 

89 return np.array([self.evaluate(geom.Point2I(xx, yy)) for xx, yy in zip(x, y, strict=True)])