BlobBase

class lsst.validate.base.BlobBase[source]

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

Base class for blobs: flexible containers of data that are serialized to JSON.

See also

The page Providing datasets to measurements through blobs describes how to create blob classes.

Attributes Summary

datums dict of Datum instances contained by the blob instance.
identifier Unique UUID4-based identifier for this blob (str).
json Job data as a JSON-serializable dict.
name Name of this blob (the BlobBase subclass’s Python namespace).

Methods Summary

from_json(json_data) Construct a Blob from a JSON dataset.
jsonify_dict(d) Recursively build JSON-renderable objects on all values in a dict.
register_datum(name[, quantity, label, ...]) Register a new Datum to be contained by, and serialized via, this blob.
write_json(filepath) Write JSON to a file.

Attributes Documentation

datums = None

dict of Datum instances contained by the blob instance.

The values of blobs can also be accessed as attributes of the BlobBase subclass. Keys in datums and attributes share the same names.

identifier

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

json

Job data as a JSON-serializable dict.

name

Name of this blob (the BlobBase subclass’s Python namespace).

Methods Documentation

classmethod from_json(json_data)[source]

Construct a Blob from a JSON dataset.

Parameters:

json_data : dict

Blob JSON object.

Returns:

blob : BlobBase-type

Blob 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_datum(name, quantity=None, label=None, description=None, datum=None)[source]

Register a new Datum to be contained by, and serialized via, this blob.

The value of the Datum can either be set at registration time (with the quantity or datum arguments) or later by setting the instance attribute named name.

Values of Datums can always be accessed or updated through instance attributes.

The full Datum object can be accessed as items of the datums dictionary attached to this class. This method is useful for accessing or updating metadata about a Datum, such as: unit, label, or description.

Parameters:

name : str

Name of the Datum; used as the key in the datums attribute of this object.

value : obj

Value of the Datum.

label : str, optional

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

description : str, optional

Extended description.

datum : Datum, optional

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

write_json(filepath)

Write JSON to a file.

Parameters:

filepath : str

Destination file name for JSON output.