MeasurementBase

class lsst.validate.base.MeasurementBase[source]

Bases: lsst.validate.base.QuantityAttributeMixin, lsst.validate.base.jsonmixin.JsonSerializationMixin, lsst.validate.base.datummixin.DatumAttributeMixin

Base class for Measurement classes.

This class isn’t instantiated directly. Instead, developers should subclass MeasurementBase to create measurement classes for each metric being measured.

Subclasses must (at least) implement the following attributes:

Subclasses are also responsible for assiging the measurement’s value to the quantity attribute (as an astropy.units.Quantity).

See also

The Creating measurement classes page shows how to create measurement classes using MeasurementBase.

Attributes Summary

blobs dict of blobs attached to this measurement instance.
datum Representation of this measurement as a Datum.
extras dict containing all measurement by-products (called extras) that
filter_name Name of the optical filter for the observations this measurement was made from.
identifier Unique UUID4-based identifier for this measurement (str).
json A dict that can be serialized as semantic SQUASH JSON.
label Name of the Metric associated with this measurement (str).
latex_unit Units as a LaTeX string, wrapped in $.
metric Metric that this measurement is associated to.
parameters dict containing all input parameters used by this measurement.
quantity Value of the datum (astropy.units.Quantity, str, bool, None).
spec_name Name of the specification level (e.g., ‘design,’ ‘minimum,’ ‘stretch’) that this measurement represents.
unit Read-only astropy.units.Unit of the quantity.
unit_str Read-only astropy.units.Unit-compatible str indicating units of quantity.

Methods Summary

check_spec(name) Check this measurement against a Specification level, of the Metric.
from_json(json_data[, blobs_json]) Construct a measurement from a JSON dataset.
jsonify_dict(d) Recursively build JSON-renderable objects on all values in a dict.
register_extra(extra_key[, quantity, unit, ...]) Register a measurement extra—a by-product of a metric measurement.
register_parameter(param_key[, quantity, ...]) Register a measurement input parameter attribute.
write_json(filepath) Write JSON to a file.

Attributes Documentation

blobs

dict of blobs attached to this measurement instance.

datum

Representation of this measurement as a Datum.

extras = None

dict containing all measurement by-products (called extras) that have been registered for serialization.

Extras are Datum instances. Values of extras can also be accessed and updated as instance attributes named after the extra.

filter_name = None

Name of the optical filter for the observations this measurement was made from.

None if a measurement is not filter-dependent.

identifier

Unique UUID4-based identifier for this measurement (str).

json

A dict that can be serialized as semantic SQUASH JSON.

label

Name of the Metric associated with this measurement (str).

latex_unit

Units as a LaTeX string, wrapped in $.

metric

Metric that this measurement is associated to.

parameters = None

dict containing all input parameters used by this measurement. Parameters are Datum instances. Parameter values can be accessed and updated as instance attributes named after the parameter.

quantity

Value of the datum (astropy.units.Quantity, str, bool, None).

spec_name = None

Name of the specification level (e.g., ‘design,’ ‘minimum,’ ‘stretch’) that this measurement represents.

None if this measurement applies to all specification levels.

unit

Read-only astropy.units.Unit of the quantity.

If the quantity is a str or bool, the unit is None.

unit_str

Read-only astropy.units.Unit-compatible str indicating units of quantity.

Methods Documentation

check_spec(name)[source]

Check this measurement against a Specification level, of the Metric.

Parameters:

name : str

Specification level name.

Returns:

passed : bool

True if the measurement meets the Specification level, False otherwise.

Notes

Internally this method retrieves the Specification object, filtering first by the name, but also by this object’s filter_name attribute if specifications are filter-dependent.

classmethod from_json(json_data, blobs_json=None)[source]

Construct a measurement from a JSON dataset.

Parameters:

json_data : dict

Measurement JSON object.

blobs_json : list

JSON serialization of blobs. This is the blobs object produced by Job.json.

Returns:

measurement : MeasurementBase-type

Measurement from JSON.

jsonify_dict(d)

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

Parameters:

d : dict

Dictionary ito 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,
    })
register_extra(extra_key, quantity=None, unit=None, label=None, description=None, datum=None)[source]

Register a measurement extra—a by-product of a metric measurement.

The value of the extra can either be set at registration time (see quantity argument), or later by setting the object’s attribute named extra_key.

The value of an extra can always be accessed through the object’s attribute named after extra_key.

Extras are stored as Datum objects, which can be accessed through the parameters attribute dict.

Parameters:

extra_key : str

Name of the extra; used as the key in the extras attribute of this object.

quantity : astropy.units.Quantity, str, or bool

Value of the extra.

label : str, optional

Label suitable for plot axes (without units). By default the extra_key is used as the label. Setting this label argument overrides both of these.

description : str, optional

Extended description.

datum : Datum, optional

If a Datum is provided, its value, label and description will be used unless overriden by other arguments to register_extra.

register_parameter(param_key, quantity=None, label=None, description=None, datum=None)[source]

Register a measurement input parameter attribute.

The value of the parameter can either be set at registration time (see quantity argument), or later by setting the object’s attribute named param_key.

The value of a parameter can always be accessed through the object’s attribute named after the provided param_key.

Parameters are stored as Datum objects, which can be accessed through the parameters attribute dict.

Parameters:

param_key : str

Name of the parameter; used as the key in the parameters attribute of this object.

quantity : astropy.units.Quantity, str or bool.

Value of the parameter.

label : str, optional

Label suitable for plot axes (without units). By default the param_key is used as the label. Setting this label argument overrides that default.

description : str, optional

Extended description of the parameter.

datum : Datum, optional

If a Datum is provided, its quantity, label and description are be used unless overriden by other arguments to this method.

write_json(filepath)

Write JSON to a file.

Parameters:

filepath : str

Destination file name for JSON output.