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

Last change on this file since 582 was 582, checked in by MatthewWhiting, 15 years ago

Separating out the functionality of the searching from the Image classes, making the search functions more generic. They now accept just a vector of bools, indicating "detection" or not. The calling functions in the classes have been renamed to findSources1D (was spectrumDetect()) and findSources2D (was lutz_detect()).

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