132 lines
3.0 KiB
Bash
132 lines
3.0 KiB
Bash
# Inspect .npz files
|
|
npz_py_str="$(cat << EOM
|
|
from sys import argv
|
|
import numpy as np
|
|
try:
|
|
import matplotlib.pyplot as plt
|
|
print('Imported matplotlib.pyplot as plt')
|
|
except ImportError:
|
|
pass
|
|
|
|
class Wrap:
|
|
def __init__(self, fname):
|
|
n = np.load(fname, allow_pickle=True)
|
|
globs = globals()
|
|
if isinstance(n, np.lib.npyio.NpzFile):
|
|
files = n.files
|
|
print('Contains files', files)
|
|
for f in files:
|
|
setattr(self, f, n[f])
|
|
globs[f] = n[f]
|
|
else:
|
|
print('Loaded data of shape', n.shape)
|
|
setattr(self, 'data', n)
|
|
globs['data'] = n
|
|
|
|
|
|
argv = argv[argv.index('--')+1:]
|
|
archives = [Wrap(arg) for arg in argv]
|
|
archive = archives[-1]
|
|
print('Global namespace populated with "archive", "archives" and all files')
|
|
for i, fname in enumerate(argv):
|
|
print(f' {i:<3.0f}: {fname}')
|
|
EOM
|
|
)"
|
|
|
|
npz_preview() {
|
|
if [ $# -lt 1 ]; then
|
|
echo "Please specify file to open as argument"
|
|
return
|
|
fi
|
|
|
|
python -ic "$npz_py_str" -- "$@"
|
|
}
|
|
|
|
npz_previewi() {
|
|
if [ $# -lt 1 ]; then
|
|
echo "Please specify file to open as argument"
|
|
return
|
|
fi
|
|
|
|
ipython -i -c "$npz_py_str" -- "$@"
|
|
}
|
|
|
|
rsync_wrap() {
|
|
cmd="rsync -a -R -r --copy-links --exclude .git --exclude __pycache__ --progress"
|
|
if [ $# == 0 ]; then
|
|
echo "Usage rsync_wrap [...]
|
|
|
|
Useful for synchronizing repositories
|
|
|
|
Calls $cmd [...]"
|
|
return
|
|
fi
|
|
$cmd $@
|
|
}
|
|
|
|
rsync_wrap_huge() {
|
|
cmd="rsync -a -R -r --copy-links --size-only --exclude .git --exclude __pycache__ --progress"
|
|
if [ $# == 0 ]; then
|
|
echo "Usage rsync_wrap_huge [...]
|
|
|
|
Useful for synchronizing repositories. Does not do checksum
|
|
|
|
Calls $cmd [...]"
|
|
return
|
|
fi
|
|
$cmd $@
|
|
}
|
|
|
|
if command -v xclip &> /dev/null; then
|
|
alias selc="xclip -sel primary -i"
|
|
alias selv="xclip -sel primary -o"
|
|
alias clipc="xclip -sel clip -i"
|
|
alias clipv="xclip -sel clip -o"
|
|
fi
|
|
|
|
watch_modify() {
|
|
if [ $# -lt 2 ]; then
|
|
echo "Usage watch_modify FILE CMD ARGS...
|
|
|
|
Run CMD ARGS... when file FILE is updated
|
|
"
|
|
return
|
|
fi
|
|
|
|
file="$1"
|
|
base="$(basename "$file")"
|
|
dir="$(dirname "$file")"
|
|
inotifywait -r -m -e modify "$dir" | while read file_path file_event file_name; do
|
|
[ "$base" == "$file_name" ] && echo ${@:2} && ${@:2}
|
|
done
|
|
}
|
|
|
|
pdftoclipboard() {
|
|
if [ $# -lt 1 ]; then
|
|
echo "Usage pdftoclipboard FILE [DPI]
|
|
|
|
Convert pdf file FILE to png and copy to clipboard. Default DPI is 600
|
|
"
|
|
return
|
|
fi
|
|
file="$1"
|
|
dpi="${2:-600}"
|
|
|
|
pdftoppm -png -r "$dpi" "$file" | xclip -sel clip -t image/png -i
|
|
}
|
|
|
|
gitgrepsed() {
|
|
if [ $# -lt 2 ]; then
|
|
echo "Usage gitgrepsed SEARCH REPLACE
|
|
|
|
Search and replace in git repository.
|
|
Alias for git grep -l \$SEARCH | xargs sed -i "s/\$SEARCH/\$REPLACE/g"
|
|
"
|
|
return
|
|
fi
|
|
|
|
search="$1"
|
|
replace="$2"
|
|
git grep -l "$search" | xargs sed -i "s/$search/$replace/g"
|
|
}
|