Skip to content

Commit

Permalink
Add limited option for Registries.
Browse files Browse the repository at this point in the history
Registries configured with limited=True do not have any DataUnit
metadata or join tables (or the foreign keys from Dataset to those
tables).  That disables a few operations, but makes it unnecessary
to populate those tables just to do simple get and put Butler
operations.
  • Loading branch information
TallJimbo committed Sep 7, 2018
1 parent a190050 commit dca2dbf
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 27 deletions.
1 change: 1 addition & 0 deletions config/registry.yaml
Expand Up @@ -2,6 +2,7 @@
registry:
cls: lsst.daf.butler.registries.sqliteRegistry.SqliteRegistry
db: 'sqlite:///:memory:'
limited: false
skypix:
cls: lsst.sphgeom.HtmPixelization
level: 7
27 changes: 27 additions & 0 deletions config/schema.yaml
Expand Up @@ -97,44 +97,51 @@ schema:
-
src: camera
tgt: Camera.camera
limited: false
-
src:
- camera
- physical_filter
tgt:
- PhysicalFilter.camera
- PhysicalFilter.physical_filter
limited: false
-
src:
- camera
- sensor
tgt:
- Sensor.camera
- Sensor.sensor
limited: false
-
src:
- camera
- visit
tgt:
- Visit.camera
- Visit.visit
limited: false
-
src:
- camera
- exposure
tgt:
- Exposure.camera
- Exposure.exposure
limited: false
-
src: skymap
tgt: Skymap.skymap
limited: false
-
src:
- skymap
- tract
tgt:
- Tract.skymap
- Tract.tract
limited: false
-
src:
- skymap
Expand All @@ -144,6 +151,7 @@ schema:
- Patch.skymap
- Patch.tract
- Patch.patch
limited: false

DatasetComposition:
doc: >
Expand Down Expand Up @@ -440,6 +448,7 @@ schema:
Camera:
doc: >
A definition table containing recognized Camera values.
limited: false
columns:
-
name: camera
Expand All @@ -452,6 +461,7 @@ schema:
doc: >
A view aggregating all distinct AbstractFilters references by any
PhysicalFilter.
limited: false
columns:
-
name: abstract_filter
Expand All @@ -467,6 +477,7 @@ schema:
doc: >
A Camera-populated table that relates a PhysicalFilter
to its Camera and optional AbstractFilter.
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -495,6 +506,7 @@ schema:
doc: >
A Camera-populated table that relates a Sensor to its Camera and
provides additional labels.
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -536,6 +548,7 @@ schema:
Visit:
doc: >
A table containing Camera-generic metadata for a Visit.
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -663,6 +676,7 @@ schema:
Exposure:
doc: >
A table containing Camera-generic Exposure metadata.
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -751,6 +765,7 @@ schema:
doc: >
A table containing registered SkyMaps and the the SHA1 hashes
used to compare them.
limited: false
columns:
-
name: skymap
Expand All @@ -773,6 +788,7 @@ schema:
doc: >
A SkyMap-populated table relating a Tract to its spatial region
on the sky.
limited: false
columns:
-
name: skymap
Expand Down Expand Up @@ -808,6 +824,7 @@ schema:
doc: >
A table relating a Patch to its position within a Tract and
on the sky.
limited: false
columns:
-
name: skymap
Expand Down Expand Up @@ -872,6 +889,7 @@ schema:
expected to be calculated outside the database and added/updated
whenever the Visit's region is. This table contains exactly one
entry for each Visit+Sensor combination.
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -920,6 +938,7 @@ schema:
- Sensor.sensor

MultiCameraExposureJoin:
limited: false
columns:
-
name: camera_1
Expand Down Expand Up @@ -958,6 +977,7 @@ schema:
- Exposure.exposure

VisitSensorSkyPixJoin:
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -991,6 +1011,7 @@ schema:
- VisitSensorRegion.sensor

VisitSkyPixJoin:
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -1020,6 +1041,7 @@ schema:
FROM VisitSensorSkyPixJoin;
PatchSkyPixJoin:
limited: false
columns:
-
name: skymap
Expand Down Expand Up @@ -1053,6 +1075,7 @@ schema:
- Patch.patch

TractSkyPixJoin:
limited: false
columns:
-
name: skymap
Expand Down Expand Up @@ -1082,6 +1105,7 @@ schema:
FROM PatchSkyPixJoin;
VisitSensorPatchJoin:
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -1146,6 +1170,7 @@ schema:
);
VisitPatchJoin:
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -1202,6 +1227,7 @@ schema:
);
VisitSensorTractJoin:
limited: false
columns:
-
name: camera
Expand Down Expand Up @@ -1258,6 +1284,7 @@ schema:
);
VisitTractJoin:
limited: false
columns:
-
name: camera
Expand Down
51 changes: 49 additions & 2 deletions python/lsst/daf/butler/core/registry.py
Expand Up @@ -21,14 +21,29 @@

