Coverage for tests/test_ingest.py : 60%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of obs_subaru.
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/>.
22"""Unit tests for Gen3 HSC raw data ingest.
23"""
25import unittest
26import os
27import lsst.utils.tests
29import lsst.afw.image
30from lsst.daf.butler import Butler, DataCoordinate
31from lsst.obs.base.ingest_tests import IngestTestBase
32from lsst.obs.subaru.strayLight.yStrayLight import SubaruStrayLightData
34testDataPackage = "testdata_subaru"
35try:
36 testDataDirectory = lsst.utils.getPackageDir(testDataPackage)
37except LookupError:
38 testDataDirectory = None
41@unittest.skipIf(testDataDirectory is None, "testdata_subaru must be set up")
42class HscIngestTestCase(IngestTestBase, lsst.utils.tests.TestCase):
44 curatedCalibrationDatasetTypes = ("defects", "camera", "bfKernel", "transmission_optics",
45 "transmission_sensor", "transmission_filter", "transmission_atmosphere")
46 ingestDir = os.path.dirname(__file__)
47 instrumentClassName = "lsst.obs.subaru.HyperSuprimeCam"
48 filterLabel = lsst.afw.image.FilterLabel(physical="HSC-I", band="i")
50 @property
51 def file(self):
52 return os.path.join(testDataDirectory, "hsc", "raw", "HSCA90402512.fits.gz")
54 dataIds = [dict(instrument="HSC", exposure=904024, detector=50)]
56 @property
57 def visits(self):
58 butler = Butler(self.root, collections=[self.outputRun])
59 return {
60 DataCoordinate.standardize(
61 instrument="HSC",
62 visit=904024,
63 universe=butler.registry.dimensions
64 ): [
65 DataCoordinate.standardize(
66 instrument="HSC",
67 exposure=904024,
68 universe=butler.registry.dimensions
69 )
70 ]
71 }
73 def testStrayLightIngest(self):
74 """Ingested stray light files."""
76 butler = Butler(self.root, run=self.outputRun)
78 straylightDir = os.path.join(testDataDirectory, "hsc", "straylight")
80 instrument = self.instrumentClass()
82 # This will warn about lots of missing files
83 with self.assertLogs(level="WARNING") as cm:
84 instrument.ingestStrayLightData(butler, straylightDir, transfer="auto")
86 collection = instrument.makeCalibrationCollectionName()
87 datasets = list(butler.registry.queryDatasetAssociations("yBackground", collections=collection))
88 # Should have at least one dataset and dataset+warnings = 112
89 self.assertGreaterEqual(len(datasets), 1)
90 self.assertEqual(len(datasets) + len(cm.output), len(instrument.getCamera()))
92 # Ensure that we can read the first stray light file
93 strayLight = butler.getDirect(datasets[0].ref)
94 self.assertIsInstance(strayLight, SubaruStrayLightData)
96 def checkRepo(self, files=None):
97 # We ignore `files` because there's only one raw file in
98 # testdata_subaru, and we know it's a science frame.
99 # If we ever add more, this test will need to change.
100 butler = Butler(self.root, collections=[self.outputRun])
101 expanded = butler.registry.expandDataId(self.dataIds[0])
102 self.assertEqual(expanded.records["exposure"].observation_type, "science")
105def setup_module(module):
106 lsst.utils.tests.init()
109if __name__ == "__main__": 109 ↛ 110line 109 didn't jump to line 110, because the condition on line 109 was never true
110 lsst.utils.tests.init()
111 unittest.main()