23from collections
import defaultdict
25from sqlalchemy.exc
import IntegrityError
27from lsst.daf.butler
import Butler
30_log = logging.getLogger(__name__)
33registeredMsg =
"Registered subfilters {subfilters} for filter band \"{band}\"."
35 "Not registering subfilters for filter band \"{band}\"; subfilters {subfilters} already existed."
39 """Represents the results of adding subfilters to a filter band."""
42 """Keeps track of the inserted and existing subfilter numbers.
46 inserted : `list` [`int`]
47 The inserted subfilters.
48 existing : `list` [`int`]
49 The subfilters that already existed.
58 def add(self, filterName, subfilter, inserted):
59 """Add result information about attemping to add a subfilter to a
65 The name of the filter band.
69 `True`
if the subfilter was inserted,
or `
False`
if this
is the id
70 of a subfilter that already existed.
73 self.
filters[filterName].inserted.append(subfilter)
75 self.
filters[filterName].existing.append(subfilter)
78 """Get the results formated for CLI output.
83 The results formatted for CLI output.
86 for filterName, subs
in self.
filters.items():
90 ret += registeredMsg.format(band=filterName, subfilters=subs.inserted)
93 ret += notRegisteredMsg.format(band=filterName, subfilters=subs.existing)
98 """Construct a set of subfilters for chromatic modeling and add them to a
104 URI to the location to read the repo.
105 num_subfilters : `int`
106 The number of subfilters to add.
107 band_names : `list` [`str`]
108 The filter band names to add.
112 insertResults : ``InsertResults``
113 A class that contains the results of the subfilters that were inserted
114 or already exist
in each filter band, that has a __str__ method so it
115 can be easily printed to the CLI output.
117 butler = Butler(repo, writeable=True)
119 for filterName
in band_names:
121 with butler.registry.transaction():
122 for sub
in range(num_subfilters):
123 butler.registry.insertDimensionData(
"subfilter", {
"band": filterName,
"subfilter": sub})
124 results.add(filterName, sub,
True)
125 except IntegrityError:
126 records = butler.registry.queryDimensionRecords(
"subfilter", dataId={
"band": filterName})
127 for record
in records:
128 results.add(filterName, record.id,
False)
def add(self, filterName, subfilter, inserted)
def registerDcrSubfilters(repo, num_subfilters, band_names)