TaskMetadata#

class lsst.pipe.base.TaskMetadata(*, scalars: dict[str, ~typing.Annotated[float, ~pydantic.types.Strict(strict=True)] | ~typing.Annotated[int, ~pydantic.types.Strict(strict=True)] | ~typing.Annotated[bool, ~pydantic.types.Strict(strict=True)] | ~typing.Annotated[str, ~pydantic.types.Strict(strict=True)]] = <factory>, arrays: dict[str, list[~typing.Annotated[float, ~pydantic.types.Strict(strict=True)]] | list[~typing.Annotated[int, ~pydantic.types.Strict(strict=True)]] | list[~typing.Annotated[bool, ~pydantic.types.Strict(strict=True)]] | list[~typing.Annotated[str, ~pydantic.types.Strict(strict=True)]]] = <factory>, metadata: dict[str, ~lsst.pipe.base._task_metadata.TaskMetadata] = <factory>)#

Bases: BaseModel

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_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Methods Summary

add(name, value)

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

copy(*args, **kwargs)

See pydantic.BaseModel.copy.

from_dict(d)

Create a TaskMetadata from a dictionary.

from_metadata(ps)

Create a TaskMetadata from a PropertySet-like object.

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.

get_dict(key)

Return a possibly-hierarchical nested dict.

items()

Yield the top-level keys and values.

keys()

Return the top-level keys.

model_construct(*args, **kwargs)

See pydantic.BaseModel.model_construct.

model_copy(*args, **kwargs)

See pydantic.BaseModel.model_copy.

model_dump(*args, **kwargs)

See pydantic.BaseModel.model_dump.

model_dump_json(*args, **kwargs)

See pydantic.BaseModel.model_dump_json.

model_json_schema(*args, **kwargs)

See pydantic.BaseModel.model_json_schema.

model_validate(*args, **kwargs)

See pydantic.BaseModel.model_validate.

model_validate_json(*args, **kwargs)

See pydantic.BaseModel.model_validate_json.

model_validate_strings(*args, **kwargs)

See pydantic.BaseModel.model_validate_strings.

names()

Return the hierarchical keys from the metadata.

paramNames(topLevelOnly)

Return hierarchical names.

set_dict(key, value)

Assign a possibly-hierarchical nested dict.

to_dict()

Convert the class to a simple dictionary.

Attributes Documentation

model_config: ClassVar[ConfigDict] = {'ser_json_inf_nan': 'constants'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

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.

valueAny

Metadata property value.

copy(*args: Any, **kwargs: Any) Any#

See pydantic.BaseModel.copy.

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.

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.

defaultAny

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.

get_dict(key: str) Mapping[str, str | float | int | bool | Mapping[str, str | float | int | bool | NestedMetadataDict]]#

Return a possibly-hierarchical nested dict.

This implements the GetDictMetadata protocol for consistency with lsst.daf.base.PropertySet and lsst.daf.base.PropertyList. The returned dict is guaranteed to be a deep copy, not a view.

Parameters#

keystr

String key associated with the mapping. May not have a . character.

Returns#

valueMapping

Possibly-nested mapping, with str keys and values that are int, float, str, bool, or another dict with the same key and value types. Will be empty if key does not exist.

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

Yield the top-level keys and values.

keys() tuple[str, ...]#

Return the top-level keys.

classmethod model_construct(*args: Any, **kwargs: Any) Any#

See pydantic.BaseModel.model_construct.

model_copy(*args: Any, **kwargs: Any) Any#

See pydantic.BaseModel.model_copy.

model_dump(*args: Any, **kwargs: Any) Any#

See pydantic.BaseModel.model_dump.

model_dump_json(*args: Any, **kwargs: Any) Any#

See pydantic.BaseModel.model_dump_json.

classmethod model_json_schema(*args: Any, **kwargs: Any) Any#

See pydantic.BaseModel.model_json_schema.

classmethod model_validate(*args: Any, **kwargs: Any) Any#

See pydantic.BaseModel.model_validate.

classmethod model_validate_json(*args: Any, **kwargs: Any) Any#

See pydantic.BaseModel.model_validate_json.

classmethod model_validate_strings(*args: Any, **kwargs: Any) Any#

See pydantic.BaseModel.model_validate_strings.

names() set[str]#

Return the hierarchical keys from the metadata.

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.

set_dict(key: str, value: Mapping[str, str | float | int | bool | Mapping[str, str | float | int | bool | NestedMetadataDict]]) None#

Assign a possibly-hierarchical nested dict.

This implements the SetDictMetadata protocol for consistency with lsst.daf.base.PropertySet and lsst.daf.base.PropertyList.

Parameters#

keystr

String key associated with the mapping. May not have a . character.

valueMapping

Possibly-nested mapping, with str keys and values that are int, float, str, bool, or another dict with the same key and value types. Nested keys may not have a . character.

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.