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

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

Ticket #148: Getting the 1D plotting working for a single spectrum out of a HIPASS cube (ie. the WCS works). Also needed some tweaks to the integrated flux calculations, and some adjustments to the minPix/Channels parameters

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