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

Last change on this file since 1242 was 1242, checked in by MatthewWhiting, 11 years ago

Tickets #193 & #195 - Implementing channel flagging. Still a lot of commented-out code, plus the MW code is still present (although not used anywhere). Also making use of the new plotting classes.

File size: 17.6 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      /// @brief Draw box showing excluded range due flagged channels.
147      void drawFlaggedChannelRange(float v1, float v2);
148   
149      /// @brief Draw thresholds
150      void drawThresholds(Param &par, Statistics::StatsContainer<float> &stats);
151
152      /// @brief Return number of spectra that go on a page.
153      int   getNumOnPage();
154
155      /// @brief Set number of spectra that go on a page.
156      void  setNumOnPage(int i);
157      float getPaperWidth();         ///< Return width of plottable region.
158      void  setPaperWidth(float f);  ///< Set width of plottable region.
159      float getPaperHeight();        ///< Return height of plottable region.
160      void  setPaperHeight(float f); ///< Set height of plottable region.
161      float getAspectRatio();        ///< Return aspect ratio
162      void  setAspectRatio(float f); ///< Set aspect ratio
163      void  goToPlot();              ///< Goes to the plot when more than one are open.
164
165    private:
166      int numOnPage;       ///< Number of spectra to put on one page.
167      int spectraCount;    ///< Number of spectra done so far: where on the page?
168      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
169      float zoomCoords[4]; ///< Boundaries for the zoomed-in spectrum [inches]
170      float mapCoords[4];  ///< Boundaries for the map box [inches]
171      float paperWidth;    ///< Width of plottable region of the paper [inches]
172      float paperHeight;   ///< Height of plottable region of the paper [inches]
173      float aspectRatio;   ///< Aspect ratio height/width (as used by PGPlot calls)
174      int   identifier;    ///< The identifier code used by cpgslct.
175   
176    };
177
178    inline int   SpectralPlot::getNumOnPage(){return numOnPage;}
179    inline void  SpectralPlot::setNumOnPage(int i){numOnPage=i;}
180    inline float SpectralPlot::getPaperWidth(){return paperWidth;}
181    inline void  SpectralPlot::setPaperWidth(float f){paperWidth=f;}
182    inline float SpectralPlot::getPaperHeight(){return paperHeight;}
183    inline void  SpectralPlot::setPaperHeight(float f){paperHeight=f;}
184    inline float SpectralPlot::getAspectRatio(){return aspectRatio;}
185    inline void  SpectralPlot::setAspectRatio(float f){aspectRatio=f;}
186
187    //***************************************************************************
188    //***************************************************************************
189
190    ///  @brief A class for plotting a single spectrum.
191    ///  @details This class is designed to hold the dimensions and
192    ///  set up for the plotting of the spectra (including the full
193    ///  spectra, the zoomed in part, and the moment map).  The
194    ///  physical dimensions (in inches) of the plot and the elements
195    ///  within it are stored, on the assumption that the plot will go
196    ///  on an A4 page.  Simple accessor functions are provided to
197    ///  enable access to quantities needed for pgplot routines.
198
199    class SimpleSpectralPlot
200    {
201    public:
202      SimpleSpectralPlot();    ///< Constructor
203      virtual ~SimpleSpectralPlot(); ///< Destructor
204      SimpleSpectralPlot(const SimpleSpectralPlot& p);
205      SimpleSpectralPlot& operator=(const SimpleSpectralPlot& p);
206
207      /// @brief Set up PGPLOT output.
208      int setUpPlot(std::string pgDestination);
209
210      /// @brief Close the PGPLOT device
211      void close();
212
213      /// @brief Write the labels
214      void label(std::string xlabel, std::string ylabel, std::string title);
215
216      /// @brief Set up main spectral plotting region.
217      void gotoMainSpectrum(float x1, float x2, float y1, float y2);
218
219      /// @brief Draw a line indicating the pixels that have been detected
220      void markDetectedPixels(short *detectMap, size_t size, FitsHeader &head);
221
222      /// @brief Draw lines indicating velocity range.
223      void drawVelRange(float v1, float v2);
224
225      /// @brief Draw box showing excluded range due to Milky Way.
226      void drawMWRange(float v1, float v2);
227   
228      float getPaperWidth();         ///< Return width of plottable region.
229      void  setPaperWidth(float f);  ///< Set width of plottable region.
230      float getPaperHeight();        ///< Return height of plottable region.
231      void  setPaperHeight(float f); ///< Set height of plottable region.
232      float getAspectRatio();        ///< Return aspect ratio
233      void  setAspectRatio(float f); ///< Set aspect ratio
234      void  goToPlot();              ///< Goes to the plot when more than one are open.
235
236    private:
237      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
238      float paperWidth;    ///< Width of plottable region of the paper [inches]
239      float paperHeight;   ///< Height of plottable region of the paper [inches]
240      float aspectRatio;   ///< Aspect ratio height/width (as used by PGPlot calls)
241      int   identifier;    ///< The identifier code used by cpgslct.
242 
243    };
244 
245    inline float SimpleSpectralPlot::getPaperWidth(){return paperWidth;}
246    inline void  SimpleSpectralPlot::setPaperWidth(float f){paperWidth=f;}
247    inline float SimpleSpectralPlot::getPaperHeight(){return paperHeight;}
248    inline void  SimpleSpectralPlot::setPaperHeight(float f){paperHeight=f;}
249    inline float SimpleSpectralPlot::getAspectRatio(){return aspectRatio;}
250    inline void  SimpleSpectralPlot::setAspectRatio(float f){aspectRatio=f;}
251
252
253    //***************************************************************************
254    //***************************************************************************
255
256    ///  @brief A class for plotting 2-dimensional maps.
257    ///  @details A class to hold the dimensions and set up for the
258    ///  plotting of maps in Duchamp.
259    ///    The physical dimensions (in inches) of the plot and the elements
260    ///     within it are stored, including maximum widths and heights
261    ///     (so that the plot will fit on an A4 page).
262    ///    Simple accessor functions are provided to enable access to quantities
263    ///     needed for pgplot routines.
264
265    class ImagePlot
266    {
267    public:
268      ImagePlot();  ///< Constructor
269      virtual ~ImagePlot(); ///< Destructor
270      ImagePlot(const ImagePlot& p);
271      ImagePlot& operator=(const ImagePlot& p);
272 
273      /// @brief Set up PGPLOT output.
274      int   setUpPlot(std::string pgDestination, float x, float y);
275
276      /// @brief Close the PGPLOT device
277      void close();
278
279      /// @brief Defines and draws box.
280      void  drawMapBox(float x1, float x2, float y1, float y2,
281                       std::string xlabel, std::string ylabel);
282
283      /// @brief Write plot title.
284      void  makeTitle(std::string title);
285
286      float cmToCoord(float cm);///< Converts distance in cm to coordinate distance on the plot.
287      float getMargin();        ///< Returns width of margin.
288      float getPaperWidth();    ///< Returns width of paper.
289      float imageWidth();       ///< Returns the calculated total width of the image part of the plot [inches]
290      float getImageHeight();   ///< Returns height of image [inches]
291      float getAspectRatio();   ///< Returns the aspect ratio of the image.
292      void  goToPlot();         ///< Goes to the plot when more than one are open
293
294    private:
295      float paperWidth;     ///< Default (maximum) width of "paper" [inches]
296      float maxPaperHeight; ///< Maximum allowed height of paper [inches]
297      float marginWidth;    ///< Width allowed for margins around main plot (ie. label & numbers) [inches]
298      float wedgeWidth;     ///< Width allowed for placement of wedge on right-hand side of plot. [inches]
299      float imageRatio;     ///< Aspect ratio of the image only (ie. y-value range / x-value range).
300      float aspectRatio;    ///< Aspect ratio of whole plot.
301      float xdim;           ///< Width of main plot, in display units.
302      float ydim;           ///< Height of main plot, in display units.
303      int   identifier;     ///< The identifier code used by cpgslct.
304    };
305    //----------------------------------------------------------
306    // Inline ImagePlot functions...
307    //----------------------------------------------------------
308
309    inline float ImagePlot::getMargin()     {return marginWidth;}
310    inline float ImagePlot::getPaperWidth() {return paperWidth;}
311    inline float ImagePlot::getImageHeight(){return imageWidth()*imageRatio;}
312    inline float ImagePlot::getAspectRatio(){return aspectRatio;}
313 
314    //***************************************************************************
315    //***************************************************************************
316
317    ///  @brief A class for plotting just the image cutouts of individual sources.
318    ///  @details This class is designed to hold the dimensions and set up for the
319    ///  plotting of the cutouts, plus the textual information for each source.
320    ///  The physical dimensions (in inches) of the plot and the elements
321    ///   within it are stored, on the assumption that the plot will go on
322    ///   an A4 page.
323    ///  Simple accessor functions are provided to enable access to quantities
324    ///   needed for pgplot routines.
325
326    class CutoutPlot
327    {
328    public:
329      CutoutPlot();    ///< Constructor
330      virtual ~CutoutPlot(); ///< Destructor
331      CutoutPlot(const CutoutPlot& p);
332      CutoutPlot& operator=(const CutoutPlot& p);
333
334      /// @brief Set up PGPLOT output.
335      int setUpPlot(std::string pgDestination);
336
337      /// @brief Calculate boundaries for boxes.
338      void calcCoords();
339      /// @brief Set up the header box
340      void gotoHeader();
341
342      /// @brief Write first line of header information (position/velocity info) in correct place.
343      void firstHeaderLine(std::string line);   
344   
345      /// @brief Write second line of header information (fluxes) in correct place.
346      void secondHeaderLine(std::string line); 
347
348      /// @brief Write third line of header information (WCS widths) in correct place.
349      void thirdHeaderLine(std::string line);   
350
351      /// @brief Write fourth line of header information (pixel coordinates) in correct place.
352      void fourthHeaderLine(std::string line);   
353
354      /// @brief Defines the region for the moment map.
355      void gotoMap();
356
357      /// @brief Goes to the plot when more than one are open.
358      void  goToPlot();   
359
360      /// @brief Return the number of objects that go on a page.
361      int   getNumOnPage(){return numOnPage;}
362      /// @brief Set number of objects that go on a page.
363      void  setNumOnPage(int i){numOnPage=i;}
364
365      /// @brief Return width of plottable region.
366      float getPaperWidth(){return paperWidth;}
367      /// @brief Set width of plottable region.
368      void  setPaperWidth(float f){paperWidth=f;}
369      /// @brief Return height of plottable region.
370      float getPaperHeight(){return paperHeight;}
371      /// @brief Set height of plottable region.
372      void  setPaperHeight(float f){paperHeight=f;}
373
374    private:
375      int numOnPage;       ///< Number of sources to put on one page.
376      int sourceCount;     ///< Number of sources done so far: where on the page?
377      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
378      float mapCoords[4];  ///< Boundaries for the map box [inches]
379      float paperWidth;    ///< Width of plottable region of the paper [inches]
380      float paperHeight;   ///< Height of plottable region of the paper [inches]
381      int   identifier;    ///< The identifier code used by cpgslct.
382   
383    };
384
385
386  }
387
388}
389
390#endif
391
Note: See TracBrowser for help on using the repository browser.