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

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

Changes aimed at calculating the w50 and w20 parameters, and printing them out.

File size: 26.7 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){return par.getopts(argc,argv);};
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    //-------------------------------------
492    // Text outputting of detected objects.
493    //   in Cubes/detectionIO.cc
494    //
495    /** Set up the output file with parameters and stats. */
496    void        prepareOutputFile();
497
498    /** Write the statistical information to the output file. */
499    void        outputStats();
500
501    /** Output detections to the output file and standard output. */
502    void        outputDetectionList();
503
504    /** Prepare the log file for output. */
505    void        prepareLogFile(int argc, char *argv[]);
506
507    /** Output detections to the log file. */
508    void        logDetectionList();
509
510    /** Output a single detection to the log file. */
511    void        logDetection(Detection obj, int counter);
512
513    /** Output detections to a Karma annotation file. */
514    void        outputDetectionsKarma(std::ostream &stream);
515
516    /** Output detections to a VOTable. */
517    void        outputDetectionsVOTable(std::ostream &stream);
518
519    // ----------------------------------
520    // Graphical plotting of the cube and the detections.
521    //
522    //  in Cubes/plotting.cc
523    /** Plot a spatial map of detections based on number of detected
524        channels. */
525    void        plotDetectionMap(std::string pgDestination);
526
527    /** Plot a spatial map of detections based on 0th moment map of each
528        object. */
529    void        plotMomentMap(std::string pgDestination);
530
531    /** Plot a spatial map of detections based on 0th moment map of each
532        object to a number of PGPLOT devices. */
533    void        plotMomentMap(std::vector<std::string> pgDestination);
534
535    /** Draw WCS axes over a PGPLOT map. */
536    void        plotWCSaxes(int textColour=DUCHAMP_ID_TEXT_COLOUR,
537                            int axisColour=DUCHAMP_WCS_AXIS_COLOUR);
538
539    //  in Cubes/outputSpectra.cc
540    /** Print spectra of each detected object. */
541    void        outputSpectra();
542
543    /** Write out text file of all spectra. */
544    void        writeSpectralData();
545
546    /** Print spectrum of a single object */
547    void        plotSpectrum(int objNum, Plot::SpectralPlot &plot);
548    /** Plot the image cutout for a single object */
549    void        plotSource(Detection obj, Plot::CutoutPlot &plot);
550
551    /** Get the spectral arrays */
552    void        getSpectralArrays(int objNumber, float *specx, float *specy, float *specRecon, float *specBase);
553
554    //  in Cubes/drawMomentCutout.cc
555    /** Draw the 0th moment map for a single object. */
556    void        drawMomentCutout(Detection &object);
557
558    /** Draw a scale bar indicating angular size of the cutout. */
559    void        drawScale(float xstart,float ystart,float channel);
560
561    /** Draw a yellow line around the edge of the spatial extent of
562        pixels. */
563    void        drawFieldEdge();
564
565  private:
566    float      *recon;            ///< reconstructed array - used when
567    ///   doing a trous reconstruction.
568    bool        reconExists;      ///< flag saying whether there is a
569    ///   reconstruction
570    short      *detectMap;        ///< "moment map" - x,y locations of
571    ///   detected pixels
572    float      *baseline;         ///< array of spectral baseline
573    ///   values.
574                             
575    bool        reconAllocated;   ///< have we allocated memory for the
576    ///   recon array?
577    bool        baselineAllocated;///< have we allocated memory for the
578    ///   baseline array?
579    FitsHeader  head;             ///< the WCS and other header
580    ///   information.
581    std::vector<Column::Col> fullCols;    ///< the list of all columns as
582    ///   printed in the results file
583    std::vector<Column::Col> logCols;     ///< the list of columns as printed in
584    ///   the log file
585
586  };
587
588  ////////////
589  //// Cube inline function definitions
590  ////////////
591
592  inline int Cube::wcsToPix(const double *world, double *pix)
593  {
594    /**
595     *  Use the WCS in the FitsHeader to convert from WCS to pixel coords for
596     *   a single point.
597     *  \param world The world coordinates.
598     *  \param pix The returned pixel coordinates.
599     */
600    return this->head.wcsToPix(world,pix);
601  }
602  inline int Cube::wcsToPix(const double *world, double *pix, const int npts)
603  {
604    /**
605     *  Use the WCS in the FitsHeader to convert from WCS to pixel coords for
606     *   a set of points.
607     *  \param world The world coordinates.
608     *  \param pix The returned pixel coordinates.
609     *  \param npts The number of points being converted.
610     */
611    return this->head.wcsToPix(world,pix,npts);
612  }
613  inline int Cube::pixToWCS(const double *pix, double *world)
614  {
615    /**
616     *  Use the WCS in the FitsHeader to convert from pixel to WCS coords for
617     *   a single point.
618     *  \param pix The pixel coordinates.
619     *  \param world The returned world coordinates.
620     */
621    return this->head.pixToWCS(pix,world);
622  }
623  inline int Cube::pixToWCS(const double *pix, double *world, const int npts)
624  {
625    /**
626     *  Use the WCS in the FitsHeader to convert from pixel to WCS coords for
627     *   a set of points.
628     *  \param pix The pixel coordinates.
629     *  \param world The returned world coordinates.
630     *  \param npts The number of points being converted.
631     */
632    return this->head.pixToWCS(pix,world,npts);
633  }
634
635
636  //============================================================================
637
638  /**
639   *  A DataArray object limited to two dimensions, and with some additional
640   *   special functions.
641   *
642   *  It is used primarily for searching a 1- or 2-D array with
643   *   lutz_detect() and spectrumDetect().
644   */
645
646  class Image : public DataArray
647  {
648  public:
649    Image(){numPixels=0; numDim=2;};
650    Image(long nPix);
651    Image(long *dimensions);
652    virtual ~Image(){};
653
654    //--------------------
655    // Defining the array
656    //
657    /** Save an external array to the Cube's pixel array */
658    void      saveArray(float *input, long size);
659
660    /** Extract a spectrum from an array and save to the local pixel array. */
661    void      extractSpectrum(float *Array, long *dim, long pixel);
662
663    /** Extract an image from an array and save to the local pixel array. */
664    void      extractImage(float *Array, long *dim, long channel);
665
666    /** Extract a spectrum from a cube and save to the local pixel array. */
667    void      extractSpectrum(Cube &cube, long pixel);
668
669    /** Extract an image from a cube and save to the local pixel array. */
670    void      extractImage(Cube &cube, long channel);
671
672    //--------------------
673    // Accessing the data.
674    //
675    float     getPixValue(long pos){ return array[pos]; };
676    float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
677    // the next few should have checks against array overflow...
678    void      setPixValue(long pos, float f){array[pos] = f;};
679    void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
680    bool      isBlank(int vox){return par.isBlank(array[vox]);};
681    bool      isBlank(long x,long y){return par.isBlank(array[y*axisDim[0]+x]);};
682
683    //-----------------------
684    // Detection-related
685    //
686    // in Detection/lutz_detect.cc:
687    /** Detect objects in a 2-D image */
688    std::vector<PixelInfo::Object2D> lutz_detect();
689
690    // in Detection/spectrumDetect.cc:
691    /** Detect objects in a 1-D spectrum */
692    std::vector<PixelInfo::Scan> spectrumDetect();
693
694    int       getMinSize(){return minSize;};
695    void      setMinSize(int i){minSize=i;};
696
697    /**  A detection test for a pixel location.  */
698    bool      isDetection(long x, long y){
699      /**
700       * Test whether a pixel (x,y) is a statistically significant detection,
701       * according to the set of statistics in the local StatsContainer object.
702       */
703      long voxel = y*axisDim[0] + x;
704      if(isBlank(x,y)) return false;
705      else return Stats.isDetection(array[voxel]);
706    }; 
707
708    /** Blank out a set of channels marked as being Milky Way channels */
709    void      removeMW();
710
711  private:
712    int       minSize;    ///< the minimum number of pixels for a
713    ///   detection to be accepted.
714  };
715
716
717}
718
719#endif
Note: See TracBrowser for help on using the repository browser.