Created
July 24, 2016 21:13
-
-
Save jrhaberstroh/12a8a41774ee9b5a1dfa12915ebb28a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
help() | |
{ | |
sed --silent -e '/^: <<.*HELPDOC/,/^HELPDOC$/p' ${BASH_SOURCE[0]} | tail -n+2 | head -n-1 | |
} | |
SRCDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | |
: <<'HELPDOC' | |
================== | |
newpy | |
================== | |
Creates a new python document with my common python headers and argparse | |
default text. It makes me happy to do this. | |
usage: | |
newpy $1 Creates a new file ($1) with header and argparse set up | |
HELPDOC | |
trap help EXIT | |
: <<VARCHECK | |
${1?} | |
VARCHECK | |
trap - EXIT | |
cat <<'NEWPY' > $1 | |
from __future__ import division, print_function | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import argparse | |
import os | |
SRCDIR=os.path.dirname(os.path.realpath(__file__)) | |
parser = argparse.ArgumentParser(description="") | |
parser.add_argument("-o", type=str, default=None, help="output image location") | |
args = parser.parse_args() | |
# START: SAFESAVEPLOT | |
if not args.o is None: | |
import matplotlib | |
matplotlib.use("agg") | |
import matplotlib.pyplot as plt | |
def safesaveplot(out=None, suffix=None, transparent=False, clf=True): | |
fig = plt.gcf() | |
if out: | |
plt.savefig(out+suffix, transparent=transparent) | |
if clf: | |
plt.clf() | |
else: | |
plt.show() | |
# END: SAFESAVEPLOT | |
NEWPY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment