Skip to content

Recover script to create the EHT imaging dependency graph #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions scripts/fetch-ehtim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
# Script to fetch and install eht-imaging project (M87 blackhole study)
# For more details on eht-imaging refer to the links below:
# https://github.com/achael/eht-imaging
# https://achael.github.io/_pages/imaging/

# The following function does the following:
# 1. Fetches latest eht-imaging software in specified working dir
# (default current-dir/numpy_ehtim_dep)
# 2. Assumes virtualenv, python and pip are available and installs graphviz, pipdeptree
# 3. Git clones eht-imaging package
#
# To generate eht-imaging package dependency graph and highlight the role of NumPy
# use the script numpy-ehtim-dep-graph.sh
#

get_latest_ehtim() {

nowdir=`pwd`
cd $1

if [ -d numpy_ehtim_dep ];
then
\rm -rf numpy_ehtim_dep
fi
mkdir numpy_ehtim_dep
cd numpy_ehtim_dep

virtualenv EHTIMENV
source EHTIMENV/bin/activate

ygraphviz=`pip list | grep graphviz`
if [ -z "$ygraphviz" ];
then
pip install graphviz
fi

ypipdeptree=`pip list | grep pipdeptree`
if [ -z "$ypipdeptree" ];
then
pip install pipdeptree
fi

git clone https://github.com/achael/eht-imaging.git
cd eht-imaging
pip install .

deactivate
cd $nowdir
return 0
}

display_help() {
echo "Usage:"
echo ""
echo "./fetch-ehtim.sh workingdir"
echo ""
echo "where workingdir is the directory where latest eht-imaging sources will be git cloned and built."
echo ""
}

curdir=`pwd`

if [[ ( $# -gt 1 ) || ( -z "$1" ) || ("$1" == "-h" ) || ("$1" == "--help") ]];
then
display_help
exit
fi

if [ ! -d "$1" ];
then
echo "Error: $1 is not a valid directory!!!"
exit
fi

get_latest_ehtim $1

echo Done!
90 changes: 90 additions & 0 deletions scripts/numpy-ehtim-dep-graph.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash
# Script to trim eht-imaging project (M87 blackhole study) dependency graph in dot format
# Trimming is done such that only NumPy oriented dependencies are in focus
# For more details on eht-imaging project visit:
# https://github.com/achael/eht-imaging
# https://achael.github.io/_pages/imaging/

display_help() {

echo "Usage:"
echo " numpy-ehtim-dep-graph.sh reqfilepath outputdir [optional color]"
echo ""
echo "reqfilepath - directory containing latest source of eht-imaging requirements.txt file."
echo "outputdir - dir or path where generated graphs will be stored."
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."
echo ""
}

check_pre_requisites() {
yehtim=`pip list | grep ehtim`
ygraphviz=`pip list | grep graphviz`
ypipdeptree=`pip list | grep pipdeptree`
if [[ ( -z "$yehtim" ) || ( -z "$ygraphviz" ) || ( -z "$ypipdeptree" ) ]];
then
echo "Error: Pre-requisite for generating dependency graph not fulfilled!"
echo "The following packages must be installed:"
echo " 1. ehtim"
echo " 2. graphviz"
echo " 3. pipdeptree"
exit
fi
}

if [[ ($# -lt 2) || ($# -gt 3 ) || ( -z "$1" ) || (-z "$2") || ("$1" == "-h") || ("$1" == "--help") ]];
then
display_help
exit
fi

reqfilepath=$1
reqfile="$1/requirements.txt"
if ! [ -f $reqfile ];
then
echo "Error: Make sure you have latest eht-imaging sources and requirements.txt file path is correct!!"
display_help
exit
fi

graphdir="$2"
if [[ ( ! -d "$graphdir" ) || ( -f "$graphdir" ) ]];
then
echo "Error: Make sure $graphdir is a valid directory to store generated graphs!"
display_help
exit
fi

check_pre_requisites
echo "Using $reqfile to prune dependency graph of ehtim."
echo "Specified output directory is $graphdir."
echo "Generating ehtim dependency graphs..."

pipdeptree --graph-output dot > $graphdir/numpy-ehtim-dep.dot
dot -T png $graphdir/numpy-ehtim-dep.dot -o $graphdir/numpy-ehtim-dep.png

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
echo digraph { > $graphdir/cleanup_pkg.dot

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

echo } >> $graphdir/cleanup_pkg.dot

dot -K twopi $graphdir/cleanup_pkg.dot -o $graphdir/numpy-clean.dot
dot -T png $graphdir/numpy-clean.dot -o $graphdir/numpy-clean.png

if [ -z "$3" ];
then
#hcolor="crimson"
hcolor="cyan"
else
hcolor="$3"
fi

echo "Highlighting numpy nodes using $hcolor."

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

dot -T png $graphdir/numpy-clean-color.dot -o $graphdir/numpy-clean-color.png

echo "-------------------------------------------------------------------"
echo Done!