Skip to main content

hgh - Hierarchical Grid Heatmap

Python package for building hierarchical evolution heatmaps from bibliometric data. Designed for visualizing how thematic structures evolve across time at micro, meso, and macro levels of a topic taxonomy.

Installation

pip install hgh

Static image export (PDF, PNG, SVG) requires kaleido:

pip install hgh[export]

Quick start

Single workbook (Excel)

from hgh.main import build_hgh

build_hgh(
    source="workbook.xlsx",
    taxonomy="taxonomy.csv",
    kind="impact",
    normalization="coverage",
    out_html="output.html",
)

Multi-unit comparison from CSV

from hgh.main import build_hgh_multiple

build_hgh_multiple(
    source="multi_long.csv",
    taxonomy="taxonomy.csv",
    focal_units=["Unit A", "Unit B"],
    kinds=["production", "impact"],
    normalization="coverage",
    export={"html": "comparison.html", "pdf": True, "paper": "a4-landscape", "dpi": 300},
    show=False,
)

Two-unit comparison with delta

from hgh import MultipleCSVEvolutionWorkbook
from hgh.main import build_hgh_comparison

mewb = MultipleCSVEvolutionWorkbook("multi_long.csv")

build_hgh_comparison(
    left_source=mewb.get("Unit A"),
    right_source=mewb.get("Unit B"),
    taxonomy="taxonomy.csv",
    measure="impact",
    normalization="coverage",
    show_delta=True,
    export={"html": "delta.html", "png": True, "paper": "double-column", "dpi": 300},
    show=False,
)

Direct workbook mode (no CSV intermediate)

from hgh import EvolutionWorkbook
from hgh.main import build_hgh_multiple

build_hgh_multiple(
    source=[
        (EvolutionWorkbook("unit_a.xlsx"), "Unit A"),
        (EvolutionWorkbook("unit_b.xlsx"), "Unit B"),
    ],
    taxonomy="taxonomy.csv",
    kinds=["production", "impact"],
    normalization="hill",
    hill_q=1.0,
    export={"html": "output.html"},
)

Data sources

EvolutionWorkbook

Reads an Excel file with period sheets (YYYY for production, YYYY_c for impact). Each sheet must have columns topic, count, percent.

from hgh import EvolutionWorkbook

wb = EvolutionWorkbook("workbook.xlsx")
print(wb.periods("impact"))   # ['2010', '2011', ...]

Export to long-format CSV:

wb.to_long_csv("output.csv", focal_unit="My Unit", fill_empty_years=True)

CSVEvolutionWorkbook

Reads the long-format CSV produced by to_long_csv(). Columns: focal_unit (optional), year, event_type, topic, count, percent.

from hgh import CSVEvolutionWorkbook

wb = CSVEvolutionWorkbook("long.csv")

MultipleCSVEvolutionWorkbook

Loads a multi-unit long-format CSV once and exposes per-unit workbook views.

from hgh import MultipleCSVEvolutionWorkbook

mewb = MultipleCSVEvolutionWorkbook("multi_long.csv")
print(mewb.focal_units())       # ['Unit A', 'Unit B']

wb_a = mewb.get("Unit A")      # CSVEvolutionWorkbook

Normalization modes

Mode Description
coverage Active micro-topics / possible micro-topics under each meso
hill Normalized Hill diversity number (order hill_q); q=1 equals Shannon
max_row Each meso divided by its maximum across all periods
period_max Each period divided by its maximum across all meso topics
impacted_max_row Active micro-topics per period / max active in span

coverage and hill require a taxonomy with at least three levels and target_level != leaf_level_in_data.

Taxonomy format

A CSV with one column per hierarchy level. The default level names are macro, meso, micro - each row defines one leaf topic path.

macro,meso,micro
1 Clinical Sciences,1.1 Cardiology,1.1.4 Heart failure biomarkers
1 Clinical Sciences,1.1 Cardiology,1.1.7 Cardiac imaging
1 Clinical Sciences,1.2 Neurology,1.2.1 Stroke rehabilitation

Export

All build_* functions accept an export dict:

export={
    "html":         "figure.html",   # interactive
    "pdf":          True,            # same stem as html
    "png":          True,
    "svg":          "/path/to/fig.svg",
    "paper":        "a4-landscape",  # size preset
    "dpi":          300,
    "matrices_dir": "matrices/",     # export evolution matrices as CSV
}

Paper presets: single-column, double-column, a4, a4-landscape, a3, a3-landscape, letter, letter-landscape.

Static formats require pip install hgh[export].

CLI

# Single workbook heatmap
hgh heneh --excel workbook.xlsx --taxonomy taxonomy.csv \
          --measure impact --normalization coverage --output output.html

# Side-by-side comparison
hgh heneh-compare --source a.xlsx --source b.xlsx \
                  --label "Unit A" --label "Unit B" \
                  --taxonomy taxonomy.csv --output comparison.html

