Graph-ARI
Graph-ARI provides graphari, a Python package for building dynamic weekly municipal graphs for geostatistical analysis in Mexico.
The package transforms bundled municipality-level weekly covariates and topology into networkx.Graph objects where:
- nodes are municipalities (
CVEGEO) - edges represent municipal adjacency with distance-based weight
- node attributes combine dynamic exogenous variables, mortality cases, and static metadata
- municipality existence is dynamic over time (a municipality appears only on/after its
creation_week)
This README follows the complete workflow shown in notebooks/visualize.ipynb.
Installation
pip install graphari==1.0.0
Requires Python 3.10+. To install from a local checkout, run pip install ..
What Is Bundled
Main weekly feature tables in graphari/data:
2m_mean_dewpoint_temperature.csv2m_mean_temperature.csv2m_relative_humidity.csvtotal_precipitation.csv10m_wind_speed.csv
Topology and metadata tables:
edges.csv: municipality identifiers, names, centroid coordinates, population, creation weekadjacency_matrix.csv: municipal adjacency matrix with distance-based edge weightsmortality_cases.csv: weekly mortality cases per municipalityEpidemiological_Weeks.csv: epidemiological week helper table
Version 1.0.0 includes weekly data through 2025.
To reproduce the previous range, pass end_week="2024/52" explicitly.
The supplied mortality table also revises historical values; the earlier climate
values are unchanged.
Default data span:
- weeks:
2003/01through2025/53 - municipalities: 2,478
- weekly snapshots: 1,201 (including all 53 bundled weeks from 2025)
Public API
graphari exposes the following top-level functions:
available_feature_tables()available_epiweeks()load_feature_tables(...)build_graph(...)build_graphs(...)get_node_feature_matrix(...)get_edge_index(...)
Complete Usage Walkthrough
1. Discover available tables and epidemiological weeks
import graphari as ga
tables = ga.available_feature_tables()
weeks = ga.available_epiweeks()
print(tables)
print(len(weeks), weeks[:5], weeks[-5:])
2. Build one weekly graph and a time window of graphs
focus_week = "2025/53"
window_start = "2024/01"
window_end = "2025/53"
G = ga.build_graph(week=focus_week)
graphs_window = ga.build_graphs(start_week=window_start, end_week=window_end)
print(G.number_of_nodes(), G.number_of_edges())
print(len(graphs_window), list(graphs_window)[:3], list(graphs_window)[-3:])
3. Inspect graph-level metadata
summary = {
"epidemiological_week": G.graph["epidemiological_week"],
"feature_names": G.graph["feature_names"],
"exogenous_variables": G.graph["exogenous_variables"],
"endogenous_variables": G.graph["endogenous_variables"],
"static_attributes": G.graph["static_attributes"],
"node_attributes": G.graph["node_attributes"],
}
summary
Expected structure:
feature_names: exogenous variables used for model-readyXexogenous_variables:feature_names + ["exists"]endogenous_variables:["mortality_cases"]static_attributes:["population", "latitude", "longitude"]
4. Verify dynamic municipality creation
Municipality 24059 is absent before 2024/30 and present from 2024/30 onward.
for week in ["2024/29", "2024/30", "2024/31"]:
Gw = ga.build_graph(week=week)
print(week, "present" if "24059" in Gw else "absent", Gw.number_of_nodes())
5. Inspect node and edge attributes
node = "24059" if "24059" in G else "24028"
attrs = G.nodes[node]
neighbor = next(iter(G.neighbors(node)))
edge_attrs = G.edges[(node, neighbor)]
print(node)
print(attrs)
print(edge_attrs)
Typical node attributes include:
- climate variables (
2m_mean_temperature,total_precipitation, etc.) mortality_casespopulation,latitude,longitude- municipality identifiers and names (
cvegeo,state,municipality, ...) exists=True
Each edge includes:
weight: centroid-distance-based weight fromadjacency_matrix.csv
6. Build model-ready tensors from a graph
X, node_order = ga.get_node_feature_matrix(G)
edge_index = ga.get_edge_index(G, node_order)
print("X shape:", X.shape) # (n_nodes, n_features)
print("edge_index shape:", edge_index.shape) # (2, 2 * n_edges)
print("first nodes:", node_order[:5])
X[i]corresponds to nodenode_order[i]edge_indexis COO format with both directions(u, v)and(v, u)
7. Load raw weekly tables directly (pandas workflow)
tables = ga.load_feature_tables(start_week="2024/01", end_week="2025/53")
print(list(tables.keys()))
temperature = tables["2m_mean_temperature"]
print(temperature.shape)
print(temperature.iloc[:3, :3])
The 2024–2025 window contains 105 weekly snapshots. This is useful when you want table-based preprocessing before graph construction.
8. Build graphs with a custom feature subset
subset_graph = ga.build_graph(
week="2025/53",
feature_files=["2m_mean_temperature", "total_precipitation"],
)
print(subset_graph.graph["feature_names"])
subset_X, subset_order = ga.get_node_feature_matrix(subset_graph)
print(subset_X.shape)
Use this to control feature dimensionality for experiments.
Detailed Example: Time Dynamics and Visualization
The notebook includes exploratory plots; below is a direct adaptation you can run in scripts or notebooks.
Dynamic graph size over a time window
import matplotlib.pyplot as plt
import pandas as pd
import graphari as ga
focus_node = "24059"
graphs = ga.build_graphs(start_week="2024/01", end_week="2025/53")
node_counts = pd.DataFrame(
{
"week": list(graphs.keys()),
"node_count": [g.number_of_nodes() for g in graphs.values()],
"focus_node_present": [focus_node in g for g in graphs.values()],
}
)
fig, ax = plt.subplots(figsize=(10, 4))
ax.plot(node_counts["week"], node_counts["node_count"], marker="o", linewidth=2)
ax.set_title("Dynamic number of municipalities per week")
ax.set_xlabel("Epidemiological week")
ax.set_ylabel("Number of nodes")
ax.tick_params(axis="x", rotation=90)
first_presence = node_counts[node_counts["focus_node_present"]].head(1)
for _, row in first_presence.iterrows():
ax.axvline(row["week"], color="crimson", linestyle="--", alpha=0.8)
ax.text(row["week"], row["node_count"] + 0.1, f"{focus_node} appears", color="crimson")
plt.tight_layout()
Municipality-level time series from graph node attributes
import matplotlib.pyplot as plt
import pandas as pd
import graphari as ga
stable_node = "24028"
graphs = ga.build_graphs(start_week="2024/01", end_week="2025/53")
rows = []
for week, g in graphs.items():
if stable_node not in g:
continue
n = g.nodes[stable_node]
rows.append(
{
"week": week,
"mortality_cases": n["mortality_cases"],
"temperature": n["2m_mean_temperature"],
"precipitation": n["total_precipitation"],
"humidity": n["2m_relative_humidity"],
"wind_speed": n["10m_wind_speed"],
}
)
df = pd.DataFrame(rows)
fig, axes = plt.subplots(2, 1, figsize=(10, 7), sharex=True)
axes[0].plot(df["week"], df["mortality_cases"], marker="o", color="crimson")
axes[0].set_title(f"Mortality cases for municipality {stable_node}")
axes[0].set_ylabel("Mortality cases")
axes[1].plot(df["week"], df["temperature"], marker="o", label="Temperature")
axes[1].plot(df["week"], df["precipitation"], marker="o", label="Precipitation")
axes[1].plot(df["week"], df["humidity"], marker="o", label="Humidity")
axes[1].plot(df["week"], df["wind_speed"], marker="o", label="10m Wind Speed")
axes[1].set_title(f"Exogenous variables for municipality {stable_node}")
axes[1].set_xlabel("Epidemiological week")
axes[1].set_ylabel("Value")
axes[1].legend()
axes[1].tick_params(axis="x", rotation=90)
plt.tight_layout()
One-hop ego network map using municipality latitude/longitude
import matplotlib.pyplot as plt
import networkx as nx
import graphari as ga
G = ga.build_graph(week="2025/53")
center_node = "24028"
ego = nx.ego_graph(G, center_node, radius=1)
positions = {
node: (ego.nodes[node]["longitude"], ego.nodes[node]["latitude"])
for node in ego.nodes()
}
node_colors = [ego.nodes[node]["mortality_cases"] for node in ego.nodes()]
node_sizes = [max(80, ego.nodes[node]["population"] / 1000) for node in ego.nodes()]
fig, ax = plt.subplots(figsize=(8, 6))
nx.draw_networkx_edges(ego, positions, alpha=0.35, ax=ax)
nodes = nx.draw_networkx_nodes(
ego,
positions,
node_color=node_colors,
node_size=node_sizes,
cmap="rainbow",
edgecolors="black",
linewidths=0.5,
ax=ax,
)
nx.draw_networkx_labels(ego, positions, font_size=9, ax=ax)
ax.set_title(f"Ego network around municipality {center_node} in 2025/53")
ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
ax.set_aspect("equal", adjustable="datalim")
cbar = plt.colorbar(nodes, ax=ax)
cbar.set_label("Mortality cases")
plt.tight_layout()
Notes and Validation
- Epidemiological week format is normalized as
YYYY/WW. build_graph(week=...)requires a valid week present in the bundled data.feature_filescan be passed with or without.csvextension.- All selected feature tables are aligned by week and municipality columns.
Notebook
For the full executable walkthrough, open:
notebooks/visualize.ipynb
Metadata
Release files for graphari 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| graphari-1.0.0.tar.gz | 49.3 MB | Without provenance | Details for graphari-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphari-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for graphari-1.0.0-py3-none-any.whl |
Total release size: 98.8 MB
Release files / graphari-1.0.0.tar.gz
| Download URL | graphari-1.0.0.tar.gz |
|---|---|
| Size | 49.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5741175769803a6ed3b7271364c462f6507e0aeda267ae90f6c61a744279fca
|
|
BLAKE2b-256 checksum How to use checksums |
bebaee55c1f11a06334ae7d4795996b418bc3b55906df40e37203b3c955cd77d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / graphari-1.0.0-py3-none-any.whl
| Download URL | graphari-1.0.0-py3-none-any.whl |
|---|---|
| Size | 49.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2fc361857d730f3eef5fa632c469ba6fbad2fafacb286bc3adc018f72909d831
|
|
BLAKE2b-256 checksum How to use checksums |
40e4d886dea9b78f346fbeb880b7976d67c280d34192e5fa6872cead04ca62b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for graphari 1.0.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.