TaskMetadata

class lsst.pipe.base.TaskMetadata(*, scalars: dict[str, pydantic.types.StrictFloat | pydantic.types.StrictInt | pydantic.types.StrictBool | pydantic.types.StrictStr] = None, arrays: dict[str, list[pydantic.types.StrictFloat] | list[pydantic.types.StrictInt] | list[pydantic.types.StrictBool] | list[pydantic.types.StrictStr]] = None, metadata: dict[str, 'TaskMetadata'] = None)

Bases: _BaseModelCompat

Dict-like object for storing task metadata.

Metadata can be stored at two levels: single task or task plus subtasks. The later is called full metadata of a task and has a form

topLevelTaskName:subtaskName:subsubtaskName.itemName

Metadata item key of a task (itemName above) must not contain , which serves as a separator in full metadata keys and turns the value into sub-dictionary. Arbitrary hierarchies are supported.

Attributes Summary

model_fields

Methods Summary

add(name, value)

Store a new value, adding to a list if one already exists.

construct([_fields_set])

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.

copy(*[, include, exclude, update, deep])

Duplicate a model, optionally choose which fields to include, exclude and change.

dict(*[, include, exclude, by_alias, ...])

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

from_dict(d)

Create a TaskMetadata from a dictionary.

from_metadata(ps)

Create a TaskMetadata from a PropertySet-like object.

from_orm(obj)

get(key[, default])

Retrieve the item associated with the key or a default.

getArray(key)

Retrieve an item as a list even if it is a scalar.

getScalar(key)

Retrieve a scalar item even if the item is a list.

items()

Yield the top-level keys and values.

json(*[, include, exclude, by_alias, ...])

Generate a JSON representation of the model, include and exclude arguments as per dict().

keys()

Return the top-level keys.

model_construct([_fields_set])

model_dump(*[, mode, include, exclude, ...])

model_dump_json(*[, indent, include, ...])

model_rebuild(*[, force, raise_errors, ...])

model_validate(obj, *[, strict, ...])

model_validate_json(json_data, *[, strict, ...])

names([topLevelOnly])

Return the hierarchical keys from the metadata.

paramNames(topLevelOnly)

Return hierarchical names.

parse_file(path, *[, content_type, ...])

parse_obj(obj)

parse_raw(b, *[, content_type, encoding, ...])

schema([by_alias, ref_template])

schema_json(*[, by_alias, ref_template])

to_dict()

Convert the class to a simple dictionary.

update_forward_refs(**localns)

Try to update ForwardRefs on fields based on this Model, globalns and localns.

validate(value)

Attributes Documentation

model_fields = {'arrays': ModelField(name='arrays', type=Mapping[str, Union[list[pydantic.types.StrictFloat], list[pydantic.types.StrictInt], list[pydantic.types.StrictBool], list[pydantic.types.StrictStr]]], required=False, default_factory='<function dict>'), 'metadata': ModelField(name='metadata', type=Mapping[str, TaskMetadata], required=False, default_factory='<function dict>'), 'scalars': ModelField(name='scalars', type=Mapping[str, Union[StrictFloat, StrictInt, StrictBool, StrictStr]], required=False, default_factory='<function dict>')}

Methods Documentation

add(name: str, value: Any) None

Store a new value, adding to a list if one already exists.

Parameters:
namestr

Name of the metadata property.

value

Metadata property value.

