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

Last change on this file since 754 was 741, checked in by MatthewWhiting, 14 years ago

Minor tweaks for performance and building improvements

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