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