-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from lsst/tickets/DM-20763
DM-20763: Add initial support for Gen3 Butler to obs_decam
- Loading branch information
Showing
3 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# This file is part of daf_butler. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (http://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Helpers for writing tests against subclassses of Instrument. | ||
These are not tests themselves, but can be subclassed (plus unittest.TestCase) | ||
to get a functional test of an Instrument. | ||
""" | ||
|
||
import abc | ||
import dataclasses | ||
import os | ||
|
||
from lsst.daf.butler import Registry | ||
from lsst.daf.butler import ButlerConfig | ||
from lsst.utils import getPackageDir | ||
|
||
|
||
@dataclasses.dataclass | ||
class InstrumentTestData: | ||
"""Values to test against in sublcasses of `InstrumentTests`. | ||
""" | ||
|
||
name: str | ||
"""The name of the Camera this instrument describes.""" | ||
|
||
nDetectors: int | ||
"""The number of detectors in the Camera.""" | ||
|
||
firstDetectorName: str | ||
"""The name of the first detector in the Camera.""" | ||
|
||
physical_filters: {str} | ||
"""A subset of the physical filters should be registered.""" | ||
|
||
|
||
class InstrumentTests(metaclass=abc.ABCMeta): | ||
"""Tests of sublcasses of Instrument. | ||
TestCase subclasses must derive from this, then `TestCase`, and override | ||
``data`` and ``instrument``. | ||
""" | ||
|
||
data = None | ||
"""`InstrumentTestData` containing the values to test against.""" | ||
|
||
instrument = None | ||
"""The `lsst.daf.butler.Instrument` to be tested.""" | ||
|
||
def test_name(self): | ||
self.assertEqual(self.instrument.getName(), self.data.name) | ||
|
||
def test_getCamera(self): | ||
"""Test that getCamera() returns a reasonable Camera definition. | ||
""" | ||
camera = self.instrument.getCamera() | ||
self.assertEqual(camera.getName(), self.instrument.getName()) | ||
self.assertEqual(len(camera), self.data.nDetectors) | ||
self.assertEqual(next(iter(camera)).getName(), self.data.firstDetectorName) | ||
|
||
def test_register(self): | ||
"""Test that register() sets appropriate Dimensions. | ||
""" | ||
registryConfigPath = os.path.join(getPackageDir("daf_butler"), "tests/config/basic/butler.yaml") | ||
registry = Registry.fromConfig(ButlerConfig(registryConfigPath)) | ||
# check that the registry starts out empty | ||
self.assertEqual(registry.findDimensionEntries('instrument'), []) | ||
self.assertEqual(registry.findDimensionEntries('detector'), []) | ||
self.assertEqual(registry.findDimensionEntries('physical_filter'), []) | ||
|
||
# register the instrument and check that certain dimensions appear | ||
self.instrument.register(registry) | ||
self.assertEqual(len(registry.findDimensionEntries('instrument')), 1) | ||
self.assertEqual(registry.findDimensionEntries('instrument')[0]['instrument'], self.data.name) | ||
self.assertEqual(len(registry.findDimensionEntries('detector')), self.data.nDetectors) | ||
filterNames = {x['physical_filter'] for x in registry.findDimensionEntries('physical_filter')} | ||
self.assertGreaterEqual(filterNames, self.data.physical_filters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters