1269 - | |
1270 - | if(vb.polFrame()==MSIter::Linear) { |
1271 - | StokesImageUtil::changeCStokesRep(theImage, StokesImageUtil::LINEAR); |
1272 - | } |
1273 - | else { |
1274 - | StokesImageUtil::changeCStokesRep(theImage, StokesImageUtil::CIRCULAR); |
1275 - | } |
1276 - | Bool useCorrected= !(vi.msColumns().correctedData().isNull()); |
1277 - | if((type==FTMachine::CORRECTED) && (!useCorrected)) |
1278 - | type=FTMachine::OBSERVED; |
1279 - | Bool normalize=true; |
1280 - | if(type==FTMachine::COVERAGE) |
1281 - | normalize=false; |
1282 - | |
1283 - | Int Nx=theImage.shape()(0); |
1284 - | Int Ny=theImage.shape()(1); |
1285 - | Int Npol=theImage.shape()(2); |
1286 - | Int Nchan=theImage.shape()(3); |
1287 - | Double memtot=Double(HostInfo::memoryTotal(true))*1024.0; |
1288 - | Int nchanInMem=Int(memtot/2.0/8.0/Double(Nx*Ny*Npol)); |
1289 - | Int nloop=nchanInMem >= Nchan ? 1 : Nchan/nchanInMem+1; |
1290 - | ImageInterface<Complex> *imCopy=NULL; |
1291 - | IPosition blc(theImage.shape()); |
1292 - | IPosition trc(theImage.shape()); |
1293 - | blc-=blc; |
1294 - | trc=theImage.shape(); |
1295 - | trc-=1; |
1296 - | if(nloop==1) { |
1297 - | imCopy=& theImage; |
1298 - | nchanInMem=Nchan; |
1299 - | } |
1300 - | else |
1301 - | logIO() << "Not enough memory to image in one go \n will process the image in " |
1302 - | << nloop |
1303 - | << " sections " |
1304 - | << LogIO::POST; |
1305 - | |
1266 + | auto cStokesRep = (vb.polFrame() == MSIter::Linear) ? |
1267 + | StokesImageUtil::LINEAR : StokesImageUtil::CIRCULAR; |
1268 + | StokesImageUtil::changeCStokesRep(theImage, cStokesRep); |
1269 + | |
1270 + | |
1271 + | auto imageShape = theImage.shape(); |
1272 + | auto Npol = imageShape(2); |
1273 + | auto Nchan = imageShape(3); |
1307 - | Matrix<Float> wgtcopy(Npol, Nchan); |
1308 - | |
1309 - | Bool isWgtZero=true; |
1310 - | for (Int k=0; k < nloop; ++k){ |
1311 - | Int bchan=k*nchanInMem; |
1312 - | Int echan=(k+1)*nchanInMem < Nchan ? (k+1)*nchanInMem-1 : Nchan-1; |
1313 - | |
1314 - | if(nloop > 1) { |
1315 - | blc[3]=bchan; |
1316 - | trc[3]=echan; |
1317 - | Slicer sl(blc, trc, Slicer::endIsLast); |
1318 - | imCopy=new SubImage<Complex>(theImage, sl, true); |
1319 - | wgtcopy.resize(npol, echan-bchan+1); |
1320 - | } |
1321 - | vi.originChunks(); |
1322 - | vi.origin(); |
1323 - | initializeToSky(*imCopy,wgtcopy,vb); |
1276 + | initializeToSky(theImage,weight,vb); |
1277 + | |
1278 + | for (vi.originChunks(); vi.moreChunks(); vi.nextChunk()) { |
1279 + | for (vi.origin(); vi.more(); vi++) { |
1280 + | FTMachine::Type actualType; |
1281 + | Bool doPSF; |
1282 + | getParamsForFTMachineType(vi, inType, doPSF, actualType); |
1283 + | setupVisBufferForFTMachineType(actualType,vb); |
1284 + | constexpr Int allVbRows = -1; |
1285 + | put(vb, allVbRows, doPSF, actualType); |
1286 + | } |
1287 + | } |
1288 + | finalizeToSky(); |
1334 - | |
1335 - | for (vi.originChunks();vi.moreChunks();vi.nextChunk()) { |
1336 - | for (vi.origin(); vi.more(); vi++) { |
1337 - | |
1338 - | switch(type) { |
1339 - | case FTMachine::RESIDUAL: |
1340 - | vb.visCube()=vb.correctedVisCube(); |
1341 - | vb.visCube()-=vb.modelVisCube(); |
1342 - | put(vb, -1, false); |
1343 - | break; |
1344 - | case FTMachine::MODEL: |
1345 - | put(vb, -1, false, FTMachine::MODEL); |
1346 - | break; |
1347 - | case FTMachine::CORRECTED: |
1348 - | put(vb, -1, false, FTMachine::CORRECTED); |
1349 - | break; |
1350 - | case FTMachine::PSF: |
1351 - | vb.visCube()=Complex(1.0,0.0); |
1352 - | put(vb, -1, true, FTMachine::PSF); |
1353 - | break; |
1354 - | case FTMachine::COVERAGE: |
1355 - | vb.visCube()=Complex(1.0); |
1356 - | put(vb, -1, true, FTMachine::COVERAGE); |
1357 - | break; |
1358 - | case FTMachine::OBSERVED: |
1359 - | default: |
1360 - | put(vb, -1, false, FTMachine::OBSERVED); |
1361 - | break; |
1362 - | } |
1363 - | } |
1364 - | } |
1365 - | finalizeToSky(); |
1366 - | |
1367 - | getImage(wgtcopy, normalize); |
1368 - | if(max(wgtcopy)==0.0){ |
1369 - | if(nloop > 1) |
1370 - | logIO() << LogIO::WARN |
1371 - | << "No useful data in SDGrid: weights all zero for image slice " << k |
1372 - | << LogIO::POST; |
1373 - | } |
1374 - | else |
1375 - | isWgtZero=false; |
1376 - | |
1377 - | weight(Slice(0, Npol), Slice(bchan, echan-bchan+1))=wgtcopy; |
1378 - | if(nloop >1) delete imCopy; |
1379 - | } |
1380 - | if(isWgtZero) |
1381 - | logIO() << LogIO::SEVERE |
1382 - | << "No useful data in SDGrid: weights all zero" |
1383 - | << LogIO::POST; |
1384 - | } |
1294 + | |
1295 + | if (allEQ(weight,0.0f)) { |
1296 + | logIO() << LogIO::SEVERE |
1297 + | << "No useful data in SDGrid: all weights are zero" |
1298 + | << LogIO::POST; |
1299 + | } |
1300 + | } |
1302 + | void SDGrid::getParamsForFTMachineType(const ROVisibilityIterator& vi, FTMachine::Type in_type, |
1303 + | casacore::Bool& out_dopsf, FTMachine::Type& out_type) const { |
1304 + | |
1305 + | |
1306 + | auto haveCorrectedData = not (vi.msColumns().correctedData().isNull()); |
1307 + | auto tunedType = |
1308 + | ((in_type == FTMachine::CORRECTED) && (not haveCorrectedData)) ? |
1309 + | FTMachine::OBSERVED : in_type; |
1310 + | |
1311 + | |
1312 + | switch(tunedType) { |
1313 + | case FTMachine::RESIDUAL: |
1314 + | case FTMachine::MODEL: |
1315 + | case FTMachine::CORRECTED: |
1316 + | out_dopsf = false; |
1317 + | out_type = tunedType; |
1318 + | break; |
1319 + | case FTMachine::PSF: |
1320 + | case FTMachine::COVERAGE: |
1321 + | out_dopsf = true; |
1322 + | out_type = tunedType; |
1323 + | break; |
1324 + | default: |
1325 + | out_dopsf = false; |
1326 + | out_type = FTMachine::OBSERVED; |
1327 + | break; |
1328 + | } |
1329 + | } |