Datum

class lsst.validate.base.Datum(quantity=None, unit=None, label=None, description=None)[source]

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

A value annotated with units, a plot label and description.

Datum supports natively support Astropy Quantity and units. In addition, a Datum can also wrap strings, booleans and integers. A Datums’s value can also be None.

Parameters:

quantity : astropy.units.Quantity, int, float or iterable.

Value of the Datum.

unit : str

Units of quantity as a str if quantity is not supplied as an astropy.units.Quantity. See http://docs.astropy.org/en/stable/units/. Units are not used by str, bool, int or None types.

label : str, optional

Label suitable for plot axes (without units).

description : str, optional

Extended description of the Datum.

Attributes Summary

description Extended description.
json Datum as a dict compatible with overall Job JSON schema.
label Label for plotting (without units).
latex_unit Units as a LaTeX string, wrapped in $.
quantity Value of the datum (astropy.units.Quantity, str, bool, None).
unit Read-only astropy.units.Unit of the quantity.
unit_str Read-only astropy.units.Unit-compatible str indicating units of quantity.

Methods Summary

from_json(json_data) Construct a Datum from a JSON dataset.
jsonify_dict(d) Recursively build JSON-renderable objects on all values in a dict.
write_json(filepath) Write JSON to a file.

Attributes Documentation

description

Extended description.

json

Datum as a dict compatible with overall Job JSON schema.

label

Label for plotting (without units).

latex_unit

Units as a LaTeX string, wrapped in $.

quantity

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

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

classmethod from_json(json_data)[source]

Construct a Datum from a JSON dataset.

Parameters:

json_data : dict

Datum JSON object.

Returns:

datum : Datum

Datum 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,
    })
write_json(filepath)

Write JSON to a file.

Parameters:

filepath : str

Destination file name for JSON output.