Coverage for python/lsst/cell_coadds/test_utils.py: 13%
39 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-16 02:22 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-16 02:22 -0700
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/>.
22"""Collection of utility functions to be used for unit tests."""
24import lsst.afw.geom as afwGeom
25import lsst.geom as geom
26from lsst.daf.butler import DataCoordinate, DimensionUniverse
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.
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
64 Returns
65 -------
66 data_id : `lsst.daf.butler.DataCoordinate`
67 An expanded data_id instance.
68 """
69 universe = DimensionUniverse()
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 )
79 skymap = universe["skymap"]
80 skymap_record = skymap.RecordClass(name="test_skymap")
82 band_element = universe["band"]
83 band_record = band_element.RecordClass(name=band)
85 visit = universe["visit"]
86 visit_record = visit.RecordClass(id=visit_id, instrument="test")
88 detector = universe["detector"]
89 detector_record = detector.RecordClass(id=detector_id, instrument="test")
91 physical_filter = universe["physical_filter"]
92 physical_filter_record = physical_filter.RecordClass(name=band, instrument="test", band=band)
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 )
99 if "day_obs" in universe:
100 day_obs_element = universe["day_obs"]
101 day_obs_record = day_obs_element.RecordClass(id=20240201, instrument="test")
102 else:
103 day_obs_record = None
105 # A dictionary with all the relevant records.
106 record = {
107 "instrument": instrument_record,
108 "visit": visit_record,
109 "detector": detector_record,
110 "patch": patch_record,
111 "tract": 9813,
112 "band": band_record.name,
113 "skymap": skymap_record.name,
114 "physical_filter": physical_filter_record,
115 }
117 if day_obs_record:
118 record["day_obs"] = day_obs_record
120 # A dictionary with all the relevant recordIds.
121 record_id = record.copy()
122 for key in ("visit", "detector"):
123 record_id[key] = record_id[key].id
125 # TODO: Catching mypy failures on Github Actions should be made easier,
126 # perhaps in DM-36873. Igroring these for now.
127 data_id = DataCoordinate.standardize(record_id, universe=universe)
128 return data_id.expanded(record)
131def generate_wcs(*, scale: float = 0.168, flipX: bool = True) -> afwGeom.SkyWcs:
132 """Generate a SkyWcs instant with a given pixel scale.
134 Parameters
135 ----------
136 scale : `float`, optional
137 Pixel scale in arcseconds.
138 flipX : `bool`, optional
139 Flip the X axis.
141 Returns
142 -------
143 wcs : `lsst.afw.geom.SkyWcs`
144 A SkyWcs instance.
145 """
146 orientation = -45 * geom.degrees
147 scale = scale * geom.arcseconds
148 crpix = geom.Point2D(100, 100)
149 crval = geom.SpherePoint(30, 60, geom.degrees)
150 cdMatrix = afwGeom.makeCdMatrix(scale=scale, orientation=orientation, flipX=flipX)
151 return afwGeom.makeSkyWcs(crpix=crpix, crval=crval, cdMatrix=cdMatrix)