[3] | 1 | #include <iostream> |
---|
| 2 | #include <iomanip> |
---|
| 3 | #include <ATrous/atrous.hh> |
---|
[74] | 4 | #include <Utils/utils.hh> |
---|
[3] | 5 | #include <param.hh> |
---|
| 6 | |
---|
[86] | 7 | void baselineSubtract(long numSpec, long specLength, float *originalCube, |
---|
| 8 | float *baselineValues, Param &par) |
---|
[3] | 9 | { |
---|
| 10 | /** |
---|
[86] | 11 | * baselineSubtract(long numSpec, long specLength, float *originalCube, |
---|
| 12 | * float *baselineValues, Param &par) |
---|
[3] | 13 | * |
---|
[86] | 14 | * A routine to find the baseline of spectra in a cube (spectral direction |
---|
| 15 | * assumed to be the third dimension) and subtract it off the original. |
---|
| 16 | * The original cube has numSpec spatial pixels, each containing a spectrum |
---|
| 17 | * of length specLength. |
---|
[3] | 18 | * The original cube is read in, and returned with the baseline removed. |
---|
| 19 | * This baseline is stored in the array baselineValues. |
---|
| 20 | * The Param variable par is needed to test for blank pixels -- these are kept as blank. |
---|
| 21 | */ |
---|
| 22 | extern Filter reconFilter; |
---|
| 23 | float *spec = new float[specLength]; |
---|
| 24 | float *thisBaseline = new float[specLength]; |
---|
| 25 | int minscale = par.getMinScale(); |
---|
| 26 | par.setMinScale(reconFilter.getNumScales(specLength)); |
---|
| 27 | float atrouscut = par.getAtrousCut(); |
---|
| 28 | par.setAtrousCut(1); |
---|
| 29 | bool flagVerb = par.isVerbose(); |
---|
| 30 | par.setVerbosity(false); |
---|
| 31 | |
---|
| 32 | std::cout << "| |" << std::flush; |
---|
| 33 | for(int pix=0; pix<numSpec; pix++){ // for each spatial pixel... |
---|
| 34 | |
---|
| 35 | if(flagVerb && ((100*(pix+1)/numSpec)%5 == 0) ){ |
---|
| 36 | std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|"; |
---|
| 37 | for(int i=0;i<(100*(pix+1)/numSpec)/5;i++) std::cout << "#"; |
---|
| 38 | for(int i=(100*(pix+1)/numSpec)/5;i<20;i++) std::cout << " "; |
---|
| 39 | std::cout << "|" << std::flush; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | for(int z=0; z<specLength; z++) |
---|
| 43 | spec[z] = originalCube[z*numSpec + pix]; |
---|
| 44 | |
---|
| 45 | atrous1DReconstruct(specLength,spec,thisBaseline,par); |
---|
| 46 | |
---|
| 47 | for(int z=0; z<specLength; z++) { |
---|
| 48 | baselineValues[z*numSpec+pix] = thisBaseline[z]; |
---|
| 49 | if(!par.isBlank(originalCube[z*numSpec+pix])) |
---|
| 50 | originalCube[z*numSpec+pix] = originalCube[z*numSpec+pix] - baselineValues[z*numSpec+pix]; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | } |
---|
| 54 | if(flagVerb) std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"; |
---|
| 55 | |
---|
| 56 | par.setMinScale(minscale); |
---|
| 57 | par.setAtrousCut(atrouscut); |
---|
| 58 | par.setVerbosity(flagVerb); |
---|
| 59 | |
---|
| 60 | delete [] spec; |
---|
| 61 | delete [] thisBaseline; |
---|
| 62 | |
---|
| 63 | } |
---|
| 64 | |
---|
[43] | 65 | void getBaseline(long size, float *input, float *baseline, Param &par) |
---|
| 66 | { |
---|
| 67 | /** |
---|
| 68 | * getBaseline(long size, float *input, float *baseline, Param &par) |
---|
| 69 | * A function to find the baseline of an input (1-D) spectrum. |
---|
| 70 | * Uses the a trous reconstruction, keeping only the highest two scales, to |
---|
| 71 | * reconstruct the baseline. |
---|
| 72 | * To avoid contamination by very strong signals, the input spectrum is trimmed |
---|
| 73 | * at 8*MADFM above the median before reconstruction. This reduces the strong |
---|
| 74 | * dips created by the presence of very strong signals. |
---|
| 75 | * The baseline array is returned -- no change is made to the input array. |
---|
| 76 | */ |
---|
[3] | 77 | |
---|
[43] | 78 | extern Filter reconFilter; |
---|
| 79 | int minscale = par.getMinScale(); |
---|
| 80 | par.setMinScale(reconFilter.getNumScales(size)); |
---|
| 81 | float atrouscut = par.getAtrousCut(); |
---|
| 82 | par.setAtrousCut(1); |
---|
| 83 | bool flagVerb = par.isVerbose(); |
---|
| 84 | par.setVerbosity(false); |
---|
| 85 | |
---|
| 86 | float *spec = new float[size]; |
---|
| 87 | float med,sig; |
---|
| 88 | findMedianStats(input,size,med,sig); |
---|
| 89 | float threshold = 8. * sig; |
---|
| 90 | for(int i=0;i<size;i++) { |
---|
| 91 | if(fabsf(input[i]-med)>threshold){ |
---|
| 92 | if(input[i]>med) spec[i] = med + threshold; |
---|
| 93 | else spec[i] = med - threshold; |
---|
| 94 | } |
---|
| 95 | else spec[i] = input[i]; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | // atrous1DReconstruct(size, input, baseline, par); |
---|
| 99 | atrous1DReconstruct(size, spec, baseline, par); |
---|
| 100 | |
---|
| 101 | par.setMinScale(minscale); |
---|
| 102 | par.setAtrousCut(atrouscut); |
---|
| 103 | par.setVerbosity(flagVerb); |
---|
| 104 | |
---|
| 105 | delete [] spec; |
---|
| 106 | |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
[74] | 110 | void getBaseline(long size, float *input, float *baseline) |
---|
[3] | 111 | { |
---|
| 112 | /** |
---|
[74] | 113 | * getBaseline(long size, float *input, float *baseline) |
---|
| 114 | * A function to find the baseline of an input (1-D) spectrum. |
---|
| 115 | * This version is designed for programs not using Param classes -- it keeps |
---|
| 116 | * that side of things hidden from the user. |
---|
| 117 | * Uses the a trous reconstruction, keeping only the highest two scales, to |
---|
| 118 | * reconstruct the baseline. |
---|
| 119 | * To avoid contamination by very strong signals, the input spectrum is trimmed |
---|
| 120 | * at 8*MADFM above the median before reconstruction. This reduces the strong |
---|
| 121 | * dips created by the presence of very strong signals. |
---|
| 122 | * The baseline array is returned -- no change is made to the input array. |
---|
[3] | 123 | */ |
---|
| 124 | |
---|
[74] | 125 | extern Filter reconFilter; |
---|
| 126 | Param par; |
---|
| 127 | par.setMinScale(reconFilter.getNumScales(size)); |
---|
| 128 | par.setAtrousCut(1); |
---|
| 129 | par.setVerbosity(false); |
---|
[43] | 130 | |
---|
[74] | 131 | float *spec = new float[size]; |
---|
| 132 | float med,sig; |
---|
| 133 | findMedianStats(input,size,med,sig); |
---|
| 134 | float threshold = 8. * sig; |
---|
| 135 | for(int i=0;i<size;i++) { |
---|
| 136 | if(fabsf(input[i]-med)>threshold){ |
---|
| 137 | if(input[i]>med) spec[i] = med + threshold; |
---|
| 138 | else spec[i] = med - threshold; |
---|
[43] | 139 | } |
---|
[74] | 140 | else spec[i] = input[i]; |
---|
| 141 | } |
---|
[43] | 142 | |
---|
[74] | 143 | atrous1DReconstruct(size, spec, baseline, par); |
---|
[43] | 144 | |
---|
[74] | 145 | delete [] spec; |
---|
[43] | 146 | |
---|
[3] | 147 | } |
---|
| 148 | |
---|