Coverage for tests / test_phosim.py: 33%
64 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-21 10:45 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-21 10:45 +0000
1# This file is part of obs_lsst.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://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 <http://www.gnu.org/licenses/>.
21#
22import os
23import sys
24import unittest
25import unittest.mock
27import lsst.utils.tests
28from lsst.geom import arcseconds, Extent2I
29import lsst.afw.image
31from lsst.obs.lsst.testHelper import ObsLsstButlerTests, ObsLsstObsBaseOverrides
32from lsst.obs.lsst import LsstCamPhoSim
34TESTDIR = os.path.abspath(os.path.dirname(__file__))
37def _clean_metadata_provenance(hdr):
38 """Remove metadata fix up provenance."""
39 for k in hdr:
40 if k.startswith("HIERARCH ASTRO METADATA"):
41 del hdr[k]
44class TestPhosim(ObsLsstObsBaseOverrides, ObsLsstButlerTests):
45 instrumentDir = "phosim"
46 DATAROOT = os.path.join(TESTDIR, "data", "input")
48 @classmethod
49 def getInstrument(cls):
50 return LsstCamPhoSim()
52 def setUp(self):
53 dataIds = {'raw': {'exposure': 204595, 'name_in_raft': 'S20', 'raft': 'R11'},
54 'bias': unittest.SkipTest,
55 'flat': unittest.SkipTest,
56 'dark': unittest.SkipTest
57 }
58 self.setUp_tests(self._butler, dataIds)
60 ccdExposureId_bits = 34
61 exposureIds = {'raw': 204595042}
62 filters = {'raw': 'i'}
63 exptimes = {'raw': 30.0}
64 detectorIds = {'raw': 42}
65 detector_names = {'raw': 'R11_S20'}
66 detector_serials = {'raw': 'ITL-3800C-102-Dev'}
67 dimensions = {'raw': Extent2I(4176, 4020)}
68 sky_origin = (55.67759886, -30.44239357)
69 raw_subsets = (({}, 1),
70 ({'physical_filter': 'i'}, 1),
71 ({'physical_filter': 'foo'}, 0),
72 ({'exposure': 204595}, 1),
73 )
74 linearizer_type = unittest.SkipTest
75 self.setUp_butler_get(ccdExposureId_bits=ccdExposureId_bits,
76 exposureIds=exposureIds,
77 filters=filters,
78 exptimes=exptimes,
79 detectorIds=detectorIds,
80 detector_names=detector_names,
81 detector_serials=detector_serials,
82 dimensions=dimensions,
83 sky_origin=sky_origin,
84 raw_subsets=raw_subsets,
85 linearizer_type=linearizer_type
86 )
88 self.raw_filename = '00204595-R11-S20-det042.fits'
90 self.setUp_camera(camera_name='LSSTCam-PhoSim',
91 n_detectors=201,
92 first_detector_name='R01_S00',
93 plate_scale=20.0 * arcseconds,
94 )
96 super().setUp()
98 def testMetadata(self):
99 """Check that we can read headers properly"""
100 dataId = {'exposure': 204595, 'name_in_raft': 'S20', 'raft': 'R11'}
101 md = self.butler.get("raw.metadata", dataId)
103 # This header comes from amp header
104 self.assertEqual(md["PRESS"], 520.0)
106 # This header is in HDU0
107 self.assertEqual(md["TESTTYPE"], "PHOSIM")
109 visitInfo = self.butler.get("raw.visitInfo", dataId)
110 weather = visitInfo.getWeather()
111 self.assertEqual(weather.getAirTemperature(), 20.0)
113 # Check that corrections are being applied
114 with unittest.mock.patch.dict(os.environ,
115 {"METADATA_CORRECTIONS_PATH": os.path.join(TESTDIR, "data")}):
116 # Check that corrections are applied during simple md get
117 md_md = self.butler.get("raw.metadata", dataId)
118 self.assertEqual(md_md["NEWHDR"], "corrected")
120 # Check that corrections are applied if we do assembly
121 raw = self.butler.get("raw", dataId)
122 raw_md = raw.getMetadata()
124 _clean_metadata_provenance(raw_md)
125 _clean_metadata_provenance(md_md)
127 self.assertEqual(raw_md, md_md)
129 # And finally ensure that visitInfo gets corrections
130 visitInfo = self.butler.get("raw.visitInfo", dataId)
131 weather = visitInfo.getWeather()
132 self.assertEqual(weather.getAirTemperature(), 10.0)
135class MemoryTester(lsst.utils.tests.MemoryTestCase):
136 pass
139def setup_module(module):
140 lsst.utils.tests.init()
143if __name__ == '__main__': 143 ↛ 144line 143 didn't jump to line 144 because the condition on line 143 was never true
144 setup_module(sys.modules[__name__])
145 unittest.main()