from abc import ABCMeta, abstractmethod
import contextlib
import functools

from .utils import doImport
from .config import Config, ConfigSubset
from .dataUnit import DataUnitConfig, DataUnitRegistry
from .schema import SchemaConfig
from .utils import transactional

__all__ = ("RegistryConfig", "Registry")
__all__ = ("RegistryConfig", "Registry", "disableWhenLimited")


def disableWhenLimited(func):
"""Decorator that indicates that a method should raise NotImplementedError
on Registries whose ``limited`` attribute is ``True``.
This implements that check and raise for all subclasses.
"""
@functools.wraps(func)
def inner(self, *args, **kwargs):
if self.limited:
raise NotImplementedError("Not implemented for limited Registry.")
return func(self, *args, **kwargs)
return inner


class RegistryConfig(ConfigSubset):
Expand Down Expand Up @@ -143,6 +158,12 @@ def __init__(self, registryConfig, schemaConfig=None, dataUnitConfig=None, creat
def __str__(self):
return "None"

@property
def limited(self):
"""If True, this Registry does not maintain DataUnit metadata or
relationships (`bool`)."""
return self.config.get("limited", False)

@contextlib.contextmanager
def transaction(self):
"""Optionally implemented in `Registry` subclasses to provide exception
Expand All @@ -168,7 +189,12 @@ def transaction(self):

@property
def pixelization(self):
"""Object that interprets SkyPix DataUnit values (`sphgeom.Pixelization`)."""
"""Object that interprets SkyPix DataUnit values (`sphgeom.Pixelization`).
``None`` for limited registries.
"""
if self.limited:
return None
if self._pixelization is None:
pixelizationCls = doImport(self.config["skypix", "cls"])
self._pixelization = pixelizationCls(level=self.config["skypix", "level"])
Expand Down Expand Up @@ -625,6 +651,7 @@ def markInputUsed(self, quantum, ref):
raise NotImplementedError("Must be implemented by subclass")

@abstractmethod
@disableWhenLimited
@transactional
def addDataUnitEntry(self, dataUnitName, values):
"""Add a new `DataUnit` entry.
Expand All @@ -648,10 +675,13 @@ def addDataUnitEntry(self, dataUnitName, values):
ValueError
If an entry with the primary-key defined in `values` is already
present.
NotImplementedError
If ``self.limited`` is ``True``.
"""
raise NotImplementedError("Must be implemented by subclass")

@abstractmethod
@disableWhenLimited
def findDataUnitEntry(self, dataUnitName, value):
"""Return a `DataUnit` entry corresponding to a `value`.
Expand All @@ -667,10 +697,13 @@ def findDataUnitEntry(self, dataUnitName, value):
dataUnitEntry : `dict`
Dictionary with all `DataUnit` values, or `None` if no matching
entry is found.
NotImplementedError
If ``self.limited`` is ``True``.
"""
raise NotImplementedError("Must be implemented by subclass")

@abstractmethod
@disableWhenLimited
@transactional
def setDataUnitRegion(self, dataUnitNames, value, region, update=True):
"""Set the region field for a DataUnit instance or a combination
Expand All @@ -689,10 +722,16 @@ def setDataUnitRegion(self, dataUnitNames, value, region, update=True):
If True, existing region information for these DataUnits is being
replaced. This is usually required because DataUnit entries are
assumed to be pre-inserted prior to calling this function.
Raises
------
NotImplementedError
If ``self.limited`` is ``True``.
"""
raise NotImplementedError("Must be implemented by subclass")

@abstractmethod
@disableWhenLimited
def getRegion(self, dataId):
"""Get region associated with a dataId.
Expand All @@ -712,10 +751,13 @@ def getRegion(self, dataId):
KeyError
If the set of dataunits for the ``dataId`` does not correspond to
a unique spatial lookup.
NotImplementedError
If ``self.limited`` is ``True``.
"""
raise NotImplementedError("Must be implemented by subclass")

@abstractmethod
@disableWhenLimited
def selectDataUnits(self, originInfo, expression, neededDatasetTypes, futureDatasetTypes):
"""Evaluate a filter expression and lists of
`DatasetTypes <DatasetType>` and return a set of data unit values.
Expand Down Expand Up @@ -746,5 +788,10 @@ def selectDataUnits(self, originInfo, expression, neededDatasetTypes, futureData
------
row : `PreFlightUnitsRow`
Single row is a unique combination of units in a transform.
Raises
------
NotImplementedError
If ``self.limited`` is ``True``.
"""
raise NotImplementedError("Must be implemented by subclass")

0 comments on commit dca2dbf

Please sign in to comment.