Skip to content

Commit

Permalink
Drop obscore manager from config when making execution butler (DM-38814)
Browse files Browse the repository at this point in the history
The fix is one additional line `executionButlerBuilder.py`, the rest is
a new unit test to reproduce the problem with execution butler and obscore.
  • Loading branch information
andy-slac committed Apr 21, 2023
1 parent 17525e2 commit cc85667
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 5 deletions.
3 changes: 3 additions & 0 deletions python/lsst/pipe/base/executionButlerBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ def _setupNewButler(
# Remove any namespace that may be set in main registry.
config.pop(("registry", "namespace"), None)

# Obscore manager cannot be used with execution butler.
config.pop(("registry", "managers", "obscore"), None)

# record the current root of the datastore if it is specified relative
# to the butler root
if datastoreRoot is not None:
Expand Down
18 changes: 13 additions & 5 deletions python/lsst/pipe/base/tests/simpleQGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ def makeSimplePipeline(nQuanta: int, instrument: Optional[str] = None) -> Pipeli
return pipeline


def makeSimpleButler(root: str, run: str = "test", inMemory: bool = True) -> Butler:
def makeSimpleButler(
root: str, run: str = "test", inMemory: bool = True, config: Config | str | None = None
) -> Butler:
"""Create new data butler instance.
Parameters
Expand All @@ -246,6 +248,10 @@ def makeSimpleButler(root: str, run: str = "test", inMemory: bool = True) -> But
Run collection name.
inMemory : `bool`, optional
If true make in-memory repository.
config : `~lsst.daf.butler.Config`, optional
Configuration to use for new Butler, if `None` then default
configuration is used. If ``inMemory`` is `True` then configuration
is updated to use SQLite registry and file datastore in ``root``.
Returns
-------
Expand All @@ -255,11 +261,13 @@ def makeSimpleButler(root: str, run: str = "test", inMemory: bool = True) -> But
root_path = ResourcePath(root, forceDirectory=True)
if not root_path.isLocal:
raise ValueError(f"Only works with local root not {root_path}")
config = Config()
butler_config = Config()
if config:
butler_config.update(Config(config))
if not inMemory:
config["registry", "db"] = f"sqlite:///{root_path.ospath}/gen3.sqlite"
config["datastore", "cls"] = "lsst.daf.butler.datastores.fileDatastore.FileDatastore"
repo = butlerTests.makeTestRepo(str(root_path), {}, config=config)
butler_config["registry", "db"] = f"sqlite:///{root_path.ospath}/gen3.sqlite"
butler_config["datastore", "cls"] = "lsst.daf.butler.datastores.fileDatastore.FileDatastore"
repo = butlerTests.makeTestRepo(str(root_path), {}, config=butler_config)
butler = Butler(butler=repo, run=run)
return butler

Expand Down
22 changes: 22 additions & 0 deletions tests/config/butler-obscore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
registry:
managers:
obscore:
cls: lsst.daf.butler.registry.obscore._manager.ObsCoreLiveTableManager
config:
namespace: "daf_butler_obscore"
version: 0
table_name: obscore
collection_type: RUN
facility_name: daf_butler_test
obs_collection: daf_butler_obs_collection
collections: []
use_butler_uri: false
dataset_types:
raw:
dataproduct_type: image
dataproduct_subtype: lsst.raw
calib_level: 1
obs_id_fmt: "{records[exposure].obs_id}-{records[detector].full_name}"
o_ucd: phot.count
access_format: image/fits
datalink_url_fmt: "https://data.lsst.cloud/api/datalink/links?ID=butler%3A//dp02/{id}"
60 changes: 60 additions & 0 deletions tests/test_executionButler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This file is part of pipe_base.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (https://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 <https://www.gnu.org/licenses/>.

"""Tests for execution butler."""

import os
import unittest

import lsst.utils.tests
from lsst.daf.butler import Butler
from lsst.pipe.base.executionButlerBuilder import buildExecutionButler
from lsst.pipe.base.tests import simpleQGraph
from lsst.utils.tests import temporaryDirectory

TESTDIR = os.path.abspath(os.path.dirname(__file__))


class ExecutionTestCase(unittest.TestCase):
"""Small bunch of tests for instantiating execution butler."""

def test_simple(self) -> None:
"""Test buildExecutionButler with default butler config."""
with temporaryDirectory() as root:
butler, qgraph = simpleQGraph.makeSimpleQGraph(root=root, inMemory=False)
buildExecutionButler(butler, qgraph, os.path.join(root, "exec_butler"), butler.run)

def test_obscore(self) -> None:
"""Test buildExecutionButler with obscore table in the butler."""
with temporaryDirectory() as root:
config = os.path.join(TESTDIR, "config/butler-obscore.yaml")
butler = simpleQGraph.makeSimpleButler(root=root, inMemory=False, config=config)
butler, qgraph = simpleQGraph.makeSimpleQGraph(butler=butler)

# Need a fresh butler instance to make sure it reads config from
# butler.yaml, which does not have full obscore config.
butler = Butler(root, run=butler.run)
buildExecutionButler(butler, qgraph, os.path.join(root, "exec_butler"), butler.run)


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()

0 comments on commit cc85667

Please sign in to comment.