-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_notebook.sh
executable file
·131 lines (100 loc) · 3.49 KB
/
run_notebook.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
librarian_conn_name=local
source activate nightlynb
echo Date: $(date)
echo sessid=$sessid
# print out help statement
if [ "$1" = '-h' -o "$1" = '--help' ] ; then
echo 'Usage:'
echo 'export sessid=<#3sessid>'
echo 'qsub -V -q hera run_notebook.sh'
exit 0
fi
if [ -z "$sessid" ] ; then
echo "environ variable 'sessid' is undefined"
exit 1
fi
# Exit with an error if any sub-command fails.
set -e
# Create a temporary Lustre directory for exporting the data and command the
# Librarian to populate it.
staging_dir=$(mktemp -d --tmpdir=/lustre/aoc/projects/hera/lberkhou/H3C_plots/nightlynb sessid$sessid.XXXXXX)
chmod ug+rwx "$staging_dir"
remove_staging_notes () {
stage_files=($(ls $1))
for f in ${stage_files[@]}
do
if [[ $f == *"STAG"* ]]
then
rm -f $staging_dir/$f
fi
done
}
remove_staging_notes $staging_dir
search="{\"session-id-is-exactly\": $sessid, \"name-matches\": \"%.uvh5\"}"
librarian stage-files --wait $librarian_conn_name "$staging_dir" "$search"
#remove_staging_notes $staging_dir
#search="{\"session-id-is-exactly\": $sessid, \"name-matches\": \"%.diff.uvh5\"}"
#librarian stage-files --wait $librarian_conn_name "$staging_dir" "$search"
remove_staging_notes $staging_dir
search="{\"session-id-is-exactly\": $sessid, \"name-matches\": \"%.json\"}"
librarian stage-files --wait $librarian_conn_name "$staging_dir" "$search"
remove_staging_notes $staging_dir
search="{\"session-id-is-exactly\": $sessid, \"name-matches\": \"%.calfits\"}"
librarian stage-files --wait $librarian_conn_name "$staging_dir" "$search"
remove_staging_notes $staging_dir
search="{\"session-id-is-exactly\": $sessid, \"name-matches\": \"%.flag_summary.npz\"}"
librarian stage-files --wait $librarian_conn_name "$staging_dir" "$search"
DATA_PATH=
for item in "$staging_dir"/2* ; do
if [ -n "$DATA_PATH" ] ; then
echo >&1 "WARNING: multiple subdirectories staged? $DATA_PATH, $item"
exit 1
fi
if [ "$(basename $item)" == "2*" ] ; then
echo >&1 "WARNING: no subdirectory staged: $item"
exit 1
fi
export DATA_PATH="$item"
done
jd=$(basename $DATA_PATH)
# get more env vars
BASENBDIR=/lustre/aoc/projects/hera/lberkhou/H3C_plots
OUTPUT=data_inspect_"$jd".ipynb
OUTPUTDIR=/lustre/aoc/projects/hera/lberkhou/H3C_plots
# copy and run notebook
echo "starting notebook execution..."
jupyter nbconvert --output=$OUTPUTDIR/$OUTPUT \
--to notebook \
--ExecutePreprocessor.allow_errors=True \
--ExecutePreprocessor.timeout=-1 \
--execute $BASENBDIR/data_inspect_H3C.ipynb
echo "finished notebook execution..."
#cd to git repo
cd $OUTPUTDIR
# add to git repo
#echo "adding to GitHub repo"
#git add $OUTPUT
# add sessid to processed_sessid.txt file
echo $sessid >> $OUTPUTDIR/processed_sessid.txt
#git add $OUTPUTDIR/processed_sessid.txt
# commit and push
#git commit -m "data inspect notebook for $jd"
#git pull
#git push
# mark these files as processed (see cronjob.py). We only need to mark one
# file but we do all of the UV files since that seems like potentially handy
# information to have.
echo "adding Librarian file events"
now_unix=$(date +%s)
#for uv in $staging_dir/*/*.uvh5 ; do
# librarian add-file-event $librarian_conn_name $uv nightlynb.processed when=$now_unix
#done
#echo "sending email to heraops"
#sed -e 's/@@JD@@/'$jd'/g' < mail_template.txt > mail.txt
#sendmail -vt < mail.txt
echo "removing staging dir"
rm -rf "$staging_dir"
echo "finished run_notebook.sh"
echo "Date:" $(date)
exit 0