TaskMetadata¶
-
class
lsst.pipe.base.
TaskMetadata
¶ Bases:
pydantic.main.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.itemNameMetadata 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.
Deprecated methods are for compatibility with the predecessor containers.
Attributes Summary
copy
Duplicate a model, optionally choose which fields to include, exclude and change. dict
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. json
Generate a JSON representation of the model, include
andexclude
arguments as perdict()
.Methods Summary
add
(name, value)Store a new value, adding to a list if one already exists. construct
(_fields_set, None] = None, **values)Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. from_dict
(d, Any])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. getAsDouble
(key)Return the value cast to a float
.getScalar
(key)Retrieve a scalar item even if the item is a list. items
()Yield the top-level keys and values. keys
()Return the top-level keys. names
(topLevelOnly)Return the hierarchical keys from the metadata. paramNames
(topLevelOnly)Return hierarchical names. parse_file
(path, pathlib.Path], *, …)parse_obj
(obj)parse_raw
(b, bytes], *, content_type, …)remove
(key)Remove the item without raising if absent. schema
(by_alias, ref_template)schema_json
(*, by_alias, ref_template, …)set
(key, item)Set the value of the supplied key. 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
-
copy
¶ 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
¶ Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
-
json
¶ Generate a JSON representation of the model,
include
andexclude
arguments as perdict()
.encoder
is an optional function to supply asdefault
to json.dumps(), other arguments as perjson.dumps()
.
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
Metadata property value.
- name :
-
classmethod
construct
(_fields_set: Optional[SetStr, None] = None, **values) → 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
-
classmethod
from_dict
(d: Mapping[str, Any]) → lsst.pipe.base._task_metadata.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: lsst.pipe.base._task_metadata.PropertySetLike) → lsst.pipe.base._task_metadata.TaskMetadata¶ Create a TaskMetadata from a PropertySet-like object.
Parameters: - ps :
PropertySetLike
orTaskMetadata
A
PropertySet
-like object to be transformed to aTaskMetadata
. ATaskMetadata
can 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 :
-
classmethod
from_orm
(obj: Any) → Model¶
-
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
The value to return if the key doesnot 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 :
list
of any A list containing the value or values associated with this item.
Raises: - KeyError
Raised if the item is not found.
- key :
-
getAsDouble
(key: str) → float¶ Return the value cast to a
float
.Parameters: - key :
str
Item to return. Can be dot-separated hierarchical.
Returns: Raises: - KeyError
Raised if the item is not found.
Deprecated since version v24: Cast the return value to float explicitly. Will be removed after v25.
- key :
-
getScalar
(key: str) → Union[str, int, float, bool]¶ Retrieve a scalar item even if the item is a list.
Parameters: - key :
str
Item to retrieve.
Returns: Raises: - KeyError
Raised if the item is not found.
- key :
-
items
() → Iterator[Tuple[str, Any]]¶ Yield the top-level keys and values.
-
keys
() → Tuple[str, ...]¶ Return the top-level keys.
-
names
(topLevelOnly: bool = True) → Set[str]¶ Return the hierarchical keys from the metadata.
Parameters: - topLevelOnly :
bool
If true, return top-level keys, otherwise full metadata item keys.
Returns: - names :
collection.abc.Set
A set of top-level keys or full metadata item keys, including the top-level keys.
Notes
Should never be called in new code with
topLevelOnly
set toTrue
– this is equivalent to asking for the keys and is the default when iterating through the task metadata. In this case a deprecation message will be issued and the ability will raise an exception in a future release.When
topLevelOnly
isFalse
all keys, including those from the hierarchy and the top-level hierarchy, are returned.- topLevelOnly :
-
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: - topLevelOnly :
-
classmethod
parse_file
(path: Union[str, pathlib.Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: pydantic.parse.Protocol = None, allow_pickle: bool = False) → Model¶
-
classmethod
parse_obj
(obj: Any) → Model¶
-
classmethod
parse_raw
(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: pydantic.parse.Protocol = None, allow_pickle: bool = False) → Model¶
-
remove
(key: str) → None¶ Remove the item without raising if absent.
Deprecated since version v24: Use standard del dict syntax. Will be removed after v25.
-
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) → unicode¶
-
set
(key: str, item: Any) → None¶ Set the value of the supplied key.
Deprecated since version v24: Use standard assignment syntax. Will be removed after v25.
-
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 :
-
classmethod
update_forward_refs
(**localns) → None¶ Try to update ForwardRefs on fields based on this Model, globalns and localns.
-
classmethod
validate
(value: Any) → Model¶
-