source: trunk/src/Cubes/cubes.hh @ 460

Last change on this file since 460 was 459, checked in by MatthewWhiting, 16 years ago

Modify the WCS axes plotting function to allow different colours to be used. The Duchamp colours are set as defaults.

File size: 27.0 KB
Line 
1// -----------------------------------------------------------------------
2// cubes.hh: Definitions of the DataArray, Cube and Image classes.
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#ifndef CUBES_H
29#define CUBES_H
30
31#include <iostream>
32#include <string>
33#include <vector>
34
35#include <duchamp/duchamp.hh>
36#include <duchamp/param.hh>
37#include <duchamp/fitsHeader.hh>
38#include <duchamp/Detection/detection.hh>
39#include <duchamp/Detection/columns.hh>
40#include <duchamp/Cubes/plots.hh>
41#include <duchamp/Utils/Statistics.hh>
42#include <duchamp/PixelMap/Scan.hh>
43#include <duchamp/PixelMap/Object2D.hh>
44
45
46namespace duchamp
47{
48
49
50  /** Search a reconstructed array for significant detections. */
51  std::vector <Detection>
52  searchReconArray(long *dim, float *originalArray, float *reconArray,
53                   Param &par, Statistics::StatsContainer<float> &stats);
54  std::vector <Detection>
55  searchReconArraySimple(long *dim, float *originalArray, float *reconArray,
56                         Param &par, Statistics::StatsContainer<float> &stats);
57
58  /** Search a 3-dimensional array for significant detections. */
59  std::vector <Detection>
60  search3DArray(long *dim, float *Array, Param &par,
61                Statistics::StatsContainer<float> &stats);
62  std::vector <Detection>
63  search3DArraySimple(long *dim, float *Array, Param &par,
64                      Statistics::StatsContainer<float> &stats);
65
66  /**
67   * Base class for the image container.
68   *
69   * Definition of an n-dimensional data array:
70   *     array of pixel values, size & dimensions
71   *     array of Detection objects
72   */
73
74  class DataArray
75  {
76  public:
77    DataArray();  ///< Basic DataArray constructor
78    DataArray(short int nDim); ///< Basic nDim-dimensional DataArray constructor
79    DataArray(short int nDim, long size);///< Basic nDim-dimensional DataArray constructor, specifying size.
80    DataArray(short int nDim, long *dimensions); ///< Basic nDim-dimensional DataArray constructor, specifying size of dimensions.
81    virtual ~DataArray(); ///< Basic DataArray constructor
82
83    //-----------------------------------------
84    // Obvious inline accessor functions.
85    //
86    long               getDimX(){if(numDim>0) return axisDim[0];else return 0;};
87    long               getDimY(){if(numDim>1) return axisDim[1];else return 1;};
88    long               getDimZ(){if(numDim>2) return axisDim[2];else return 1;};
89    long               getSize(){ return numPixels; };
90    short int          getNumDim(){ return numDim; };
91    virtual float      getPixValue(long pos){ return array[pos]; };
92    virtual void       setPixValue(long pos, float f){array[pos] = f;};
93    Detection          getObject(long number){ return objectList->at(number); };
94    Detection *        pObject(long number){ return &(objectList->at(number));};
95    std::vector <Detection> getObjectList(){ return *objectList; };
96    std::vector <Detection> *pObjectList(){ return objectList; };
97    std::vector <Detection> &ObjectList(){ std::vector<Detection> &rlist = *objectList; return rlist; };
98    long               getNumObj(){ return objectList->size(); };
99
100    /** Delete all objects from the list of detections. */
101    void               clearDetectionList(){
102      //objectList->clear();
103      delete objectList;
104      objectList = new std::vector<Detection>;
105    };
106
107    /** Read a parameter set from file. */
108    int                readParam(std::string paramfile){
109      /**
110       *  Uses Param::readParams() to read parameters from a file.
111       *  \param paramfile The file to be read.
112       */
113      return par.readParams(paramfile);
114    };
115
116    //-----------------------------------------
117    // Related to the various arrays
118    //
119    /**  Return first three dimensional axes. */
120    void               getDim(long &x, long &y, long &z);
121    /** Return array of dimensional sizes.*/
122    void               getDimArray(long *output);
123    long *             getDimArray(){return axisDim;};
124
125    /** Return pixel value array. */
126    void               getArray(float *output);
127    float *            getArray(){return array;};
128
129    /** Save pixel value array. */
130    virtual void       saveArray(float *input, long size);
131
132    //-----------------------------------------
133    // Related to the object lists
134    //
135    /** Adds a single detection to the object list.*/
136    void               addObject(Detection object);
137
138    /** Adds all objects in a detection list to the object list. */
139    void               addObjectList(std::vector <Detection> newlist);   
140
141    /** Add pixel offsets to object coordinates. */
142    void               addObjectOffsets();
143
144    //-----------------------------------------
145    // Parameter list related.
146    //
147    /** Output the Param set.*/
148    void               showParam(std::ostream &stream){ stream << par; };
149    /** Return the Param set.*/
150    Param              getParam(){ return par; };
151    /** Save a Param set to the Cube.*/
152    void               saveParam(Param &newpar){par = newpar;};
153    /** Provides a reference to the Param set.*/
154    Param&             pars(){ Param &rpar = par; return rpar; };
155    /** Is the voxel number given by vox a BLANK value?*/
156    bool               isBlank(int vox);
157
158    // --------------------------------------------
159    // Statistics
160    //
161    /**  Returns the StatsContainer. */
162    Statistics::StatsContainer<float> getStats(){ return Stats; };
163
164    /** Provides a reference to the StatsContainer. */
165    Statistics::StatsContainer<float>& stats(){
166      Statistics::StatsContainer<float> &rstats = Stats;  return rstats;
167    };
168 
169    /** Save a StatsContainer to the Cube. */
170    void saveStats(Statistics::StatsContainer<float> newStats){ Stats = newStats;};
171
172    /** A detection test for value. */
173    bool isDetection(float value);
174
175    /**  A detection test for pixel.  */
176    bool isDetection(long voxel);
177
178
179    /** Output operator for DataArray.*/
180    friend std::ostream& operator<< (std::ostream& theStream, DataArray &array);
181 
182
183  protected:
184    short int                numDim;     ///< Number of dimensions.
185    long                    *axisDim;    ///< Array of axis dimensions of cube
186    bool                     axisDimAllocated; ///< has axisDim been allocated?
187    long                     numPixels;  ///< Total number of pixels in cube.
188    float                   *array;      ///< Array of data.
189    bool                     arrayAllocated; ///< has the array been allocated?
190    std::vector <Detection> *objectList; ///< The list of detected objects.
191    Param                    par;        ///< A parameter list.
192    Statistics::StatsContainer<float> Stats; ///< The statistics for the DataArray.
193  };
194
195
196
197  //=========================================================================
198
199  /**
200   * Definition of an data-cube object (3D):
201   *     a DataArray object limited to dim=3
202   */
203
204  class Cube : public DataArray
205  {
206  public:
207    Cube();                 ///< Basic Cube constructor.
208    Cube(long nPix);        ///< Alternative Cube constructor.
209    Cube(long *dimensions); ///< Alternative Cube constructor.
210    virtual ~Cube();        ///< Basic Cube destructor.
211
212    // INLINE functions -- definitions included after class declaration.
213    /** Is the voxel number given by vox a BLANK value? */
214    bool        isBlank(int vox){ return par.isBlank(array[vox]); };
215
216    /** Is the voxel at (x,y,z) a BLANK value? */
217    bool        isBlank(long x, long y, long z){
218      return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]); };
219
220    /** Does the Cube::recon array exist? */
221    bool        isRecon(){ return reconExists; };
222
223    float       getPixValue(long pos){ return array[pos]; };
224    float       getPixValue(long x, long y, long z){
225      return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
226    short       getDetectMapValue(long pos){ return detectMap[pos]; };
227    short       getDetectMapValue(long x, long y){ return detectMap[y*axisDim[0]+x]; };
228    float       getReconValue(long pos){ return recon[pos]; };
229    float       getReconValue(long x, long y, long z){
230      return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
231    float       getBaselineValue(long pos){ return baseline[pos]; };
232    float       getBaselineValue(long x, long y, long z){
233      return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
234    void        setPixValue(long pos, float f){array[pos] = f;};
235    void        setPixValue(long x, long y, long z, float f){
236      array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
237    void        setDetectMapValue(long pos, short f){ detectMap[pos] = f;};
238    void        setDetectMapValue(long x, long y, short f){ detectMap[y*axisDim[0] + x] = f;};
239    void        setReconValue(long pos, float f){recon[pos] = f;};
240    void        setReconValue(long x, long y, long z, float f){
241      recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f; };
242    void        setReconFlag(bool f){reconExists = f;};
243
244    std::vector<Column::Col> getLogCols(){return logCols;};
245    void        setLogCols(std::vector<Column::Col> C){logCols=C;};
246    std::vector<Column::Col> getFullCols(){return fullCols;};
247    void        setFullCols(std::vector<Column::Col> C){fullCols=C;};
248
249    // additional functions -- in Cubes/cubes.cc
250    /** Allocate memory correctly, with WCS defining the correct axes. */
251    void        initialiseCube(long *dimensions);
252
253    /** Read in a FITS file, with subsection correction. */
254    int         getCube();
255    /** Read in a FITS file, with subsection correction. */
256    int         getMetadata();
257
258    /** Read in command-line options. */
259    //   int         getopts(int argc, char ** argv);
260    int         getopts(int argc, char ** argv){return par.getopts(argc,argv);};
261
262    /** Read in reconstructed & smoothed arrays from FITS files on disk. */
263    void        readSavedArrays();
264
265    /** Save an external array to the Cube's pixel array */
266    void        saveArray(float *input, long size);
267
268    /** Save an external array to the Cube's reconstructed array. */
269    void        saveRecon(float *input, long size);
270
271    /** Save reconstructed array to an external array. */
272    void        getRecon(float *output);
273    float *     getRecon(){return recon; };
274
275    /** Set Milky Way channels to zero. */
276    void        removeMW();
277
278    //------------------------
279    // Statistics for cube
280    //
281
282    /** Calculate the statistics for the Cube (older version). */
283    void        setCubeStatsOld();
284
285    /** Calculate the statistics for the Cube. */
286    void        setCubeStats();
287
288    /** Set up thresholds for the False Discovery Rate routine. */
289    void        setupFDR();
290    /** Set up thresholds for the False Discovery Rate routine using a
291        particular array. */
292    void        setupFDR(float *input);
293
294    /** A detection test for a given voxel. */
295    bool        isDetection(long x, long y, long z);
296
297    //-----------------------------
298    // Dealing with the detections
299    //
300
301    /** Calculate the object fluxes */
302    void        calcObjectFluxes();
303
304    /** Calculate the WCS parameters for each Cube Detection. */
305    void        calcObjectWCSparams();
306    /** Calculate the WCS parameters for each Cube Detection, using flux information in Voxels. */
307    void        calcObjectWCSparams(std::vector< std::vector<PixelInfo::Voxel> > bigVoxList);
308
309    /** Sort the list of detections. */
310    void        sortDetections();
311
312    /** Update the map of detected pixels. */
313    void        updateDetectMap();
314
315    /** Update the map of detected pixels for a given Detection. */
316    void        updateDetectMap(Detection obj);
317
318    /** Clear the map of detected pixels. */
319    void        clearDetectMap(){
320      for(int i=0;i<axisDim[0]*axisDim[1];i++) detectMap[i]=0;
321    };
322
323    /** Find the flux enclosed by a Detection. */
324    float       enclosedFlux(Detection obj);
325
326    /** Set up the output column definitions for the Cube and its
327        Detection list. */
328    void        setupColumns();
329
330    /** Is the object at the edge of the image? */
331    bool        objAtSpatialEdge(Detection obj);
332
333    /** Is the object at an end of the spectrum? */
334    bool        objAtSpectralEdge(Detection obj);
335
336    /** Set warning flags for the detections. */
337    void        setObjectFlags();
338
339    // ----------------------------
340    // Dealing with the WCS
341    //
342    /** Return the FitsHeader object. */
343    FitsHeader  getHead(){ return head; };
344    /** Define the FitsHeader object. */
345    void        setHead(FitsHeader F){head = F;};
346    /** Provide a reference to the FitsHeader object.*/
347    FitsHeader& header(){ FitsHeader &h = head; return h; };
348
349    /** Convert a point from WCS to Pixel coords. */
350    int         wcsToPix(const double *world, double *pix);
351
352    /** Convert a set of points from WCS to Pixel coords. */
353    int         wcsToPix(const double *world, double *pix, const int npts);
354
355    /** Convert a point from Pixel to WCS coords. */
356    int         pixToWCS(const double *pix, double *world);
357
358    /** Convert a set of points from Pixel to WCS coords. */
359    int         pixToWCS(const double *pix, double *world, const int npts);
360
361    //-------------------------------------------
362    // FITS-I/O related functions -- not in cubes.cc
363    //
364    /** Function to read in FITS file.*/
365    int         getMetadata(std::string fname);  // in Cubes/getImage.cc
366    int         getCube(std::string fname);  // in Cubes/getImage.cc
367
368    /** Convert the flux units to something user-specified.*/
369    void        convertFluxUnits(); // in Cubes/getImage.cc
370
371    /** Function to retrieve FITS data array */
372    int         getFITSdata(std::string fname);   // in FitsIO/dataIO.cc
373
374    /** Save a mask array to disk.*/
375    void        saveMaskCube();       // in Cubes/saveImage.cc
376
377    /** Save Smoothed array to disk.*/
378    void        saveSmoothedCube();       // in Cubes/saveImage.cc
379
380    /** Save Reconstructed array to disk. */
381    void        saveReconstructedCube();  // in Cubes/saveImage.cc
382
383    /** Read in reconstructed array from FITS file. */
384    int         readReconCube();  // in Cubes/readRecon.cc
385 
386    /** Read in Hanning-smoothed array from FITS file. */
387    int         readSmoothCube();     // in Cubes/readSmooth.cc 
388
389    //-------------------------------------
390    // Functions that act on the cube
391    //
392
393    /** Remove excess BLANK pixels from spatial edge of cube. */
394    void        trimCube();         // in Cubes/trimImage.cc
395
396    /** Replace BLANK pixels to spatial edge of cube. */
397    void        unTrimCube();       // in Cubes/trimImage.cc
398
399    /** Removes the baselines from the spectra, and stores in Cube::baseline */
400    void        removeBaseline();   // in Cubes/baseline.cc
401
402    /** Replace the baselines stored in Cube::baseline */
403    void        replaceBaseline();  // in Cubes/baseline.cc
404
405    /** Multiply all pixel values by -1. */
406    void        invert();           // in Cubes/invertCube.cc
407
408    /** Undo the inversion, and invert fluxes of all detected objects. */
409    void        reInvert();         // in Cubes/invertCube.cc
410
411    //-------------------------------------
412    // Reconstruction, Searching and Merging functions
413    //
414    // in ATrous/ReconSearch.cc
415    /** Front-end to reconstruction & searching functions.*/
416    void        ReconSearch();
417    /** Switcher to reconstruction functions */
418    void        ReconCube();
419    /** Performs 1-dimensional a trous reconstruction on the Cube. */
420    void        ReconCube1D();
421    /** Performs 2-dimensional a trous reconstruction on the Cube. */
422    void        ReconCube2D();
423    /** Performs 3-dimensional a trous reconstruction on the Cube. */
424    void        ReconCube3D();
425
426    // in Cubes/CubicSearch.cc
427    /** Front-end to the cubic searching routine. */
428    void        CubicSearch();
429
430    // in Cubes/smoothCube.cc
431    /** Smooth the cube with the requested method.*/
432    void        SmoothCube();
433    /** Front-end to the smoothing and searching functions. */
434    void        SmoothSearch();
435    /** A function to spatially smooth the cube and search the result. */
436    void        SpatialSmoothNSearch();
437    /** A function to Hanning-smooth the cube. */
438    void        SpectralSmooth();
439    /** A function to spatially-smooth the cube. */
440    void        SpatialSmooth();
441
442    void        Simple3DSearch(){
443      /**
444       * Basic front-end to the simple 3d searching function -- does
445       * nothing more.
446       *
447       * This function just runs the search3DArraySimple function,
448       * storing the results in the Cube::objectList vector. No stats
449       * are calculated beforehand, and no logging or detection map
450       * updating is done.
451       */
452      *objectList = search3DArraySimple(axisDim,array,par,Stats);
453    };
454
455    void        Simple3DSearchRecon(){
456      /**
457       * Basic front-end to the 3d searching function used in the
458       * reconstruction case -- does nothing more.
459       *
460       * This function just runs the searchReconArraySimple function,
461       * storing the results in the Cube::objectList vector. No stats
462       * are calculated beforehand, and no logging or detection map
463       * updating is done. The recon array is assumed to have been
464       * defined already.
465       */
466      *objectList = searchReconArraySimple(axisDim,array,recon,par,Stats);
467    };
468
469    void        Simple3DSearchSmooth(){
470      /**
471       * Basic front-end to the simple 3d searching function run on the
472       * smoothed array -- does nothing more.
473       *
474       * This function just runs the search3DArraySimple function on the
475       * recon array (which contains the smoothed array), storing the
476       * results in the Cube::objectList vector. No stats are calculated
477       * beforehand, and no logging or detection map updating is
478       * done. The recon array is assumed to have been defined already.
479       */
480      *objectList = search3DArraySimple(axisDim,recon,par,Stats);
481    };
482
483    // in Cubes/Merger.cc
484    /** Merge all objects in the detection list so that only distinct
485        ones are left. */
486    void        ObjectMerger();
487 
488    //-------------------------------------
489    // Text outputting of detected objects.
490    //   in Cubes/detectionIO.cc
491    //
492    /** Set up the output file with parameters and stats. */
493    void        prepareOutputFile();
494
495    /** Write the statistical information to the output file. */
496    void        outputStats();
497
498    /** Output detections to the output file and standard output. */
499    void        outputDetectionList();
500
501    /** Prepare the log file for output. */
502    void        prepareLogFile(int argc, char *argv[]);
503
504    /** Output detections to the log file. */
505    void        logDetectionList();
506
507    /** Output a single detection to the log file. */
508    void        logDetection(Detection obj, int counter);
509
510    /** Output detections to a Karma annotation file. */
511    void        outputDetectionsKarma(std::ostream &stream);
512
513    /** Output detections to a VOTable. */
514    void        outputDetectionsVOTable(std::ostream &stream);
515
516    // ----------------------------------
517    // Graphical plotting of the cube and the detections.
518    //
519    //  in Cubes/plotting.cc
520    /** Plot a spatial map of detections based on number of detected
521        channels. */
522    void        plotDetectionMap(std::string pgDestination);
523
524    /** Plot a spatial map of detections based on 0th moment map of each
525        object. */
526    void        plotMomentMap(std::string pgDestination);
527
528    /** Plot a spatial map of detections based on 0th moment map of each
529        object to a number of PGPLOT devices. */
530    void        plotMomentMap(std::vector<std::string> pgDestination);
531
532    /** Draw WCS axes over a PGPLOT map. */
533    void        plotWCSaxes(int textColour=DUCHAMP_ID_TEXT_COLOUR,
534                            int axisColour=DUCHAMP_WCS_AXIS_COLOUR);
535
536    //  in Cubes/outputSpectra.cc
537    /** Print spectra of each detected object. */
538    void        outputSpectra();
539
540    /** Write out text file of all spectra. */
541    void        writeSpectralData();
542
543    /** Print spectrum of a single object */
544    void        plotSpectrum(int objNum, Plot::SpectralPlot &plot);
545    /** Plot the image cutout for a single object */
546    void        plotSource(Detection obj, Plot::CutoutPlot &plot);
547
548    /** Get the spectral arrays */
549    void        getSpectralArrays(int objNumber, float *specx, float *specy, float *specRecon, float *specBase);
550
551    //  in Cubes/drawMomentCutout.cc
552    /** Draw the 0th moment map for a single object. */
553    void        drawMomentCutout(Detection &object);
554
555    /** Draw a scale bar indicating angular size of the cutout. */
556    void        drawScale(float xstart,float ystart,float channel);
557
558    /** Draw a yellow line around the edge of the spatial extent of
559        pixels. */
560    void        drawFieldEdge();
561
562  private:
563    float      *recon;            ///< reconstructed array - used when
564    ///   doing a trous reconstruction.
565    bool        reconExists;      ///< flag saying whether there is a
566    ///   reconstruction
567    short      *detectMap;        ///< "moment map" - x,y locations of
568    ///   detected pixels
569    float      *baseline;         ///< array of spectral baseline
570    ///   values.
571                             
572    bool        reconAllocated;   ///< have we allocated memory for the
573    ///   recon array?
574    bool        baselineAllocated;///< have we allocated memory for the
575    ///   baseline array?
576    FitsHeader  head;             ///< the WCS and other header
577    ///   information.
578    std::vector<Column::Col> fullCols;    ///< the list of all columns as
579    ///   printed in the results file
580    std::vector<Column::Col> logCols;     ///< the list of columns as printed in
581    ///   the log file
582
583  };
584
585  ////////////
586  //// Cube inline function definitions
587  ////////////
588
589  inline int Cube::wcsToPix(const double *world, double *pix)
590  {
591    /**
592     *  Use the WCS in the FitsHeader to convert from WCS to pixel coords for
593     *   a single point.
594     *  \param world The world coordinates.
595     *  \param pix The returned pixel coordinates.
596     */
597    return this->head.wcsToPix(world,pix);
598  }
599  inline int Cube::wcsToPix(const double *world, double *pix, const int npts)
600  {
601    /**
602     *  Use the WCS in the FitsHeader to convert from WCS to pixel coords for
603     *   a set of points.
604     *  \param world The world coordinates.
605     *  \param pix The returned pixel coordinates.
606     *  \param npts The number of points being converted.
607     */
608    return this->head.wcsToPix(world,pix,npts);
609  }
610  inline int Cube::pixToWCS(const double *pix, double *world)
611  {
612    /**
613     *  Use the WCS in the FitsHeader to convert from pixel to WCS coords for
614     *   a single point.
615     *  \param pix The pixel coordinates.
616     *  \param world The returned world coordinates.
617     */
618    return this->head.pixToWCS(pix,world);
619  }
620  inline int Cube::pixToWCS(const double *pix, double *world, const int npts)
621  {
622    /**
623     *  Use the WCS in the FitsHeader to convert from pixel to WCS coords for
624     *   a set of points.
625     *  \param pix The pixel coordinates.
626     *  \param world The returned world coordinates.
627     *  \param npts The number of points being converted.
628     */
629    return this->head.pixToWCS(pix,world,npts);
630  }
631
632
633  //============================================================================
634
635  /**
636   *  A DataArray object limited to two dimensions, and with some additional
637   *   special functions.
638   *
639   *  It is used primarily for searching a 1- or 2-D array with
640   *   lutz_detect() and spectrumDetect().
641   */
642
643  class Image : public DataArray
644  {
645  public:
646    Image(){numPixels=0; numDim=2;};
647    Image(long nPix);
648    Image(long *dimensions);
649    virtual ~Image(){};
650
651    //--------------------
652    // Defining the array
653    //
654    /** Save an external array to the Cube's pixel array */
655    void      saveArray(float *input, long size);
656
657    /** Extract a spectrum from an array and save to the local pixel array. */
658    void      extractSpectrum(float *Array, long *dim, long pixel);
659
660    /** Extract an image from an array and save to the local pixel array. */
661    void      extractImage(float *Array, long *dim, long channel);
662
663    /** Extract a spectrum from a cube and save to the local pixel array. */
664    void      extractSpectrum(Cube &cube, long pixel);
665
666    /** Extract an image from a cube and save to the local pixel array. */
667    void      extractImage(Cube &cube, long channel);
668
669    //--------------------
670    // Accessing the data.
671    //
672    float     getPixValue(long pos){ return array[pos]; };
673    float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
674    // the next few should have checks against array overflow...
675    void      setPixValue(long pos, float f){array[pos] = f;};
676    void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
677    bool      isBlank(int vox){return par.isBlank(array[vox]);};
678    bool      isBlank(long x,long y){return par.isBlank(array[y*axisDim[0]+x]);};
679
680    //-----------------------
681    // Detection-related
682    //
683    // in Detection/lutz_detect.cc:
684    /** Detect objects in a 2-D image */
685    std::vector<PixelInfo::Object2D> lutz_detect();
686
687    // in Detection/spectrumDetect.cc:
688    /** Detect objects in a 1-D spectrum */
689    std::vector<PixelInfo::Scan> spectrumDetect();
690
691    int       getMinSize(){return minSize;};
692    void      setMinSize(int i){minSize=i;};
693
694    /**  A detection test for a pixel location.  */
695    bool      isDetection(long x, long y){
696      /**
697       * Test whether a pixel (x,y) is a statistically significant detection,
698       * according to the set of statistics in the local StatsContainer object.
699       */
700      long voxel = y*axisDim[0] + x;
701      if(isBlank(x,y)) return false;
702      else return Stats.isDetection(array[voxel]);
703    }; 
704
705    /** Blank out a set of channels marked as being Milky Way channels */
706    void      removeMW();
707
708  private:
709    int       minSize;    ///< the minimum number of pixels for a
710    ///   detection to be accepted.
711  };
712
713
714  /****************************************************************/
715  //////////////////////////////////////////////////////
716  // Prototypes for functions that use above classes
717  //////////////////////////////////////////////////////
718
719  /** Grow an object to a lower threshold */
720  void growObject(Detection &object, Cube &cube);
721
722  /** Draw the edge of the BLANK region on a map.*/
723  void drawBlankEdges(float *dataArray, int xdim, int ydim, Param &par);
724
725}
726
727#endif
Note: See TracBrowser for help on using the repository browser.