Skip to content

Commit

Permalink
Allow passing in ids for graph files
Browse files Browse the repository at this point in the history
This will make the file name more informative by having the item id in
the file name, instead of just counting up the number for each graph.

See realrate/RealRate-Private#190.
  • Loading branch information
karlb committed Sep 10, 2021
1 parent f35eec8 commit 5277cdb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions causing/graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Create direct, total and mediation Graphviz graph from dot_str using pydot."""

from typing import Dict
from typing import Dict, Sequence, Optional
from itertools import chain
import numpy as np
from numpy import amax, array_equal, allclose, isnan, logical_and
Expand Down Expand Up @@ -210,6 +210,7 @@ def create_graphs(
node_name,
show_nr_indiv,
final_var_in_percent=False,
ids: Optional[Sequence[str]] = None,
):
"""creates direct, total and mediation graph,
for theoretical model and estimated model"""
Expand Down Expand Up @@ -253,13 +254,18 @@ def make_graph(filename, x_weights_idmat_nodeff, y_weights_idmat_nodeff, **kwarg
print()

for i in range(min(show_nr_indiv, len(graph_json["mx_indivs"]))):
if ids:
item_id = ids[i]
else:
item_id = str(i)

# compute color base for each individual separately
# using _indiv quantities based on _theo quantities times absolute deviation from median
print("Generate graphs for individual {:5}".format(i))

# IDE
direct_indiv_graph = make_graph(
"IDE" + "_" + str(i),
f"IDE_{item_id}",
(graph_json["mx_indivs"][i], None),
(graph_json["my_indivs"][i], None),
color=True,
Expand All @@ -268,7 +274,7 @@ def make_graph(filename, x_weights_idmat_nodeff, y_weights_idmat_nodeff, **kwarg

# IME
mediation_indiv_graph = make_graph(
"IME" + "_" + str(i),
f"IME_{item_id}",
(graph_json["eyx_indivs"][i], np.array(graph_json["exj_indivs"])[:, i]),
(graph_json["eyy_indivs"][i], np.array(graph_json["eyj_indivs"])[:, i]),
color=True,
Expand All @@ -278,7 +284,7 @@ def make_graph(filename, x_weights_idmat_nodeff, y_weights_idmat_nodeff, **kwarg

# ITE
total_indiv_graph = make_graph(
"ITE" + "_" + str(i),
f"ITE_{item_id}",
(graph_json["ex_indivs"][i], None),
(graph_json["ey_indivs"][i], None),
color=True,
Expand Down

0 comments on commit 5277cdb

Please sign in to comment.