source: tags/release-1.1.9/src/Cubes/cubes.hh

Last change on this file was 700, checked in by MatthewWhiting, 14 years ago

Making use of the returned OUTCOME values.

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