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

Last change on this file since 863 was 863, checked in by MatthewWhiting, 13 years ago

Adding in versions of the parametrisation functions that take std:maps of Voxels (suggested in #123).

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