Coverage for python/lsst/cell_coadds/_common_components.py: 91%

36 statements  

« prev     ^ index     » next       coverage.py v7.3.3, created at 2023-12-16 14:04 +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 

24__all__ = ("CoaddUnits", "CommonComponents", "CommonComponentsProperties") 

25 

26import enum 

27from abc import ABC, abstractmethod 

28from dataclasses import dataclass 

29from typing import TYPE_CHECKING 

30 

31if TYPE_CHECKING: 

32 from lsst.afw.geom import SkyWcs # pragma: no cover 

33 

34 from ._identifiers import PatchIdentifiers # pragma: no cover 

35 

36 

37class CoaddUnits(enum.Enum): 

38 """Enumeration of units a coadd's pixels may have. 

39 

40 Notes 

41 ----- 

42 This list is intentionally limited to the units we know we need rather than 

43 units we think somewhat might want (which is also why we do not support any 

44 flux unit other than nJy). 

45 """ 

46 

47 nJy = enum.auto() 

48 """Pixels represent flux in nanojanskies. 

49 """ 

50 

51 chi = enum.auto() 

52 """Pixels represent a signal-to-noise ratio. 

53 """ 

54 

55 

56@dataclass(frozen=True, eq=False, repr=False) 

57class CommonComponents: 

58 """Struct containing image attributes that are common to all cells in a 

59 patch. 

60 """ 

61 

62 units: CoaddUnits 

63 """Units of the coadd's data pixels. 

64 """ 

65 

66 wcs: SkyWcs 

67 """World Coordinate System object that maps the pixel grid to sky 

68 coordinates. 

69 """ 

70 

71 band: str | None 

72 """String label for the filter bandpass. 

73 

74 May be `None` only for coadds that represent a combination of multiple 

75 passbands (e.g. chi^2 detection coadds), not just to indicate absence of 

76 knowledge. 

77 """ 

78 

79 identifiers: PatchIdentifiers 

80 """Struct of unique identifiers for this coadd's patch.""" 

81 

82 

83class CommonComponentsProperties(ABC): 

84 """A mix-in class that provides properties for all common components to 

85 any derived class that provides a property for the common components struct 

86 itself. 

87 """ 

88 

89 @property 

90 def units(self) -> CoaddUnits: 

91 """Units of the coadd's data pixels.""" 

92 return self.common.units 

93 

94 @property 

95 def wcs(self) -> SkyWcs: 

96 """World Coordinate System object that maps the pixel grid to sky 

97 coordinates. 

98 """ 

99 return self.common.wcs 

100 

101 @property 

102 def band(self) -> str | None: 

103 """String label for the filter bandpass. 

104 

105 May be `None` only for coadds that represent a combination of multiple 

106 passbands (e.g. chi^2 detection coadds), not just to indicate absence 

107 of knowledge. 

108 """ 

109 return self.common.band 

110 

111 @property 

112 def identifiers(self) -> PatchIdentifiers: 

113 """Struct of unique identifiers for this coadd's patch.""" 

114 return self.common.identifiers 

115 

116 @property 

117 @abstractmethod 

118 def common(self) -> CommonComponents: 

119 """Struct of image components common to all cells in a patch.""" 

120 raise NotImplementedError()