Metric¶
-
class
lsst.validate.base.Metric(name, description, operator_str, specs=None, parameters=None, reference_doc=None, reference_url=None, reference_page=None)[source]¶ Bases:
lsst.validate.base.jsonmixin.JsonSerializationMixinContainer for the definition of a metric and its specification levels.
Metrics can either be instantiated programatically, or from a metric YAML file with the
from_yamlclass method.See also
See the Using metrics and specifications in Python page for usage details.
Parameters: name :
strName of the metric (e.g.,
'PA1').description :
strShort description about the metric.
operator_str :
strA string, such as
'<=', that defines a success test for a measurement (on the left hand side) against the metric specification level (right hand side).specs :
list, optionalA
listofSpecificationobjects that define various specification levels for this metric.parameters :
dict, optionalreference_doc :
str, optionalThe document handle that originally defined the metric (e.g.,
'LPM-17').reference_url :
str, optionalThe document’s URL.
reference_page :
str, optionalPage where metric in defined in the reference document.
Attributes Summary
descriptionShort description of the metric ( str).jsondictthat can be serialized as semantic JSON, compatible withnameName of the metric ( str).operatorBinary comparision operator that tests success of a measurement fulfilling a specification of this metric. operator_strString representation of comparison operator. parametersdictof namedDatumvalues that must be known when measuringreferenceDocumentation reference as human-readable text ( str, read-only).reference_docName of the document that specifies this metric ( str).reference_pagePage number in the document that specifies this metric ( int).reference_urlURL of the document that specifies this metric ( str).Methods Summary
check_spec(quantity, spec_name[, filter_name])Compare a measurement against a named specification level. convert_operator_str(op_str)Convert a string representing a binary comparison operator to the operator function itself. from_json(json_data)Construct a Metric from a JSON dataset. from_yaml(metric_name[, yaml_doc, ...])Create a Metricinstance from a YAML document that defines metrics.get_spec(name[, filter_name])Get a specification by name and other qualifications. get_spec_dependency(spec_name, dep_name[, ...])Get the Datumof a specification’s dependency.get_spec_names([filter_name])List names of all specification levels defined for this metric; optionally filtering by attributes such as filter name. jsonify_dict(d)Recursively build JSON-renderable objects on all values in a dict. write_json(filepath)Write JSON to a file. Attributes Documentation
-
operator¶ Binary comparision operator that tests success of a measurement fulfilling a specification of this metric.
Measured value is on left side of comparison and specification level is on right side.
-
operator_str¶ String representation of comparison operator.
The comparison is oriented with the measurement on the left-hand side and the specification level on the right-hand side.
-
parameters= {}¶ dictof namedDatumvalues that must be known when measuring a metric.Parameters can also be accessed as attributes of the metric. Attribute names are the same as key names in
parameters.
-
reference¶ Documentation reference as human-readable text (
str, read-only).Uses
reference_doc,reference_page, andreference_url, as available.
Methods Documentation
-
check_spec(quantity, spec_name, filter_name=None)[source]¶ Compare a measurement against a named specification level.
Parameters: value :
astropy.units.QuantityThe measurement value.
spec_name :
strName of a
Specificationassociated with this metric.filter_name :
str, optionalName of the applicable filter, if needed.
Returns: passed :
bool
-
static
convert_operator_str(op_str)[source]¶ Convert a string representing a binary comparison operator to the operator function itself.
Operators are oriented so that the measurement is on the left-hand side, and specification level on the right hand side.
The following operators are permitted:
op_strFunction >=operator.ge>operator.gt<operator.lt<=operator.le==operator.eq!=operator.neParameters: op_str :
strA string representing a binary operator.
Returns: op_func : obj
An operator function from the
operatorstandard library module.
-
classmethod
from_json(json_data)[source]¶ Construct a Metric from a JSON dataset.
Parameters: json_data :
dictMetric JSON object.
Returns: metric :
MetricMetric from JSON.
-
classmethod
from_yaml(metric_name, yaml_doc=None, yaml_path=None, resolve_dependencies=True)[source]¶ Create a
Metricinstance from a YAML document that defines metrics.See also
See Defining metrics and specifications in YAML for details on the metric YAML schema.
Parameters: metric_name :
strName of the metric (e.g.,
'PA1').yaml_doc :
dict, optionalA full metric YAML document loaded as a
dict. Use this option to increase performance by eliminating redundant reads of a common metric YAML file. Alternatively, setyaml_path.yaml_path :
str, optionalThe full file path to a metric YAML file. Alternatively, set
yaml_doc.resolve_dependencies :
bool, optionalAPI users should always set this to
True. The opposite is used only used internally.Raises: RuntimeError
Raised when neither
yaml_docoryaml_pathare set.
-
get_spec(name, filter_name=None)[source]¶ Get a specification by name and other qualifications.
Parameters: name :
strName of a specification level (e.g.,
'design','minimum','stretch').filter_name :
str, optionalThe name of the optical filter to qualify a filter-dependent specification level.
Returns: spec :
SpecificationThe
Specificationthat matches the name and other qualifications.Raises: RuntimeError
If a specification cannot be found.
-
get_spec_dependency(spec_name, dep_name, filter_name=None)[source]¶ Get the
Datumof a specification’s dependency.If the dependency is a metric, this method resolves the value of the dependent metric’s specification level
spec_name. In other words,spec_namerefers to the specification level of both this metric and of the dependency metric.Parameters: spec_name :
strSpecificationname.dep_name :
strName of the dependency.
filter_name :
str, optionalName of the optical filter, if this metric’s specifications are optical filter dependent.
Returns: datum :
DatumThe dependency resolved for the metric’s specification.
-
get_spec_names(filter_name=None)[source]¶ List names of all specification levels defined for this metric; optionally filtering by attributes such as filter name.
Parameters: filter_name :
str, optionalName of the applicable filter, if needed.
Returns: spec_names :
listSpecification names as a list of strings, e.g.
['design', 'minimum', 'stretch'].
-
jsonify_dict(d)¶ Recursively build JSON-renderable objects on all values in a dict.
Parameters: d :
dictDictionary ito 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, })
-