-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath
executable file
·61 lines (50 loc) · 1.67 KB
/
math
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
#!/bin/bash
#
# quick math between 2 images
#
readarray -t <<< ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}
path=$(dirname "${MAPFILE[0]}")
file=$(basename "${MAPFILE[0]}")
if [[ $file == *.nii ]]
then
outname="${file/.nii/"_$op.nii"}"
else
outname="${file/.nii.gz/"_$op.nii.gz"}"
fi
# built input python list from selected files & remove last empty element
unset MAPFILE[-1]
printf -v FILESET " %s" "${MAPFILE[@]}"
CHARSET=({a..z})
# loop in the array and ad dprefix for ID
## now loop through the above array
for i in "${!MAPFILE[@]}"; do
path=$(dirname "${MAPFILE[$i]}")
file=$(basename "${MAPFILE[$i]}")
MAPFILE[$i]="\n\t${CHARSET[$i]} = ${file}"
done
assigned=${MAPFILE[@]}
printf -v finaltext "%s\n" "Input formula in python-numpy style using letters as placeholders for the files: \n\n${assigned[@]}"
exprs=$(zenity \
--forms \
--title="Math operation" \
--text="$finaltext" \
--add-entry="Numpy expression" \
--add-entry="Save as" \
)
readarray -d "|" -t <<< ${exprs}
exprs=${MAPFILE[0]}
outname=${MAPFILE[1]}
if [ -z $outname ]; then outname="result.nii.gz"; fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Execute the Python script and capture its output and error
#python3 $SCRIPT_DIR/lib/neuronautilus_evalexprs.py -ex "$exprs" -o ${path}/${outname} -vars $FILESET
py_output=$(python3 "$SCRIPT_DIR/lib/neuronautilus_evalexprs.py" -ex "$exprs" -o "${path}/${outname}" -vars $FILESET 2>&1)
if [[ -f "${path}/${outname}" ]]; then
notify-send "Done: $outname"
else
# Check exit code of the Python script
if [ $? -ne 0 ]; then
# Display error in xterm
xterm -hold -e "bash -c 'echo Error occurred:; echo \"$py_output\"'"
fi
fi