Line data Source code
1 : //# FreqAxisTVI.h: This file contains the implementation of the FreqAxisTVI class. 2 : //# 3 : //# CASA - Common Astronomy Software Applications (http://casa.nrao.edu/) 4 : //# Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved. 5 : //# Copyright (C) European Southern Observatory, 2011, All rights reserved. 6 : //# 7 : //# This library is free software; you can redistribute it and/or 8 : //# modify it under the terms of the GNU Lesser General Public 9 : //# License as published by the Free software Foundation; either 10 : //# version 2.1 of the License, or (at your option) any later version. 11 : //# 12 : //# This library is distributed in the hope that it will be useful, 13 : //# but WITHOUT ANY WARRANTY, without even the implied warranty of 14 : //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 : //# Lesser General Public License for more details. 16 : //# 17 : //# You should have received a copy of the GNU Lesser General Public 18 : //# License along with this library; if not, write to the Free Software 19 : //# Foundation, Inc., 59 Temple Place, Suite 330, Boston, 20 : //# MA 02111-1307 USA 21 : //# $Id: $ 22 : 23 : #include <mstransform/TVI/FreqAxisTVI.h> 24 : 25 : using namespace casacore; 26 : namespace casa { //# NAMESPACE CASA - BEGIN 27 : 28 : namespace vi { //# NAMESPACE VI - BEGIN 29 : 30 : ////////////////////////////////////////////////////////////////////////// 31 : // FreqAxisTVI class 32 : ////////////////////////////////////////////////////////////////////////// 33 : 34 : // ----------------------------------------------------------------------- 35 : // 36 : // ----------------------------------------------------------------------- 37 247 : FreqAxisTVI::FreqAxisTVI( ViImplementation2 * inputVii) : 38 247 : TransformingVi2 (inputVii) 39 : { 40 247 : initialize(); 41 : 42 : // Initialize attached VisBuffer 43 247 : setVisBuffer(createAttachedVisBuffer (VbRekeyable)); 44 : 45 247 : return; 46 : } 47 : 48 : // ----------------------------------------------------------------------- 49 : // 50 : // ----------------------------------------------------------------------- 51 247 : FreqAxisTVI::~FreqAxisTVI() 52 : { 53 : // The parent class destructor (~TransformingVi2) deletes the inner 54 : // ViImplementation2 object. However if it might have been already 55 : // deleted at the top level context 56 : // 2/8/2016 (jagonzal): As per request from George M. (via CAS-8220) 57 : // I allow TransformingVi2 destructor to delete its inner input VI; 58 : // This relies on the application layer that produces the inner VI not 59 : // deleting it which can be guaranteed when using the Factory pattern. 60 : // inputVii_p = NULL; 61 : 62 247 : return; 63 247 : } 64 : 65 : 66 : // ----------------------------------------------------------------------- 67 : // 68 : // ----------------------------------------------------------------------- 69 247 : void FreqAxisTVI::initialize() 70 : { 71 : 72 247 : if (inputVii_p == nullptr) 73 0 : return; 74 : 75 : //Create a map with the input SPWs and their channels. 76 : //Note that this access directly the information provided by the previous 77 : //layer and it is no longer based on the original MS selection, which 78 : //for this particular layer might not make any sense (see CAS-9679). 79 247 : formChanMap(); 80 247 : return; 81 : } 82 : 83 : // ----------------------------------------------------------------------- 84 : // 85 : // ----------------------------------------------------------------------- 86 247 : void FreqAxisTVI::formChanMap() 87 : { 88 : // This triggers realization of the channel selection 89 247 : inputVii_p->originChunks(); 90 : 91 : // Refresh map 92 247 : spwInpChanIdxMap_p.clear(); 93 : 94 1163 : for (Int ispw = 0; ispw < inputVii_p->nSpectralWindows(); ++ispw) 95 : { 96 : // TBD trap unselected spws with a continue 97 : 98 1832 : Vector<Int> chansV; 99 916 : chansV.reference(inputVii_p->getChannels(0.0, -1, ispw, 0)); 100 : 101 916 : Int nChan = chansV.nelements(); 102 916 : if (nChan > 0) 103 : { 104 916 : spwInpChanIdxMap_p[ispw].clear(); // creates ispw's map 105 263232 : for (Int ich = 0; ich < nChan; ++ich) 106 : { 107 262316 : spwInpChanIdxMap_p[ispw].push_back(chansV[ich]); // accum into map 108 : } 109 : } 110 : } // ispw 111 : 112 247 : return; 113 : } 114 : 115 : // ----------------------------------------------------------------------- 116 : // 117 : // ----------------------------------------------------------------------- 118 18351 : void FreqAxisTVI::origin() 119 : { 120 : // Drive underlying ViImplementation2 121 18351 : getVii()->origin(); 122 : 123 18351 : configureShapes(); 124 : 125 : // Synchronize own VisBuffer 126 18351 : configureNewSubchunk(); 127 : 128 18351 : return; 129 : } 130 : 131 : // ----------------------------------------------------------------------- 132 : // 133 : // ----------------------------------------------------------------------- 134 207390 : void FreqAxisTVI::next() 135 : { 136 : // Drive underlying ViImplementation2 137 207390 : getVii()->next(); 138 : 139 207390 : configureShapes(); 140 : 141 : // Synchronize own VisBuffer 142 207390 : configureNewSubchunk(); 143 : 144 207390 : return; 145 : } 146 : 147 227972 : void FreqAxisTVI::configureShapes() 148 : { 149 455944 : Vector<Int> spws; 150 227972 : spectralWindows(spws); 151 227972 : Vector<Int> channels = getChannels (0, 0, spws (0) , msId()); 152 227972 : nChannPerShape_ = casacore::Vector<casacore::Int> (1, channels.nelements()); 153 227972 : } 154 : 155 : // ----------------------------------------------------------------------- 156 : // 157 : // ----------------------------------------------------------------------- 158 18306 : Bool FreqAxisTVI::existsColumn (VisBufferComponent2 id) const 159 : { 160 : 161 : Bool ret; 162 18306 : switch (id) 163 : { 164 0 : case VisBufferComponent2::WeightSpectrum: 165 : { 166 0 : ret = true; 167 0 : break; 168 : } 169 0 : case VisBufferComponent2::SigmaSpectrum: 170 : { 171 0 : ret = true; 172 0 : break; 173 : } 174 18306 : default: 175 : { 176 18306 : ret = getVii()->existsColumn(id); 177 18306 : break; 178 : } 179 : } 180 : 181 18306 : return ret; 182 : } 183 : 184 : // ----------------------------------------------------------------------- 185 : // 186 : // ----------------------------------------------------------------------- 187 227972 : Vector<Int> FreqAxisTVI::getChannels (Double,Int,Int spectralWindowId,Int) const 188 : { 189 227972 : Vector<Int> ret(spwOutChanNumMap_p[spectralWindowId]); 190 : 191 2820078 : for (uInt chanIdx = 0; chanIdx<spwOutChanNumMap_p[spectralWindowId];chanIdx++) 192 : { 193 2592106 : ret(chanIdx) = chanIdx; 194 : } 195 : 196 227972 : return ret; 197 : } 198 : 199 : const casacore::Vector<casacore::Int>& 200 227972 : FreqAxisTVI::nChannelsPerShape () const 201 : { 202 227972 : return nChannPerShape_; 203 : } 204 : 205 : 206 : // ----------------------------------------------------------------------- 207 : // 208 : // ----------------------------------------------------------------------- 209 12 : void FreqAxisTVI::writeFlagRow (const Vector<Bool> & flag) 210 : { 211 12 : getVii()->writeFlagRow(flag); 212 12 : } 213 : 214 : // ----------------------------------------------------------------------- 215 : // 216 : // ----------------------------------------------------------------------- 217 19790 : void FreqAxisTVI::flagRow (Vector<Bool> & flagRow) const 218 : { 219 : // Get flagCube from own VisBuffer 220 19790 : const Cube<Bool> &flagCube = getVisBuffer()->flagCube(); 221 : 222 : // Calculate output flagRow 223 19790 : accumulateFlagCube(flagCube,flagRow); 224 19790 : } 225 : 226 : // ----------------------------------------------------------------------- 227 : // 228 : // ----------------------------------------------------------------------- 229 191472 : void FreqAxisTVI::weight (Matrix<Float> & weight) const 230 : { 231 191472 : if (weightSpectrumExists()) // Defined by each derived class or inner TVI 232 : { 233 : // Get flags and weightSpectrum from own VisBuffer 234 189695 : const Cube<Bool> &flags = getVisBuffer()->flagCube(); 235 189695 : const Cube<Float> &weightSpectrum = getVisBuffer()->weightSpectrum(); 236 : 237 : // Calculate output weight 238 189695 : accumulateWeightCube(weightSpectrum,flags,weight); 239 : } 240 : else 241 : { 242 1777 : getVii()->weight (weight); 243 : } 244 : 245 191472 : return; 246 : } 247 : 248 : // ----------------------------------------------------------------------- 249 : // 250 : // ----------------------------------------------------------------------- 251 194429 : void FreqAxisTVI::sigma (Matrix<Float> & sigma) const 252 : { 253 194429 : if (sigmaSpectrumExists()) 254 : { 255 : // Get flags and sigmaSpectrum from own VisBuffer 256 189479 : const Cube<Bool> &flags = getVisBuffer()->flagCube(); 257 189479 : const Cube<Float> &sigmaSpectrum = getVisBuffer()->sigmaSpectrum(); 258 : 259 : // Calculate output sigma 260 189479 : accumulateWeightCube(sigmaSpectrum,flags,sigma); 261 : } 262 : else 263 : { 264 4950 : getVii()->sigma (sigma); 265 : } 266 : 267 194429 : return; 268 : } 269 : 270 : } //# NAMESPACE VI - END 271 : 272 : } //# NAMESPACE CASA - END 273 : 274 :