Coverage for python/lsst/cell_coadds/test_utils.py: 17%

33 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 

22"""Collection of utility functions to be used for unit tests.""" 

23 

24import lsst.afw.geom as afwGeom 

25import lsst.geom as geom 

26from lsst.daf.butler import DataCoordinate, DimensionUniverse 

27 

28 

29def generate_data_id( 

30 *, 

31 tract: int = 9813, 

32 patch: int = 42, 

33 cell_x: int = 4, 

34 cell_y: int = 2, 

35 band: str = "r", 

36 detector_id: int = 9, 

37 visit_id: int = 1234, 

38 detector_max: int = 109, 

39 visit_max: int = 10000 

40) -> DataCoordinate: 

41 """Generate a DataCoordinate instance to use as data_id. 

42 

43 Parameters 

44 ---------- 

45 tract : `int`, optional 

46 Tract ID for the data_id 

47 patch : `int`, optional 

48 Patch ID for the data_id 

49 cell_x : `int`, optional 

50 X index of the cell this patch corresponds to 

51 cell_y : `int`, optional 

52 Y index of the cell this patch corresponds to 

53 band : `str`, optional 

54 Band for the data_id 

55 detector_id : `int`, optional 

56 Detector ID for the data_id 

57 visit_id : `int`, optional 

58 Visit ID for the data_id 

59 detector_max : `int`, optional 

60 Maximum detector ID for the data_id 

61 visit_max : `int`, optional 

62 Maximum visit ID for the data_id 

63 

64 Returns 

65 ------- 

66 data_id : `lsst.daf.butler.DataCoordinate` 

67 An expanded data_id instance. 

68 """ 

69 universe = DimensionUniverse() 

70 

71 instrument = universe["instrument"] 

72 instrument_record = instrument.RecordClass( 

73 name="DummyCam", 

74 class_name="lsst.obs.base.instrument_tests.DummyCam", 

75 detector_max=detector_max, 

76 visit_max=visit_max, 

77 ) 

78 

79 skymap = universe["skymap"] 

80 skymap_record = skymap.RecordClass(name="test_skymap") 

81 

82 band_element = universe["band"] 

83 band_record = band_element.RecordClass(name=band) 

84 

85 visit = universe["visit"] 

86 visit_record = visit.RecordClass(id=visit_id, instrument="test") 

87 

88 detector = universe["detector"] 

89 detector_record = detector.RecordClass(id=detector_id, instrument="test") 

90 

91 physical_filter = universe["physical_filter"] 

92 physical_filter_record = physical_filter.RecordClass(name=band, instrument="test", band=band) 

93 

94 patch_element = universe["patch"] 

95 patch_record = patch_element.RecordClass( 

96 skymap="test_skymap", tract=tract, patch=patch, cell_x=cell_x, cell_y=cell_y 

97 ) 

98 

99 # A dictionary with all the relevant records. 

100 record = { 

101 "instrument": instrument_record, 

102 "visit": visit_record, 

103 "detector": detector_record, 

104 "patch": patch_record, 

105 "tract": 9813, 

106 "band": band_record.name, 

107 "skymap": skymap_record.name, 

108 "physical_filter": physical_filter_record, 

109 } 

110 

111 # A dictionary with all the relevant recordIds. 

112 record_id = record.copy() 

113 for key in ("visit", "detector"): 

114 record_id[key] = record_id[key].id 

115 

116 # TODO: Catching mypy failures on Github Actions should be made easier, 

117 # perhaps in DM-36873. Igroring these for now. 

118 data_id = DataCoordinate.standardize(record_id, universe=universe) 

119 return data_id.expanded(record) 

120 

121 

122def generate_wcs(*, scale: float = 0.168, flipX: bool = True) -> afwGeom.SkyWcs: 

123 """Generate a SkyWcs instant with a given pixel scale. 

124 

125 Parameters 

126 ---------- 

127 scale : `float`, optional 

128 Pixel scale in arcseconds. 

129 flipX : `bool`, optional 

130 Flip the X axis. 

131 

132 Returns 

133 ------- 

134 wcs : `lsst.afw.geom.SkyWcs` 

135 A SkyWcs instance. 

136 """ 

137 orientation = -45 * geom.degrees 

138 scale = scale * geom.arcseconds 

139 crpix = geom.Point2D(100, 100) 

140 crval = geom.SpherePoint(30, 60, geom.degrees) 

141 cdMatrix = afwGeom.makeCdMatrix(scale=scale, orientation=orientation, flipX=flipX) 

142 return afwGeom.makeSkyWcs(crpix=crpix, crval=crval, cdMatrix=cdMatrix)