Peano
Loading...
Searching...
No Matches
CustomGridGenerator Namespace Reference

Functions

 parse_tuple_string (tuple_str)
 Parse a string representation of a (weight, subtree_id) tuple.
 
 CustomGridGenerator (name, yaml_file_path)
 Generate a Tree object by reading from a YAML file created by generate_tree_yaml().
 

Function Documentation

◆ CustomGridGenerator()

CustomGridGenerator.CustomGridGenerator (   name,
  yaml_file_path 
)

Generate a Tree object by reading from a YAML file created by generate_tree_yaml().

This function reconstructs the complete tree structure from a YAML file, including all spatial data, metadata, and subtree assignments. It provides a way to reload previously processed trees for further analysis or modification.

YAML Structure Processing

The function expects YAML files with the structure created by generate_tree_yaml():

title: "Complete Tree Structure from [source]"
description: "Spatial representation of tree with (weight, subtree_id) tuples"
version: "2.0"
tree_info:
name: [tree_name]
dimension: [2 or 3]
max_level: [number_of_levels]
domain_offset: [x, y] or [x, y, z]
domain_size: [width, height] or [width, height, depth]
total_leaf_count: [total_leaves]
subtree_count: [number_of_subtrees]
split_summary:
subtree_distribution: [count_per_subtree]
tree_structure:
- level: 1
size: 3
data:
0: "(1,0), (1,0), (1,1)"
...

Data Reconstruction

The function rebuilds the tree arrays by:

  1. Parsing metadata to determine tree structure
  2. Creating numpy arrays for each refinement level
  3. Parsing tuple strings to extract (weight, subtree_id) values
  4. Populating arrays according to spatial indexing
  5. Updating tree statistics and metadata

Error Handling

Comprehensive validation includes:

  • File existence and readability
  • YAML syntax validation
  • Required field presence
  • Data type consistency
  • Tuple format validation
  • Dimensional compatibility

Args: name (str): Descriptive name for the loaded tree (overrides YAML name if desired) yaml_file_path (str): Path to the YAML file containing tree structure

Returns: Tree: Reconstructed Tree object with complete structure

Raises: FileNotFoundError: If YAML file doesn't exist or isn't readable yaml.YAMLError: If YAML file has syntax errors KeyError: If required fields are missing from YAML structure ValueError: If data formats are inconsistent or invalid

Example: ```python

Load a previously saved tree structure

tree = CustomGridGenerator( name="ReloadedTree", yaml_file_path="TreeStructure_l4_s3_split.yaml" )

print(f"Loaded tree: {tree._name}") print(f"Dimensions: {tree._dimension}D") print(f"Levels: {tree._max_level}") print(f"Leaf count: {tree._leaf_count}") print(f"Subtrees: {tree._subtree_count}")

Apply additional processing

from strategies.SplitTrees import split_tree split_tree(tree, number_of_subtrees=2) ```

Note:

  • The function preserves all original spatial relationships and metadata
  • Tree name can be overridden with the name parameter
  • Large YAML files may require significant memory during reconstruction
  • The reconstructed tree is functionally identical to the original

Definition at line 139 of file CustomGridGenerator.py.

References parse_tuple_string().

Here is the call graph for this function:

◆ parse_tuple_string()

CustomGridGenerator.parse_tuple_string (   tuple_str)

Parse a string representation of a (weight, subtree_id) tuple.

Supports various formats:

  • "(1,0)" - standard format
  • "(1, 0)" - with spaces
  • "1,0" - without parentheses

Args: tuple_str (str): String representation of the tuple

Returns: tuple: (weight, subtree_id) as integers

Raises: ValueError: If the string cannot be parsed as a valid tuple

Definition at line 105 of file CustomGridGenerator.py.

Referenced by CustomGridGenerator().

Here is the caller graph for this function: