-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouchmpl.sh
More file actions
executable file
·179 lines (146 loc) · 3.36 KB
/
touchmpl.sh
File metadata and controls
executable file
·179 lines (146 loc) · 3.36 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/bash
filename=$1
if [[ $# -eq 0 ]]; then
>&2 echo "Error: no arguments provided"
>&2 echo "USAGE: $(basename $0) [NEW_FILE_NAME]"
exit 1
fi
touch ${filename}.py
chmod u+x ${filename}.py
template() {
cat <<'EOF'
#!/usr/bin/env python3
"""
Description
Input:
...
Output:
...
Prerequisites:
...
"""
import sys
import argparse
import numpy as np
import pandas as pd
import polars as pl
import seaborn as sns
import matplotlib.pyplot as plt
from pathlib import Path
from matplotlib import rcParams
import matplotlib.font_manager as fm
import matplotlib.ticker as ticker
from matplotlib.ticker import FormatStrFormatter
#=============================================
# set font
arial_font = "/home/james/Downloads/arial.ttf"
arial_font_bold = "/home/james/Downloads/Arial Bold.ttf"
fm.fontManager.addfont(arial_font)
fm.fontManager.addfont(arial_font_bold)
rcParams["font.sans-serif"] = "Arial"
rcParams["font.family"] = "Arial"
rcParams["font.size"] = 10
# =============================================================
def parse_args() -> argparse.Namespace:
"""Argument parsing"""
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"-i",
"--input",
dest="input",
type=Path,
metavar="IN",
required=True,
help="Path to input file [Required]",
)
parser.add_argument(
"-o",
"--outdir",
dest="outdir",
type=Path,
required=False,
default="plots",
metavar="DIR",
help="Output target directory [Optional][Default: $(pwd)/plots]",
)
parser.add_argument(
"-D",
"--dpi",
dest="dpi",
type=int,
required=False,
default=300,
metavar="N",
help="Resolution in dpi for output .png [Default: 300]",
)
parser.add_argument(
"-F",
"--arial_fonts",
dest="arial_fonts",
type=Path,
required=False,
default="./auxfiles",
metavar="TFF",
help="Path to Arial fonts dir",
)
args = parser.parse_args()
return args
# or import from sys
file = Path(sys.argv[1])
#=============================================
# uses argparse to take input
def custom_plot(file, filename):
"""Plot"""
# read data
df = pl.read_csv(
file,
separator="\t",
has_header=False,
new_columns=["col1", "col2"]
)
print(df)
# make plot
fig, ax = plt.subplots(figsize=(5,5))
# write plot
plt.savefig(
f"./plot_{filename}.png",
format="png",
dpi=300,
bbox_inches="tight",
)
plt.tight_layout()
plt.show()
plt.close("all")
custom_plot(args.input, args.input.stem)
# =============================================================
def funca(args):
"""Description
---
Args:
arg1 (dtype): description
Returns:
dtype: description
"""
# stuff
print("Hello world")
# =============================================================
def main() -> None:
"""Workflow:
---
main
├── args
└── func
│
"""
# get args
args = parse_args()
# func
funca(args)
if __name__ == "__main__":
sys.exit(main())
EOF
}
template >"${filename}.py"