Skip to content

Commit

Permalink
Add a script to define DCR subfilters in a Gen 3 registry.
Browse files Browse the repository at this point in the history
  • Loading branch information
isullivan committed Jan 30, 2020
1 parent 8a2ed1b commit 97020d4
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
53 changes: 53 additions & 0 deletions bin.src/makeGen3DcrSubfilters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# This file is part of pipe_tasks.
#
# 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/>.

import argparse
import os.path
import sys

from lsst.daf.butler import Butler
from lsst.pipe.tasks.makeGen3DcrSubfilters import MakeGen3DcrSubfiltersConfig, MakeGen3DcrSubfiltersTask

# Build a parser for command line arguments
parser = argparse.ArgumentParser(description="Define the set of subfilters for chromatic modeling.")
parser.add_argument("butler", metavar="Butler", type=str, help="Path to a gen3 butler")
parser.add_argument("-C", "--config-file", dest="configFile",
help="Path to a config file overrides file")

args = parser.parse_args()

# Verify any supplied paths actually exist on disk
if not os.path.exists(args.butler):
print("Butler path specified does not exists")
sys.exit(1)

config = MakeGen3DcrSubfiltersConfig()
if args.configFile:
if not os.path.exists(args.configFile):
print("Path to config file specified does not exist")
sys.exit(1)
config.load(args.configFile)

# Construct the SkyMap Creation task and run it
subfilterTask = MakeGen3DcrSubfiltersTask(config=config)
butler = Butler(args.butler, run=args.collection)
subfilterTask.run(butler)
93 changes: 93 additions & 0 deletions python/lsst/pipe/tasks/makeGen3DcrSubfilters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# This file is part of pipe_tasks.
#
# 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/>.
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase

from sqlalchemy.exc import IntegrityError


class MakeGen3DcrSubfiltersConfig(pexConfig.Config):
"""Config for MakeGen3DcrSubfiltersTask.
"""
numSubfilters = pexConfig.Field(
doc="The number of subfilters to be used for chromatic modeling.",
dtype=int,
default=3,
optional=False
)
filterNames = pexConfig.ListField(
doc="The filters to add chromatic subfilters to in the registry.",
dtype=str,
default=["g"],
optional=False
)


class MakeGen3DcrSubfiltersTask(pipeBase.Task):
ConfigClass = MakeGen3DcrSubfiltersConfig
_DefaultName = "makeGen3DcrSubfilters"

"""This is a task to construct the set of subfilters for chromatic modeling.
Parameters
----------
config : `MakeGen3DcrSubfiltersConfig` or None
Instance of a configuration class specifying task options, a default
config is created if value is None
"""

def __init__(self, *, config=None, **kwargs):
super().__init__(config=config, **kwargs)

def run(self, butler):
"""Construct a set of subfilters for chromatic modeling.
Parameters
----------
butler : `lsst.daf.butler.Butler`
Butler repository to add the subfilter definitions to.
"""
with butler.registry.transaction():
try:
self.register(butler.registry)
except IntegrityError as err:
raise RuntimeError(f"Subfilters for at least one filter of {self.config.filterNames} "
"are already defined.") from err

def register(self, registry):
"""Add Subfilters to the given registry.
Parameters
----------
registry : `lsst.daf.butler.Registry`
The registry to add to.
"""
record = []
for filterName in self.config.filterNames:
self.log.info(f"Initializing filter {filterName} with "
f"{self.config.numSubfilters} subfilters")
for sub in range(self.config.numSubfilters):
subfilterName = f"{filterName}-{sub + 1}"
record.append({
"abstract_filter": filterName,
"subfilter": subfilterName
})
registry.insertDimensionData("subfilter", *record)

0 comments on commit 97020d4

Please sign in to comment.