Coverage for tests / test_guider.py: 31%
47 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-25 08:44 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-25 08:44 +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#
23import os
24import unittest
25import contextlib
26from lsst.daf.butler import MissingDatasetTypeError, Config
27from lsst.daf.butler.tests import makeTestRepo
28from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir
29from lsst.obs.lsst import LsstCam, ingest_guider
30from lsst.obs.base import RawIngestTask
32TESTDIR = os.path.abspath(os.path.dirname(__file__))
33DATAROOT = os.path.join(TESTDIR, "data", "input", "guider")
36class GuiderIngestTestCase(unittest.TestCase):
37 """Test guider file ingest."""
39 def setUp(self):
40 # Repository should be re-created for each test case since
41 # dimension records are set.
42 self.root = makeTestTempDir(TESTDIR)
43 self.addClassCleanup(removeTestTempDir, self.root)
45 config = Config()
46 config["datastore", "cls"] = "lsst.daf.butler.datastores.fileDatastore.FileDatastore"
47 self.butler = makeTestRepo(self.root, config=config)
48 self.enterContext(self.butler)
49 self.instrument = LsstCam()
50 self.instrument.register(self.butler.registry)
52 def test_ingest_guider_fail(self):
54 failed = {}
56 def on_undefined_exposure(path, obsid):
57 failed[path] = obsid
59 with self.assertRaises(MissingDatasetTypeError):
60 ingest_guider(
61 self.butler,
62 [os.path.join(DATAROOT, "guider_data", "MC_C_20230616_000013_R04_SG0.fits")],
63 on_undefined_exposure=on_undefined_exposure,
64 )
66 with contextlib.suppress(Exception):
67 ingest_guider(
68 self.butler,
69 [os.path.join(DATAROOT, "guider_data", "MC_C_20230616_000013_R04_SG0.fits")],
70 register_dataset_type=True,
71 on_undefined_exposure=on_undefined_exposure,
72 )
74 failed_obsids = list(failed.values())
75 self.assertEqual(failed_obsids, ["MC_C_20230616_000013"], msg=f"{failed}")
77 def test_ingest_guider(self):
78 # First ingest a raw to get the exposure defined.
79 config = RawIngestTask.ConfigClass()
80 task = RawIngestTask(config=config, butler=self.butler)
81 # This will read the metadata from the sidecar file.
82 task.run([os.path.join(DATAROOT, "raw", "MC_C_20240918_000013_R42_S11.fits")])
84 ingested = []
86 def on_success(datasets):
87 ingested.extend(datasets)
89 # Ingest guider data.
90 refs = ingest_guider(
91 self.butler,
92 [os.path.join(DATAROOT, "guider_data", "MC_C_20240918_000013_R00_SG0_guider.fits")],
93 group_files=False,
94 register_dataset_type=True,
95 on_success=on_success,
96 )
98 self.assertEqual(len(ingested), 1)
100 # Check that the guider metadata is set.
101 guider = self.butler.get(refs[0])
102 self.assertIsNotNone(guider.metadata)
103 for stamp in guider:
104 self.assertIn("STMPTIME", stamp.metadata)
106 self.assertEqual(guider[0].metadata["STMPTIME"], "2024-09-18T13:51:28.526")
107 self.assertEqual(guider[-1].metadata["STMPTIME"], "2024-09-18T13:51:43.319")
111if __name__ == '__main__': 111 ↛ 112line 111 didn't jump to line 112 because the condition on line 111 was never true
112 unittest.main()