Changes in trunk/src/STMath.cpp [2467:2345]
- File:
-
- 1 edited
-
trunk/src/STMath.cpp (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STMath.cpp
r2467 r2345 57 57 using namespace asap; 58 58 59 // 2012/02/17 TN60 // Since STGrid is implemented, average doesn't consider direction61 // when accumulating62 59 // tolerance for direction comparison (rad) 63 //#define TOL_OTF 1.0e-1564 //#define TOL_POINT 2.9088821e-4 // 1 arcmin60 #define TOL_OTF 1.0e-15 61 #define TOL_POINT 2.9088821e-4 // 1 arcmin 65 62 66 63 STMath::STMath(bool insitu) : … … 86 83 WeightType wtype = stringToWeight(weight); 87 84 88 // 2012/02/17 TN89 // Since STGrid is implemented, average doesn't consider direction90 // when accumulating91 85 // check if OTF observation 92 //String obstype = in[0]->getHeader().obstype ;93 //Double tol = 0.0 ;94 //if ( (obstype.find( "OTF" ) != String::npos) || (obstype.find( "OBSERVE_TARGET" ) != String::npos) ) {95 //tol = TOL_OTF ;96 //}97 //else {98 //tol = TOL_POINT ;99 //}86 String obstype = in[0]->getHeader().obstype ; 87 Double tol = 0.0 ; 88 if ( (obstype.find( "OTF" ) != String::npos) || (obstype.find( "OBSERVE_TARGET" ) != String::npos) ) { 89 tol = TOL_OTF ; 90 } 91 else { 92 tol = TOL_POINT ; 93 } 100 94 101 95 // output … … 148 142 while (!iter.pastEnd()) { 149 143 Table subt = iter.table(); 150 // copy the first row of this selection into the new table 151 tout.addRow(); 152 TableCopy::copyRows(tout, subt, outrowCount, 0, 1); 153 // re-index to 0 154 if ( avmode != "SCAN" && avmode != "SOURCE" ) { 155 scanColOut.put(outrowCount, uInt(0)); 156 } 157 ++outrowCount; 158 // 2012/02/17 TN 159 // Since STGrid is implemented, average doesn't consider direction 160 // when accumulating 161 // MDirection::ScalarColumn dircol ; 162 // dircol.attach( subt, "DIRECTION" ) ; 163 // Int length = subt.nrow() ; 164 // vector< Vector<Double> > dirs ; 165 // vector<int> indexes ; 166 // for ( Int i = 0 ; i < length ; i++ ) { 167 // Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ; 168 // //os << << count++ << ": " ; 169 // //os << "[" << t[0] << "," << t[1] << "]" << LogIO::POST ; 170 // bool adddir = true ; 171 // for ( uInt j = 0 ; j < dirs.size() ; j++ ) { 172 // //if ( allTrue( t == dirs[j] ) ) { 173 // Double dx = t[0] - dirs[j][0] ; 174 // Double dy = t[1] - dirs[j][1] ; 175 // Double dd = sqrt( dx * dx + dy * dy ) ; 176 // //if ( allNearAbs( t, dirs[j], tol ) ) { 177 // if ( dd <= tol ) { 178 // adddir = false ; 179 // break ; 180 // } 181 // } 182 // if ( adddir ) { 183 // dirs.push_back( t ) ; 184 // indexes.push_back( i ) ; 185 // } 144 // // copy the first row of this selection into the new table 145 // tout.addRow(); 146 // TableCopy::copyRows(tout, subt, outrowCount, 0, 1); 147 // // re-index to 0 148 // if ( avmode != "SCAN" && avmode != "SOURCE" ) { 149 // scanColOut.put(outrowCount, uInt(0)); 186 150 // } 187 // uInt rowNum = dirs.size() ; 188 // tout.addRow( rowNum ) ; 189 // for ( uInt i = 0 ; i < rowNum ; i++ ) { 190 // TableCopy::copyRows( tout, subt, outrowCount+i, indexes[i], 1 ) ; 191 // // re-index to 0 192 // if ( avmode != "SCAN" && avmode != "SOURCE" ) { 193 // scanColOut.put(outrowCount+i, uInt(0)); 194 // } 195 // } 196 // outrowCount += rowNum ; 151 // ++outrowCount; 152 MDirection::ScalarColumn dircol ; 153 dircol.attach( subt, "DIRECTION" ) ; 154 Int length = subt.nrow() ; 155 vector< Vector<Double> > dirs ; 156 vector<int> indexes ; 157 for ( Int i = 0 ; i < length ; i++ ) { 158 Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ; 159 //os << << count++ << ": " ; 160 //os << "[" << t[0] << "," << t[1] << "]" << LogIO::POST ; 161 bool adddir = true ; 162 for ( uInt j = 0 ; j < dirs.size() ; j++ ) { 163 //if ( allTrue( t == dirs[j] ) ) { 164 Double dx = t[0] - dirs[j][0] ; 165 Double dy = t[1] - dirs[j][1] ; 166 Double dd = sqrt( dx * dx + dy * dy ) ; 167 //if ( allNearAbs( t, dirs[j], tol ) ) { 168 if ( dd <= tol ) { 169 adddir = false ; 170 break ; 171 } 172 } 173 if ( adddir ) { 174 dirs.push_back( t ) ; 175 indexes.push_back( i ) ; 176 } 177 } 178 uInt rowNum = dirs.size() ; 179 tout.addRow( rowNum ) ; 180 for ( uInt i = 0 ; i < rowNum ; i++ ) { 181 TableCopy::copyRows( tout, subt, outrowCount+i, indexes[i], 1 ) ; 182 // re-index to 0 183 if ( avmode != "SCAN" && avmode != "SOURCE" ) { 184 scanColOut.put(outrowCount+i, uInt(0)); 185 } 186 } 187 outrowCount += rowNum ; 197 188 ++iter; 198 189 } … … 227 218 } 228 219 229 // 2012/02/17 TN 230 // Since STGrid is implemented, average doesn't consider direction 231 // when accumulating 232 // vector<uInt> removeRows ; 233 // uInt nrsubt = subt.nrow() ; 234 // for ( uInt irow = 0 ; irow < nrsubt ; irow++ ) { 235 // //if ( !allTrue((subt.col("DIRECTION").getArrayDouble(TableExprId(irow)))==rec.asArrayDouble("DIRECTION")) ) { 236 // Vector<Double> x0 = (subt.col("DIRECTION").getArrayDouble(TableExprId(irow))) ; 237 // Vector<Double> x1 = rec.asArrayDouble("DIRECTION") ; 238 // double dx = x0[0] - x1[0]; 239 // double dy = x0[1] - x1[1]; 240 // Double dd = sqrt( dx * dx + dy * dy ) ; 241 // //if ( !allNearAbs((subt.col("DIRECTION").getArrayDouble(TableExprId(irow))), rec.asArrayDouble("DIRECTION"), tol ) ) { 242 // if ( dd > tol ) { 243 // removeRows.push_back( irow ) ; 244 // } 245 // } 246 // if ( removeRows.size() != 0 ) { 247 // subt.removeRow( removeRows ) ; 248 // } 220 vector<uInt> removeRows ; 221 uInt nrsubt = subt.nrow() ; 222 for ( uInt irow = 0 ; irow < nrsubt ; irow++ ) { 223 //if ( !allTrue((subt.col("DIRECTION").getArrayDouble(TableExprId(irow)))==rec.asArrayDouble("DIRECTION")) ) { 224 Vector<Double> x0 = (subt.col("DIRECTION").getArrayDouble(TableExprId(irow))) ; 225 Vector<Double> x1 = rec.asArrayDouble("DIRECTION") ; 226 double dx = x0[0] - x1[0]; 227 double dy = x0[1] - x1[1]; 228 Double dd = sqrt( dx * dx + dy * dy ) ; 229 //if ( !allNearAbs((subt.col("DIRECTION").getArrayDouble(TableExprId(irow))), rec.asArrayDouble("DIRECTION"), tol ) ) { 230 if ( dd > tol ) { 231 removeRows.push_back( irow ) ; 232 } 233 } 234 if ( removeRows.size() != 0 ) { 235 subt.removeRow( removeRows ) ; 236 } 249 237 250 //if ( nrsubt == removeRows.size() )251 //throw(AipsError("Averaging data is empty.")) ;238 if ( nrsubt == removeRows.size() ) 239 throw(AipsError("Averaging data is empty.")) ; 252 240 253 241 specCol.attach(subt,"SPECTRA"); … … 333 321 { 334 322 (void) mode; // currently unused 335 // 2012/02/17 TN336 // Since STGrid is implemented, average doesn't consider direction337 // when accumulating338 323 // check if OTF observation 339 //String obstype = in->getHeader().obstype ;340 //Double tol = 0.0 ;341 //if ( obstype.find( "OTF" ) != String::npos ) {342 //tol = TOL_OTF ;343 //}344 //else {345 //tol = TOL_POINT ;346 //}324 String obstype = in->getHeader().obstype ; 325 Double tol = 0.0 ; 326 if ( obstype.find( "OTF" ) != String::npos ) { 327 tol = TOL_OTF ; 328 } 329 else { 330 tol = TOL_POINT ; 331 } 347 332 348 333 // clone as this is non insitu … … 377 362 flagCol.attach(subt,"FLAGTRA"); 378 363 tsysCol.attach(subt,"TSYS"); 379 380 tout.addRow(); 381 TableCopy::copyRows(tout, subt, outrowCount, 0, 1); 382 if ( avmode != "SCAN") { 383 scanColOut.put(outrowCount, uInt(0)); 384 } 385 Vector<Float> tmp; 386 specCol.get(0, tmp); 387 uInt nchan = tmp.nelements(); 388 // have to do channel by channel here as MaskedArrMath 389 // doesn't have partialMedians 390 Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0))); 391 Vector<Float> outspec(nchan); 392 Vector<uChar> outflag(nchan,0); 393 Vector<Float> outtsys(1);/// @fixme when tsys is channel based 394 for (uInt i=0; i<nchan; ++i) { 395 Vector<Float> specs = specCol.getColumn(Slicer(Slice(i))); 396 MaskedArray<Float> ma = maskedArray(specs,flags); 397 outspec[i] = median(ma); 398 if ( allEQ(ma.getMask(), False) ) 399 outflag[i] = userflag;// flag data 400 } 401 outtsys[0] = median(tsysCol.getColumn()); 402 specColOut.put(outrowCount, outspec); 403 flagColOut.put(outrowCount, outflag); 404 tsysColOut.put(outrowCount, outtsys); 405 Double intsum = sum(intCol.getColumn()); 406 intColOut.put(outrowCount, intsum); 407 ++outrowCount; 364 // tout.addRow(); 365 // TableCopy::copyRows(tout, subt, outrowCount, 0, 1); 366 // if ( avmode != "SCAN") { 367 // scanColOut.put(outrowCount, uInt(0)); 368 // } 369 // Vector<Float> tmp; 370 // specCol.get(0, tmp); 371 // uInt nchan = tmp.nelements(); 372 // // have to do channel by channel here as MaskedArrMath 373 // // doesn't have partialMedians 374 // Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0))); 375 // Vector<Float> outspec(nchan); 376 // Vector<uChar> outflag(nchan,0); 377 // Vector<Float> outtsys(1);/// @fixme when tsys is channel based 378 // for (uInt i=0; i<nchan; ++i) { 379 // Vector<Float> specs = specCol.getColumn(Slicer(Slice(i))); 380 // MaskedArray<Float> ma = maskedArray(specs,flags); 381 // outspec[i] = median(ma); 382 // if ( allEQ(ma.getMask(), False) ) 383 // outflag[i] = userflag;// flag data 384 // } 385 // outtsys[0] = median(tsysCol.getColumn()); 386 // specColOut.put(outrowCount, outspec); 387 // flagColOut.put(outrowCount, outflag); 388 // tsysColOut.put(outrowCount, outtsys); 389 // Double intsum = sum(intCol.getColumn()); 390 // intColOut.put(outrowCount, intsum); 391 // ++outrowCount; 392 // ++iter; 393 MDirection::ScalarColumn dircol ; 394 dircol.attach( subt, "DIRECTION" ) ; 395 Int length = subt.nrow() ; 396 vector< Vector<Double> > dirs ; 397 vector<int> indexes ; 398 // Handle MX mode averaging 399 if (in->nbeam() > 1 ) { 400 length = 1; 401 } 402 for ( Int i = 0 ; i < length ; i++ ) { 403 Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ; 404 bool adddir = true ; 405 for ( uInt j = 0 ; j < dirs.size() ; j++ ) { 406 //if ( allTrue( t == dirs[j] ) ) { 407 Double dx = t[0] - dirs[j][0] ; 408 Double dy = t[1] - dirs[j][1] ; 409 Double dd = sqrt( dx * dx + dy * dy ) ; 410 //if ( allNearAbs( t, dirs[j], tol ) ) { 411 if ( dd <= tol ) { 412 adddir = false ; 413 break ; 414 } 415 } 416 if ( adddir ) { 417 dirs.push_back( t ) ; 418 indexes.push_back( i ) ; 419 } 420 } 421 uInt rowNum = dirs.size() ; 422 tout.addRow( rowNum ); 423 for ( uInt i = 0 ; i < rowNum ; i++ ) { 424 TableCopy::copyRows(tout, subt, outrowCount+i, indexes[i], 1) ; 425 // Handle MX mode averaging 426 if ( avmode != "SCAN") { 427 scanColOut.put(outrowCount+i, uInt(0)); 428 } 429 } 430 MDirection::ScalarColumn dircolOut ; 431 dircolOut.attach( tout, "DIRECTION" ) ; 432 for ( uInt irow = 0 ; irow < rowNum ; irow++ ) { 433 Vector<Double> t = \ 434 dircolOut(outrowCount+irow).getAngle(Unit(String("rad"))).getValue() ; 435 Vector<Float> tmp; 436 specCol.get(0, tmp); 437 uInt nchan = tmp.nelements(); 438 // have to do channel by channel here as MaskedArrMath 439 // doesn't have partialMedians 440 Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0))); 441 // mask spectra for different DIRECTION 442 for ( uInt jrow = 0 ; jrow < subt.nrow() ; jrow++ ) { 443 Vector<Double> direction = \ 444 dircol(jrow).getAngle(Unit(String("rad"))).getValue() ; 445 //if ( t[0] != direction[0] || t[1] != direction[1] ) { 446 Double dx = t[0] - direction[0]; 447 Double dy = t[1] - direction[1]; 448 Double dd = sqrt(dx*dx + dy*dy); 449 //if ( !allNearAbs( t, direction, tol ) ) { 450 if ( dd > tol && in->nbeam() < 2 ) { 451 flags[jrow] = userflag ; 452 } 453 } 454 Vector<Float> outspec(nchan); 455 Vector<uChar> outflag(nchan,0); 456 Vector<Float> outtsys(1);/// @fixme when tsys is channel based 457 for (uInt i=0; i<nchan; ++i) { 458 Vector<Float> specs = specCol.getColumn(Slicer(Slice(i))); 459 MaskedArray<Float> ma = maskedArray(specs,flags); 460 outspec[i] = median(ma); 461 if ( allEQ(ma.getMask(), False) ) 462 outflag[i] = userflag;// flag data 463 } 464 outtsys[0] = median(tsysCol.getColumn()); 465 specColOut.put(outrowCount+irow, outspec); 466 flagColOut.put(outrowCount+irow, outflag); 467 tsysColOut.put(outrowCount+irow, outtsys); 468 Vector<Double> integ = intCol.getColumn() ; 469 MaskedArray<Double> mi = maskedArray( integ, flags ) ; 470 Double intsum = sum(mi); 471 intColOut.put(outrowCount+irow, intsum); 472 } 473 outrowCount += rowNum ; 408 474 ++iter; 409 410 // 2012/02/17 TN411 // Since STGrid is implemented, average doesn't consider direction412 // when accumulating413 // MDirection::ScalarColumn dircol ;414 // dircol.attach( subt, "DIRECTION" ) ;415 // Int length = subt.nrow() ;416 // vector< Vector<Double> > dirs ;417 // vector<int> indexes ;418 // // Handle MX mode averaging419 // if (in->nbeam() > 1 ) {420 // length = 1;421 // }422 // for ( Int i = 0 ; i < length ; i++ ) {423 // Vector<Double> t = dircol(i).getAngle(Unit(String("rad"))).getValue() ;424 // bool adddir = true ;425 // for ( uInt j = 0 ; j < dirs.size() ; j++ ) {426 // //if ( allTrue( t == dirs[j] ) ) {427 // Double dx = t[0] - dirs[j][0] ;428 // Double dy = t[1] - dirs[j][1] ;429 // Double dd = sqrt( dx * dx + dy * dy ) ;430 // //if ( allNearAbs( t, dirs[j], tol ) ) {431 // if ( dd <= tol ) {432 // adddir = false ;433 // break ;434 // }435 // }436 // if ( adddir ) {437 // dirs.push_back( t ) ;438 // indexes.push_back( i ) ;439 // }440 // }441 // uInt rowNum = dirs.size() ;442 // tout.addRow( rowNum );443 // for ( uInt i = 0 ; i < rowNum ; i++ ) {444 // TableCopy::copyRows(tout, subt, outrowCount+i, indexes[i], 1) ;445 // // Handle MX mode averaging446 // if ( avmode != "SCAN") {447 // scanColOut.put(outrowCount+i, uInt(0));448 // }449 // }450 // MDirection::ScalarColumn dircolOut ;451 // dircolOut.attach( tout, "DIRECTION" ) ;452 // for ( uInt irow = 0 ; irow < rowNum ; irow++ ) {453 // Vector<Double> t = \454 // dircolOut(outrowCount+irow).getAngle(Unit(String("rad"))).getValue() ;455 // Vector<Float> tmp;456 // specCol.get(0, tmp);457 // uInt nchan = tmp.nelements();458 // // have to do channel by channel here as MaskedArrMath459 // // doesn't have partialMedians460 // Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));461 // // mask spectra for different DIRECTION462 // for ( uInt jrow = 0 ; jrow < subt.nrow() ; jrow++ ) {463 // Vector<Double> direction = \464 // dircol(jrow).getAngle(Unit(String("rad"))).getValue() ;465 // //if ( t[0] != direction[0] || t[1] != direction[1] ) {466 // Double dx = t[0] - direction[0];467 // Double dy = t[1] - direction[1];468 // Double dd = sqrt(dx*dx + dy*dy);469 // //if ( !allNearAbs( t, direction, tol ) ) {470 // if ( dd > tol && in->nbeam() < 2 ) {471 // flags[jrow] = userflag ;472 // }473 // }474 // Vector<Float> outspec(nchan);475 // Vector<uChar> outflag(nchan,0);476 // Vector<Float> outtsys(1);/// @fixme when tsys is channel based477 // for (uInt i=0; i<nchan; ++i) {478 // Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));479 // MaskedArray<Float> ma = maskedArray(specs,flags);480 // outspec[i] = median(ma);481 // if ( allEQ(ma.getMask(), False) )482 // outflag[i] = userflag;// flag data483 // }484 // outtsys[0] = median(tsysCol.getColumn());485 // specColOut.put(outrowCount+irow, outspec);486 // flagColOut.put(outrowCount+irow, outflag);487 // tsysColOut.put(outrowCount+irow, outtsys);488 // Vector<Double> integ = intCol.getColumn() ;489 // MaskedArray<Double> mi = maskedArray( integ, flags ) ;490 // Double intsum = sum(mi);491 // intColOut.put(outrowCount+irow, intsum);492 // }493 // outrowCount += rowNum ;494 // ++iter;495 475 } 496 476 return out; … … 1930 1910 ArrayColumn<Float> specCol(tout, "SPECTRA"); 1931 1911 ArrayColumn<uChar> flagCol(tout, "FLAGTRA"); 1932 ArrayColumn<Float> tsysCol(tout, "TSYS");1933 1934 1912 for (uInt i=0; i < tout.nrow(); ++i ) { 1935 1913 MaskedArray<Float> main = maskedArray(specCol(i), flagCol(i)); 1936 1914 MaskedArray<Float> maout; 1937 1915 LatticeUtilities::bin(maout, main, 0, Int(width)); 1916 /// @todo implement channel based tsys binning 1938 1917 specCol.put(i, maout.getArray()); 1939 1918 flagCol.put(i, flagsFromMA(maout)); 1940 if (tsysCol(i).nelements() == specCol(i).nelements()) {1941 MaskedArray<Float> matsysin = maskedArray(tsysCol(i), flagCol(i));1942 MaskedArray<Float> matsysout;1943 LatticeUtilities::bin(matsysout, matsysin, 0, Int(width));1944 tsysCol.put(i, matsysout.getArray());1945 }1946 1919 // take only the first binned spectrum's length for the deprecated 1947 1920 // global header item nChan … … 2777 2750 mask, timeCol(i), !first, 2778 2751 interp, False); 2779 (void) ok; // unused stop compiler nagging 2752 (void) ok; // unused stop compiler nagging 2780 2753 // back into scantable 2781 2754 flagOut.resize(maskOut.nelements()); … … 2981 2954 "Use merge first.")); 2982 2955 2983 // 2012/02/17 TN2984 // Since STGrid is implemented, average doesn't consider direction2985 // when accumulating2986 2956 // check if OTF observation 2987 //String obstype = in[0]->getHeader().obstype ;2988 //Double tol = 0.0 ;2989 //if ( obstype.find( "OTF" ) != String::npos ) {2990 //tol = TOL_OTF ;2991 //}2992 //else {2993 //tol = TOL_POINT ;2994 //}2957 String obstype = in[0]->getHeader().obstype ; 2958 Double tol = 0.0 ; 2959 if ( obstype.find( "OTF" ) != String::npos ) { 2960 tol = TOL_OTF ; 2961 } 2962 else { 2963 tol = TOL_POINT ; 2964 } 2995 2965 2996 2966 CountedPtr<Scantable> out ; // processed result … … 3045 3015 uInt rows = tmpin[itable]->nrow() ; 3046 3016 uInt freqnrows = tmpin[itable]->frequencies().table().nrow() ; 3047 freqIDCol.attach( tmpin[itable]->table(), "FREQ_ID" ) ;3048 //ifnoCol.attach( tmpin[itable]->table(), "IFNO" ) ;3049 3017 for ( uInt irow = 0 ; irow < rows ; irow++ ) { 3050 3018 if ( freqid[itable].size() == freqnrows ) { … … 3052 3020 } 3053 3021 else { 3022 freqIDCol.attach( tmpin[itable]->table(), "FREQ_ID" ) ; 3023 ifnoCol.attach( tmpin[itable]->table(), "IFNO" ) ; 3054 3024 uInt id = freqIDCol( irow ) ; 3055 3025 if ( freqid[itable].size() == 0 || count( freqid[itable].begin(), freqid[itable].end(), id ) == 0 ) { 3056 3026 //os << "itable = " << itable << ": IF " << id << " is included in the list" << LogIO::POST ; 3057 3027 vector<double> abcissa = tmpin[itable]->getAbcissa( irow ) ; 3058 double lbedge, rbedge;3059 3028 freqid[itable].push_back( id ) ; 3060 lbedge = abcissa[0] - 0.5 * ( abcissa[1] - abcissa[0] ); 3061 rbedge = abcissa[abcissa.size()-1] + 0.5 * ( abcissa[1] - abcissa[0] ); 3062 iffreq[itable].push_back( min(lbedge, rbedge) ) ; 3063 iffreq[itable].push_back( max(lbedge, rbedge) ) ; 3029 iffreq[itable].push_back( abcissa[0] - 0.5 * ( abcissa[1] - abcissa[0] ) ) ; 3030 iffreq[itable].push_back( abcissa[abcissa.size()-1] + 0.5 * ( abcissa[1] - abcissa[0] ) ) ; 3064 3031 } 3065 3032 } … … 3146 3113 // Grouping continuous IF groups (without frequency gap) 3147 3114 // freqgrp: list of IF group indexes in each frequency group 3115 // freqrange: list of minimum and maximum frequency in each frequency group 3148 3116 // freqgrp[numgrp][nummember] 3149 3117 // freqgrp: [[ifgrp00, ifgrp01, ifgrp02, ...], … … 3151 3119 // ... 3152 3120 // [ifgrpn0, ifgrpn1, ifgrpn2, ...]] 3121 // freqrange[numgrp*2] 3122 // freqrange: [min_grp0, max_grp0, min_grp1, max_grp1, ...] 3153 3123 vector< vector<uInt> > freqgrp ; 3154 3124 double freqrange = 0.0 ; … … 3166 3136 freqrange = ifgfreq[2*i+1] ; 3167 3137 } 3168 3138 3169 3139 3170 3140 // print IF groups … … 3355 3325 3356 3326 // save column values in the vector 3327 vector< vector<uInt> > freqTableIdVec( insize ) ; 3357 3328 vector< vector<uInt> > freqIdVec( insize ) ; 3358 3329 vector< vector<uInt> > ifNoVec( insize ) ; 3359 3330 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 3331 ScalarColumn<uInt> freqIDs ; 3332 freqIDs.attach( newin[itable]->frequencies().table(), "ID" ) ; 3360 3333 ifnoCol.attach( newin[itable]->table(), "IFNO" ) ; 3361 3334 freqIDCol.attach( newin[itable]->table(), "FREQ_ID" ) ; 3335 for ( uInt irow = 0 ; irow < newin[itable]->frequencies().table().nrow() ; irow++ ) { 3336 freqTableIdVec[itable].push_back( freqIDs( irow ) ) ; 3337 } 3362 3338 for ( uInt irow = 0 ; irow < newin[itable]->table().nrow() ; irow++ ) { 3363 3339 freqIdVec[itable].push_back( freqIDCol( irow ) ) ; … … 3374 3350 vector<uInt> freqIdUpdate ; 3375 3351 for ( uInt irow = 0 ; irow < rows ; irow++ ) { 3376 uInt ifno = ifNoVec[itable][irow] ; // IFNO is reset by group index (IF group index)3352 uInt ifno = ifNoVec[itable][irow] ; // IFNO is reset by group index 3377 3353 double minfreq = ifgfreq[2*ifno] ; 3378 3354 double maxfreq = ifgfreq[2*ifno+1] ; … … 3382 3358 double resol = abcissa[1] - abcissa[0] ; 3383 3359 //os << "abcissa range : [" << abcissa[0] << "," << abcissa[nchan-1] << "]" << LogIO::POST ; 3384 uInt imin, imax; 3385 int sigres; 3386 if ( resol >= 0. ) { 3387 imin = 0; 3388 imax = nchan - 1 ; 3389 sigres = 1 ; 3390 } else { 3391 imin = nchan - 1 ; 3392 imax = 0 ; 3393 sigres = -1 ; 3394 resol = abs(resol) ; 3395 } 3396 if ( minfreq <= abcissa[imin] ) 3397 nminchan = imin ; 3360 if ( minfreq <= abcissa[0] ) 3361 nminchan = 0 ; 3398 3362 else { 3399 3363 //double cfreq = ( minfreq - abcissa[0] ) / resol ; 3400 double cfreq = ( minfreq - abcissa[ imin] + 0.5 * resol ) / resol ;3401 nminchan = i min + sigres * (int(cfreq) + ( ( cfreq - int(cfreq) <= 0.5 ) ? 0 : 1 )) ;3364 double cfreq = ( minfreq - abcissa[0] + 0.5 * resol ) / resol ; 3365 nminchan = int(cfreq) + ( ( cfreq - int(cfreq) <= 0.5 ) ? 0 : 1 ) ; 3402 3366 } 3403 if ( maxfreq >= abcissa[ imax] )3404 nmaxchan = imax;3367 if ( maxfreq >= abcissa[abcissa.size()-1] ) 3368 nmaxchan = abcissa.size() - 1 ; 3405 3369 else { 3406 3370 //double cfreq = ( abcissa[abcissa.size()-1] - maxfreq ) / resol ; 3407 double cfreq = ( abcissa[ imax] - maxfreq + 0.5 * resol ) / resol ;3408 nmaxchan = imax - sigres * (int(cfreq) +( ( cfreq - int(cfreq) >= 0.5 ) ? 1 : 0 )) ;3371 double cfreq = ( abcissa[abcissa.size()-1] - maxfreq + 0.5 * resol ) / resol ; 3372 nmaxchan = abcissa.size() - 1 - int(cfreq) - ( ( cfreq - int(cfreq) >= 0.5 ) ? 1 : 0 ) ; 3409 3373 } 3410 3374 //os << "channel range (" << irow << "): [" << nminchan << "," << nmaxchan << "]" << LogIO::POST ; 3411 if ( nmaxchan < nminchan ) {3412 int tmp = nmaxchan ;3413 nmaxchan = nminchan ;3414 nminchan = tmp ;3415 }3416 3375 if ( nmaxchan > nminchan ) { 3417 3376 newin[itable]->reshapeSpectrum( nminchan, nmaxchan, irow ) ; 3418 3377 int newchan = nmaxchan - nminchan + 1 ; 3419 if ( count( freqIdUpdate.begin(), freqIdUpdate.end(), freqIdVec[itable][irow] ) == 0 && newchan < nchan ) {3378 if ( count( freqIdUpdate.begin(), freqIdUpdate.end(), freqIdVec[itable][irow] ) == 0 && newchan < nchan ) 3420 3379 freqIdUpdate.push_back( freqIdVec[itable][irow] ) ; 3421 3422 // Update before nminchan is lost3423 uInt freqId = freqIdVec[itable][irow] ;3424 Double refpix ;3425 Double refval ;3426 Double increment ;3427 newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ;3428 //refval = refval - ( refpix - nminchan ) * increment ;3429 refval = abcissa[nminchan] ;3430 refpix = 0 ;3431 newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ;3432 }3433 3380 } 3434 3381 else { … … 3436 3383 } 3437 3384 } 3438 //for ( uInt i = 0 ; i < freqIdUpdate.size() ; i++ ) {3439 //uInt freqId = freqIdUpdate[i] ;3440 //Double refpix ;3441 //Double refval ;3442 //Double increment ;3385 for ( uInt i = 0 ; i < freqIdUpdate.size() ; i++ ) { 3386 uInt freqId = freqIdUpdate[i] ; 3387 Double refpix ; 3388 Double refval ; 3389 Double increment ; 3443 3390 3444 //// update row3445 //newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ;3446 //refval = refval - ( refpix - nminchan ) * increment ;3447 //refpix = 0 ;3448 //newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ;3449 //}3391 // update row 3392 newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ; 3393 refval = refval - ( refpix - nminchan ) * increment ; 3394 refpix = 0 ; 3395 newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ; 3396 } 3450 3397 } 3451 3398 … … 3484 3431 if ( nchan < minchan ) { 3485 3432 minchan = nchan ; 3486 maxdnu = abs(dnu);3433 maxdnu = dnu ; 3487 3434 newin[tableid]->frequencies().getEntry( refpixref, refvalref, refinc, rowid ) ; 3488 3435 refreqid = rowid ; 3489 3436 reftable = tableid ; 3490 // Spectra are reversed when dnu < 03491 if (dnu < 0)3492 refpixref = minchan - 1 -refpixref ;3493 3437 } 3494 3438 } … … 3505 3449 //os << " regridChannel applied to " ; 3506 3450 //if ( tableid != reftable ) 3507 refreqid = newin[tableid]->frequencies().addEntry( refpixref, refvalref, maxdnu) ;3451 refreqid = newin[tableid]->frequencies().addEntry( refpixref, refvalref, refinc ) ; 3508 3452 for ( uInt irow = 0 ; irow < newin[tableid]->table().nrow() ; irow++ ) { 3509 3453 uInt tfreqid = freqIdVec[tableid][irow] ; … … 3526 3470 vector<double> abcissa = newin[tableid]->getAbcissa( index ) ; 3527 3471 minchan = abcissa.size() ; 3528 maxdnu = ab s( abcissa[1] - abcissa[0]);3472 maxdnu = abcissa[1] - abcissa[0] ; 3529 3473 } 3530 3474 } … … 3596 3540 vector<double> abcissa = tmpout->getAbcissa( irow ) ; 3597 3541 double bw = ( abcissa[1] - abcissa[0] ) * abcissa.size() ; 3598 int nchan = (int) abs( bw / gmaxdnu[igrp] ) ; 3599 // All spectra will have positive frequency increments 3542 int nchan = (int)( bw / gmaxdnu[igrp] ) ; 3600 3543 tmpout->regridChannel( nchan, gmaxdnu[igrp], irow ) ; 3601 3544 break ; … … 3614 3557 ScalarColumn<uInt> freqidColOut ; 3615 3558 freqidColOut.attach( out->table(), "FREQ_ID" ) ; 3616 //MDirection::ScalarColumn dirColOut ;3617 //dirColOut.attach( out->table(), "DIRECTION" ) ;3559 MDirection::ScalarColumn dirColOut ; 3560 dirColOut.attach( out->table(), "DIRECTION" ) ; 3618 3561 Table &tab = tmpout->table() ; 3619 3562 Block<String> cols(1); 3620 3563 cols[0] = String("POLNO") ; 3621 3564 TableIterator iter( tab, cols ) ; 3565 bool done = false ; 3622 3566 vector< vector<uInt> > sizes( freqgrp.size() ) ; 3623 3567 while( !iter.pastEnd() ) { … … 3631 3575 ScalarColumn<uInt> polnos ; 3632 3576 polnos.attach( iter.table(), "POLNO" ) ; 3633 //MDirection::ScalarColumn dircol ;3634 //dircol.attach( iter.table(), "DIRECTION" ) ;3577 MDirection::ScalarColumn dircol ; 3578 dircol.attach( iter.table(), "DIRECTION" ) ; 3635 3579 uInt polno = polnos( 0 ) ; 3636 3580 //os << "POLNO iteration: " << polno << LogIO::POST ; … … 3670 3614 // } 3671 3615 // get a list of number of channels for each frequency group member 3672 for ( uInt igrp = 0 ; igrp < freqgrp.size() ; igrp++ ) { 3673 sizes[igrp].resize( freqgrp[igrp].size() ) ; 3674 for ( uInt imem = 0 ; imem < freqgrp[igrp].size() ; imem++ ) { 3675 for ( uInt irow = 0 ; irow < iter.table().nrow() ; irow++ ) { 3676 uInt ifno = ifnoCol( irow ) ; 3677 if ( ifno == freqgrp[igrp][imem] ) { 3678 Vector<Float> spec = specCols( irow ) ; 3679 sizes[igrp][imem] = spec.nelements() ; 3680 break ; 3681 } 3682 } 3683 } 3616 if ( !done ) { 3617 for ( uInt igrp = 0 ; igrp < freqgrp.size() ; igrp++ ) { 3618 sizes[igrp].resize( freqgrp[igrp].size() ) ; 3619 for ( uInt imem = 0 ; imem < freqgrp[igrp].size() ; imem++ ) { 3620 for ( uInt irow = 0 ; irow < iter.table().nrow() ; irow++ ) { 3621 uInt ifno = ifnoCol( irow ) ; 3622 if ( ifno == freqgrp[igrp][imem] ) { 3623 Vector<Float> spec = specCols( irow ) ; 3624 sizes[igrp][imem] = spec.nelements() ; 3625 break ; 3626 } 3627 } 3628 } 3629 } 3630 done = true ; 3684 3631 } 3685 3632 // combine spectra … … 3688 3635 if ( polout == polno ) { 3689 3636 uInt ifout = ifnoColOut( irow ) ; 3690 //Vector<Double> direction = dirColOut(irow).getAngle(Unit(String("rad"))).getValue() ;3637 Vector<Double> direction = dirColOut(irow).getAngle(Unit(String("rad"))).getValue() ; 3691 3638 uInt igrp ; 3692 3639 for ( uInt jgrp = 0 ; jgrp < freqgrp.size() ; jgrp++ ) { … … 3699 3646 for ( uInt jrow = 0 ; jrow < iter.table().nrow() ; jrow++ ) { 3700 3647 uInt ifno = ifnoCol( jrow ) ; 3701 // 2012/02/17 TN 3702 // Since STGrid is implemented, average doesn't consider direction 3703 // when accumulating 3704 // Vector<Double> tdir = dircol(jrow).getAngle(Unit(String("rad"))).getValue() ; 3705 // //if ( ifno == freqgrp[igrp][imem] && allTrue( tdir == direction ) ) { 3706 // Double dx = tdir[0] - direction[0] ; 3707 // Double dy = tdir[1] - direction[1] ; 3708 // Double dd = sqrt( dx * dx + dy * dy ) ; 3648 Vector<Double> tdir = dircol(jrow).getAngle(Unit(String("rad"))).getValue() ; 3649 //if ( ifno == freqgrp[igrp][imem] && allTrue( tdir == direction ) ) { 3650 Double dx = tdir[0] - direction[0] ; 3651 Double dy = tdir[1] - direction[1] ; 3652 Double dd = sqrt( dx * dx + dy * dy ) ; 3709 3653 //if ( ifno == freqgrp[igrp][imem] && allNearAbs( tdir, direction, tol ) ) { 3710 // if ( ifno == freqgrp[igrp][imem] && dd <= tol ) { 3711 if ( ifno == freqgrp[igrp][imem] ) { 3654 if ( ifno == freqgrp[igrp][imem] && dd <= tol ) { 3712 3655 Vector<Float> spec = specCols( jrow ) ; 3713 3656 Vector<uChar> flag = flagCols( jrow ) ; … … 3728 3671 specColOut.put( irow, newspec ) ; 3729 3672 flagColOut.put( irow, newflag ) ; 3730 // IFNO renumbering (renumbered as frequency group ID)3673 // IFNO renumbering 3731 3674 ifnoColOut.put( irow, igrp ) ; 3732 3675 } … … 3739 3682 uInt index = 0 ; 3740 3683 uInt pixShift = 0 ; 3741 3742 3684 while ( freqgrp[igrp][index] != gmemid[igrp] ) { 3743 3685 pixShift += sizes[igrp][index++] ; 3744 3686 } 3745 3687 for ( uInt irow = 0 ; irow < out->table().nrow() ; irow++ ) { 3746 //if ( ifnoColOut( irow ) == gmemid[igrp] && !updated[igrp] ) { 3747 if ( ifnoColOut( irow ) == igrp && !updated[igrp] ) { 3688 if ( ifnoColOut( irow ) == gmemid[igrp] && !updated[igrp] ) { 3748 3689 uInt freqidOut = freqidColOut( irow ) ; 3749 3690 //os << "freqgrp " << igrp << " freqidOut = " << freqidOut << LogIO::POST ; … … 3752 3693 double increm ; 3753 3694 out->frequencies().getEntry( refpix, refval, increm, freqidOut ) ; 3754 if (increm < 0)3755 refpix = sizes[igrp][index] - 1 - refpix ; // reversed3756 3695 refpix += pixShift ; 3757 out->frequencies().setEntry( refpix, refval, gmaxdnu[igrp], freqidOut ) ;3696 out->frequencies().setEntry( refpix, refval, increm, freqidOut ) ; 3758 3697 updated[igrp] = true ; 3759 3698 }
Note:
See TracChangeset
for help on using the changeset viewer.
