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