dantro: a Python package for handling, transforming, and visualizing hierarchically structured data

Yunus Sevinchan, Benjamin Herdeanu, Jeremias TraubJ. Open Source Softw 2020 · DBLP

Abstract

In modeling-based research, particularly computer simulations, scientists often face significant challenges in managing high volumes of complex, hierarchically structured data. dantro is a Python package designed to bridge the gap between raw simulation output and polished visualization. By providing a uniform "data tree" abstraction and a YAML-based configuration system, it enables the construction of robust, reproducible data processing pipelines. dantro integrates seamlessly with industry-standard tools like numpy, xarray, and dask, allowing researchers to automate the handling, transformation, and visualization of heterogeneous datasets.

Introduction

Computer simulations frequently generate data that is difficult to process using standard flat-table tools. This difficulty stems from two primary issues: hierarchical complexity and semantic heterogeneity. Simulation data is often nested in trees reflecting the modular structure of the model, and a single project may involve diverse data types, including numerical arrays, metadata, and custom objects. While specialized packages like pandas or xarray excel at handling specific formats, "gluing" them into a reliable, automated pipeline often results in brittle, project-specific scripts that hinder reproducibility. dantro addresses this by acting as a universal interface and orchestration layer for these specialized tools.

Methods and Architecture

The dantro framework is built around a three-stage pipeline: handling, transformation, and visualization. Its architecture emphasizes abstraction and separation of concerns.

The Data Tree Abstraction

The core of dantro is the "data tree," which organizes information into groups (branches) and containers (leaves). This abstraction provides a uniform API regardless of the underlying data format (e.g., lists, HDF5 files). By using abstract base classes, dantro ensures that heterogeneous data sources appear homogeneous to the processing pipeline.

Data Management and Lazy Loading

A DataManager serves as the root of the tree, managing the interface between disk storage and memory. To handle massive datasets, dantro utilizes "data proxies" to delay loading until necessary and integrates with dask for out-of-core computations. This approach allows for efficient processing of data that exceeds available RAM.

Transformation via Directed Acyclic Graphs (DAGs)

Data manipulations in dantro are specified as Directed Acyclic Graphs (DAGs). Instead of hard-coding transformations, users define a sequence of operations—ranging from standard Python functions to custom logic. The framework supports file-based caching for these operations, preventing redundant calculations and speeding up iterative analysis.

Configuration-Based Workflow

A defining feature of dantro is its reliance on YAML configuration files. The entire pipeline, including data selection, transformation parameters, and plot aesthetics, is controlled via these external files. This separation of logic (Python code) from specification (YAML config) ensures that analyses are easily adjustable and highly reproducible without modifying the underlying codebase.

Implementation and Integration

dantro was developed as a core component of the Utopia project, a large-scale modeling framework for complex evolving systems. It is specifically optimized for the high-volume, hierarchical output typical of such simulations, such as HDF5 files. Through the use of "mixins," the package is highly extensible; for instance, a GraphGroup can automatically instantiate networkx objects from its child nodes, facilitating specialized analysis of network data.

Results and Discussion

dantro successfully synthesizes the Python data science ecosystem, providing a flexible and automated workflow for scientific data. Key results of its architectural design include:

  • Interoperability: Seamlessly bridges h5py, xarray, dask, and matplotlib.
  • Flexibility: Allows for easy specialization of data containers through mixins.
  • Automation: Enables complex parameter space sweeps, where a range of parameters defined in a config file automatically triggers the generation of corresponding visualizations.
  • Reproducibility: The declarative nature of the YAML configuration ensures that the exact steps taken to produce a result are documented and shareable.

Limitations and Future Work

Adopting dantro requires an initial investment in architectural planning, which may be higher than writing simple scripts. Additionally, while the current visualization stage is closely tied to matplotlib, future developments aim to integrate declarative plotting frameworks like Altair (Vega-Lite) to further decouple data transformation from visual representation.

Conclusion

dantro provides a powerful solution for researchers dealing with complex simulation data. By standardizing the way hierarchical data is handled and transformed, it promotes the creation of maintainable and reproducible scientific workflows, allowing researchers to focus on analysis rather than data plumbing.

Summary updated

BibTeX
@article{sevinchan2020dantro,
  author = {Yunus Sevinchan and Benjamin Herdeanu and Jeremias Traub and Yunus Sevinchan and Benjamin Herdeanu},
  title = {{dantro: a Python package for handling, transforming, and visualizing hierarchically structured data}},
  journal = {J. Open Source Softw.},
  year = {2020},
  doi = {10.21105/joss.02316},
}
Figure