MetadataQuery¶
-
class
lsst.verify.MetadataQuery(terms=None)[source]¶ Bases:
lsst.verify.jsonmixin.JsonSerializationMixinQuery of
lsst.verify.Job.metametadata.Parameters: terms :
dict, optionalA mapping of key-value query terms. In the default query mode, the user-provided job metadata must have all these terms, and matching values, to pass the query.
Examples
A MetadataQuery returns
Trueif all key-value terms found inMetadataQuery.termsare 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
The
arg_driven=Truemode reverses the matching logic so that all terms in the user-provided metadata must be in the MetadataQuery:>>> query3(metadata, arg_driven=True) True >>> query2(metadata, arg_driven=True) False
Attributes Summary
jsonA JSON-serializable dict. termsTerm mapping ( dict).Methods Summary
__call__(metadata[, arg_driven])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.
Methods Documentation
-
__call__(metadata, arg_driven=False)[source]¶ Determine if a metadata set matches the query terms.
Parameters: metadata :
dictorlsst.verify.MetadataMetadata mapping. Typically this is a job’s
lsst.verify.Job.meta.arg_driven :
bool, optionalIf
False(default),metadatamatches theMetadataQueryifmetadatahas all the terms defined inMetadataQuery, and those terms match. Ifmetadatahas more terms thanMetadataQuery, it can still match.If
True, the orientation of the matching is reversed. Nowmetadatamatches theMetadataQueryifMetadataQueryhas all the terms defined inmetadataand those terms match. IfMetadataQueryhas more terms thanmetadata, it can still match.Returns: match :
bool
-
jsonify_dict(d)¶ Recursively build JSON-renderable objects on all values in a dict.
Parameters: d :
dictDictionary to convert into a JSON-serializable object. Values are recursively JSON-ified.
Returns: json_dict :
dictDictionary 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, })
-