Skip to content

Commit

Permalink
Store DimensionConfig in the DimensionUniverse
Browse files Browse the repository at this point in the history
This makes it easier to send a server universe to a client without
needing to re-read from the database. Memory impact is minimal since
DimensionUniverse is already cached by version number.
  • Loading branch information
timj committed Apr 14, 2021
1 parent d4f76ea commit a12398b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/core/dimensions/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def makeBuilder(self) -> DimensionConstructionBuilder:
configuration. The `~DimensionConstructionBuilder.finish` method
will not have been called.
"""
builder = DimensionConstructionBuilder(self["version"], self["skypix", "common"])
builder = DimensionConstructionBuilder(self["version"], self["skypix", "common"], self)
builder.update(self._extractSkyPixVisitors())
builder.update(self._extractElementVisitors())
builder.update(self._extractTopologyVisitors())
Expand Down
4 changes: 4 additions & 0 deletions python/lsst/daf/butler/core/dimensions/_universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def __new__(
self._elements = builder.elements
self._topology = builder.topology
self._packers = builder.packers
self.dimensionConfig = builder.config
commonSkyPix = self._dimensions[builder.commonSkyPixName]
assert isinstance(commonSkyPix, SkyPixDimension)
self.commonSkyPix = commonSkyPix
Expand Down Expand Up @@ -448,6 +449,9 @@ def __deepcopy__(self, memo: dict) -> DimensionUniverse:
dimensions in the `Registry` database (`SkyPixDimension`).
"""

dimensionConfig: DimensionConfig
"""The configuration used to create this Universe (`DimensionConfig`)."""

_cache: Dict[FrozenSet[str], DimensionGraph]

_dimensions: NamedValueAbstractSet[Dimension]
Expand Down
5 changes: 4 additions & 1 deletion python/lsst/daf/butler/core/dimensions/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
if TYPE_CHECKING:
from ._elements import Dimension, DimensionElement
from ._packer import DimensionPackerFactory
from ._config import DimensionConfig


class DimensionConstructionVisitor(ABC):
Expand Down Expand Up @@ -121,14 +122,16 @@ class DimensionConstructionBuilder:
def __init__(
self,
version: int,
commonSkyPixName: str, *,
commonSkyPixName: str,
config: DimensionConfig, *,
visitors: Iterable[DimensionConstructionVisitor] = ()
) -> None:
self.dimensions = NamedValueSet()
self.elements = NamedValueSet()
self.topology = {space: NamedValueSet() for space in TopologicalSpace.__members__.values()}
self.packers = {}
self.version = version
self.config = config
self.commonSkyPixName = commonSkyPixName
self._todo: Dict[str, DimensionConstructionVisitor] = {v.name: v for v in visitors}

Expand Down
5 changes: 5 additions & 0 deletions tests/test_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
DataCoordinateSequence,
DataCoordinateSet,
Dimension,
DimensionConfig,
DimensionGraph,
DimensionUniverse,
NamedKeyDict,
Expand Down Expand Up @@ -117,6 +118,10 @@ def checkGraphInvariants(self, graph):
self.assertTrue(any(element in s.implied for s in seen))
self.assertCountEqual(seen, graph.elements)

def testConfigPresent(self):
config = self.universe.dimensionConfig
self.assertIsInstance(config, DimensionConfig)

def testConfigRead(self):
self.assertEqual(self.universe.getStaticDimensions().names,
{"instrument", "visit", "visit_system", "exposure", "detector",
Expand Down

0 comments on commit a12398b

Please sign in to comment.