[299] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // baseline.cc: Removing and replacing the spectral baseline of a Cube. |
---|
| 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 | // ----------------------------------------------------------------------- |
---|
[74] | 28 | #include <iostream> |
---|
| 29 | #include <iomanip> |
---|
[393] | 30 | #include <duchamp/param.hh> |
---|
| 31 | #include <duchamp/ATrous/atrous.hh> |
---|
| 32 | #include <duchamp/Cubes/cubes.hh> |
---|
| 33 | #include <duchamp/Utils/feedback.hh> |
---|
[74] | 34 | |
---|
[378] | 35 | namespace duchamp |
---|
[74] | 36 | { |
---|
| 37 | |
---|
[378] | 38 | void Cube::removeBaseline() |
---|
| 39 | { |
---|
| 40 | /** |
---|
| 41 | * A front-end to the getBaseline routine, specialised for the |
---|
| 42 | * Cube data structure. Calls getBaseline on each spectrum individually. |
---|
| 43 | * Upon exit, the original array minus its spectral baseline is stored |
---|
| 44 | * in this->array and the baseline is in this->baseline. |
---|
| 45 | * If the reconstructed array exists, the baseline is subtracted from |
---|
| 46 | * it as well. |
---|
| 47 | */ |
---|
[74] | 48 | |
---|
[378] | 49 | float *spec = new float[this->axisDim[2]]; |
---|
| 50 | float *thisBaseline = new float[this->axisDim[2]]; |
---|
| 51 | int numSpec = this->axisDim[0]*this->axisDim[1]; |
---|
[74] | 52 | |
---|
[378] | 53 | ProgressBar bar; |
---|
| 54 | if(this->par.isVerbose()) bar.init(numSpec); |
---|
| 55 | for(int pix=0; pix<numSpec; pix++){ // for each spatial pixel... |
---|
[74] | 56 | |
---|
[378] | 57 | if(this->par.isVerbose() ) bar.update(pix+1); |
---|
[74] | 58 | |
---|
[378] | 59 | for(int z=0; z<this->axisDim[2]; z++) |
---|
| 60 | spec[z] = this->array[z*numSpec + pix]; |
---|
[74] | 61 | |
---|
[378] | 62 | getBaseline(this->axisDim[2], spec, thisBaseline, this->par); |
---|
[74] | 63 | |
---|
[378] | 64 | for(int z=0; z<this->axisDim[2]; z++) { |
---|
| 65 | this->baseline[z*numSpec+pix] = thisBaseline[z]; |
---|
| 66 | if(!par.isBlank(this->array[z*numSpec+pix])){ |
---|
| 67 | this->array[z*numSpec+pix] -= thisBaseline[z]; |
---|
| 68 | if(this->reconExists) this->recon[z*numSpec+pix] -= thisBaseline[z]; |
---|
| 69 | } |
---|
| 70 | } |
---|
[86] | 71 | |
---|
[378] | 72 | } |
---|
| 73 | |
---|
| 74 | delete [] spec; |
---|
| 75 | delete [] thisBaseline; |
---|
[74] | 76 | |
---|
[378] | 77 | if(this->par.isVerbose()) bar.remove(); |
---|
| 78 | } |
---|
[74] | 79 | |
---|
[86] | 80 | |
---|
| 81 | |
---|
[378] | 82 | void Cube::replaceBaseline() |
---|
| 83 | { |
---|
| 84 | /** |
---|
| 85 | * A routine to replace the baseline flux on the reconstructed array |
---|
| 86 | * (if it exists) and the fluxes of each of the detected objects (if any). |
---|
| 87 | */ |
---|
[74] | 88 | |
---|
[378] | 89 | if(this->par.getFlagBaseline()){ |
---|
[74] | 90 | |
---|
| 91 | for(int i=0;i<this->numPixels;i++){ |
---|
| 92 | if(!(this->par.isBlank(this->array[i]))) |
---|
[378] | 93 | this->array[i] += this->baseline[i]; |
---|
[74] | 94 | } |
---|
[378] | 95 | |
---|
| 96 | if(this->reconExists){ |
---|
| 97 | // if we made a reconstruction, we need to add the baseline back in |
---|
| 98 | // for plotting purposes |
---|
| 99 | for(int i=0;i<this->numPixels;i++){ |
---|
| 100 | if(!(this->par.isBlank(this->array[i]))) |
---|
| 101 | this->recon[i] += this->baseline[i]; |
---|
| 102 | } |
---|
| 103 | } |
---|
[74] | 104 | |
---|
[378] | 105 | for(int obj=0;obj<this->objectList->size();obj++){ |
---|
| 106 | // for each detection, correct the flux calculations. |
---|
| 107 | this->objectList->at(obj).calcFluxes(this->array, this->axisDim); |
---|
[258] | 108 | |
---|
[378] | 109 | } |
---|
| 110 | |
---|
[74] | 111 | } |
---|
[378] | 112 | |
---|
[74] | 113 | } |
---|
| 114 | |
---|
| 115 | } |
---|