Commits
Takeshi Nakazato authored c3d98a9e0c9 Merge
451 451 | freqSpws_p.push_back(make_pair(key, spwId)); |
452 452 | frameSel.add(spwId, freqBeg, freqEnd); |
453 453 | } |
454 454 | CountedPtr<vi::FrequencySelections> copyFsels=fselections_p->clone(); |
455 455 | uInt nMSs=copyFsels->size() <=msId ? msId+1 : copyFsels->size(); |
456 456 | //cerr << "nms " << nMSs << endl; |
457 457 | fselections_p=new FrequencySelections(); |
458 458 | for (uInt k=0; k < nMSs ; ++k){ |
459 459 | if(k==uInt(key)){ |
460 460 | fselections_p->add(frameSel); |
461 - | //cerr <<"framesel " << frameSel.toString() << endl; |
461 + | //cerr <<"adding framesel " << frameSel.toString() << endl; |
462 462 | } |
463 463 | else{ |
464 464 | const FrequencySelectionUsingFrame& thissel= static_cast<const FrequencySelectionUsingFrame &> (copyFsels->get(k)); |
465 465 | //cerr <<"framesel orig " << thissel.toString() << endl; |
466 466 | fselections_p->add(thissel); |
467 467 | |
468 468 | } |
469 469 | } |
470 470 | |
471 471 | |
472 472 | |
473 473 | } |
474 474 | |
475 475 | void SynthesisImagerVi2::tuneChunk(const Int gmap){ |
476 476 | |
477 477 | |
478 478 | CoordinateSystem cs=itsMappers.imageStore(gmap)->getCSys(); |
479 479 | IPosition imshape=itsMappers.imageStore(gmap)->getShape(); |
480 480 | /////For some reason imagestore returns 0 channel image sometimes |
481 481 | //// |
482 - | if(imshape(3) < 1) |
482 + | if(imshape(3) < 1) { |
483 483 | return; |
484 + | } |
484 485 | Double minFreq=SpectralImageUtil::worldFreq(cs, 0.0); |
485 486 | Double maxFreq=SpectralImageUtil::worldFreq(cs,imshape(3)-1); |
486 487 | |
487 488 | if(maxFreq < minFreq){ |
488 489 | Double tmp=minFreq; |
489 490 | minFreq=maxFreq; |
490 491 | maxFreq=tmp; |
491 492 | } |
493 + | |
492 494 | Int spectralIndex=cs.findCoordinate(Coordinate::SPECTRAL); |
493 495 | SpectralCoordinate spectralCoord=cs.spectralCoordinate(spectralIndex); |
496 + | maxFreq+=fabs(spectralCoord.increment()(0))/2.0; |
497 + | minFreq-=fabs(spectralCoord.increment()(0))/2.0; |
498 + | if(minFreq < 0.0) minFreq=0.0; |
494 499 | MFrequency::Types intype=spectralCoord.frequencySystem(True); |
500 + | |
495 501 | if(!VisBufferUtil::getFreqRangeFromRange(minFreq, maxFreq, intype, minFreq, maxFreq, *vi_p, selFreqFrame_p)){ |
496 502 | //Do not retune if conversion did not happen |
497 503 | return; |
498 504 | } |
499 505 | |
500 506 | maxFreq+=fabs(spectralCoord.increment()(0))/2.0; |
501 507 | minFreq-=fabs(spectralCoord.increment()(0))/2.0; |
502 508 | if(minFreq < 0.0) minFreq=0.0; |
503 509 | |
504 510 | auto copyFreqBegs=freqBegs_p; |
505 511 | auto copyFreqEnds=freqEnds_p; |
506 512 | auto copyFreqSpws= freqSpws_p; |
507 - | |
513 + | ///////////////TESTOO |
514 + | //cerr << std::setprecision(12) << "AFTER maxFreq " << maxFreq << " minFreq " << minFreq << endl; |
515 + | //for (Int k =0 ; k < (fselections_p->size()) ; ++k){ |
516 + | // cerr << k << (fselections_p->get(k)).toString() << endl; |
517 + | // } |
518 + | /////////////////////////////////////// |
519 + | ///TESTOO |
520 + | // andFreqSelection(-1, -1, minFreq, maxFreq, MFrequency::TOPO); |
508 521 | andFreqSelection(-1, -1, minFreq, maxFreq, selFreqFrame_p); |
509 522 | |
510 523 | vi_p->setFrequencySelection (*fselections_p); |
511 524 | |
512 525 | freqBegs_p=copyFreqBegs; |
513 526 | freqEnds_p=copyFreqEnds; |
514 527 | freqSpws_p=copyFreqSpws; |
515 528 | |
516 529 | |
517 530 | |
1082 1095 | } |
1083 1096 | }// setting model to zero |
1084 1097 | |
1085 1098 | |
1086 1099 | for(Int gmap=0;gmap<itsMappers.nMappers();gmap++) |
1087 1100 | { |
1088 1101 | os << "Running major cycle for chunk : " << gmap << LogIO::POST; |
1089 1102 | |
1090 1103 | SynthesisUtilMethods::getResource("Start Major Cycle for mapper"+String::toString(gmap)); |
1091 1104 | CountedPtr<vi::FrequencySelections> copyFsels=fselections_p->clone(); |
1105 + | ///CAS-12132 create a new visiter for each chunk |
1106 + | createVisSet(writeAccess_p); |
1107 + | //////////////////////// |
1092 1108 | vi::VisBuffer2* vb=vi_p->getVisBuffer(); |
1109 + | /// Careful where tunechunk |
1110 + | tuneChunk(gmap); |
1111 + | |
1093 1112 | vi_p->originChunks(); |
1094 1113 | vi_p->origin(); |
1095 - | tuneChunk(gmap); |
1114 + | |
1096 1115 | Double numcoh=0; |
1097 1116 | for (uInt k=0; k< mss_p.nelements(); ++k) |
1098 1117 | numcoh+=Double(mss_p[k]->nrow()); |
1099 1118 | |
1100 1119 | |
1101 1120 | ProgressMeter pm(1.0, numcoh, |
1102 1121 | dopsf?"Gridding Weights and PSF":"Major Cycle", "","","",true); |
1103 1122 | Int cohDone=0; |
1104 1123 | |
1105 1124 | |
1106 1125 | itsMappers.getFTM2(gmap, False)->reset(); |
1107 1126 | itsMappers.getFTM2(gmap, True)->reset(); |
1108 1127 | |
1109 1128 | if(!dopsf){ |
1110 1129 | itsMappers.initializeDegrid(*vb, gmap); |
1111 1130 | //itsMappers.getMapper(gmap)->initializeDegrid(*vb); |
1112 1131 | } |
1113 1132 | itsMappers.initializeGrid(*vb,dopsf, gmap); |
1114 1133 | //itsMappers.getMapper(gmap)->initializeGrid(*vb,dopsf); |
1115 1134 | |
1116 1135 | SynthesisUtilMethods::getResource("After initialize for mapper"+String::toString(gmap)); |
1136 + | Int iterNum=0; |
1117 1137 | |
1138 + | |
1118 1139 | for (vi_p->originChunks(); vi_p->moreChunks();vi_p->nextChunk()) |
1119 1140 | { |
1120 1141 | |
1121 1142 | for (vi_p->origin(); vi_p->more(); vi_p->next()) |
1122 1143 | { |
1123 1144 | //if (SynthesisUtilMethods::validate(*vb)==SynthesisUtilMethods::NOVALIDROWS) break; // No valid rows in this VB |
1124 1145 | // cerr << "nRows "<< vb->nRow() << " " << max(vb->visCube()) << endl; |
1125 1146 | if (SynthesisUtilMethods::validate(*vb)!=SynthesisUtilMethods::NOVALIDROWS) |
1126 1147 | { |
1148 + | |
1127 1149 | if(!dopsf) { |
1128 1150 | if(resetModel==False) |
1129 1151 | { |
1130 1152 | Cube<Complex> mod(vb->nCorrelations(), vb->nChannels(), vb->nRows(), Complex(0.0)); |
1131 1153 | vb->setVisCubeModel(mod); |
1132 1154 | } |
1133 1155 | itsMappers.degrid(*vb, savevirtualmodel, gmap ); |
1134 1156 | //itsMappers.getMapper(gmap)->degrid(*vb); //, savevirtualmodel ); |
1135 1157 | if(savemodelcolumn && writeAccess_p ){ |
1136 1158 | vi_p->writeVisModel(vb->visCubeModel()); |
1137 1159 | //vi_p->writeBackChanges(vb); |
1138 1160 | // static_cast<VisibilityIteratorImpl2 *> (vi_p->getImpl())->writeVisModel(vb->visCubeModel()); |
1139 1161 | } |
1140 1162 | |
1141 1163 | } |
1142 1164 | itsMappers.grid(*vb, dopsf, (refim::FTMachine::Type)(datacol_p), gmap); |
1143 1165 | //itsMappers.getMapper(gmap)->grid(*vb, dopsf, datacol_p); |
1144 1166 | cohDone += vb->nRows(); |
1167 + | ++iterNum; |
1145 1168 | pm.update(Double(cohDone)); |
1146 1169 | } |
1147 1170 | } |
1148 1171 | } |
1149 1172 | //cerr << "IN SYNTHE_IMA" << endl; |
1150 1173 | //VisModelData::listModel(rvi_p->getMeasurementSet()); |
1151 1174 | |
1152 1175 | SynthesisUtilMethods::getResource("Before finalize for mapper"+String::toString(gmap)); |
1153 1176 | |
1154 1177 | if(!dopsf) |
1158 1181 | } |
1159 1182 | itsMappers.finalizeGrid(*vb, dopsf,gmap); |
1160 1183 | //itsMappers.getMapper(gmap)->finalizeGrid(*vb, dopsf); |
1161 1184 | |
1162 1185 | // itsMappers.getMapper(gmap)->releaseImageLocks(); |
1163 1186 | itsMappers.getMapper(gmap)->imageStore()->releaseComplexGrids(); |
1164 1187 | |
1165 1188 | SynthesisUtilMethods::getResource("End Major Cycle for mapper"+String::toString(gmap)); |
1166 1189 | fselections_p=copyFsels; |
1167 1190 | }// end of mapper loop |
1168 - | vi_p->setFrequencySelection(*fselections_p); |
1191 + | ///CAS-12132 create a new visiter for each chunk |
1192 + | createVisSet(writeAccess_p); |
1193 + | //////////////////////// |
1194 + | //////vi_p->setFrequencySelection(*fselections_p); |
1169 1195 | |
1170 1196 | itsMappers.checkOverlappingModels("restore"); |
1171 1197 | |
1172 1198 | unlockMSs(); |
1173 1199 | |
1174 1200 | SynthesisUtilMethods::getResource("End Major Cycle"); |
1175 1201 | |
1176 1202 | }// end runMajorCycle2 |
1177 1203 | |
1178 1204 | |