Changes in trunk/src/STMath.cpp [2345:2467]
- File:
-
- 1 edited
-
trunk/src/STMath.cpp (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STMath.cpp
r2345 r2467 57 57 using namespace asap; 58 58 59 // 2012/02/17 TN 60 // Since STGrid is implemented, average doesn't consider direction 61 // when accumulating 59 62 // tolerance for direction comparison (rad) 60 #define TOL_OTF 1.0e-1561 #define TOL_POINT 2.9088821e-4 // 1 arcmin63 // #define TOL_OTF 1.0e-15 64 // #define TOL_POINT 2.9088821e-4 // 1 arcmin 62 65 63 66 STMath::STMath(bool insitu) : … … 83 86 WeightType wtype = stringToWeight(weight); 84 87 88 // 2012/02/17 TN 89 // Since STGrid is implemented, average doesn't consider direction 90 // when accumulating 85 91 // check if OTF observation 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 }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 // } 94 100 95 101 // output … … 142 148 while (!iter.pastEnd()) { 143 149 Table subt = iter.table(); 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)); 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 // } 150 186 // } 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 ; 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 ; 188 197 ++iter; 189 198 } … … 218 227 } 219 228 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 } 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 // } 237 249 238 if ( nrsubt == removeRows.size() )239 throw(AipsError("Averaging data is empty.")) ;250 // if ( nrsubt == removeRows.size() ) 251 // throw(AipsError("Averaging data is empty.")) ; 240 252 241 253 specCol.attach(subt,"SPECTRA"); … … 321 333 { 322 334 (void) mode; // currently unused 335 // 2012/02/17 TN 336 // Since STGrid is implemented, average doesn't consider direction 337 // when accumulating 323 338 // check if OTF observation 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 }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 // } 332 347 333 348 // clone as this is non insitu … … 362 377 flagCol.attach(subt,"FLAGTRA"); 363 378 tsysCol.attach(subt,"TSYS"); 364 // tout.addRow(); 365 // TableCopy::copyRows(tout, subt, outrowCount, 0, 1); 366 // if ( avmode != "SCAN") { 367 // scanColOut.put(outrowCount, uInt(0)); 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; 408 ++iter; 409 410 // 2012/02/17 TN 411 // Since STGrid is implemented, average doesn't consider direction 412 // when accumulating 413 // 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 averaging 419 // if (in->nbeam() > 1 ) { 420 // length = 1; 368 421 // } 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 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 // } 384 440 // } 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; 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 averaging 446 // 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 MaskedArrMath 459 // // doesn't have partialMedians 460 // Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0))); 461 // // mask spectra for different DIRECTION 462 // 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 based 477 // 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 data 483 // } 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 ; 392 494 // ++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 averaging399 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 averaging426 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 MaskedArrMath439 // doesn't have partialMedians440 Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));441 // mask spectra for different DIRECTION442 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 based457 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 data463 }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 ;474 ++iter;475 495 } 476 496 return out; … … 1910 1930 ArrayColumn<Float> specCol(tout, "SPECTRA"); 1911 1931 ArrayColumn<uChar> flagCol(tout, "FLAGTRA"); 1932 ArrayColumn<Float> tsysCol(tout, "TSYS"); 1933 1912 1934 for (uInt i=0; i < tout.nrow(); ++i ) { 1913 1935 MaskedArray<Float> main = maskedArray(specCol(i), flagCol(i)); 1914 1936 MaskedArray<Float> maout; 1915 1937 LatticeUtilities::bin(maout, main, 0, Int(width)); 1916 /// @todo implement channel based tsys binning1917 1938 specCol.put(i, maout.getArray()); 1918 1939 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 } 1919 1946 // take only the first binned spectrum's length for the deprecated 1920 1947 // global header item nChan … … 2750 2777 mask, timeCol(i), !first, 2751 2778 interp, False); 2752 (void) ok; // unused stop compiler nagging 2779 (void) ok; // unused stop compiler nagging 2753 2780 // back into scantable 2754 2781 flagOut.resize(maskOut.nelements()); … … 2954 2981 "Use merge first.")); 2955 2982 2983 // 2012/02/17 TN 2984 // Since STGrid is implemented, average doesn't consider direction 2985 // when accumulating 2956 2986 // check if OTF observation 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 }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 // } 2965 2995 2966 2996 CountedPtr<Scantable> out ; // processed result … … 3015 3045 uInt rows = tmpin[itable]->nrow() ; 3016 3046 uInt freqnrows = tmpin[itable]->frequencies().table().nrow() ; 3047 freqIDCol.attach( tmpin[itable]->table(), "FREQ_ID" ) ; 3048 //ifnoCol.attach( tmpin[itable]->table(), "IFNO" ) ; 3017 3049 for ( uInt irow = 0 ; irow < rows ; irow++ ) { 3018 3050 if ( freqid[itable].size() == freqnrows ) { … … 3020 3052 } 3021 3053 else { 3022 freqIDCol.attach( tmpin[itable]->table(), "FREQ_ID" ) ;3023 ifnoCol.attach( tmpin[itable]->table(), "IFNO" ) ;3024 3054 uInt id = freqIDCol( irow ) ; 3025 3055 if ( freqid[itable].size() == 0 || count( freqid[itable].begin(), freqid[itable].end(), id ) == 0 ) { 3026 3056 //os << "itable = " << itable << ": IF " << id << " is included in the list" << LogIO::POST ; 3027 3057 vector<double> abcissa = tmpin[itable]->getAbcissa( irow ) ; 3058 double lbedge, rbedge; 3028 3059 freqid[itable].push_back( id ) ; 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] ) ) ; 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) ) ; 3031 3064 } 3032 3065 } … … 3113 3146 // Grouping continuous IF groups (without frequency gap) 3114 3147 // freqgrp: list of IF group indexes in each frequency group 3115 // freqrange: list of minimum and maximum frequency in each frequency group3116 3148 // freqgrp[numgrp][nummember] 3117 3149 // freqgrp: [[ifgrp00, ifgrp01, ifgrp02, ...], … … 3119 3151 // ... 3120 3152 // [ifgrpn0, ifgrpn1, ifgrpn2, ...]] 3121 // freqrange[numgrp*2]3122 // freqrange: [min_grp0, max_grp0, min_grp1, max_grp1, ...]3123 3153 vector< vector<uInt> > freqgrp ; 3124 3154 double freqrange = 0.0 ; … … 3136 3166 freqrange = ifgfreq[2*i+1] ; 3137 3167 } 3138 3168 3139 3169 3140 3170 // print IF groups … … 3325 3355 3326 3356 // save column values in the vector 3327 vector< vector<uInt> > freqTableIdVec( insize ) ;3328 3357 vector< vector<uInt> > freqIdVec( insize ) ; 3329 3358 vector< vector<uInt> > ifNoVec( insize ) ; 3330 3359 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 3331 ScalarColumn<uInt> freqIDs ;3332 freqIDs.attach( newin[itable]->frequencies().table(), "ID" ) ;3333 3360 ifnoCol.attach( newin[itable]->table(), "IFNO" ) ; 3334 3361 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 }3338 3362 for ( uInt irow = 0 ; irow < newin[itable]->table().nrow() ; irow++ ) { 3339 3363 freqIdVec[itable].push_back( freqIDCol( irow ) ) ; … … 3350 3374 vector<uInt> freqIdUpdate ; 3351 3375 for ( uInt irow = 0 ; irow < rows ; irow++ ) { 3352 uInt ifno = ifNoVec[itable][irow] ; // IFNO is reset by group index 3376 uInt ifno = ifNoVec[itable][irow] ; // IFNO is reset by group index (IF group index) 3353 3377 double minfreq = ifgfreq[2*ifno] ; 3354 3378 double maxfreq = ifgfreq[2*ifno+1] ; … … 3358 3382 double resol = abcissa[1] - abcissa[0] ; 3359 3383 //os << "abcissa range : [" << abcissa[0] << "," << abcissa[nchan-1] << "]" << LogIO::POST ; 3360 if ( minfreq <= abcissa[0] ) 3361 nminchan = 0 ; 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 ; 3362 3398 else { 3363 3399 //double cfreq = ( minfreq - abcissa[0] ) / resol ; 3364 double cfreq = ( minfreq - abcissa[ 0] + 0.5 * resol ) / resol ;3365 nminchan = i nt(cfreq) + ( ( cfreq - int(cfreq) <= 0.5 ) ? 0 : 1) ;3400 double cfreq = ( minfreq - abcissa[imin] + 0.5 * resol ) / resol ; 3401 nminchan = imin + sigres * (int(cfreq) + ( ( cfreq - int(cfreq) <= 0.5 ) ? 0 : 1 )) ; 3366 3402 } 3367 if ( maxfreq >= abcissa[ abcissa.size()-1] )3368 nmaxchan = abcissa.size() - 1;3403 if ( maxfreq >= abcissa[imax] ) 3404 nmaxchan = imax; 3369 3405 else { 3370 3406 //double cfreq = ( abcissa[abcissa.size()-1] - maxfreq ) / resol ; 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) ;3407 double cfreq = ( abcissa[imax] - maxfreq + 0.5 * resol ) / resol ; 3408 nmaxchan = imax - sigres * (int(cfreq) +( ( cfreq - int(cfreq) >= 0.5 ) ? 1 : 0 )) ; 3373 3409 } 3374 3410 //os << "channel range (" << irow << "): [" << nminchan << "," << nmaxchan << "]" << LogIO::POST ; 3411 if ( nmaxchan < nminchan ) { 3412 int tmp = nmaxchan ; 3413 nmaxchan = nminchan ; 3414 nminchan = tmp ; 3415 } 3375 3416 if ( nmaxchan > nminchan ) { 3376 3417 newin[itable]->reshapeSpectrum( nminchan, nmaxchan, irow ) ; 3377 3418 int newchan = nmaxchan - nminchan + 1 ; 3378 if ( count( freqIdUpdate.begin(), freqIdUpdate.end(), freqIdVec[itable][irow] ) == 0 && newchan < nchan ) 3419 if ( count( freqIdUpdate.begin(), freqIdUpdate.end(), freqIdVec[itable][irow] ) == 0 && newchan < nchan ) { 3379 3420 freqIdUpdate.push_back( freqIdVec[itable][irow] ) ; 3421 3422 // Update before nminchan is lost 3423 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 } 3380 3433 } 3381 3434 else { … … 3383 3436 } 3384 3437 } 3385 for ( uInt i = 0 ; i < freqIdUpdate.size() ; i++ ) {3386 uInt freqId = freqIdUpdate[i] ;3387 Double refpix ;3388 Double refval ;3389 Double increment ;3438 // for ( uInt i = 0 ; i < freqIdUpdate.size() ; i++ ) { 3439 // uInt freqId = freqIdUpdate[i] ; 3440 // Double refpix ; 3441 // Double refval ; 3442 // Double increment ; 3390 3443 3391 // update row3392 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 }3444 // // update row 3445 // 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 // } 3397 3450 } 3398 3451 … … 3431 3484 if ( nchan < minchan ) { 3432 3485 minchan = nchan ; 3433 maxdnu = dnu;3486 maxdnu = abs(dnu) ; 3434 3487 newin[tableid]->frequencies().getEntry( refpixref, refvalref, refinc, rowid ) ; 3435 3488 refreqid = rowid ; 3436 3489 reftable = tableid ; 3490 // Spectra are reversed when dnu < 0 3491 if (dnu < 0) 3492 refpixref = minchan - 1 -refpixref ; 3437 3493 } 3438 3494 } … … 3449 3505 //os << " regridChannel applied to " ; 3450 3506 //if ( tableid != reftable ) 3451 refreqid = newin[tableid]->frequencies().addEntry( refpixref, refvalref, refinc) ;3507 refreqid = newin[tableid]->frequencies().addEntry( refpixref, refvalref, maxdnu ) ; 3452 3508 for ( uInt irow = 0 ; irow < newin[tableid]->table().nrow() ; irow++ ) { 3453 3509 uInt tfreqid = freqIdVec[tableid][irow] ; … … 3470 3526 vector<double> abcissa = newin[tableid]->getAbcissa( index ) ; 3471 3527 minchan = abcissa.size() ; 3472 maxdnu = ab cissa[1] - abcissa[0];3528 maxdnu = abs( abcissa[1] - abcissa[0]) ; 3473 3529 } 3474 3530 } … … 3540 3596 vector<double> abcissa = tmpout->getAbcissa( irow ) ; 3541 3597 double bw = ( abcissa[1] - abcissa[0] ) * abcissa.size() ; 3542 int nchan = (int)( bw / gmaxdnu[igrp] ) ; 3598 int nchan = (int) abs( bw / gmaxdnu[igrp] ) ; 3599 // All spectra will have positive frequency increments 3543 3600 tmpout->regridChannel( nchan, gmaxdnu[igrp], irow ) ; 3544 3601 break ; … … 3557 3614 ScalarColumn<uInt> freqidColOut ; 3558 3615 freqidColOut.attach( out->table(), "FREQ_ID" ) ; 3559 MDirection::ScalarColumn dirColOut ;3560 dirColOut.attach( out->table(), "DIRECTION" ) ;3616 // MDirection::ScalarColumn dirColOut ; 3617 // dirColOut.attach( out->table(), "DIRECTION" ) ; 3561 3618 Table &tab = tmpout->table() ; 3562 3619 Block<String> cols(1); 3563 3620 cols[0] = String("POLNO") ; 3564 3621 TableIterator iter( tab, cols ) ; 3565 bool done = false ;3566 3622 vector< vector<uInt> > sizes( freqgrp.size() ) ; 3567 3623 while( !iter.pastEnd() ) { … … 3575 3631 ScalarColumn<uInt> polnos ; 3576 3632 polnos.attach( iter.table(), "POLNO" ) ; 3577 MDirection::ScalarColumn dircol ;3578 dircol.attach( iter.table(), "DIRECTION" ) ;3633 // MDirection::ScalarColumn dircol ; 3634 // dircol.attach( iter.table(), "DIRECTION" ) ; 3579 3635 uInt polno = polnos( 0 ) ; 3580 3636 //os << "POLNO iteration: " << polno << LogIO::POST ; … … 3614 3670 // } 3615 3671 // get a list of number of channels for each frequency group member 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 ; 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 } 3631 3684 } 3632 3685 // combine spectra … … 3635 3688 if ( polout == polno ) { 3636 3689 uInt ifout = ifnoColOut( irow ) ; 3637 Vector<Double> direction = dirColOut(irow).getAngle(Unit(String("rad"))).getValue() ;3690 // Vector<Double> direction = dirColOut(irow).getAngle(Unit(String("rad"))).getValue() ; 3638 3691 uInt igrp ; 3639 3692 for ( uInt jgrp = 0 ; jgrp < freqgrp.size() ; jgrp++ ) { … … 3646 3699 for ( uInt jrow = 0 ; jrow < iter.table().nrow() ; jrow++ ) { 3647 3700 uInt ifno = ifnoCol( jrow ) ; 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 ) ; 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 ) ; 3653 3709 //if ( ifno == freqgrp[igrp][imem] && allNearAbs( tdir, direction, tol ) ) { 3654 if ( ifno == freqgrp[igrp][imem] && dd <= tol ) { 3710 // if ( ifno == freqgrp[igrp][imem] && dd <= tol ) { 3711 if ( ifno == freqgrp[igrp][imem] ) { 3655 3712 Vector<Float> spec = specCols( jrow ) ; 3656 3713 Vector<uChar> flag = flagCols( jrow ) ; … … 3671 3728 specColOut.put( irow, newspec ) ; 3672 3729 flagColOut.put( irow, newflag ) ; 3673 // IFNO renumbering 3730 // IFNO renumbering (renumbered as frequency group ID) 3674 3731 ifnoColOut.put( irow, igrp ) ; 3675 3732 } … … 3682 3739 uInt index = 0 ; 3683 3740 uInt pixShift = 0 ; 3741 3684 3742 while ( freqgrp[igrp][index] != gmemid[igrp] ) { 3685 3743 pixShift += sizes[igrp][index++] ; 3686 3744 } 3687 3745 for ( uInt irow = 0 ; irow < out->table().nrow() ; irow++ ) { 3688 if ( ifnoColOut( irow ) == gmemid[igrp] && !updated[igrp] ) { 3746 //if ( ifnoColOut( irow ) == gmemid[igrp] && !updated[igrp] ) { 3747 if ( ifnoColOut( irow ) == igrp && !updated[igrp] ) { 3689 3748 uInt freqidOut = freqidColOut( irow ) ; 3690 3749 //os << "freqgrp " << igrp << " freqidOut = " << freqidOut << LogIO::POST ; … … 3693 3752 double increm ; 3694 3753 out->frequencies().getEntry( refpix, refval, increm, freqidOut ) ; 3754 if (increm < 0) 3755 refpix = sizes[igrp][index] - 1 - refpix ; // reversed 3695 3756 refpix += pixShift ; 3696 out->frequencies().setEntry( refpix, refval, increm, freqidOut ) ;3757 out->frequencies().setEntry( refpix, refval, gmaxdnu[igrp], freqidOut ) ; 3697 3758 updated[igrp] = true ; 3698 3759 }
Note:
See TracChangeset
for help on using the changeset viewer.
