lsst.pipe.tasks  20.0.0-41-gf735745d+28c625756b
makeGen3DcrSubfilters.py
Go to the documentation of this file.
1 # This file is part of pipe_tasks.
2 #
3 # Developed for the LSST Data Management System.
4 # This product includes software developed by the LSST Project
5 # (https://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 <https://www.gnu.org/licenses/>.
21 import lsst.pex.config as pexConfig
22 import lsst.pipe.base as pipeBase
23 
24 from sqlalchemy.exc import IntegrityError
25 
26 
27 class MakeGen3DcrSubfiltersConfig(pexConfig.Config):
28  """Config for MakeGen3DcrSubfiltersTask.
29  """
30  numSubfilters = pexConfig.Field(
31  doc="The number of subfilters to be used for chromatic modeling.",
32  dtype=int,
33  default=3,
34  optional=False
35  )
36  filterNames = pexConfig.ListField(
37  doc="The filters to add chromatic subfilters to in the registry.",
38  dtype=str,
39  default=["g"],
40  optional=False
41  )
42 
43 
44 class MakeGen3DcrSubfiltersTask(pipeBase.Task):
45  ConfigClass = MakeGen3DcrSubfiltersConfig
46  _DefaultName = "makeGen3DcrSubfilters"
47 
48  """This is a task to construct the set of subfilters for chromatic modeling.
49 
50  Parameters
51  ----------
52  config : `MakeGen3DcrSubfiltersConfig` or None
53  Instance of a configuration class specifying task options, a default
54  config is created if value is None
55  """
56 
57  def __init__(self, *, config=None, **kwargs):
58  super().__init__(config=config, **kwargs)
59 
60  def run(self, butler):
61  """Construct a set of subfilters for chromatic modeling.
62 
63  Parameters
64  ----------
65  butler : `lsst.daf.butler.Butler`
66  Butler repository to add the subfilter definitions to.
67  """
68  with butler.registry.transaction():
69  try:
70  self.register(butler.registry)
71  except IntegrityError as err:
72  raise RuntimeError(f"Subfilters for at least one filter of {self.config.filterNames} "
73  "are already defined.") from err
74 
75  def register(self, registry):
76  """Add Subfilters to the given registry.
77 
78  Parameters
79  ----------
80  registry : `lsst.daf.butler.Registry`
81  The registry to add to.
82  """
83  record = []
84  for filterName in self.config.filterNames:
85  self.log.info(f"Initializing filter {filterName} with "
86  f"{self.config.numSubfilters} subfilters")
87  for sub in range(self.config.numSubfilters):
88  record.append({
89  "band": filterName,
90  "subfilter": sub
91  })
92  registry.insertDimensionData("subfilter", *record)
lsst.pipe.tasks.makeGen3DcrSubfilters.MakeGen3DcrSubfiltersConfig
Definition: makeGen3DcrSubfilters.py:27
lsst.pipe.tasks.makeGen3DcrSubfilters.MakeGen3DcrSubfiltersTask
Definition: makeGen3DcrSubfilters.py:44
lsst.pipe.tasks.makeGen3DcrSubfilters.MakeGen3DcrSubfiltersTask.__init__
def __init__(self, *config=None, **kwargs)
Definition: makeGen3DcrSubfilters.py:57
lsst::pex::config
lsst.pipe.tasks.makeGen3DcrSubfilters.MakeGen3DcrSubfiltersTask.register
def register(self, registry)
Definition: makeGen3DcrSubfilters.py:75
lsst.pipe.tasks.makeGen3DcrSubfilters.MakeGen3DcrSubfiltersTask.run
def run(self, butler)
Definition: makeGen3DcrSubfilters.py:60
lsst.pipe::base