[299] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // cubes_extended.cc: Extra member functions for the Cube class, that |
---|
| 3 | // depend on extra classes. |
---|
| 4 | // ----------------------------------------------------------------------- |
---|
| 5 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 6 | // |
---|
| 7 | // This program is free software; you can redistribute it and/or modify it |
---|
| 8 | // under the terms of the GNU General Public License as published by the |
---|
| 9 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 10 | // option) any later version. |
---|
| 11 | // |
---|
| 12 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 13 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 15 | // for more details. |
---|
| 16 | // |
---|
| 17 | // You should have received a copy of the GNU General Public License |
---|
| 18 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 19 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 20 | // |
---|
| 21 | // Correspondence concerning Duchamp may be directed to: |
---|
| 22 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 23 | // Postal address: Dr. Matthew Whiting |
---|
| 24 | // Australia Telescope National Facility, CSIRO |
---|
| 25 | // PO Box 76 |
---|
| 26 | // Epping NSW 1710 |
---|
| 27 | // AUSTRALIA |
---|
| 28 | // ----------------------------------------------------------------------- |
---|
[224] | 29 | #include <unistd.h> |
---|
| 30 | #include <iostream> |
---|
| 31 | #include <iomanip> |
---|
| 32 | #include <vector> |
---|
| 33 | #include <algorithm> |
---|
| 34 | #include <string> |
---|
| 35 | #include <math.h> |
---|
| 36 | |
---|
[394] | 37 | #include <wcslib/wcs.h> |
---|
[224] | 38 | |
---|
[393] | 39 | #include <duchamp/duchamp.hh> |
---|
| 40 | #include <duchamp/param.hh> |
---|
| 41 | #include <duchamp/fitsHeader.hh> |
---|
| 42 | #include <duchamp/Cubes/cubes.hh> |
---|
[1123] | 43 | #include <duchamp/FitsIO/ReadExistingRecon.hh> |
---|
| 44 | #include <duchamp/FitsIO/ReadExistingSmooth.hh> |
---|
[393] | 45 | #include <duchamp/Detection/detection.hh> |
---|
[1061] | 46 | #include <duchamp/Outputs/columns.hh> |
---|
[393] | 47 | #include <duchamp/Utils/utils.hh> |
---|
| 48 | #include <duchamp/Utils/mycpgplot.hh> |
---|
| 49 | #include <duchamp/Utils/Statistics.hh> |
---|
[224] | 50 | using namespace mycpgplot; |
---|
| 51 | using namespace Statistics; |
---|
| 52 | |
---|
[378] | 53 | namespace duchamp |
---|
[224] | 54 | { |
---|
[378] | 55 | |
---|
| 56 | void Cube::sortDetections() |
---|
| 57 | { |
---|
[528] | 58 | /// @details |
---|
| 59 | /// A front end to the sort-by functions. |
---|
[571] | 60 | /// If there is a good WCS, the detection list is sorted by the requested parameter. |
---|
[528] | 61 | /// Otherwise, it is sorted by increasing z-pixel value. |
---|
| 62 | /// The ID numbers are then re-calculated. |
---|
[224] | 63 | |
---|
[571] | 64 | // if(this->head.isWCS()) SortByVel(*this->objectList); |
---|
| 65 | // else SortByZ(*this->objectList); |
---|
| 66 | if(!this->head.isWCS()){ |
---|
| 67 | if(this->par.getSortingParam()=="ra"){ |
---|
[974] | 68 | DUCHAMPWARN("sortDetections","No good WCS, so sorting by xvalue"); |
---|
| 69 | SortDetections(*this->objectList, "xvalue"); |
---|
[571] | 70 | } |
---|
| 71 | else if(this->par.getSortingParam()=="dec"){ |
---|
[974] | 72 | DUCHAMPWARN("sortDetections","No good WCS, so sorting by yvalue"); |
---|
| 73 | SortDetections(*this->objectList, "yvalue"); |
---|
[571] | 74 | } |
---|
| 75 | else if(this->par.getSortingParam()=="vel" || this->par.getSortingParam()=="w50"){ |
---|
[974] | 76 | DUCHAMPWARN("sortDetections","No good WCS, so sorting by zvalue"); |
---|
| 77 | SortDetections(*this->objectList, "zvalue"); |
---|
[571] | 78 | } |
---|
[844] | 79 | else { |
---|
| 80 | SortDetections(*this->objectList, this->par.getSortingParam()); |
---|
| 81 | } |
---|
[571] | 82 | } |
---|
| 83 | else SortDetections(*this->objectList, this->par.getSortingParam()); |
---|
[623] | 84 | for(size_t i=0; i<this->objectList->size();i++) |
---|
[378] | 85 | this->objectList->at(i).setID(i+1); |
---|
[224] | 86 | |
---|
[378] | 87 | } |
---|
| 88 | //-------------------------------------------------------------------- |
---|
[224] | 89 | |
---|
[378] | 90 | void Cube::readSavedArrays() |
---|
| 91 | { |
---|
[528] | 92 | /// @details |
---|
| 93 | /// This function reads in reconstructed and/or smoothed arrays that have |
---|
| 94 | /// been saved on disk in FITS files. |
---|
| 95 | /// To do this it calls the functions Cube::readReconCube() and |
---|
| 96 | /// Cube::readSmoothCube(). |
---|
| 97 | /// The Param set is consulted to determine which of these arrays are needed. |
---|
[224] | 98 | |
---|
[378] | 99 | // If the reconstructed array is to be read in from disk |
---|
| 100 | if( this->par.getFlagReconExists() && this->par.getFlagATrous() ){ |
---|
| 101 | std::cout << "Reading reconstructed array: "<<std::endl; |
---|
[1096] | 102 | ReadExistingRecon reconReader(this); |
---|
| 103 | if( reconReader.read() == FAILURE){ |
---|
[913] | 104 | DUCHAMPWARN("Duchamp", "Could not read in existing reconstructed array. Will perform reconstruction using assigned parameters."); |
---|
[378] | 105 | this->par.setFlagReconExists(false); |
---|
| 106 | } |
---|
| 107 | else std::cout << "Reconstructed array available.\n"; |
---|
[224] | 108 | } |
---|
| 109 | |
---|
[378] | 110 | if( this->par.getFlagSmoothExists() && this->par.getFlagSmooth() ){ |
---|
| 111 | std::cout << "Reading smoothed array: "<<std::endl; |
---|
[1096] | 112 | ReadExistingSmooth smoothReader(this); |
---|
| 113 | if( smoothReader.read() == FAILURE){ |
---|
[913] | 114 | DUCHAMPWARN("Duchamp", "Could not read in existing smoothed array. Will smooth the cube using assigned parameters."); |
---|
[378] | 115 | this->par.setFlagSmoothExists(false); |
---|
| 116 | } |
---|
| 117 | else std::cout << "Smoothed array available.\n"; |
---|
[224] | 118 | } |
---|
[378] | 119 | |
---|
[224] | 120 | } |
---|
[378] | 121 | |
---|
[224] | 122 | } |
---|