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

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

Changing the documentation comments to match the askapsoft style. Also have split ChanMap? and Object3D into separate files.

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