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

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

Allowing initialisation of a cube without the allocation of the pixel arrays. This comes from askapsoft development - not used by normal Duchamp work.

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