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