identity

module of dascore.utils source

Hash things into ids, and say which data a patch is.

One hash, H, digests the canonical JSON of a domain and a payload. Everything which has an id gets it from there: a coordinate, an operation, and the two ids a patch carries.

origin_id says which stored data a patch came from. It survives every operation and folds when patches are combined. data_id says which array this is: a freshly read patch takes its origin’s id, and an operation’s result takes the digest of its inputs’ ids and the operation’s id, so the id commits to everything upstream of it.

An id is never knowingly false. A parameter the encoder cannot spell, or an input which carries no id, gives the result a random data_id rather than one another result could share.

Examples

from dascore.utils.identity import H, derive, fold_origin_ids

# Domains keep equal payloads apart.
assert H("operation", {"dim": "time"}) != H("coord", {"dim": "time"})

# Which array: the inputs, in order, and what was done to them.
assert derive(["a", "b"], "op") != derive(["b", "a"], "op")

# Which stored data: one origin stays itself however often it is met.
assert fold_origin_ids(["a", "a"]) == "a"

Functions

Name Description
H Return the 32 character id of a payload within a domain.
callable_name Return a name which says which function or class this is.
derive Return the data id of an operation’s result.
dtype_description Return the description a dtype is named by, fields and all.
encode Return the canonical JSON-safe tree standing for an object.
extract_patches Return parameters with each patch replaced by a marker, and the patches.
fold_origin_ids Return the origin id of a patch combined from several.
ids_enabled Whether this process is keeping track of what a patch is.
inside_operation Whether an operation is running, and will stamp its own result.
merge_operation Return the id of merging patches into one, under these merge options.
narrowed_data_id Return the id of a window of the array a patch already is, or None.
new_id Return a random id, for data nothing can be derived for.
operation_id Return the id of an operation and its parameters.
origin_id_for Return the origin id of a stored patch without touching the filesystem.
read_operation_id Return the id of decoding a resource under non-default options, or None.
result_ids Return the two ids of an operation’s result.
stamp Return attrs carrying the ids of an operation’s result.
strong_data_id Return the id of the content a patch holds.
try_operation_id Return an operation’s id, or None (and warn) if a parameter is refused.
warn_random_id Say that an operation worked but its result’s id could not be derived.
with_ids Return attrs which name which data they belong to.

Classes

Name Description
PatchMarker Stands for a patch handed to an operation as an argument.
operation_context Run a block as the body of an operation.