Coverage for python/lsst/verify/spec/base.py : 88%

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
# # LSST Data Management System # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # See COPYRIGHT file at the top of the source tree. # # 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 LSST License Statement and # the GNU General Public License along with this program. If not, # see <https://www.lsstcorp.org/LegalNotices/>. #
"""Specification base class.
Specification classes must implement:
- `type` - `_serialize_type` - `check`
Subclasses should also call ``Specification.__init__`` to initialize the specifications ``name`` attribute (a `~lsst.verify.Name` instance). """
# interal object behind self.tags
# name attibute must be a Name instance representing a specification else:
else:
def name(self): """Specification name (`lsst.verify.Name`)."""
def metric_name(self): """Name of the metric this specification corresponds to (`lsst.verify.Name`).""" return Name(package=self.name.package, metric=self.name.metric)
def tags(self): """Tag labels (`set` of `str`)."""
def tags(self, t): # Ensure that tags is always a set. t = [t]
def type(self): """Specification type (`str`).""" pass
def _serialize_type(self): """Serialize type-specific specification data to a JSON-serializable `dict`.
This method is used by the `json` property as the value associated with the key named for `type`. """ pass
def json(self): """`dict` that can be serialized as semantic JSON, compatible with the SQUASH metric service. """ { 'name': str(self.name), 'type': self.type, self.type: self._serialize_type(), 'metadata_query': self._metadata_query, 'tags': self.tags } )
def check(self, measurement): """Check if a measurement passes this specification.
Parameters ---------- measurement : `astropy.units.Quantity` The measurement value. The measurement `~astropy.units.Quantity` must have units *compatible* with the specification.
Returns ------- passed : `bool` `True` if the measurement meets the specification, `False` otherwise. """ pass
"""Query a Job's metadata to determine if this specification applies.
Parameters ---------- metadata : `lsst.verify.Metadata` or `dict`-type Metadata mapping. Typically this is the `lsst.verify.Job.meta` attribute. arg_driven : `bool`, optional If `False` (default), ``metadata`` matches the ``MetadataQuery`` if ``metadata`` has all the terms defined in ``MetadataQuery``, and those terms match. If ``metadata`` has more terms than ``MetadataQuery``, it can still match. This behavior is appropriate for finding if a specification applies to a Job given metadata.
If `True`, the orientation of the matching is reversed. Now ``metadata`` matches the ``MetadataQuery`` if ``MetadataQuery`` has all the terms defined in ``metadata`` and those terms match. If ``MetadataQuery`` has more terms than ``metadata``, it can still match. This behavior is appropriate for discovering specifications.
Returns ------- matched : `bool` `True` if this specification matches, `False` otherwise.
See also -------- lsst.verify.MetadataQuery """ |