classmethod construct(_fields_set: SetStr | None = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = 'allow' was set since it adds all passed values

copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: DictStrAny | None = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters:
  • include – fields to include in new model

  • exclude – fields to exclude from new model, as with values this takes precedence over include

  • update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep – set to True to make a deep copy of the model

Returns:

new model instance

dict(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

classmethod from_dict(d: Mapping[str, Any]) TaskMetadata

Create a TaskMetadata from a dictionary.

Parameters:
dMapping

Mapping to convert. Can be hierarchical. Any dictionaries in the hierarchy are converted to TaskMetadata.

Returns:
metaTaskMetadata

Newly-constructed metadata.

classmethod from_metadata(ps: PropertySetLike) TaskMetadata

Create a TaskMetadata from a PropertySet-like object.

Parameters:
psPropertySetLike or TaskMetadata

A PropertySet-like object to be transformed to a TaskMetadata. A TaskMetadata can be copied using this class method.

Returns:
tmTaskMetadata

Newly-constructed metadata.

Notes

Items stored in single-element arrays in the supplied object will be converted to scalars in the newly-created object.

classmethod from_orm(obj: Any) Model
get(key: str, default: Any = None) Any

Retrieve the item associated with the key or a default.

Parameters:
keystr

The key to retrieve. Can be dot-separated hierarchical.

default

The value to return if the key does not exist.

Returns:
valueTaskMetadata, float, int, bool, str

A scalar value. If the key refers to an array, the final element is returned and not the array itself; this is consistent with __getitem__ and PropertySet.get, but not to_dict().get.

getArray(key: str) list[Any]

Retrieve an item as a list even if it is a scalar.

Parameters:
keystr

Item to retrieve.

Returns:
valueslist of any

A list containing the value or values associated with this item.

Raises:
KeyError

Raised if the item is not found.

getScalar(key: str) str | int | float | bool

Retrieve a scalar item even if the item is a list.

Parameters:
keystr

Item to retrieve.

Returns:
valuestr, int, float, or bool

Either the value associated with the key or, if the key corresponds to a list, the last item in the list.

Raises:
KeyError

Raised if the item is not found.

items() Iterator[tuple[str, Any]]

Yield the top-level keys and values.

json(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = None, models_as_dict: bool = True, **dumps_kwargs: Any) unicode

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

keys() tuple[str, ...]

Return the top-level keys.

classmethod model_construct(_fields_set: set[str] | None = None, **values: Any) Self
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: set[int] | set[str] | dict[int, Any] | dict[str, Any] | None = None, exclude: set[int] | set[str] | dict[int, Any] | dict[str, Any] | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: bool = True) dict[str, Any]
model_dump_json(*, indent: int | None = None, include: set[int] | set[str] | dict[int, Any] | dict[str, Any] | None = None, exclude: set[int] | set[str] | dict[int, Any] | dict[str, Any] | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: bool = True) str
classmethod model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: dict[str, Any] | None = None) bool | None
classmethod model_validate(obj: Any, *, strict: bool | None = None, from_attributes: bool | None = None, context: dict[str, Any] | None = None) Self
classmethod model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, context: dict[str, Any] | None = None) Self
names(topLevelOnly: bool | None = None) set[str]

Return the hierarchical keys from the metadata.

Parameters:
topLevelOnlybool or None, optional

This parameter is deprecated and will be removed in the future. If given it can only be False. All names in the hierarchy are always returned.

Returns:
namescollections.abc.Set

A set of all keys, including those from the hierarchy and the top-level hierarchy.

paramNames(topLevelOnly: bool) set[str]

Return hierarchical names.

Parameters:
topLevelOnlybool

Control whether only top-level items are returned or items from the hierarchy.

Returns:
paramNamesset of str

If topLevelOnly is True, returns any keys that are not part of a hierarchy. If False also returns fully-qualified names from the hierarchy. Keys associated with the top of a hierarchy are never returned.

classmethod parse_file(path: str | Path, *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) Model
classmethod parse_obj(obj: Any) Model
classmethod parse_raw(b: str | bytes, *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) Model
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') DictStrAny
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) unicode
to_dict() dict[str, Any]

Convert the class to a simple dictionary.

Returns:
ddict

Simple dictionary that can contain scalar values, array values or other dictionary values.

Notes

Unlike dict(), this method hides the model layout and combines scalars, arrays, and other metadata in the same dictionary. Can be used when a simple dictionary is needed. Use TaskMetadata.from_dict() to convert it back.

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

classmethod validate(value: Any) Model