Use in notebooks and applications

Jupyter

from hgh import MultipleCSVEvolutionWorkbook
from hgh.main import build_hgh_comparison

mewb = MultipleCSVEvolutionWorkbook("multi_long.csv")

fig = build_hgh_comparison(
    left_source=mewb.get("Unit A"),
    right_source=mewb.get("Unit B"),
    taxonomy="taxonomy.csv",
    measure="impact",
    show_delta=True,
    show=False,
)
fig.show()

Dash

import dash
from dash import dcc, html, Input, Output
from hgh import EvolutionWorkbook
from hgh.io.hierarchy import HierarchyIndex
from hgh.viz.figure import plot_hierarchical_heatmap

wb = EvolutionWorkbook("workbook.xlsx")
hierarchy = HierarchyIndex.from_csv("taxonomy.csv")

app = dash.Dash(__name__)
app.layout = html.Div([
    dcc.Dropdown(
        id="normalization",
        options=["coverage", "hill", "max_row"],
        value="coverage",
    ),
    dcc.Graph(id="heatmap"),
])

@app.callback(Output("heatmap", "figure"), Input("normalization", "value"))
def update(normalization):
    import pandas as pd
    mat = wb.evolution_matrix(
        hierarchy=hierarchy,
        leaf_level_in_data="micro",
        target_level="meso",
        kind="impact",
        normalization_mode=normalization,
    )
    return plot_hierarchical_heatmap(
        evolution_matrix=mat,
        classification_df=pd.read_csv("taxonomy.csv"),
        title=f"Impact evolution ({normalization})",
        return_figure=True,
    )

if __name__ == "__main__":
    app.run(debug=True)

Streamlit

import streamlit as st
import pandas as pd
from hgh import EvolutionWorkbook
from hgh.io.hierarchy import HierarchyIndex
from hgh.viz.figure import plot_hierarchical_heatmap

@st.cache_resource
def load_data():
    wb = EvolutionWorkbook("workbook.xlsx")
    hierarchy = HierarchyIndex.from_csv("taxonomy.csv")
    taxonomy = pd.read_csv("taxonomy.csv")
    return wb, hierarchy, taxonomy

wb, hierarchy, taxonomy = load_data()

normalization = st.selectbox("Normalization", ["coverage", "hill", "max_row"])
kind = st.radio("Measure", ["impact", "production"], horizontal=True)

mat = wb.evolution_matrix(
    hierarchy=hierarchy,
    leaf_level_in_data="micro",
    target_level="meso",
    kind=kind,
    normalization_mode=normalization,
)

fig = plot_hierarchical_heatmap(
    evolution_matrix=mat,
    classification_df=taxonomy,
    title=f"{kind.title()} evolution ({normalization})",
    return_figure=True,
)
st.plotly_chart(fig, use_container_width=True)

API reference

High-level functions (hgh.main)

Function Description
build_hgh Single workbook heatmap (Excel or CSV)
build_hgh_multiple N-unit side-by-side from CSV or workbook list
build_hgh_comparison Two-unit comparison with optional delta panel
run_temporal_analysis Pivot years, adoption waves, trend detection
run_persistence_analysis Core/emerging/declining/sporadic classification
run_delta_analysis Cell-level delta and dominance between two matrices

Workbooks

Class Source
EvolutionWorkbook Excel file (.xlsx)
CSVEvolutionWorkbook Long-format CSV
MultipleCSVEvolutionWorkbook Multi-unit long-format CSV

Analytics

Class Description
TemporalDynamicsAnalyzer Pivot years, waves, growth rates
PersistenceAnalyzer Topic persistence profiles and bands
DeltaAnalyzer Delta matrix and dominance analysis

License

MIT

Metadata

Release files for hgh 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hgh 0.1.0
File Size Uploaded Provenance Actions
hgh-0.1.0.tar.gz 138.0 kB Without provenance Details for hgh-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hgh 0.1.0
File Interpreter ABI Platform Actions
hgh-0.1.0-py3-none-any.whl Python 3 none any Details for hgh-0.1.0-py3-none-any.whl

Total release size: 211.5 kB

Release files / hgh-0.1.0.tar.gz

Download URL hgh-0.1.0.tar.gz
Size 138.0 kB
Tags Source
SHA-256 checksum
How to use checksums
28489623280253ffe99df4281c37999910e72c9c0a20034405f264fd19df6e95
BLAKE2b-256 checksum
How to use checksums
d4309f71d0c4005b20ef8dea02084f5e004634295a22e716559daa0058493b61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release files / hgh-0.1.0-py3-none-any.whl

Download URL hgh-0.1.0-py3-none-any.whl
Size 73.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e33e09790df02e5157b3b935b724579de7359e125e65358e9b47531068b169c3
BLAKE2b-256 checksum
How to use checksums
86cbff06a68b85e800df2c422eb3d32b93e295ed82349548ba784cad1af8ab56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Security for hgh 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page