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:
BaseModelDict-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 (
itemNameabove) 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
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#
- name
str Name of the metadata property.
- value
Any Metadata property value.
- name
- 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#
- d
Mapping Mapping to convert. Can be hierarchical. Any dictionaries in the hierarchy are converted to
TaskMetadata.
Returns#
- meta
TaskMetadata Newly-constructed metadata.
- d
- classmethod from_metadata(ps: PropertySetLike) TaskMetadata#
Create a TaskMetadata from a PropertySet-like object.
Parameters#
- ps
PropertySetLikeorTaskMetadata A
PropertySet-like object to be transformed to aTaskMetadata. ATaskMetadatacan be copied using this class method.
Returns#
- tm
TaskMetadata Newly-constructed metadata.
Notes#
Items stored in single-element arrays in the supplied object will be converted to scalars in the newly-created object.
- ps
- get(key: str, default: Any = None) Any#
Retrieve the item associated with the key or a default.
Parameters#
- key
str The key to retrieve. Can be dot-separated hierarchical.
- default
Any The value to return if the key does not exist.
Returns#
- value
TaskMetadata,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__andPropertySet.get, but notto_dict().get.
- key
- getArray(key: str) list[Any]#
Retrieve an item as a list even if it is a scalar.
Parameters#
- key
str Item to retrieve.
Returns#
- values
listof any A list containing the value or values associated with this item.
Raises#
- KeyError
Raised if the item is not found.
- key
- getScalar(key: str) str | int | float | bool#
Retrieve a scalar item even if the item is a list.
Parameters#
- key
str Item to retrieve.
Returns#
- value
str,int,float, orbool 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.
- key
- 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
GetDictMetadataprotocol for consistency withlsst.daf.base.PropertySetandlsst.daf.base.PropertyList. The returneddictis guaranteed to be a deep copy, not a view.Parameters#
- key
str String key associated with the mapping. May not have a
.character.
Returns#
- value
Mapping Possibly-nested mapping, with
strkeys and values that areint,float,str,bool, or anotherdictwith the same key and value types. Will be empty ifkeydoes not exist.
- key
- 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#
- names
collections.abc.Set A set of all keys, including those from the hierarchy and the top-level hierarchy.
- names
- paramNames(topLevelOnly: bool) set[str]#
Return hierarchical names.
Parameters#
- topLevelOnly
bool Control whether only top-level items are returned or items from the hierarchy.
Returns#
- paramNames
setofstr If
topLevelOnlyisTrue, returns any keys that are not part of a hierarchy. IfFalsealso returns fully-qualified names from the hierarchy. Keys associated with the top of a hierarchy are never returned.
- topLevelOnly
- 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
SetDictMetadataprotocol for consistency withlsst.daf.base.PropertySetandlsst.daf.base.PropertyList.Parameters#
- key
str String key associated with the mapping. May not have a
.character.- value
Mapping Possibly-nested mapping, with
strkeys and values that areint,float,str,bool, or anotherdictwith the same key and value types. Nested keys may not have a.character.
- key
- to_dict() dict[str, Any]#
Convert the class to a simple dictionary.
Returns#
- d
dict 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. UseTaskMetadata.from_dict()to convert it back.- d