1 | // ----------------------------------------------------------------------- |
---|
2 | // SpectralPlot.cc: Definition of the class producing a page of spectral plots |
---|
3 | // ----------------------------------------------------------------------- |
---|
4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
5 | // |
---|
6 | // This program is free software; you can redistribute it and/or modify it |
---|
7 | // under the terms of the GNU General Public License as published by the |
---|
8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
9 | // option) any later version. |
---|
10 | // |
---|
11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
14 | // for more details. |
---|
15 | // |
---|
16 | // You should have received a copy of the GNU General Public License |
---|
17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
19 | // |
---|
20 | // Correspondence concerning Duchamp may be directed to: |
---|
21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
22 | // Postal address: Dr. Matthew Whiting |
---|
23 | // Australia Telescope National Facility, CSIRO |
---|
24 | // PO Box 76 |
---|
25 | // Epping NSW 1710 |
---|
26 | // AUSTRALIA |
---|
27 | // ----------------------------------------------------------------------- |
---|
28 | #include <duchamp/Plotting/SpectralPlot.hh> |
---|
29 | #include <duchamp/Plotting/MultipleDuchampPlot.hh> |
---|
30 | #include <duchamp/Plotting/DuchampPlot.hh> |
---|
31 | #include <duchamp/duchamp.hh> |
---|
32 | #include <duchamp/param.hh> |
---|
33 | #include <duchamp/Utils/Statistics.hh> |
---|
34 | #include <duchamp/Utils/mycpgplot.hh> |
---|
35 | #include <string> |
---|
36 | #include <iostream> |
---|
37 | #include <sstream> |
---|
38 | |
---|
39 | using namespace mycpgplot; |
---|
40 | |
---|
41 | namespace duchamp { |
---|
42 | |
---|
43 | namespace Plot { |
---|
44 | |
---|
45 | SpectralPlot::SpectralPlot(): |
---|
46 | MultipleDuchampPlot() |
---|
47 | { |
---|
48 | this->numOnPage = 5; |
---|
49 | } |
---|
50 | |
---|
51 | SpectralPlot::SpectralPlot(const SpectralPlot& other) |
---|
52 | { |
---|
53 | this->operator=(other); |
---|
54 | } |
---|
55 | |
---|
56 | SpectralPlot& SpectralPlot::operator=(const SpectralPlot& other) |
---|
57 | { |
---|
58 | if(this == &other) return *this; |
---|
59 | ((MultipleDuchampPlot &) *this) = other; |
---|
60 | for(int i=0;i<4;i++) this->zoomCoords[i] = other.zoomCoords[i]; |
---|
61 | return *this; |
---|
62 | } |
---|
63 | |
---|
64 | void SpectralPlot::calcCoords() |
---|
65 | { |
---|
66 | /// @details |
---|
67 | /// Calculates the boundaries for the various boxes, in inches measured |
---|
68 | /// from the lower left corner. |
---|
69 | /// Based on the fact that there are numOnPage spectra shown on each |
---|
70 | /// page, going down the page in increasing number (given by |
---|
71 | /// SpectralPlot::spectraCount). |
---|
72 | |
---|
73 | int posOnPage = (this->numOnPage - (this->spectraCount%this->numOnPage)) % this->numOnPage; |
---|
74 | this->mainCoords[0] = Plot::spMainX1/inchToCm; |
---|
75 | this->mainCoords[1] = Plot::spMainX2/inchToCm; |
---|
76 | this->zoomCoords[0] = Plot::spZoomX1/inchToCm; |
---|
77 | this->zoomCoords[1] = Plot::spZoomX2/inchToCm; |
---|
78 | this->mainCoords[2] = this->zoomCoords[2] = this->mapCoords[2] = |
---|
79 | posOnPage*paperHeight/float(this->numOnPage) + Plot::spMainY1/inchToCm; |
---|
80 | this->mainCoords[3] = this->zoomCoords[3] = this->mapCoords[3] = |
---|
81 | posOnPage*paperHeight/float(this->numOnPage) + Plot::spMainY2/inchToCm; |
---|
82 | this->mapCoords[0] = Plot::spMapX1/inchToCm; |
---|
83 | this->mapCoords[1] = this->mapCoords[0] + (this->mapCoords[3]-this->mapCoords[2]); |
---|
84 | } |
---|
85 | |
---|
86 | void SpectralPlot::gotoHeader(std::string xlabel) |
---|
87 | { |
---|
88 | this->MultipleDuchampPlot::gotoHeader(); |
---|
89 | cpgsch(Plot::plotLabelSize); |
---|
90 | cpgmtxt("b",Plot::spXlabelOffset,0.5,0.5,xlabel.c_str()); |
---|
91 | } |
---|
92 | |
---|
93 | void SpectralPlot::firstHeaderLine(std::string line) |
---|
94 | { |
---|
95 | cpgsch(Plot::plotTitleSize); |
---|
96 | cpgmtxt("t",Plot::spTitleOffset1*Plot::plotLabelSize/Plot::plotTitleSize,0.5,0.5,line.c_str()); |
---|
97 | } |
---|
98 | void SpectralPlot::secondHeaderLine(std::string line) |
---|
99 | { |
---|
100 | cpgsch(Plot::plotLabelSize); |
---|
101 | cpgmtxt("t",Plot::spTitleOffset2,0.5,0.5,line.c_str()); |
---|
102 | } |
---|
103 | void SpectralPlot::thirdHeaderLine(std::string line) |
---|
104 | { |
---|
105 | cpgsch(Plot::plotLabelSize); |
---|
106 | cpgmtxt("t",Plot::spTitleOffset3,0.5,0.5,line.c_str()); |
---|
107 | } |
---|
108 | void SpectralPlot::fourthHeaderLine(std::string line) |
---|
109 | { |
---|
110 | cpgsch(Plot::plotLabelSize); |
---|
111 | cpgmtxt("t",Plot::spTitleOffset4,0.5,0.5,line.c_str()); |
---|
112 | } |
---|
113 | |
---|
114 | void SpectralPlot::gotoMainSpectrum(float x1, float x2, float y1, float y2, std::string ylabel) |
---|
115 | { |
---|
116 | /// @details |
---|
117 | /// Defines the region for the main spectrum. |
---|
118 | /// Draws the box, with tick marks, and |
---|
119 | /// writes the flux (y axis) label, given by the string argument. |
---|
120 | /// \param x1 Minimum X-coordinate of box. |
---|
121 | /// \param x2 Maximum X-coordinate of box. |
---|
122 | /// \param y1 Minimum Y-coordinate of box. |
---|
123 | /// \param y2 Maximum Y-coordinate of box. |
---|
124 | /// \param ylabel Label for the flux (Y) axis. |
---|
125 | |
---|
126 | cpgvsiz(this->mainCoords[0],this->mainCoords[1], |
---|
127 | this->mainCoords[2],this->mainCoords[3]); |
---|
128 | cpgsch(Plot::plotIndexSize); |
---|
129 | cpgswin(x1,x2,y1,y2); |
---|
130 | cpgbox("1bcnst",0.,0,"bcnst1v",0.,0); |
---|
131 | cpgsch(Plot::plotLabelSize); |
---|
132 | cpgmtxt("l",Plot::spYlabelOffset,0.5,0.5,ylabel.c_str()); |
---|
133 | } |
---|
134 | |
---|
135 | void SpectralPlot::gotoZoomSpectrum(float x1, float x2, float y1, float y2) |
---|
136 | { |
---|
137 | /// @details |
---|
138 | /// Defines the region for the zoomed-in part of the spectrum. |
---|
139 | /// Draws the box, with special tick marks on the bottom axis. |
---|
140 | /// \param x1 Minimum X-coordinate of box. |
---|
141 | /// \param x2 Maximum X-coordinate of box. |
---|
142 | /// \param y1 Minimum Y-coordinate of box. |
---|
143 | /// \param y2 Maximum Y-coordinate of box. |
---|
144 | |
---|
145 | cpgvsiz(this->zoomCoords[0],this->zoomCoords[1], |
---|
146 | this->zoomCoords[2],this->zoomCoords[3]); |
---|
147 | cpgsch(Plot::plotIndexSize); |
---|
148 | cpgswin(x1,x2,y1,y2); |
---|
149 | cpgbox("bc",0.,0,"bcstn1v",0.,0); |
---|
150 | float lengthL,lengthR,disp,tickpt,step; |
---|
151 | std::stringstream label; |
---|
152 | for(int i=1;i<10;i++){ |
---|
153 | tickpt = x1+(x2-x1)*float(i)/10.; // spectral coord of the tick |
---|
154 | switch(i) |
---|
155 | { |
---|
156 | case 2: |
---|
157 | case 8: |
---|
158 | lengthL = lengthR = 0.5; |
---|
159 | disp = 0.3 + float(i-2)/6.; // i==2 --> disp=0.3, i==8 --> disp=1.3 |
---|
160 | label.str(""); |
---|
161 | label << tickpt; |
---|
162 | // do a labelled tick mark |
---|
163 | cpgtick(x1,y1,x2,y1,float(i)/10.,lengthL,lengthR, |
---|
164 | disp, 0., label.str().c_str()); |
---|
165 | break; |
---|
166 | default: |
---|
167 | label.str(""); |
---|
168 | lengthL = 0.25; |
---|
169 | lengthR = 0.; |
---|
170 | disp = 0.; // not used in this case, but set it anyway. |
---|
171 | break; |
---|
172 | } |
---|
173 | // first the bottom axis, just the ticks |
---|
174 | if(fabs(tickpt)<(x2-x1)/1.e4) step = 2.*(x2-x1); |
---|
175 | else step = tickpt; |
---|
176 | cpgaxis("", |
---|
177 | tickpt-0.001*(x2-x1), y1, |
---|
178 | tickpt+0.001*(x2-x1), y1, |
---|
179 | tickpt-0.001*(x2-x1), tickpt+0.001*(x2-x1), |
---|
180 | step, -1, lengthL,lengthR, 0.5, disp, 0.); |
---|
181 | //and now the top -- no labels, just tick marks |
---|
182 | cpgtick(x1,y2,x2,y2,float(i)/10.,lengthL,lengthR,0.,0.,""); |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | void SpectralPlot::gotoMap() |
---|
187 | { |
---|
188 | cpgvsiz(this->mapCoords[0],this->mapCoords[1], |
---|
189 | this->mapCoords[2],this->mapCoords[3]); |
---|
190 | cpgsch(Plot::plotIndexSize); |
---|
191 | } |
---|
192 | |
---|
193 | void SpectralPlot::drawVelRange(float v1, float v2) |
---|
194 | { |
---|
195 | /// @details |
---|
196 | /// Draws two vertical lines at the limits of velocity |
---|
197 | /// given by the arguments. |
---|
198 | /// \param v1 Minimum velocity. |
---|
199 | /// \param v2 Maximum velocity. |
---|
200 | |
---|
201 | int ci,ls; |
---|
202 | float dud,min,max; |
---|
203 | cpgqwin(&dud,&dud,&min,&max); |
---|
204 | cpgqci(&ci); |
---|
205 | cpgqls(&ls); |
---|
206 | cpgsci(DUCHAMP_OBJECT_OUTLINE_COLOUR); |
---|
207 | cpgsls(DASHED); |
---|
208 | cpgmove(v1,min); cpgdraw(v1,max); |
---|
209 | cpgmove(v2,min); cpgdraw(v2,max); |
---|
210 | cpgsci(ci); |
---|
211 | cpgsls(ls); |
---|
212 | } |
---|
213 | |
---|
214 | void SpectralPlot::drawFlaggedChannelRange(float v1, float v2) |
---|
215 | { |
---|
216 | /// @details |
---|
217 | /// Draws a box showing the extent of flagged channels. |
---|
218 | /// \param v1 Minimum world coordinate of the flagged channel range. |
---|
219 | /// \param v2 Maximum world coordinate of the flagged channel range. |
---|
220 | |
---|
221 | int ci,fs; |
---|
222 | float dud,min,max,height; |
---|
223 | cpgqwin(&dud,&dud,&min,&max); |
---|
224 | height = max-min; |
---|
225 | max += 0.01*height; |
---|
226 | min -= 0.01*height; |
---|
227 | cpgqci(&ci); |
---|
228 | cpgqfs(&fs); |
---|
229 | setDarkGreen(); |
---|
230 | cpgsci(DUCHAMP_MILKY_WAY_COLOUR); |
---|
231 | cpgsfs(HATCHED); |
---|
232 | cpgrect(v1,v2,min,max); |
---|
233 | cpgsfs(OUTLINE); |
---|
234 | cpgrect(v1,v2,min,max); |
---|
235 | cpgsci(ci); |
---|
236 | cpgsfs(fs); |
---|
237 | } |
---|
238 | |
---|
239 | void SpectralPlot::drawThresholds(Param &par, Statistics::StatsContainer<float> &stats) |
---|
240 | { |
---|
241 | |
---|
242 | float dud,vmin,vmax; |
---|
243 | cpgqwin(&vmin,&vmax,&dud,&dud); |
---|
244 | cpgsci(BLUE); |
---|
245 | cpgsls(DASHED); |
---|
246 | float thresh = stats.getThreshold(); |
---|
247 | if(par.getFlagNegative()) thresh *= -1.; |
---|
248 | cpgmove(vmin,thresh); |
---|
249 | cpgdraw(vmax,thresh); |
---|
250 | if(par.getFlagGrowth()){ |
---|
251 | if(par.getFlagUserGrowthThreshold()) thresh= par.getGrowthThreshold(); |
---|
252 | else thresh= stats.snrToValue(par.getGrowthCut()); |
---|
253 | if(par.getFlagNegative()) thresh *= -1.; |
---|
254 | cpgsls(DOTTED); |
---|
255 | cpgmove(vmin,thresh); |
---|
256 | cpgdraw(vmax,thresh); |
---|
257 | } |
---|
258 | cpgsci(FOREGND); |
---|
259 | cpgsls(SOLID); |
---|
260 | } |
---|
261 | |
---|
262 | void SpectralPlot::drawThresholds(Param &par, Statistics::StatsContainer<float> &stats, float *vel, float *baseline, size_t size) |
---|
263 | { |
---|
264 | |
---|
265 | cpgsci(BLUE); |
---|
266 | cpgsls(DASHED); |
---|
267 | float thresh = stats.getThreshold(); |
---|
268 | if(par.getFlagNegative()) thresh *= -1.; |
---|
269 | for(size_t i=0;i<size;i++) baseline[i]+= thresh; |
---|
270 | cpgline(size,vel,baseline); |
---|
271 | for(size_t i=0;i<size;i++) baseline[i]-= thresh; |
---|
272 | if(par.getFlagGrowth()){ |
---|
273 | if(par.getFlagUserGrowthThreshold()) thresh= par.getGrowthThreshold(); |
---|
274 | else thresh= stats.snrToValue(par.getGrowthCut()); |
---|
275 | if(par.getFlagNegative()) thresh *= -1.; |
---|
276 | for(size_t i=0;i<size;i++) baseline[i]+= thresh; |
---|
277 | cpgsls(DOTTED); |
---|
278 | cpgline(size,vel,baseline); |
---|
279 | for(size_t i=0;i<size;i++) baseline[i]-= thresh; |
---|
280 | } |
---|
281 | cpgsci(FOREGND); |
---|
282 | cpgsls(SOLID); |
---|
283 | } |
---|
284 | |
---|
285 | } |
---|
286 | |
---|
287 | } |
---|
288 | |
---|