source: tags/release-1.1.6/src/Cubes/cubes.hh

Last change on this file was 475, checked in by MatthewWhiting, 16 years ago

Implemented changes to Duchamp to allow the re-plotting of object spectra. This incorporates the functionality of Selavy into Duchamp, so that you only need a single executable.

File size: 26.9 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    /** Return a bool array masking blank pixels: 1=good, 0=blank */
221    bool *      makeBlankMask(){return par.makeBlankMask(array, numPixels);};
222
223    /** Does the Cube::recon array exist? */
224    bool        isRecon(){ return reconExists; };
225
226    float       getPixValue(long pos){ return array[pos]; };
227    float       getPixValue(long x, long y, long z){
228      return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
229    short       getDetectMapValue(long pos){ return detectMap[pos]; };
230    short       getDetectMapValue(long x, long y){ return detectMap[y*axisDim[0]+x]; };
231    float       getReconValue(long pos){ return recon[pos]; };
232    float       getReconValue(long x, long y, long z){
233      return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
234    float       getBaselineValue(long pos){ return baseline[pos]; };
235    float       getBaselineValue(long x, long y, long z){
236      return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
237    void        setPixValue(long pos, float f){array[pos] = f;};
238    void        setPixValue(long x, long y, long z, float f){
239      array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
240    void        setDetectMapValue(long pos, short f){ detectMap[pos] = f;};
241    void        setDetectMapValue(long x, long y, short f){ detectMap[y*axisDim[0] + x] = f;};
242    void        setReconValue(long pos, float f){recon[pos] = f;};
243    void        setReconValue(long x, long y, long z, float f){
244      recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f; };
245    void        setReconFlag(bool f){reconExists = f;};
246
247    std::vector<Column::Col> getLogCols(){return logCols;};
248    void        setLogCols(std::vector<Column::Col> C){logCols=C;};
249    std::vector<Column::Col> getFullCols(){return fullCols;};
250    void        setFullCols(std::vector<Column::Col> C){fullCols=C;};
251
252    // additional functions -- in Cubes/cubes.cc
253    /** Allocate memory correctly, with WCS defining the correct axes. */
254    void        initialiseCube(long *dimensions);
255
256    /** Read in a FITS file, with subsection correction. */
257    int         getCube();
258    /** Read in a FITS file, with subsection correction. */
259    int         getMetadata();
260
261    /** Read in command-line options. */
262    //   int         getopts(int argc, char ** argv);
263    int         getopts(int argc, char ** argv, std::string progname="Duchamp"){return par.getopts(argc,argv,progname);};
264
265    /** Read in reconstructed & smoothed arrays from FITS files on disk. */
266    void        readSavedArrays();
267
268    /** Save an external array to the Cube's pixel array */
269    void        saveArray(float *input, long size);
270
271    /** Save an external array to the Cube's reconstructed array. */
272    void        saveRecon(float *input, long size);
273
274    /** Save reconstructed array to an external array. */
275    void        getRecon(float *output);
276    float *     getRecon(){return recon; };
277
278    /** Set Milky Way channels to zero. */
279    void        removeMW();
280
281    //------------------------
282    // Statistics for cube
283    //
284
285    /** Calculate the statistics for the Cube (older version). */
286    void        setCubeStatsOld();
287
288    /** Calculate the statistics for the Cube. */
289    void        setCubeStats();
290
291    /** Set up thresholds for the False Discovery Rate routine. */
292    void        setupFDR();
293    /** Set up thresholds for the False Discovery Rate routine using a
294        particular array. */
295    void        setupFDR(float *input);
296
297    /** A detection test for a given voxel. */
298    bool        isDetection(long x, long y, long z);
299
300    //-----------------------------
301    // Dealing with the detections
302    //
303
304    /** Calculate the object fluxes */
305    void        calcObjectFluxes();
306
307    /** Calculate the WCS parameters for each Cube Detection. */
308    void        calcObjectWCSparams();
309    /** Calculate the WCS parameters for each Cube Detection, using flux information in Voxels. */
310    void        calcObjectWCSparams(std::vector< std::vector<PixelInfo::Voxel> > bigVoxList);
311
312    /** Sort the list of detections. */
313    void        sortDetections();
314
315    /** Update the map of detected pixels. */
316    void        updateDetectMap();
317
318    /** Update the map of detected pixels for a given Detection. */
319    void        updateDetectMap(Detection obj);
320
321    /** Clear the map of detected pixels. */
322    void        clearDetectMap(){
323      for(int i=0;i<axisDim[0]*axisDim[1];i++) detectMap[i]=0;
324    };
325
326    /** Find the flux enclosed by a Detection. */
327    float       enclosedFlux(Detection obj);
328
329    /** Set up the output column definitions for the Cube and its
330        Detection list. */
331    void        setupColumns();
332
333    /** Is the object at the edge of the image? */
334    bool        objAtSpatialEdge(Detection obj);
335
336    /** Is the object at an end of the spectrum? */
337    bool        objAtSpectralEdge(Detection obj);
338
339    /** Set warning flags for the detections. */
340    void        setObjectFlags();
341
342    // ----------------------------
343    // Dealing with the WCS
344    //
345    /** Return the FitsHeader object. */
346    FitsHeader  getHead(){ return head; };
347    /** Define the FitsHeader object. */
348    void        setHead(FitsHeader F){head = F;};
349    /** Provide a reference to the FitsHeader object.*/
350    FitsHeader& header(){ FitsHeader &h = head; return h; };
351
352    /** Convert a point from WCS to Pixel coords. */
353    int         wcsToPix(const double *world, double *pix);
354
355    /** Convert a set of points from WCS to Pixel coords. */
356    int         wcsToPix(const double *world, double *pix, const int npts);
357
358    /** Convert a point from Pixel to WCS coords. */
359    int         pixToWCS(const double *pix, double *world);
360
361    /** Convert a set of points from Pixel to WCS coords. */
362    int         pixToWCS(const double *pix, double *world, const int npts);
363
364    //-------------------------------------------
365    // FITS-I/O related functions -- not in cubes.cc
366    //
367    /** Function to read in FITS file.*/
368    int         getMetadata(std::string fname);  // in Cubes/getImage.cc
369    int         getCube(std::string fname);  // in Cubes/getImage.cc
370
371    /** Convert the flux units to something user-specified.*/
372    void        convertFluxUnits(); // in Cubes/getImage.cc
373
374    /** Function to retrieve FITS data array */
375    int         getFITSdata(std::string fname);   // in FitsIO/dataIO.cc
376
377    /** Save a mask array to disk.*/
378    void        saveMaskCube();       // in Cubes/saveImage.cc
379
380    /** Save Smoothed array to disk.*/
381    void        saveSmoothedCube();       // in Cubes/saveImage.cc
382
383    /** Save Reconstructed array to disk. */
384    void        saveReconstructedCube();  // in Cubes/saveImage.cc
385
386    /** Read in reconstructed array from FITS file. */
387    int         readReconCube();  // in Cubes/readRecon.cc
388 
389    /** Read in Hanning-smoothed array from FITS file. */
390    int         readSmoothCube();     // in Cubes/readSmooth.cc 
391
392    //-------------------------------------
393    // Functions that act on the cube
394    //
395
396    /** Remove excess BLANK pixels from spatial edge of cube. */
397    void        trimCube();         // in Cubes/trimImage.cc
398
399    /** Replace BLANK pixels to spatial edge of cube. */
400    void        unTrimCube();       // in Cubes/trimImage.cc
401
402    /** Removes the baselines from the spectra, and stores in Cube::baseline */
403    void        removeBaseline();   // in Cubes/baseline.cc
404
405    /** Replace the baselines stored in Cube::baseline */
406    void        replaceBaseline();  // in Cubes/baseline.cc
407
408    /** Multiply all pixel values by -1. */
409    void        invert();           // in Cubes/invertCube.cc
410
411    /** Undo the inversion, and invert fluxes of all detected objects. */
412    void        reInvert();         // in Cubes/invertCube.cc
413
414    //-------------------------------------
415    // Reconstruction, Searching and Merging functions
416    //
417    // in ATrous/ReconSearch.cc
418    /** Front-end to reconstruction & searching functions.*/
419    void        ReconSearch();
420    /** Switcher to reconstruction functions */
421    void        ReconCube();
422    /** Performs 1-dimensional a trous reconstruction on the Cube. */
423    void        ReconCube1D();
424    /** Performs 2-dimensional a trous reconstruction on the Cube. */
425    void        ReconCube2D();
426    /** Performs 3-dimensional a trous reconstruction on the Cube. */
427    void        ReconCube3D();
428
429    // in Cubes/CubicSearch.cc
430    /** Front-end to the cubic searching routine. */
431    void        CubicSearch();
432
433    // in Cubes/smoothCube.cc
434    /** Smooth the cube with the requested method.*/
435    void        SmoothCube();
436    /** Front-end to the smoothing and searching functions. */
437    void        SmoothSearch();
438    /** A function to spatially smooth the cube and search the result. */
439    void        SpatialSmoothNSearch();
440    /** A function to Hanning-smooth the cube. */
441    void        SpectralSmooth();
442    /** A function to spatially-smooth the cube. */
443    void        SpatialSmooth();
444
445    void        Simple3DSearch(){
446      /**
447       * Basic front-end to the simple 3d searching function -- does
448       * nothing more.
449       *
450       * This function just runs the search3DArraySimple function,
451       * storing the results in the Cube::objectList vector. No stats
452       * are calculated beforehand, and no logging or detection map
453       * updating is done.
454       */
455      *objectList = search3DArraySimple(axisDim,array,par,Stats);
456    };
457
458    void        Simple3DSearchRecon(){
459      /**
460       * Basic front-end to the 3d searching function used in the
461       * reconstruction case -- does nothing more.
462       *
463       * This function just runs the searchReconArraySimple function,
464       * storing the results in the Cube::objectList vector. No stats
465       * are calculated beforehand, and no logging or detection map
466       * updating is done. The recon array is assumed to have been
467       * defined already.
468       */
469      *objectList = searchReconArraySimple(axisDim,array,recon,par,Stats);
470    };
471
472    void        Simple3DSearchSmooth(){
473      /**
474       * Basic front-end to the simple 3d searching function run on the
475       * smoothed array -- does nothing more.
476       *
477       * This function just runs the search3DArraySimple function on the
478       * recon array (which contains the smoothed array), storing the
479       * results in the Cube::objectList vector. No stats are calculated
480       * beforehand, and no logging or detection map updating is
481       * done. The recon array is assumed to have been defined already.
482       */
483      *objectList = search3DArraySimple(axisDim,recon,par,Stats);
484    };
485
486    // in Cubes/Merger.cc
487    /** Merge all objects in the detection list so that only distinct
488        ones are left. */
489    void        ObjectMerger();
490 
491    // in Cubes/existingDetections.cc
492    /** Read a previously-created log file to get the detections without searching */
493    int getExistingDetections();
494
495    //-------------------------------------
496    // Text outputting of detected objects.
497    //   in Cubes/detectionIO.cc
498    //
499    /** Set up the output file with parameters and stats. */
500    void        prepareOutputFile();
501
502    /** Write the statistical information to the output file. */
503    void        outputStats();
504
505    /** Output detections to the output file and standard output. */
506    void        outputDetectionList();
507
508    /** Prepare the log file for output. */
509    void        prepareLogFile(int argc, char *argv[]);
510
511    /** Output detections to the log file. */
512    void        logDetectionList();
513
514    /** Output a single detection to the log file. */
515    void        logDetection(Detection obj, int counter);
516
517    /** Output detections to a Karma annotation file. */
518    void        outputDetectionsKarma(std::ostream &stream);
519
520    /** Output detections to a VOTable. */
521    void        outputDetectionsVOTable(std::ostream &stream);
522
523    // ----------------------------------
524    // Graphical plotting of the cube and the detections.
525    //
526    //  in Cubes/plotting.cc
527    /** Plot a spatial map of detections based on number of detected
528        channels. */
529    void        plotDetectionMap(std::string pgDestination);
530
531    /** Plot a spatial map of detections based on 0th moment map of each
532        object. */
533    void        plotMomentMap(std::string pgDestination);
534
535    /** Plot a spatial map of detections based on 0th moment map of each
536        object to a number of PGPLOT devices. */
537    void        plotMomentMap(std::vector<std::string> pgDestination);
538
539    /** Draw WCS axes over a PGPLOT map. */
540    void        plotWCSaxes(int textColour=DUCHAMP_ID_TEXT_COLOUR,
541                            int axisColour=DUCHAMP_WCS_AXIS_COLOUR);
542
543    //  in Cubes/outputSpectra.cc
544    /** Print spectra of each detected object. */
545    void        outputSpectra();
546
547    /** Write out text file of all spectra. */
548    void        writeSpectralData();
549
550    /** Print spectrum of a single object */
551    void        plotSpectrum(int objNum, Plot::SpectralPlot &plot);
552    /** Plot the image cutout for a single object */
553    void        plotSource(Detection obj, Plot::CutoutPlot &plot);
554
555    /** Get the spectral arrays */
556    void        getSpectralArrays(int objNumber, float *specx, float *specy, float *specRecon, float *specBase);
557
558    //  in Cubes/drawMomentCutout.cc
559    /** Draw the 0th moment map for a single object. */
560    void        drawMomentCutout(Detection &object);
561
562    /** Draw a scale bar indicating angular size of the cutout. */
563    void        drawScale(float xstart,float ystart,float channel);
564
565    /** Draw a yellow line around the edge of the spatial extent of
566        pixels. */
567    void        drawFieldEdge();
568
569  private:
570    float      *recon;            ///< reconstructed array - used when
571    ///   doing a trous reconstruction.
572    bool        reconExists;      ///< flag saying whether there is a
573    ///   reconstruction
574    short      *detectMap;        ///< "moment map" - x,y locations of
575    ///   detected pixels
576    float      *baseline;         ///< array of spectral baseline
577    ///   values.
578                             
579    bool        reconAllocated;   ///< have we allocated memory for the
580    ///   recon array?
581    bool        baselineAllocated;///< have we allocated memory for the
582    ///   baseline array?
583    FitsHeader  head;             ///< the WCS and other header
584    ///   information.
585    std::vector<Column::Col> fullCols;    ///< the list of all columns as
586    ///   printed in the results file
587    std::vector<Column::Col> logCols;     ///< the list of columns as printed in
588    ///   the log file
589
590  };
591
592  ////////////
593  //// Cube inline function definitions
594  ////////////
595
596  inline int Cube::wcsToPix(const double *world, double *pix)
597  {
598    /**
599     *  Use the WCS in the FitsHeader to convert from WCS to pixel coords for
600     *   a single point.
601     *  \param world The world coordinates.
602     *  \param pix The returned pixel coordinates.
603     */
604    return this->head.wcsToPix(world,pix);
605  }
606  inline int Cube::wcsToPix(const double *world, double *pix, const int npts)
607  {
608    /**
609     *  Use the WCS in the FitsHeader to convert from WCS to pixel coords for
610     *   a set of points.
611     *  \param world The world coordinates.
612     *  \param pix The returned pixel coordinates.
613     *  \param npts The number of points being converted.
614     */
615    return this->head.wcsToPix(world,pix,npts);
616  }
617  inline int Cube::pixToWCS(const double *pix, double *world)
618  {
619    /**
620     *  Use the WCS in the FitsHeader to convert from pixel to WCS coords for
621     *   a single point.
622     *  \param pix The pixel coordinates.
623     *  \param world The returned world coordinates.
624     */
625    return this->head.pixToWCS(pix,world);
626  }
627  inline int Cube::pixToWCS(const double *pix, double *world, const int npts)
628  {
629    /**
630     *  Use the WCS in the FitsHeader to convert from pixel to WCS coords for
631     *   a set of points.
632     *  \param pix The pixel coordinates.
633     *  \param world The returned world coordinates.
634     *  \param npts The number of points being converted.
635     */
636    return this->head.pixToWCS(pix,world,npts);
637  }
638
639
640  //============================================================================
641
642  /**
643   *  A DataArray object limited to two dimensions, and with some additional
644   *   special functions.
645   *
646   *  It is used primarily for searching a 1- or 2-D array with
647   *   lutz_detect() and spectrumDetect().
648   */
649
650  class Image : public DataArray
651  {
652  public:
653    Image(){numPixels=0; numDim=2;};
654    Image(long nPix);
655    Image(long *dimensions);
656    virtual ~Image(){};
657
658    //--------------------
659    // Defining the array
660    //
661    /** Save an external array to the Cube's pixel array */
662    void      saveArray(float *input, long size);
663
664    /** Extract a spectrum from an array and save to the local pixel array. */
665    void      extractSpectrum(float *Array, long *dim, long pixel);
666
667    /** Extract an image from an array and save to the local pixel array. */
668    void      extractImage(float *Array, long *dim, long channel);
669
670    /** Extract a spectrum from a cube and save to the local pixel array. */
671    void      extractSpectrum(Cube &cube, long pixel);
672
673    /** Extract an image from a cube and save to the local pixel array. */
674    void      extractImage(Cube &cube, long channel);
675
676    //--------------------
677    // Accessing the data.
678    //
679    float     getPixValue(long pos){ return array[pos]; };
680    float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
681    // the next few should have checks against array overflow...
682    void      setPixValue(long pos, float f){array[pos] = f;};
683    void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
684    bool      isBlank(int vox){return par.isBlank(array[vox]);};
685    bool      isBlank(long x,long y){return par.isBlank(array[y*axisDim[0]+x]);};
686
687    //-----------------------
688    // Detection-related
689    //
690    // in Detection/lutz_detect.cc:
691    /** Detect objects in a 2-D image */
692    std::vector<PixelInfo::Object2D> lutz_detect();
693
694    // in Detection/spectrumDetect.cc:
695    /** Detect objects in a 1-D spectrum */
696    std::vector<PixelInfo::Scan> spectrumDetect();
697
698    int       getMinSize(){return minSize;};
699    void      setMinSize(int i){minSize=i;};
700
701    /**  A detection test for a pixel location.  */
702    bool      isDetection(long x, long y){
703      /**
704       * Test whether a pixel (x,y) is a statistically significant detection,
705       * according to the set of statistics in the local StatsContainer object.
706       */
707      long voxel = y*axisDim[0] + x;
708      if(isBlank(x,y)) return false;
709      else return Stats.isDetection(array[voxel]);
710    }; 
711
712    /** Blank out a set of channels marked as being Milky Way channels */
713    void      removeMW();
714
715  private:
716    int       minSize;    ///< the minimum number of pixels for a
717    ///   detection to be accepted.
718  };
719
720
721}
722
723#endif
Note: See TracBrowser for help on using the repository browser.