-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot
executable file
·231 lines (187 loc) · 6.69 KB
/
plot
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
usage() {
cat <<EOF
Usage: $(basename $0) [-H] [-I] [-L] [--CFL] [--CIS] [--INT] CSVfile
Plot Spectrum
Options:
-H Show this message
-B -B1 enable background image. -B0 disable
-L -L1 enable landmarks display. -L0 disable
--CFL Plot pixel averages and CFL landmarks
--CIS Plot color averages and CIS landmarks
--INT Plot pixel averages as filled curve
CSVfile Spectrum data to plot
EOF
}
CFLplot=0
CISplot=0
INTplot=0
INT2plot=0
INT3plot=0
plotSelected=0
landmarks=1
image=1
file=""
while [ $OPTIND -le "$#" ]; do
if getopts "\-:b:B:l:L:hH" optchar; then
case "${optchar}" in
-)
plotSelected=1
case "${OPTARG}" in
CFL) CFLplot=1 ;;
CIS) CISplot=1 ;;
INT) INTplot=1 ;;
INT2) INT2plot=1 ;;
INT3) INT3plot=1 ;;
*) echo "Unknown option --${OPTARG}"
usage
exit 2 ;;
esac;;
h|H) usage ; exit 2 ;;
l|L) landmarks=${OPTARG} ;;
b|B) image=${OPTARG} ;;
*) usage ; exit 2 ;;
esac
else
file=("${!OPTIND}")
((OPTIND++))
fi
done
if [[ $file == "" ]]; then
echo "Missing CSVfile"
usage
exit 2
fi
if [[ $plotSelected == 0 ]]; then
CFLplot=1
fi
IN="$file"
DIR=$(dirname $IN)
FILE=${IN##*/}
BASE="${DIR}/${FILE%.*}"
# CAL file generated by calibrate.py
# use the CAL file if there is one, otherwise the CSV file from average.py
CSV="${BASE}.cal"
if [[ ! -f $CSV ]]; then CSV="${BASE}.csv"; fi
if [[ ! -f $CSV ]]; then echo "CSV file not found: ${CSV}"; exit 3; fi
JPG="${BASE}.jpg"
Multiplier=$(awk -F ',' '{print $1;exit}' $CSV)
Offset=$(awk -F ',' '{print $2;exit}' $CSV)
C436=$(awk -F ',' '{print $3;exit}' $CSV) # old version
C611=$(awk -F ',' '{print $4;exit}' $CSV) # old version
SNAME=$(awk -F ',' '{print $5;exit}' $CSV)
SDESC=$(awk -F ',' '{print $6;exit}' $CSV)
export NO_AT_BRIDGE=1
gnuplot <<EOF
width = 1280 # size of background image
height = 286
set term qt size width,height
set datafile separator ","
m = $Multiplier + 0.0
b = $Offset + 0.0
if ( m == 0 ) { # old version
m = ($C611 - $C436) / (611.0 - 436.0) # calibration multiplier
b = 436.0 * m - $C436 # calibration offset
}
nmCol(nm) = nm * m - b
colNM(col) = (col + b) / m
set y2range [0:height-1]
set yrange [-30:255]
set x2range [nmCol(375):nmCol(695)]
set xrange [375:695]
set autoscale noextend
set border 0
set lmargin screen 0
set bmargin screen 0
set rmargin screen 1
set tmargin screen 1
unset ytics
set xtics nomirror
set mxtics 5
unset key
#set xzeroaxis ls 1 # draw zero line (or not. Changes label position)
#-------------------------
if ($image) {
# mostly the lines will be white against a black image background
set object rectangle from screen 0,0 to screen 1,1 behind fillcolor rgb 'black'
set style line 1 lw 1 lc rgb "white"
set style arrow 1 nohead front lc rgb "white" dashtype 2
set style textbox transparent border lc "white"
set grid xtics lc rgb "white" front # use set grid to get xtic marks white and in front
unset grid # ...unset grid to turn off the grid lines
set xtics axis in 50 tc "white" # put the xtics on the zero axis and tic text white
set border ls 1 # tic lines use the border color
} else {
# mostly black lines against a white background
set style line 1 lw 1 lc rgb "black"
set style arrow 1 nohead front lc rgb "black" dashtype 2
set style textbox transparent border lc "black"
set grid xtics lc rgb "black" front # use set grid to get xtic marks black and in front
unset grid # ...unset grid to turn off the grid lines
set xtics axis in 50 tc "black" # put the xtics on the zero axis and tic text black
}
set label "$SDESC" at graph .99, graph .94 right tc ls 1 front boxed
set label "nm" at graph 0.98,character 1 tc ls 1 front
if ($CFLplot && $landmarks%2 || $landmarks & 2 ) { #L = 2
set arrow from 405,graph 0 to 405,720 as 1
set label "Hg405" at 405,character 3 tc ls 1 front
set arrow from 436,graph 0 to 436,720 as 1
set label "Hg436" at 436,character 3 tc ls 1 front
set arrow from 487,graph 0 to 487,720 as 1
set label "Tb487" at 487,character 3 tc ls 1 front
set arrow from 542,graph 0 to 542,720 as 1
set arrow from 546,graph 0 to 546,720 as 1
set label "Hg546" at 546,character 3 tc ls 1 front
set arrow from 611,graph 0 to 611,720 as 1
set label "Eu611" at 611,character 3 tc ls 1 front
}
if ($CISplot && $landmarks%2 || $landmarks & 4 ) { #L = 4
set arrow from 474,graph 0 to 474,720 as 1
set label "474" at 474,character 3 tc ls 1 front
set arrow from 536,graph 0 to 536,720 as 1
set label "536" at 536,character 3 tc ls 1 front
set arrow from 595,graph 0 to 595,720 as 1
set label "595" at 595,character 3 tc ls 1 front
}
set style line 2 lc rgb "red"
set style line 3 lc rgb "green"
set style line 4 lc rgb "blue"
plot_command = "plot "
if ($image) {
plot_command = sprintf("%s%s,",plot_command,'"$JPG" binary filetype=jpg with rgbimage axes x2y2')
}
if ($INTplot) {
set yrange [0:255]
unset grid
unset xtics
unset label
plot_command = sprintf("%s%s,",plot_command,'"$CSV" using (colNM(\$1)):2:(-12) skip 1 lc rgb "black" with filledcurves fs transparent solid 1.0 axes x1y1')
}
if ($INT2plot) {
#set yrange [0:255]
#unset grid
#unset xtics
#unset label
plot_command = sprintf("%s%s,",plot_command,'"$CSV" using (colNM(\$1)):2 skip 1 lc rgb "black" with filledcurves below y=256 fs transparent solid 1.0 axes x1y1')
}
if ($INT3plot) {
set yrange [0:255]
unset grid
unset xtics
unset label
plot_command = sprintf("%s%s,",plot_command,'"$CSV" using (colNM(\$1)):5:(-12) skip 1 lc rgb "blue" with filledcurves fs transparent solid 0.2 axes x1y1')
plot_command = sprintf("%s%s,",plot_command,'"$CSV" using (colNM(\$1)):4:(-12) skip 1 lc rgb "green" with filledcurves fs transparent solid 0.2 axes x1y1')
plot_command = sprintf("%s%s,",plot_command,'"$CSV" using (colNM(\$1)):3:(-12) skip 1 lc rgb "red" with filledcurves fs transparent solid 0.2 axes x1y1')
}
if ($CFLplot) {
plot_command = sprintf("%s%s,",plot_command,'"$CSV" using (colNM(\$1)):2 skip 1 ls 1 title "$SNAME" with lines axes x1y1')
}
if ($CISplot) {
plot_command = sprintf("%s%s,",plot_command,'"$CSV" using (colNM(\$1)):3 skip 1 ls 2 with lines axes x1y1')
plot_command = sprintf("%s%s,",plot_command,' "" using (colNM(\$1)):4 skip 1 ls 3 with lines axes x1y1')
plot_command = sprintf("%s%s,",plot_command,' "" using (colNM(\$1)):5 skip 1 ls 4 with lines axes x1y1')
}
# create the plot
eval plot_command
pause mouse button2 "button2 to exit"
EOF