zea.data.metadata¶
Selective metadata loading for Dataloader.
See the return_metadata argument of Dataloader
for the path syntax and the shape of the result.
Functions
|
Whether any of |
|
Return |
|
Map every leaf reachable from |
|
Return the subset of |
|
Normalize the |
|
Read |
|
Return a copy of |
|
Resolve |
|
Return |
|
Return a copy of |
- zea.data.metadata.batch_leaf_shape(path, shape, n_frames, dim_selections=None, dim_sizes=None)[source]¶
Return
shapeas batching sees it: selected, with the frame axis a placeholder.Batching stacks metadata leaf by leaf, so the leaves of every file must line up. Both cuts a sample’s metadata undergoes are applied here, since a leaf only has to match after them: the selection (
selected_leaf_shape()), and the frame axis, sliced to the sample’s frame count and so normalized rather than compared. Everything else must match exactly.- Return type:
tuple
- zea.data.metadata.has_per_frame_paths(paths)[source]¶
Whether any of
pathscan resolve to a field with a leadingn_framesaxis.Lets the caller skip the per-frame slicing pass entirely when only static metadata (scan parameters, probe geometry, subject) was requested.
- Return type:
bool
- zea.data.metadata.metadata_signature(file, paths)[source]¶
Map every leaf reachable from
pathsto its shape infile.The shapes are the raw stored ones: normalizing the frame axis needs the file’s own frame count, which the caller holds. Dtypes are deliberately left out – stacking promotes them (
float32withfloat64,<U4with<U9), so a difference there is not a batching failure.- Parameters:
- Returns:
Leaf dotted path -> shape tuple. A path absent from the file maps to the shape of
None, i.e.(); usemissing_metadata_paths()to tell absence apart from a genuine scalar.- Return type:
dict[str,tuple]
- zea.data.metadata.missing_metadata_paths(file, paths)[source]¶
Return the subset of
pathsthatfilecannot supply.Lets a caller check a whole dataset up front instead of discovering a missing path when
read_metadata()reaches the file mid-epoch.
- zea.data.metadata.normalize_metadata_paths(return_metadata)[source]¶
Normalize the
return_metadataargument into a tuple of dotted paths.- Parameters:
return_metadata –
False/Noneto return arrays only,Truefor file identity only, or a string / iterable of dotted paths.- Return type:
tuple[str,...] |None- Returns:
Nonewhen no metadata should be returned, otherwise a tuple of dotted paths (possibly empty, meaning file identity only).
- zea.data.metadata.read_metadata(file, paths)[source]¶
Read
pathsoff an open file into a nested,FileSpec-shaped dict.
- zea.data.metadata.select_metadata_axes(tree, dim_selections, dim_sizes, prefix='')[source]¶
Return a copy of
treenarrowed by the sample’saxis_selections.A selection means something about the acquisition – “these 21 transmits” – so a field carrying that dimension stops describing the sample it comes with unless it is cut the same way. Unlike the frame axis of
slice_metadata(), the cut is the same for every sample of a file, so this runs once per file rather than per sample.- Parameters:
tree (
dict) – Nested metadata dict as returned byread_metadata().dim_selections (
dict) – Dimension name -> selection, fromselected_dimensions().dim_sizes (
dict) – Dimension name -> that dimension’s full extent in this file.prefix (
str) – Dotted prefix oftreewithin the file spec (internal).
- Returns:
A new nested dict; values with no selected axis are shared, not copied.
- Return type:
dict
- zea.data.metadata.selected_dimensions(key, num_dims, axis_selections)[source]¶
Resolve
{axis: selection}onkeyinto{dimension name: selection}.Naming the dimension is what lets the same take reach metadata laid out differently: axis 1 of
data/raw_dataisn_tx, which is axis 0 ofscan.t0_delays. Empty for a key the spec cannot name, and for dimensions the take may not travel along (PROPAGATED_DIMENSIONS).- Return type:
dict[str,Any]
- zea.data.metadata.selected_leaf_shape(path, shape, dim_selections, dim_sizes)[source]¶
Return
shapeas it is afterselect_metadata_axes()narrows it.- Return type:
tuple
- zea.data.metadata.slice_metadata(tree, frame_selection, n_frames, prefix='')[source]¶
Return a copy of
treewith per-frame fields sliced to the sample’s frames.- Parameters:
tree (
dict) – Nested metadata dict as returned byread_metadata().frame_selection – The frame selector used to read the sample’s images (a
sliceover the file’s frame axis).n_frames (
int|None) – Total number of frames in the file, used to recognize which arrays actually carry a frame axis.Nonedisables slicing.prefix (
str) – Dotted prefix oftreewithin the file spec (internal).
- Returns:
A new nested dict; unsliced values are shared, not copied.
- Return type:
dict