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 248 : FreqAxisTVI::FreqAxisTVI( ViImplementation2 * inputVii) : 38 248 : TransformingVi2 (inputVii) 39 : { 40 248 : initialize(); 41 : 42 : // Initialize attached VisBuffer 43 248 : setVisBuffer(createAttachedVisBuffer (VbRekeyable)); 44 : 45 248 : return; 46 0 : } 47 : 48 : // ----------------------------------------------------------------------- 49 : // 50 : // ----------------------------------------------------------------------- 51 248 : 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 248 : return; 63 248 : } 64 : 65 : 66 : // ----------------------------------------------------------------------- 67 : // 68 : // ----------------------------------------------------------------------- 69 248 : void FreqAxisTVI::initialize() 70 : { 71 : 72 248 : 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 248 : formChanMap(); 80 248 : return; 81 : } 82 : 83 : // ----------------------------------------------------------------------- 84 : // 85 : // ----------------------------------------------------------------------- 86 248 : void FreqAxisTVI::formChanMap() 87 : { 88 : // This triggers realization of the channel selection 89 248 : inputVii_p->originChunks(); 90 : 91 : // Refresh map 92 248 : spwInpChanIdxMap_p.clear(); 93 : 94 1168 : for (Int ispw = 0; ispw < inputVii_p->nSpectralWindows(); ++ispw) 95 : { 96 : // TBD trap unselected spws with a continue 97 : 98 920 : Vector<Int> chansV; 99 920 : chansV.reference(inputVii_p->getChannels(0.0, -1, ispw, 0)); 100 : 101 920 : Int nChan = chansV.nelements(); 102 920 : if (nChan > 0) 103 : { 104 920 : spwInpChanIdxMap_p[ispw].clear(); // creates ispw's map 105 263268 : for (Int ich = 0; ich < nChan; ++ich) 106 : { 107 262348 : spwInpChanIdxMap_p[ispw].push_back(chansV[ich]); // accum into map 108 : } 109 : } 110 920 : } // ispw 111 : 112 248 : return; 113 : } 114 : 115 : // ----------------------------------------------------------------------- 116 : // 117 : // ----------------------------------------------------------------------- 118 18376 : void FreqAxisTVI::origin() 119 : { 120 : // Drive underlying ViImplementation2 121 18376 : getVii()->origin(); 122 : 123 18376 : configureShapes(); 124 : 125 : // Synchronize own VisBuffer 126 18376 : configureNewSubchunk(); 127 : 128 18376 : return; 129 : } 130 : 131 : // ----------------------------------------------------------------------- 132 : // 133 : // ----------------------------------------------------------------------- 134 208086 : void FreqAxisTVI::next() 135 : { 136 : // Drive underlying ViImplementation2 137 208086 : getVii()->next(); 138 : 139 208086 : configureShapes(); 140 : 141 : // Synchronize own VisBuffer 142 208086 : configureNewSubchunk(); 143 : 144 208086 : return; 145 : } 146 : 147 228693 : void FreqAxisTVI::configureShapes() 148 : { 149 228693 : Vector<Int> spws; 150 228693 : spectralWindows(spws); 151 228693 : Vector<Int> channels = getChannels (0, 0, spws (0) , msId()); 152 228693 : nChannPerShape_ = casacore::Vector<casacore::Int> (1, channels.nelements()); 153 228693 : } 154 : 155 : // ----------------------------------------------------------------------- 156 : // 157 : // ----------------------------------------------------------------------- 158 18456 : Bool FreqAxisTVI::existsColumn (VisBufferComponent2 id) const 159 : { 160 : 161 : Bool ret; 162 18456 : 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 18456 : default: 175 : { 176 18456 : ret = getVii()->existsColumn(id); 177 18456 : break; 178 : } 179 : } 180 : 181 18456 : return ret; 182 : } 183 : 184 : // ----------------------------------------------------------------------- 185 : // 186 : // ----------------------------------------------------------------------- 187 228693 : Vector<Int> FreqAxisTVI::getChannels (Double,Int,Int spectralWindowId,Int) const 188 : { 189 228693 : Vector<Int> ret(spwOutChanNumMap_p[spectralWindowId]); 190 : 191 2821520 : for (uInt chanIdx = 0; chanIdx<spwOutChanNumMap_p[spectralWindowId];chanIdx++) 192 : { 193 2592827 : ret(chanIdx) = chanIdx; 194 : } 195 : 196 228693 : return ret; 197 0 : } 198 : 199 : const casacore::Vector<casacore::Int>& 200 228693 : FreqAxisTVI::nChannelsPerShape () const 201 : { 202 228693 : return nChannPerShape_; 203 : } 204 : 205 : 206 : // ----------------------------------------------------------------------- 207 : // 208 : // ----------------------------------------------------------------------- 209 9 : void FreqAxisTVI::writeFlagRow (const Vector<Bool> & flag) 210 : { 211 9 : getVii()->writeFlagRow(flag); 212 9 : } 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 192168 : void FreqAxisTVI::weight (Matrix<Float> & weight) const 230 : { 231 192168 : if (weightSpectrumExists()) // Defined by each derived class or inner TVI 232 : { 233 : // Get flags and weightSpectrum from own VisBuffer 234 190391 : const Cube<Bool> &flags = getVisBuffer()->flagCube(); 235 190391 : const Cube<Float> &weightSpectrum = getVisBuffer()->weightSpectrum(); 236 : 237 : // Calculate output weight 238 190391 : accumulateWeightCube(weightSpectrum,flags,weight); 239 : } 240 : else 241 : { 242 1777 : getVii()->weight (weight); 243 : } 244 : 245 192168 : return; 246 : } 247 : 248 : // ----------------------------------------------------------------------- 249 : // 250 : // ----------------------------------------------------------------------- 251 195125 : void FreqAxisTVI::sigma (Matrix<Float> & sigma) const 252 : { 253 195125 : if (sigmaSpectrumExists()) 254 : { 255 : // Get flags and sigmaSpectrum from own VisBuffer 256 190175 : const Cube<Bool> &flags = getVisBuffer()->flagCube(); 257 190175 : const Cube<Float> &sigmaSpectrum = getVisBuffer()->sigmaSpectrum(); 258 : 259 : // Calculate output sigma 260 190175 : accumulateWeightCube(sigmaSpectrum,flags,sigma); 261 : } 262 : else 263 : { 264 4950 : getVii()->sigma (sigma); 265 : } 266 : 267 195125 : return; 268 : } 269 : 270 : } //# NAMESPACE VI - END 271 : 272 : } //# NAMESPACE CASA - END 273 : 274 :