easyclimate_map.core.datanode

Hierarchical data structure that dynamically manages attributes and nested nodes

Classes

DataNode

A hierarchical data structure that dynamically manages attributes and nested nodes.

Functions

open_datanode(→ DataNode)

Load a DataNode object from native location.

Module Contents

class easyclimate_map.core.datanode.DataNode(name='root')

A hierarchical data structure that dynamically manages attributes and nested nodes.

The DataNode class provides a flexible way to organize and access data in a tree-like structure. It supports automatic creation of nested nodes, path-style access, and rich HTML representation in Jupyter environments.

Parameters

namestr, optional

The name of the root node (default: "root").

_attributes
name = 'root'
__getattr__(key)

Dynamically access or create node attributes.

Automatically creates nested DataNode for non-existent attributes, while filtering out special IPython/Jupyter attribute requests.

Parameters

keystr

The attribute name to access.

Returns

Any

The requested attribute or a new DataNode if attribute doesn’t exist.

Raises

AttributeError

If the attribute is a special IPython/Jupyter attribute.

__setattr__(key, value)

Set node attributes while protecting internal attributes.

Parameters

keystr

The attribute name to set.

valueAny

The value to assign to the attribute.

__getitem__(key)

Access attributes using path-style notation (e.g., “path/to/attribute”).

Parameters

keystr

The attribute path to access, with ‘/’ separators for nested nodes.

Returns

Any

The value at the specified path.

Raises

KeyError

If any part of the path doesn’t exist.

__contains__(key)
__setitem__(key, value)

Set attributes using path-style notation, creating intermediate nodes as needed.

Parameters

keystr

The attribute path to set, with ‘/’ separators for nested nodes.

valueAny

The value to assign at the specified path.

_repr_html_()

Generate HTML representation for Jupyter notebooks.

Returns

str

HTML string representing the node and its contents.

_format_html()

Generate complete HTML representation including styles and scripts.

Returns

str

Complete HTML document as a string.

_format_node_html(node, level=0, parent_id=None)

Recursively generate HTML for a node and its children.

Parameters

nodeDataNode

The node to format.

levelint, optional

Current nesting level (default: 0).

parent_idstr, optional

ID of parent node for DOM construction (default: None).

Returns

str

HTML string representing the node.

_format_value(value)

Format values for display, truncating long sequences.

Parameters

valueAny

The value to format.

Returns

str

Formatted string representation of the value.

format_tree(level=0, html=False, is_last_list=None)

Generate a tree-structured representation of the node.

Parameters

levelint, optional

Current indentation level (default: 0).

htmlbool, optional

Whether to generate HTML output (default: False).

is_last_listlist of bool, optional

Track position in hierarchy for proper indentation (default: None).

Returns

str

Formatted tree representation.

__repr__()
_repr_pretty_(p, cycle)

Support the IPython of pretty printing

_repr_mimebundle_(include=None, exclude=None)
__dir__()
to_zarr(filepath: str | pathlib.Path, zarr_format: Literal[2, 3] = 2)

Save the DataNode and its contents to a Zarr storage format.

Parameters

filepathUnion[str, Path]

Directory path to save the data.

zarr_formatLiteral[2, 3], optional

Zarr storage format version (default: 2).

classmethod load(filepath: str | pathlib.Path)

Load a DataNode from a Zarr storage directory.

Parameters

filepathUnion[str, Path]

Directory path containing the saved DataNode.

Returns

DataNode

The reconstructed DataNode with all its attributes.

easyclimate_map.core.datanode.open_datanode(filepath: str) DataNode

Load a DataNode object from native location.

This function provides a convenient way to load a DataNode that was previously saved using the DataNode.to_zarr() method.

Parameters

filepathstr

The path to the directory containing the saved DataNode data. This should be the same path used with DataNode.to_zarr().

Returns

DataNode

The loaded DataNode object with all its attributes and nested structure.

Examples

>>> node = open_datanode("path/to/saved_node")
>>> node.some_attribute  # Access attributes as usual