Datum¶
-
class
lsst.verify.
Datum
(quantity=None, unit=None, label=None, description=None)[source]¶ Bases:
lsst.verify.datum.QuantityAttributeMixin
,lsst.verify.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 beNone
.Parameters: quantity :
astropy.units.Quantity
,int
,float
or iterable.Value of the
Datum
.unit :
str
Units of
quantity
as astr
ifquantity
is not supplied as anastropy.units.Quantity
. See http://docs.astropy.org/en/stable/units/. Units are not used bystr
,bool
,int
orNone
types.label :
str
, optionalLabel suitable for plot axes (without units).
description :
str
, optionalExtended description of the
Datum
.Attributes Summary
description
Extended description. json
Datum as a dict
compatible with overallJob
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 thequantity
.unit_str
Read-only astropy.units.Unit
-compatiblestr
indicating units ofquantity
.Methods Summary
deserialize
([label, description, value, unit])Deserialize fields from a Datum JSON object into a Datum
instance.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.
-
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 thequantity
.
-
unit_str
¶ Read-only
astropy.units.Unit
-compatiblestr
indicating units ofquantity
.
Methods Documentation
-
classmethod
deserialize
(label=None, description=None, value=None, unit=None)[source]¶ Deserialize fields from a Datum JSON object into a
Datum
instance.Parameters: value :
float
,int
,bool
,str
, orlist
Values, which may be scalars or lists of scalars.
An
astropy.units
-compatible string with units ofvalue
, orNone
if the value does not have physical units.label :
str
, optionalLabel suitable for plot axes (without units).
description :
str
, optionalExtended description of the
Datum
.Returns: datum :
Datum
Datum instantiated from provided JSON fields.
Examples
With this class method, a
Datum
may be round-tripped from its JSON serialized form.>>> datum = Datum(50. * u.mmag, label='sigma', ... description="Photometric uncertainty.") >>> print(datum) sigma = 50.0 mmag Photometric uncertainty. >>> json_data = datum.json >>> new_datum = datum.deserialize(**json_data) >>> print(new_datum) sigma = 50.0 mmag Photometric uncertainty.
-
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, })
-