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
RevLine 
[299]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// -----------------------------------------------------------------------
[103]29#ifndef PLOTS_H
30#define PLOTS_H
31
[11]32#include <iostream>
33#include <sstream>
34#include <string>
35#include <math.h>
[581]36#include <duchamp/duchamp.hh>
[987]37#include <duchamp/param.hh>
38#include <duchamp/fitsHeader.hh>
[393]39#include <duchamp/pgheader.hh>
[987]40#include <duchamp/Utils/Statistics.hh>
[11]41
[378]42namespace duchamp
[11]43{
44
[581]45  /// @brief A function to handle plotting of WCS axes, with duchamp-suitable defaults.
[884]46  void plotWCSaxes(struct wcsprm *wcs, size_t *axes, int textColour=DUCHAMP_ID_TEXT_COLOUR, int axisColour=DUCHAMP_WCS_AXIS_COLOUR);
[581]47
[528]48  /// @brief A namespace to control plotting of the spectral output and the
49  /// spatial image output.
[11]50
[378]51  namespace Plot
52  {
[485]53    const float inchToCm=2.54;        ///< Conversion factor from inches to centimetres.
[378]54    const float a4width=21.0;         ///< A4 width in cm
55    const float a4height=29.7;        ///< A4 height in cm
[485]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
[284]58
[378]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]
[485]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]
[378]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.
[220]73
[485]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
[367]77
[378]78    // These are the constants used for spacing out elements in ImagePlot.
79    const float imTitleOffset = 2.7;  ///< Offset for title of map.
[11]80
[378]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;
[11]87
[378]88    //***************************************************************************
89    //***************************************************************************
[274]90
[528]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
[378]100    class SpectralPlot
101    {
102    public:
103      SpectralPlot();    ///< Constructor
104      virtual ~SpectralPlot(); ///< Destructor
105      SpectralPlot(const SpectralPlot& p);
106      SpectralPlot& operator=(const SpectralPlot& p);
[274]107
[528]108      /// @brief Set up PGPLOT output.
[378]109      int setUpPlot(std::string pgDestination);
110
[985]111      /// @brief Close the PGPLOT device
112      void close();
113
[528]114      /// @brief Calculate boundaries for boxes.
[378]115      void calcCoords();
[528]116      /// @brief Set up the header & write the X-label.
[378]117      void gotoHeader(std::string xlabel);
118
[528]119      /// @brief Write first line of header information (position/velocity info) in correct place.
[378]120      void firstHeaderLine(std::string line);   
[274]121   
[528]122      /// @brief Write second line of header information (fluxes) in correct place.
[378]123      void secondHeaderLine(std::string line); 
[274]124
[528]125      /// @brief Write third line of header information (WCS widths) in correct place.
[378]126      void thirdHeaderLine(std::string line);   
[274]127
[528]128      /// @brief Write fourth line of header information (pixel coordinates) in correct place.
[378]129      void fourthHeaderLine(std::string line);   
[282]130
[528]131      /// @brief Set up main spectral plotting region.
[378]132      void gotoMainSpectrum(float x1, float x2, float y1, float y2,
133                            std::string ylabel);
[274]134   
[528]135      /// @brief Set up zoomed-in spectral plotting region.
[378]136      void gotoZoomSpectrum(float x1, float x2, float y1, float y2);   
[11]137   
[528]138      /// @brief Defines the region for the moment map.
[378]139      void gotoMap();
[274]140
[528]141      /// @brief Draw lines indicating velocity range.
[378]142      void drawVelRange(float v1, float v2);
[274]143
[1242]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);
[274]148   
[987]149      /// @brief Draw thresholds
150      void drawThresholds(Param &par, Statistics::StatsContainer<float> &stats);
151
[528]152      /// @brief Return number of spectra that go on a page.
[378]153      int   getNumOnPage();
[274]154
[528]155      /// @brief Set number of spectra that go on a page.
[378]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.
[985]161      float getAspectRatio();        ///< Return aspect ratio
162      void  setAspectRatio(float f); ///< Set aspect ratio
[528]163      void  goToPlot();              ///< Goes to the plot when more than one are open.
[11]164
[378]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]
[985]173      float aspectRatio;   ///< Aspect ratio height/width (as used by PGPlot calls)
[378]174      int   identifier;    ///< The identifier code used by cpgslct.
[11]175   
[378]176    };
[11]177
[378]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;}
[985]184    inline float SpectralPlot::getAspectRatio(){return aspectRatio;}
185    inline void  SpectralPlot::setAspectRatio(float f){aspectRatio=f;}
[220]186
[378]187    //***************************************************************************
188    //***************************************************************************
[11]189
[985]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
[1013]219      /// @brief Draw a line indicating the pixels that have been detected
220      void markDetectedPixels(short *detectMap, size_t size, FitsHeader &head);
[986]221
[985]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
[528]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
[378]265    class ImagePlot
266    {
267    public:
268      ImagePlot();  ///< Constructor
269      virtual ~ImagePlot(); ///< Destructor
270      ImagePlot(const ImagePlot& p);
271      ImagePlot& operator=(const ImagePlot& p);
[11]272 
[528]273      /// @brief Set up PGPLOT output.
[378]274      int   setUpPlot(std::string pgDestination, float x, float y);
[274]275
[985]276      /// @brief Close the PGPLOT device
277      void close();
278
[528]279      /// @brief Defines and draws box.
[378]280      void  drawMapBox(float x1, float x2, float y1, float y2,
281                       std::string xlabel, std::string ylabel);
[103]282
[528]283      /// @brief Write plot title.
[378]284      void  makeTitle(std::string title);
[274]285
[485]286      float cmToCoord(float cm);///< Converts distance in cm to coordinate distance on the plot.
[378]287      float getMargin();        ///< Returns width of margin.
288      float getPaperWidth();    ///< Returns width of paper.
[485]289      float imageWidth();       ///< Returns the calculated total width of the image part of the plot [inches]
[378]290      float getImageHeight();   ///< Returns height of image [inches]
291      float getAspectRatio();   ///< Returns the aspect ratio of the image.
[485]292      void  goToPlot();         ///< Goes to the plot when more than one are open
[103]293
[378]294    private:
295      float paperWidth;     ///< Default (maximum) width of "paper" [inches]
296      float maxPaperHeight; ///< Maximum allowed height of paper [inches]
[485]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).
[378]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    //----------------------------------------------------------
[11]308
[378]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;}
[220]313 
[378]314    //***************************************************************************
315    //***************************************************************************
[367]316
[528]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
[378]326    class CutoutPlot
327    {
328    public:
329      CutoutPlot();    ///< Constructor
330      virtual ~CutoutPlot(); ///< Destructor
331      CutoutPlot(const CutoutPlot& p);
332      CutoutPlot& operator=(const CutoutPlot& p);
[367]333
[528]334      /// @brief Set up PGPLOT output.
[378]335      int setUpPlot(std::string pgDestination);
[367]336
[528]337      /// @brief Calculate boundaries for boxes.
[378]338      void calcCoords();
[528]339      /// @brief Set up the header box
[378]340      void gotoHeader();
[367]341
[528]342      /// @brief Write first line of header information (position/velocity info) in correct place.
[378]343      void firstHeaderLine(std::string line);   
[367]344   
[528]345      /// @brief Write second line of header information (fluxes) in correct place.
[378]346      void secondHeaderLine(std::string line); 
[367]347
[528]348      /// @brief Write third line of header information (WCS widths) in correct place.
[378]349      void thirdHeaderLine(std::string line);   
[367]350
[528]351      /// @brief Write fourth line of header information (pixel coordinates) in correct place.
[378]352      void fourthHeaderLine(std::string line);   
[367]353
[528]354      /// @brief Defines the region for the moment map.
[378]355      void gotoMap();
[367]356
[528]357      /// @brief Goes to the plot when more than one are open.
[378]358      void  goToPlot();   
[367]359
[528]360      /// @brief Return the number of objects that go on a page.
[378]361      int   getNumOnPage(){return numOnPage;}
[528]362      /// @brief Set number of objects that go on a page.
[378]363      void  setNumOnPage(int i){numOnPage=i;}
[367]364
[528]365      /// @brief Return width of plottable region.
[378]366      float getPaperWidth(){return paperWidth;}
[528]367      /// @brief Set width of plottable region.
[378]368      void  setPaperWidth(float f){paperWidth=f;}
[528]369      /// @brief Return height of plottable region.
[378]370      float getPaperHeight(){return paperHeight;}
[528]371      /// @brief Set height of plottable region.
[378]372      void  setPaperHeight(float f){paperHeight=f;}
[367]373
[378]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.
[367]382   
[378]383    };
[367]384
385
[378]386  }
387
[11]388}
[103]389
390#endif
391
Note: See TracBrowser for help on using the repository browser.