source: trunk/src/Cubes/plots.hh @ 987

Last change on this file since 987 was 987, checked in by MatthewWhiting, 12 years ago

Enabling the plotting of the thresholds for the regular spectral output. This makes it much more clear how robust the detection is. This is only done for the peak flux spectrum - if spectralMethod = sum it is not plotted.

File size: 17.4 KB
Line 
1// -----------------------------------------------------------------------
2// plots.hh: Definition of the SpectralPlot and ImagePlot classes, for
3//           plotting spectra and maps of detected objects.
4// -----------------------------------------------------------------------
5// Copyright (C) 2006, Matthew Whiting, ATNF
6//
7// This program is free software; you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2 of the License, or (at your
10// option) any later version.
11//
12// Duchamp is distributed in the hope that it will be useful, but WITHOUT
13// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15// for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Duchamp; if not, write to the Free Software Foundation,
19// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20//
21// Correspondence concerning Duchamp may be directed to:
22//    Internet email: Matthew.Whiting [at] atnf.csiro.au
23//    Postal address: Dr. Matthew Whiting
24//                    Australia Telescope National Facility, CSIRO
25//                    PO Box 76
26//                    Epping NSW 1710
27//                    AUSTRALIA
28// -----------------------------------------------------------------------
29#ifndef PLOTS_H
30#define PLOTS_H
31
32#include <iostream>
33#include <sstream>
34#include <string>
35#include <math.h>
36#include <duchamp/duchamp.hh>
37#include <duchamp/param.hh>
38#include <duchamp/fitsHeader.hh>
39#include <duchamp/pgheader.hh>
40#include <duchamp/Utils/Statistics.hh>
41
42namespace duchamp
43{
44
45  /// @brief A function to handle plotting of WCS axes, with duchamp-suitable defaults.
46  void plotWCSaxes(struct wcsprm *wcs, size_t *axes, int textColour=DUCHAMP_ID_TEXT_COLOUR, int axisColour=DUCHAMP_WCS_AXIS_COLOUR);
47
48  /// @brief A namespace to control plotting of the spectral output and the
49  /// spatial image output.
50
51  namespace Plot
52  {
53    const float inchToCm=2.54;        ///< Conversion factor from inches to centimetres.
54    const float a4width=21.0;         ///< A4 width in cm
55    const float a4height=29.7;        ///< A4 height in cm
56    const float psHoffset=0.35;       ///< The default horizontal pgplot offset applied to ps files
57    const float psVoffset=0.25;       ///< The default vertical pgplot offset applied to ps files
58
59    // These are the constants used for spacing out elements in SpectralPlot.
60    const float spMainX1 =  2.0;      ///< min X-value of main box [cm]
61    const float spMainX2 = 13.7;      ///< max X-value of main box [cm]
62    const float spZoomX1 = 15.0;      ///< min X-value of zoom box [cm]
63    const float spZoomX2 = 16.8;      ///< max X-value of zoom box [cm]
64    const float spMapX1  = 17.0;      ///< min X-value of map box [cm]
65    const float spMainY1 =  1.5;      ///< min Y-value of box wrt base of current spectrum [cm]
66    const float spMainY2 =  3.4;      ///< max Y-value of box wrt base of current spectrum [cm]
67    const float spXlabelOffset = 3.0; ///< Offset for X-axis label.
68    const float spYlabelOffset = 4.0; ///< Offset for Y-axis label.
69    const float spTitleOffset1 = 5.1; ///< Offset for first title line.
70    const float spTitleOffset2 = 3.6; ///< Offset for second title line.
71    const float spTitleOffset3 = 2.1; ///< Offset for third title line.
72    const float spTitleOffset4 = 0.6; ///< Offset for fourth title line.
73
74    const float spIndexSize = 0.6;    ///< PGPlot character height for tick mark labels
75    const float spLabelSize = 0.7;    ///< PGPlot character height for axis labels
76    const float spTitleSize = 0.8;    ///< PGPlot character height for plot title line
77
78    // These are the constants used for spacing out elements in ImagePlot.
79    const float imTitleOffset = 2.7;  ///< Offset for title of map.
80
81    // These are the constants used for spacing out elements in CutoutPlot.
82    const float cuMainX1 = 1.0;
83    const float cuMainX2 = 15.8;
84    const float cuMainY1 = 1.0;
85    const float cuMainY2 = 3.8;
86    const float cuMapX1 = 16.0;
87
88    //***************************************************************************
89    //***************************************************************************
90
91    ///  @brief A class for plotting spectra of detections.
92    ///  @details This class is designed to hold the dimensions and
93    ///  set up for the plotting of the spectra (including the full
94    ///  spectra, the zoomed in part, and the moment map).  The
95    ///  physical dimensions (in inches) of the plot and the elements
96    ///  within it are stored, on the assumption that the plot will go
97    ///  on an A4 page.  Simple accessor functions are provided to
98    ///  enable access to quantities needed for pgplot routines.
99
100    class SpectralPlot
101    {
102    public:
103      SpectralPlot();    ///< Constructor
104      virtual ~SpectralPlot(); ///< Destructor
105      SpectralPlot(const SpectralPlot& p);
106      SpectralPlot& operator=(const SpectralPlot& p);
107
108      /// @brief Set up PGPLOT output.
109      int setUpPlot(std::string pgDestination);
110
111      /// @brief Close the PGPLOT device
112      void close();
113
114      /// @brief Calculate boundaries for boxes.
115      void calcCoords();
116      /// @brief Set up the header & write the X-label.
117      void gotoHeader(std::string xlabel);
118
119      /// @brief Write first line of header information (position/velocity info) in correct place.
120      void firstHeaderLine(std::string line);   
121   
122      /// @brief Write second line of header information (fluxes) in correct place.
123      void secondHeaderLine(std::string line); 
124
125      /// @brief Write third line of header information (WCS widths) in correct place.
126      void thirdHeaderLine(std::string line);   
127
128      /// @brief Write fourth line of header information (pixel coordinates) in correct place.
129      void fourthHeaderLine(std::string line);   
130
131      /// @brief Set up main spectral plotting region.
132      void gotoMainSpectrum(float x1, float x2, float y1, float y2,
133                            std::string ylabel);
134   
135      /// @brief Set up zoomed-in spectral plotting region.
136      void gotoZoomSpectrum(float x1, float x2, float y1, float y2);   
137   
138      /// @brief Defines the region for the moment map.
139      void gotoMap();
140
141      /// @brief Draw lines indicating velocity range.
142      void drawVelRange(float v1, float v2);
143
144      /// @brief Draw box showing excluded range due to Milky Way.
145      void drawMWRange(float v1, float v2);
146   
147      /// @brief Draw thresholds
148      void drawThresholds(Param &par, Statistics::StatsContainer<float> &stats);
149
150      /// @brief Return number of spectra that go on a page.
151      int   getNumOnPage();
152
153      /// @brief Set number of spectra that go on a page.
154      void  setNumOnPage(int i);
155      float getPaperWidth();         ///< Return width of plottable region.
156      void  setPaperWidth(float f);  ///< Set width of plottable region.
157      float getPaperHeight();        ///< Return height of plottable region.
158      void  setPaperHeight(float f); ///< Set height of plottable region.
159      float getAspectRatio();        ///< Return aspect ratio
160      void  setAspectRatio(float f); ///< Set aspect ratio
161      void  goToPlot();              ///< Goes to the plot when more than one are open.
162
163    private:
164      int numOnPage;       ///< Number of spectra to put on one page.
165      int spectraCount;    ///< Number of spectra done so far: where on the page?
166      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
167      float zoomCoords[4]; ///< Boundaries for the zoomed-in spectrum [inches]
168      float mapCoords[4];  ///< Boundaries for the map box [inches]
169      float paperWidth;    ///< Width of plottable region of the paper [inches]
170      float paperHeight;   ///< Height of plottable region of the paper [inches]
171      float aspectRatio;   ///< Aspect ratio height/width (as used by PGPlot calls)
172      int   identifier;    ///< The identifier code used by cpgslct.
173   
174    };
175
176    inline int   SpectralPlot::getNumOnPage(){return numOnPage;}
177    inline void  SpectralPlot::setNumOnPage(int i){numOnPage=i;}
178    inline float SpectralPlot::getPaperWidth(){return paperWidth;}
179    inline void  SpectralPlot::setPaperWidth(float f){paperWidth=f;}
180    inline float SpectralPlot::getPaperHeight(){return paperHeight;}
181    inline void  SpectralPlot::setPaperHeight(float f){paperHeight=f;}
182    inline float SpectralPlot::getAspectRatio(){return aspectRatio;}
183    inline void  SpectralPlot::setAspectRatio(float f){aspectRatio=f;}
184
185    //***************************************************************************
186    //***************************************************************************
187
188    ///  @brief A class for plotting a single spectrum.
189    ///  @details This class is designed to hold the dimensions and
190    ///  set up for the plotting of the spectra (including the full
191    ///  spectra, the zoomed in part, and the moment map).  The
192    ///  physical dimensions (in inches) of the plot and the elements
193    ///  within it are stored, on the assumption that the plot will go
194    ///  on an A4 page.  Simple accessor functions are provided to
195    ///  enable access to quantities needed for pgplot routines.
196
197    class SimpleSpectralPlot
198    {
199    public:
200      SimpleSpectralPlot();    ///< Constructor
201      virtual ~SimpleSpectralPlot(); ///< Destructor
202      SimpleSpectralPlot(const SimpleSpectralPlot& p);
203      SimpleSpectralPlot& operator=(const SimpleSpectralPlot& p);
204
205      /// @brief Set up PGPLOT output.
206      int setUpPlot(std::string pgDestination);
207
208      /// @brief Close the PGPLOT device
209      void close();
210
211      /// @brief Write the labels
212      void label(std::string xlabel, std::string ylabel, std::string title);
213
214      /// @brief Set up main spectral plotting region.
215      void gotoMainSpectrum(float x1, float x2, float y1, float y2);
216
217      /// @brief Draw a line indicating the relevant pixel is detected
218      void drawDetectPixel(int z, FitsHeader &head);
219
220      /// @brief Draw lines indicating velocity range.
221      void drawVelRange(float v1, float v2);
222
223      /// @brief Draw box showing excluded range due to Milky Way.
224      void drawMWRange(float v1, float v2);
225   
226      float getPaperWidth();         ///< Return width of plottable region.
227      void  setPaperWidth(float f);  ///< Set width of plottable region.
228      float getPaperHeight();        ///< Return height of plottable region.
229      void  setPaperHeight(float f); ///< Set height of plottable region.
230      float getAspectRatio();        ///< Return aspect ratio
231      void  setAspectRatio(float f); ///< Set aspect ratio
232      void  goToPlot();              ///< Goes to the plot when more than one are open.
233
234    private:
235      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
236      float paperWidth;    ///< Width of plottable region of the paper [inches]
237      float paperHeight;   ///< Height of plottable region of the paper [inches]
238      float aspectRatio;   ///< Aspect ratio height/width (as used by PGPlot calls)
239      int   identifier;    ///< The identifier code used by cpgslct.
240 
241    };
242 
243    inline float SimpleSpectralPlot::getPaperWidth(){return paperWidth;}
244    inline void  SimpleSpectralPlot::setPaperWidth(float f){paperWidth=f;}
245    inline float SimpleSpectralPlot::getPaperHeight(){return paperHeight;}
246    inline void  SimpleSpectralPlot::setPaperHeight(float f){paperHeight=f;}
247    inline float SimpleSpectralPlot::getAspectRatio(){return aspectRatio;}
248    inline void  SimpleSpectralPlot::setAspectRatio(float f){aspectRatio=f;}
249
250
251    //***************************************************************************
252    //***************************************************************************
253
254    ///  @brief A class for plotting 2-dimensional maps.
255    ///  @details A class to hold the dimensions and set up for the
256    ///  plotting of maps in Duchamp.
257    ///    The physical dimensions (in inches) of the plot and the elements
258    ///     within it are stored, including maximum widths and heights
259    ///     (so that the plot will fit on an A4 page).
260    ///    Simple accessor functions are provided to enable access to quantities
261    ///     needed for pgplot routines.
262
263    class ImagePlot
264    {
265    public:
266      ImagePlot();  ///< Constructor
267      virtual ~ImagePlot(); ///< Destructor
268      ImagePlot(const ImagePlot& p);
269      ImagePlot& operator=(const ImagePlot& p);
270 
271      /// @brief Set up PGPLOT output.
272      int   setUpPlot(std::string pgDestination, float x, float y);
273
274      /// @brief Close the PGPLOT device
275      void close();
276
277      /// @brief Defines and draws box.
278      void  drawMapBox(float x1, float x2, float y1, float y2,
279                       std::string xlabel, std::string ylabel);
280
281      /// @brief Write plot title.
282      void  makeTitle(std::string title);
283
284      float cmToCoord(float cm);///< Converts distance in cm to coordinate distance on the plot.
285      float getMargin();        ///< Returns width of margin.
286      float getPaperWidth();    ///< Returns width of paper.
287      float imageWidth();       ///< Returns the calculated total width of the image part of the plot [inches]
288      float getImageHeight();   ///< Returns height of image [inches]
289      float getAspectRatio();   ///< Returns the aspect ratio of the image.
290      void  goToPlot();         ///< Goes to the plot when more than one are open
291
292    private:
293      float paperWidth;     ///< Default (maximum) width of "paper" [inches]
294      float maxPaperHeight; ///< Maximum allowed height of paper [inches]
295      float marginWidth;    ///< Width allowed for margins around main plot (ie. label & numbers) [inches]
296      float wedgeWidth;     ///< Width allowed for placement of wedge on right-hand side of plot. [inches]
297      float imageRatio;     ///< Aspect ratio of the image only (ie. y-value range / x-value range).
298      float aspectRatio;    ///< Aspect ratio of whole plot.
299      float xdim;           ///< Width of main plot, in display units.
300      float ydim;           ///< Height of main plot, in display units.
301      int   identifier;     ///< The identifier code used by cpgslct.
302    };
303    //----------------------------------------------------------
304    // Inline ImagePlot functions...
305    //----------------------------------------------------------
306
307    inline float ImagePlot::getMargin()     {return marginWidth;}
308    inline float ImagePlot::getPaperWidth() {return paperWidth;}
309    inline float ImagePlot::getImageHeight(){return imageWidth()*imageRatio;}
310    inline float ImagePlot::getAspectRatio(){return aspectRatio;}
311 
312    //***************************************************************************
313    //***************************************************************************
314
315    ///  @brief A class for plotting just the image cutouts of individual sources.
316    ///  @details This class is designed to hold the dimensions and set up for the
317    ///  plotting of the cutouts, plus the textual information for each source.
318    ///  The physical dimensions (in inches) of the plot and the elements
319    ///   within it are stored, on the assumption that the plot will go on
320    ///   an A4 page.
321    ///  Simple accessor functions are provided to enable access to quantities
322    ///   needed for pgplot routines.
323
324    class CutoutPlot
325    {
326    public:
327      CutoutPlot();    ///< Constructor
328      virtual ~CutoutPlot(); ///< Destructor
329      CutoutPlot(const CutoutPlot& p);
330      CutoutPlot& operator=(const CutoutPlot& p);
331
332      /// @brief Set up PGPLOT output.
333      int setUpPlot(std::string pgDestination);
334
335      /// @brief Calculate boundaries for boxes.
336      void calcCoords();
337      /// @brief Set up the header box
338      void gotoHeader();
339
340      /// @brief Write first line of header information (position/velocity info) in correct place.
341      void firstHeaderLine(std::string line);   
342   
343      /// @brief Write second line of header information (fluxes) in correct place.
344      void secondHeaderLine(std::string line); 
345
346      /// @brief Write third line of header information (WCS widths) in correct place.
347      void thirdHeaderLine(std::string line);   
348
349      /// @brief Write fourth line of header information (pixel coordinates) in correct place.
350      void fourthHeaderLine(std::string line);   
351
352      /// @brief Defines the region for the moment map.
353      void gotoMap();
354
355      /// @brief Goes to the plot when more than one are open.
356      void  goToPlot();   
357
358      /// @brief Return the number of objects that go on a page.
359      int   getNumOnPage(){return numOnPage;}
360      /// @brief Set number of objects that go on a page.
361      void  setNumOnPage(int i){numOnPage=i;}
362
363      /// @brief Return width of plottable region.
364      float getPaperWidth(){return paperWidth;}
365      /// @brief Set width of plottable region.
366      void  setPaperWidth(float f){paperWidth=f;}
367      /// @brief Return height of plottable region.
368      float getPaperHeight(){return paperHeight;}
369      /// @brief Set height of plottable region.
370      void  setPaperHeight(float f){paperHeight=f;}
371
372    private:
373      int numOnPage;       ///< Number of sources to put on one page.
374      int sourceCount;     ///< Number of sources done so far: where on the page?
375      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
376      float mapCoords[4];  ///< Boundaries for the map box [inches]
377      float paperWidth;    ///< Width of plottable region of the paper [inches]
378      float paperHeight;   ///< Height of plottable region of the paper [inches]
379      int   identifier;    ///< The identifier code used by cpgslct.
380   
381    };
382
383
384  }
385
386}
387
388#endif
389
Note: See TracBrowser for help on using the repository browser.