MetadataQuery

class lsst.verify.MetadataQuery(terms=None)[source]

Bases: lsst.verify.jsonmixin.JsonSerializationMixin

Query of lsst.verify.Job.meta metadata.

Parameters:

terms : dict, optional

A mapping of key-value query terms. A job’s metadata must have all these keys, and matching values, to pass the query.

Examples

A MetadataQuery returns True if all keys-value terms found in MetadataQuery.terms are equal to key-value metadata items.

>>> metadata = {'filter': 'r', 'camera': 'MegaCam'}

An example of a query with a conflicting term:

>>> query1 = MetadataQuery({'filter': 'r', 'camera': 'SDSS'})
>>> query1(metadata)
False

A query with matching terms (albeit, a subset of the metadata):

>>> query2 = MetadataQuery({'filter': 'r'})
>>> query2(metadata)
True

A query that overconstrains the available metadata:

>>> query3 = MetadataQuery({'filter': 'r', 'camera': 'MegaCam',
...                         'photometric': True})
>>> query3(metadata)
False

Attributes Summary

json A JSON-serializable dict.
terms Term mapping (dict).

Methods Summary

__call__(metadata) Determine if a metadata set matches the query terms.
jsonify_dict(d) Recursively build JSON-renderable objects on all values in a dict.
write_json(filepath) Write JSON to a file.

Attributes Documentation

json

A JSON-serializable dict.

Keys are metadata keys. Values are the associated metadata values of the query term.

terms = None

Term mapping (dict). Metadata must have all keys and corresponding values.

Methods Documentation

__call__(metadata)[source]

Determine if a metadata set matches the query terms.

Parameters:

metadata : dict or lsst.verify.Metadata

Metadata mapping. Typically this is a job’s lsst.verify.Job.meta.

Returns:

match : bool

True if the metadata matches the query terms; False otherwise.

jsonify_dict(d)

Recursively build JSON-renderable objects on all values in a dict.

Parameters:

d : dict

Dictionary to convert into a JSON-serializable object. Values are recursively JSON-ified.

Returns:

json_dict : dict

Dictionary that can be serialized to JSON.

Examples

Subclasses can use this method to prepare output in their json-method implementation. For example:

def json(self):
    return JsonSerializationMixin.jsonify_dict({
        'value': self.value,
    })
write_json(filepath)

Write JSON to a file.

Parameters:

filepath : str

Destination file name for JSON output.