shnitsel.data.shnitsel_db_helpers#

Attributes#

Functions#

concat_subtree(subtree[, only_direct_children])

Helper function to concatenate the trajectories in a subtree into a multi-trajetctory dataset.

layer_subtree(subtree[, only_direct_children])

Helper function to layer the trajectories in a subtree into a multi-trajetctory dataset.

list_subtree(subtree[, only_direct_children])

Helper function to collect the data in a subtree into a list.

unwrap_single_entry_in_tree(tree)

Attempts to unwrap a single dataset from a tree.

aggregate_xr_over_levels(tree, func, level_name[, dtype])

Apply an aggregation function to every node at a level of a db structure

get_data_with_path(subtree)

Function to get a list of all data in a tree with their respective path

Module Contents#

DataType#
AggType#
R#
TrajType#
concat_subtree(subtree, only_direct_children=False)#

Helper function to concatenate the trajectories in a subtree into a multi-trajetctory dataset.

The resulting dataset has a new frame dimension along which we can iterate through all individual frames of all trajectories.

Parameters:
  • subtree (TreeNode[Any, TrajType]) – The subtree of the ShnitselDB datastructure

  • only_direct_children (bool, optional) – Whether to only gather trajectories from direct children of this subtree.

Returns:

The resulting multi-trajectory dataset

Return type:

xr.Dataset

layer_subtree(subtree, only_direct_children=False)#

Helper function to layer the trajectories in a subtree into a multi-trajetctory dataset.

The resulting dataset has a new trajectory dimension along which we can iterate through all individual frames of all trajectories.

Parameters:
  • subtree (TreeNode[Any, TrajTrajectoryType]) – The subtree of the ShnitselDB datastructure

  • only_direct_children (bool, optional) – Whether to only gather trajectories from direct children of this subtree, by default false.

Returns:

The resulting multi-trajectory dataset

Return type:

xr.Dataset

list_subtree(subtree, only_direct_children=False)#

Helper function to collect the data in a subtree into a list.

Parameters:
  • subtree (TreeNode[Any, DataType]) – The subtree of the ShnitselDB datastructure holding the DataType entries to collect

  • only_direct_children (bool, optional) – Whether to only gather trajectories from direct children of this subtree, by default false

Returns:

The resulting data/trajectory list

Return type:

list[DataType]

unwrap_single_entry_in_tree(tree)#

Attempts to unwrap a single dataset from a tree.

If multiple or none are found, it will return the original tree If a single entry was found, will return the dataset

Parameters: root : TreeNode[Any, DataType]

Root of the subtree to parse

Returns:

Returns either the single point of data in the subtree or the full tree, if unwrapping would be unfeasible.

Return type:

DataType|TreeNode[Any, DataType]

Parameters:

tree (shnitsel.data.tree.TreeNode[Any, DataType])

aggregate_xr_over_levels(tree, func, level_name, dtype=None)#

Apply an aggregation function to every node at a level of a db structure

Parameters:
  • tree (TreeNode[Any, DataType]) – The tree to aggregate at the specific level

  • func (Callable[[TreeNode[Any, DataType]], R]) – The function to apply to the subtree at the specified level

  • level_name (Literal['root', 'compound', 'group', 'data']) – The target level to apply the function func to. See tree.datatree_level for values.

  • dtype (type | UnionType, optional) – The dtype of the resulting tree after aggregation.

Returns:

The resulting tree after applying the transform func to the subtrees.

Return type:

TreeNode[Any, R]

get_data_with_path(subtree)#

Function to get a list of all data in a tree with their respective path

Parameters:

subtree (TreeNode[Any, DataType]) – The subtree to generate the collection for.

Returns:

A list of tuples (path, data at that path) for all data in the subtree.

Return type:

List[tuple[str, DataType]]