Skip to content

Commit 8707512

Browse files
authored
Merge pull request #161 from rgommers/ehtim-script
Recover script to create the EHT imaging dependency graph
2 parents 0b23ecb + e1efb0e commit 8707512

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

scripts/fetch-ehtim.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
# Script to fetch and install eht-imaging project (M87 blackhole study)
3+
# For more details on eht-imaging refer to the links below:
4+
# https://github.com/achael/eht-imaging
5+
# https://achael.github.io/_pages/imaging/
6+
7+
# The following function does the following:
8+
# 1. Fetches latest eht-imaging software in specified working dir
9+
# (default current-dir/numpy_ehtim_dep)
10+
# 2. Assumes virtualenv, python and pip are available and installs graphviz, pipdeptree
11+
# 3. Git clones eht-imaging package
12+
#
13+
# To generate eht-imaging package dependency graph and highlight the role of NumPy
14+
# use the script numpy-ehtim-dep-graph.sh
15+
#
16+
17+
get_latest_ehtim() {
18+
19+
nowdir=`pwd`
20+
cd $1
21+
22+
if [ -d numpy_ehtim_dep ];
23+
then
24+
\rm -rf numpy_ehtim_dep
25+
fi
26+
mkdir numpy_ehtim_dep
27+
cd numpy_ehtim_dep
28+
29+
virtualenv EHTIMENV
30+
source EHTIMENV/bin/activate
31+
32+
ygraphviz=`pip list | grep graphviz`
33+
if [ -z "$ygraphviz" ];
34+
then
35+
pip install graphviz
36+
fi
37+
38+
ypipdeptree=`pip list | grep pipdeptree`
39+
if [ -z "$ypipdeptree" ];
40+
then
41+
pip install pipdeptree
42+
fi
43+
44+
git clone https://github.com/achael/eht-imaging.git
45+
cd eht-imaging
46+
pip install .
47+
48+
deactivate
49+
cd $nowdir
50+
return 0
51+
}
52+
53+
display_help() {
54+
echo "Usage:"
55+
echo ""
56+
echo "./fetch-ehtim.sh workingdir"
57+
echo ""
58+
echo "where workingdir is the directory where latest eht-imaging sources will be git cloned and built."
59+
echo ""
60+
}
61+
62+
curdir=`pwd`
63+
64+
if [[ ( $# -gt 1 ) || ( -z "$1" ) || ("$1" == "-h" ) || ("$1" == "--help") ]];
65+
then
66+
display_help
67+
exit
68+
fi
69+
70+
if [ ! -d "$1" ];
71+
then
72+
echo "Error: $1 is not a valid directory!!!"
73+
exit
74+
fi
75+
76+
get_latest_ehtim $1
77+
78+
echo Done!

scripts/numpy-ehtim-dep-graph.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
# Script to trim eht-imaging project (M87 blackhole study) dependency graph in dot format
3+
# Trimming is done such that only NumPy oriented dependencies are in focus
4+
# For more details on eht-imaging project visit:
5+
# https://github.com/achael/eht-imaging
6+
# https://achael.github.io/_pages/imaging/
7+
8+
display_help() {
9+
10+
echo "Usage:"
11+
echo " numpy-ehtim-dep-graph.sh reqfilepath outputdir [optional color]"
12+
echo ""
13+
echo "reqfilepath - directory containing latest source of eht-imaging requirements.txt file."
14+
echo "outputdir - dir or path where generated graphs will be stored."
15+
echo "optional color. For e.g., cyan, crimson or any of the https://graphviz.gitlab.io/_pages/doc/info/colors.html specifications for graphviz. Default cyan."
16+
echo ""
17+
}
18+
19+
check_pre_requisites() {
20+
yehtim=`pip list | grep ehtim`
21+
ygraphviz=`pip list | grep graphviz`
22+
ypipdeptree=`pip list | grep pipdeptree`
23+
if [[ ( -z "$yehtim" ) || ( -z "$ygraphviz" ) || ( -z "$ypipdeptree" ) ]];
24+
then
25+
echo "Error: Pre-requisite for generating dependency graph not fulfilled!"
26+
echo "The following packages must be installed:"
27+
echo " 1. ehtim"
28+
echo " 2. graphviz"
29+
echo " 3. pipdeptree"
30+
exit
31+
fi
32+
}
33+
34+
if [[ ($# -lt 2) || ($# -gt 3 ) || ( -z "$1" ) || (-z "$2") || ("$1" == "-h") || ("$1" == "--help") ]];
35+
then
36+
display_help
37+
exit
38+
fi
39+
40+
reqfilepath=$1
41+
reqfile="$1/requirements.txt"
42+
if ! [ -f $reqfile ];
43+
then
44+
echo "Error: Make sure you have latest eht-imaging sources and requirements.txt file path is correct!!"
45+
display_help
46+
exit
47+
fi
48+
49+
graphdir="$2"
50+
if [[ ( ! -d "$graphdir" ) || ( -f "$graphdir" ) ]];
51+
then
52+
echo "Error: Make sure $graphdir is a valid directory to store generated graphs!"
53+
display_help
54+
exit
55+
fi
56+
57+
check_pre_requisites
58+
echo "Using $reqfile to prune dependency graph of ehtim."
59+
echo "Specified output directory is $graphdir."
60+
echo "Generating ehtim dependency graphs..."
61+
62+
pipdeptree --graph-output dot > $graphdir/numpy-ehtim-dep.dot
63+
dot -T png $graphdir/numpy-ehtim-dep.dot -o $graphdir/numpy-ehtim-dep.png
64+
65+
awk '/^[0-9]*[.]+/ {printf(" %s\n", $0); found=1; next} !/^[0-9]*[.]+/ {printf((found==1)? "%s" : "\n%s", $0); found=0 } END {print ""}' $graphdir/numpy-ehtim-dep.dot > $graphdir/cleanup.dot
66+
echo digraph { > $graphdir/cleanup_pkg.dot
67+
68+
awk ' NR==FNR{a[$1]; next} {for (i in a) if ((index($0, i)&& $3 == "") || ($3 != "" && index($0, i) && index($3, i) )) print}' $reqfile $graphdir/cleanup.dot >> $graphdir/cleanup_pkg.dot
69+
70+
echo } >> $graphdir/cleanup_pkg.dot
71+
72+
dot -K twopi $graphdir/cleanup_pkg.dot -o $graphdir/numpy-clean.dot
73+
dot -T png $graphdir/numpy-clean.dot -o $graphdir/numpy-clean.png
74+
75+
if [ -z "$3" ];
76+
then
77+
#hcolor="crimson"
78+
hcolor="cyan"
79+
else
80+
hcolor="$3"
81+
fi
82+
83+
echo "Highlighting numpy nodes using $hcolor."
84+
85+
awk -v ac=${hcolor} '{ if ($1 == "numpy") {print $0, "color=",ac,", style=filled," } else { if ($2 == "->" && $3 == "numpy") {print $0, "color=",ac,","} else {print}}}' $graphdir/numpy-clean.dot > $graphdir/numpy-clean-color.dot
86+
87+
dot -T png $graphdir/numpy-clean-color.dot -o $graphdir/numpy-clean-color.png
88+
89+
echo "-------------------------------------------------------------------"
90+
echo Done!

0 commit comments

Comments
 (0)