Coverage for python/lsst/daf/butler/core/dataUnit.py : 91%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of daf_butler. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://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 <http://www.gnu.org/licenses/>.
"""A discrete abstract unit of data that can be associated with metadata and used to label datasets.
`DataUnit` instances represent concrete units such as e.g. `Camera`, `Sensor`, `Visit` and `SkyMap`.
Parameters ---------- name : `str` Name of this `DataUnit`. Also assumed to be the name of the primary table (if present). requiredDependencies : `frozenset` Related `DataUnit` instances on which existence this `DataUnit` instance depends. optionalDependencies : `frozenset` Related `DataUnit` instances that may also be provided (and when they are, they must be kept in sync). link : `tuple` Names of columns that form the `DataUnit` specific part of the primary-key in this `DataUnit` table and are also the names of the link column in the Datasets table. spatial : `bool`, optional Is this a spatial `DataUnit`? If so then it either has a ``region`` column, or some other way to get a region (e.g. ``SkyPix``). """
link=(), spatial=False):
return "DataUnit({})".format(self.name)
except AttributeError: return NotImplemented
def name(self): """Name of this `DataUnit` (`str`, read-only).
Also assumed to be the name of the primary table (if present)."""
def requiredDependencies(self): """Related `DataUnit` instances on which existence this `DataUnit` instance depends (`frozenset`, read-only). """
def optionalDependencies(self): """Related `DataUnit` instances that may also be provided (and when they are, they must be kept in sync) (`frozenset`, read-only). """
def dependencies(self): """The union of `requiredDependencies` and `optionalDependencies` (`frozenset`, read-only). """
def link(self): """Names of columns that form the `DataUnit` specific part of the primary-key in this `DataUnit` table and are also the names of the link column in the Datasets table (`tuple`). """
def primaryKey(self): """Full primary-key column name tuple. Consists of the ``link`` of this `DataUnit` and that of all its ``requiredDependencies`` (`set`). """
def spatial(self): """Is this a spatial `DataUnitJoin`? """ return self._spatial
"""Check if given dataId is valid.
Parameters ---------- dataId : `dict` A `dict` of `DataUnit` link name, value pairs that label the `DatasetRef` within a Collection.
Raises ------ ValueError If a value for a required dependency is missing. """ missing, dataId, self.name))
"""Represents a join between one or more `DataUnit`s.
Parameters ---------- name : `str` Name of this `DataUnit` (`str`, read-only). Also assumed to be the name of the primary table (if present). lhs : `tuple` Left-hand-side of the join. rhs : `tuple` Right-hand-side of the join. summarizes : `DataUnitJoin` Summarizes this other `DataUnitJoin`. relates : `tuple` of `DataUnit` The DataUnits in this relationship. spatial : `bool`, optional Is this a spatial `DataUnit`? If so then it either has a ``region`` column, or some other way to get a region (e.g. ``SkyPix``). """
relates=None, spatial=False):
def name(self): """Name of this `DataUnit` (`str`, read-only).
Also assumed to be the name of the primary table (if present)."""
def lhs(self):
def rhs(self):
def relates(self):
def spatial(self):
def summarizes(self):
def primaryKey(self): """Full primary-key column name tuple. """
def primaryKeyColumns(self): """Dictionary keyed on ``primaryKey`` names with `sqlalchemy.Column` entries into this `DataUnitJoin` primary table as values (`dict`). """ return {name: self.table.columns[name] for name in self.primaryKey}
def regionColumn(self): """Table column with encoded region data, ``None`` if table has no region column (`sqlalchemy.Column`, optional). """ table = self.table if table is not None and self.spatial: return table.c["region"] return None
"""Instances of this class keep track of `DataUnit` relations.
Entries in this `dict`-like object represent `DataUnit` instances, keyed on `DataUnit` names. """
def fromConfig(cls, config): """Alternative constructor.
Build a `DataUnitRegistry` instance from a `Config` object.
Parameters ---------- config : `SchemaConfig` `Registry` DataUnit configuration containing "dataUnits", "joins" entries. """
return len(self._dataUnits)
return iter(self._dataUnitNames)
return iter(self._dataUnitNames)
return (self[dataUnitName] for dataUnitName in self._dataUnitNames)
"""Return the DataUnit or DataUnitJoin that holds region for the given combination of DataUnits.
Arguments may be either DataUnit instances or their names (but not link names), and required dependencies may or may not be included. Optional dependencies must not be included.
Returned object can be either `DataUnitJoin` or `DataUnit`. Use ``table`` and/or ``regionColumn`` properties of returned object to retrieve region data from database table.
Returns ------- `DataUnitJoin` or `DataUnit` instance.
Raises ------ KeyError Raised if there is no Region associated with the given combination of DataUnits. """ # Add all dependencies, so the caller can say just "Patch" as well as # "SkyMap", "Tract", "Patch" and get the same result.
"""Return the DataUnitJoin that relates the given DataUnit names.
While DataUnitJoins are associated with a specific ordering or lhs and rhs, this method tries both.
Parameters ---------- lhs : `str` or sequence DataUnit name or sequence of names for one side of the join. rhs : `str` or sequence DataUnit name or sequence of names for the other side of the join.
Returns ------- join : `DataUnitJoin` The DataUnitJoin that relates the given DataUnits, or None. """
"""Initialize DataUnit names.
Because `DataUnit` entries may apear in any order in the `Config`, but dependencies between them define a topological order in which objects should be created, store them in a `TopologicalSet`.
Parameters ---------- config : `SchemaConfig` The `dataUnits` component of a `SchemaConfig`. """
"""Initialize `DataUnit` entries.
Parameters ---------- config : `Config` The `dataUnits` component of a `DataUnitRegistryConfig`. """ # Visit DataUnits in dependency order requiredDependencies=requiredDependencies, optionalDependencies=optionalDependencies, link=link, spatial=spatial) # The DataUnit (or DataUnitJoin) instance that can be used # to retreive the region is keyed based on the union # of the DataUnit and its required dependencies that are also spatial. # E.g. "Patch" is keyed on ("Tract", "Patch"). # This requires that DataUnit's are visited in topologically sorted order # (which they are). tuple(d.name for d in dataUnit.requiredDependencies if d.name in self._spatialDataUnits))
"""Initialize `DataUnit` join entries.
Parameters ---------- config : `DataUnitRegistryConfig` Configuration describing `DataUnit` join relations. """ lhs=lhs, rhs=rhs, summarizes=summarizes, spatial=spatial, relates=relates)
"""Get all primary-key column names for the given ``dataUnitNames``.
Parameters ---------- dataUnitNames : `sequence` A sequence of `DataUnit` names.
Returns ------- primaryKeyNames : `set` All primary-key column names for the given ``dataUnitNames``. """
"""Get a `DataUnit` for which ``name`` is part of the link.
Parameters ---------- name : `str` Link name.
Returns ------- dataUnit : `DataUnit` The corresponding `DataUnit` instance.
Raises ------ KeyError When the provided ``name`` does not correspond to a link for any of the `DataUnit` entries in the registry. """ |