Changeset 2466
- Timestamp:
- 04/13/12 21:33:47 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STMath.cpp
r2437 r2466 3045 3045 uInt rows = tmpin[itable]->nrow() ; 3046 3046 uInt freqnrows = tmpin[itable]->frequencies().table().nrow() ; 3047 freqIDCol.attach( tmpin[itable]->table(), "FREQ_ID" ) ; 3048 //ifnoCol.attach( tmpin[itable]->table(), "IFNO" ) ; 3047 3049 for ( uInt irow = 0 ; irow < rows ; irow++ ) { 3048 3050 if ( freqid[itable].size() == freqnrows ) { … … 3050 3052 } 3051 3053 else { 3052 freqIDCol.attach( tmpin[itable]->table(), "FREQ_ID" ) ;3053 ifnoCol.attach( tmpin[itable]->table(), "IFNO" ) ;3054 3054 uInt id = freqIDCol( irow ) ; 3055 3055 if ( freqid[itable].size() == 0 || count( freqid[itable].begin(), freqid[itable].end(), id ) == 0 ) { 3056 3056 //os << "itable = " << itable << ": IF " << id << " is included in the list" << LogIO::POST ; 3057 3057 vector<double> abcissa = tmpin[itable]->getAbcissa( irow ) ; 3058 double lbedge, rbedge; 3058 3059 freqid[itable].push_back( id ) ; 3059 iffreq[itable].push_back( abcissa[0] - 0.5 * ( abcissa[1] - abcissa[0] ) ) ; 3060 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) ) ; 3061 3064 } 3062 3065 } … … 3143 3146 // Grouping continuous IF groups (without frequency gap) 3144 3147 // freqgrp: list of IF group indexes in each frequency group 3145 // freqrange: list of minimum and maximum frequency in each frequency group3146 3148 // freqgrp[numgrp][nummember] 3147 3149 // freqgrp: [[ifgrp00, ifgrp01, ifgrp02, ...], … … 3149 3151 // ... 3150 3152 // [ifgrpn0, ifgrpn1, ifgrpn2, ...]] 3151 // freqrange[numgrp*2]3152 // freqrange: [min_grp0, max_grp0, min_grp1, max_grp1, ...]3153 3153 vector< vector<uInt> > freqgrp ; 3154 3154 double freqrange = 0.0 ; … … 3388 3388 double resol = abcissa[1] - abcissa[0] ; 3389 3389 //os << "abcissa range : [" << abcissa[0] << "," << abcissa[nchan-1] << "]" << LogIO::POST ; 3390 if ( minfreq <= abcissa[0] ) 3391 nminchan = 0 ; 3390 uInt imin, imax; 3391 int sigres; 3392 if ( resol >= 0. ) { 3393 imin = 0; 3394 imax = nchan - 1 ; 3395 sigres = 1 ; 3396 } else { 3397 imin = nchan - 1 ; 3398 imax = 0 ; 3399 sigres = -1 ; 3400 resol = abs(resol) ; 3401 } 3402 if ( minfreq <= abcissa[imin] ) 3403 nminchan = imin ; 3392 3404 else { 3393 3405 //double cfreq = ( minfreq - abcissa[0] ) / resol ; 3394 double cfreq = ( minfreq - abcissa[ 0] + 0.5 * resol ) / resol ;3395 nminchan = i nt(cfreq) + ( ( cfreq - int(cfreq) <= 0.5 ) ? 0 : 1) ;3406 double cfreq = ( minfreq - abcissa[imin] + 0.5 * resol ) / resol ; 3407 nminchan = imin + sigres * (int(cfreq) + ( ( cfreq - int(cfreq) <= 0.5 ) ? 0 : 1 )) ; 3396 3408 } 3397 if ( maxfreq >= abcissa[ abcissa.size()-1] )3398 nmaxchan = abcissa.size() - 1;3409 if ( maxfreq >= abcissa[imax] ) 3410 nmaxchan = imax; 3399 3411 else { 3400 3412 //double cfreq = ( abcissa[abcissa.size()-1] - maxfreq ) / resol ; 3401 double cfreq = ( abcissa[ abcissa.size()-1] - maxfreq + 0.5 * resol ) / resol ;3402 nmaxchan = abcissa.size() - 1 - int(cfreq) - ( ( cfreq - int(cfreq) >= 0.5 ) ? 1 : 0) ;3413 double cfreq = ( abcissa[imax] - maxfreq + 0.5 * resol ) / resol ; 3414 nmaxchan = imax - sigres * (int(cfreq) +( ( cfreq - int(cfreq) >= 0.5 ) ? 1 : 0 )) ; 3403 3415 } 3404 //os << "channel range (" << irow << "): [" << nminchan << "," << nmaxchan << "]" << LogIO::POST ; 3416 //os << "freqrange = [" << abcissa[nminchan] << ", " << abcissa[nmaxchan] << "]"<< LogIO::POST; 3417 if ( nmaxchan < nminchan ) { 3418 int tmp = nmaxchan ; 3419 nmaxchan = nminchan ; 3420 nminchan = tmp ; 3421 } 3405 3422 if ( nmaxchan > nminchan ) { 3406 3423 newin[itable]->reshapeSpectrum( nminchan, nmaxchan, irow ) ; 3407 3424 int newchan = nmaxchan - nminchan + 1 ; 3408 if ( count( freqIdUpdate.begin(), freqIdUpdate.end(), freqIdVec[itable][irow] ) == 0 && newchan < nchan ) 3425 if ( count( freqIdUpdate.begin(), freqIdUpdate.end(), freqIdVec[itable][irow] ) == 0 && newchan < nchan ) { 3409 3426 freqIdUpdate.push_back( freqIdVec[itable][irow] ) ; 3427 3428 // Update before nminchan is lost 3429 uInt freqId = freqIdVec[itable][irow] ; 3430 Double refpix ; 3431 Double refval ; 3432 Double increment ; 3433 newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ; 3434 //refval = refval - ( refpix - nminchan ) * increment ; 3435 refval = abcissa[nminchan] ; 3436 refpix = 0 ; 3437 newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ; 3438 } 3410 3439 } 3411 3440 else { … … 3413 3442 } 3414 3443 } 3415 for ( uInt i = 0 ; i < freqIdUpdate.size() ; i++ ) {3416 uInt freqId = freqIdUpdate[i] ;3417 Double refpix ;3418 Double refval ;3419 Double increment ;3444 // for ( uInt i = 0 ; i < freqIdUpdate.size() ; i++ ) { 3445 // uInt freqId = freqIdUpdate[i] ; 3446 // Double refpix ; 3447 // Double refval ; 3448 // Double increment ; 3420 3449 3421 // update row3422 newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ;3423 refval = refval - ( refpix - nminchan ) * increment ;3424 refpix = 0 ;3425 newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ;3426 }3450 // // update row 3451 // newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ; 3452 // refval = refval - ( refpix - nminchan ) * increment ; 3453 // refpix = 0 ; 3454 // newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ; 3455 // } 3427 3456 } 3428 3457 … … 3461 3490 if ( nchan < minchan ) { 3462 3491 minchan = nchan ; 3463 maxdnu = dnu;3492 maxdnu = abs(dnu) ; 3464 3493 newin[tableid]->frequencies().getEntry( refpixref, refvalref, refinc, rowid ) ; 3465 3494 refreqid = rowid ; 3466 3495 reftable = tableid ; 3496 // Spectra are reversed when dnu < 0 3497 if (dnu < 0) 3498 refpixref = minchan - 1 -refpixref ; 3467 3499 } 3468 3500 } … … 3479 3511 //os << " regridChannel applied to " ; 3480 3512 //if ( tableid != reftable ) 3481 refreqid = newin[tableid]->frequencies().addEntry( refpixref, refvalref, refinc) ;3513 refreqid = newin[tableid]->frequencies().addEntry( refpixref, refvalref, maxdnu ) ; 3482 3514 for ( uInt irow = 0 ; irow < newin[tableid]->table().nrow() ; irow++ ) { 3483 3515 uInt tfreqid = freqIdVec[tableid][irow] ; … … 3500 3532 vector<double> abcissa = newin[tableid]->getAbcissa( index ) ; 3501 3533 minchan = abcissa.size() ; 3502 maxdnu = ab cissa[1] - abcissa[0];3534 maxdnu = abs( abcissa[1] - abcissa[0]) ; 3503 3535 } 3504 3536 } … … 3538 3570 // combine frequency group 3539 3571 os << "Combine spectra based on frequency grouping" << LogIO::POST ; 3540 os << "IFNO is renumbered as frequency group ID (see above)" << LogIO::POST ; 3572 //os << "IFNO is renumbered as frequency group ID (see above)" << LogIO::POST ; 3573 os << "IFNO is renumbered as IF group ID (see above)" << LogIO::POST ; 3541 3574 vector<string> coordinfo = tmpout->getCoordInfo() ; 3542 3575 oldinfo[0] = coordinfo[0] ; … … 3570 3603 vector<double> abcissa = tmpout->getAbcissa( irow ) ; 3571 3604 double bw = ( abcissa[1] - abcissa[0] ) * abcissa.size() ; 3572 int nchan = (int)( bw / gmaxdnu[igrp] ) ; 3605 int nchan = (int) abs( bw / gmaxdnu[igrp] ) ; 3606 // All spectra will have positive frequency increments 3573 3607 tmpout->regridChannel( nchan, gmaxdnu[igrp], irow ) ; 3574 3608 break ; … … 3593 3627 cols[0] = String("POLNO") ; 3594 3628 TableIterator iter( tab, cols ) ; 3595 bool done = false ;3596 3629 vector< vector<uInt> > sizes( freqgrp.size() ) ; 3597 3630 while( !iter.pastEnd() ) { … … 3644 3677 // } 3645 3678 // get a list of number of channels for each frequency group member 3646 if ( !done ) { 3647 for ( uInt igrp = 0 ; igrp < freqgrp.size() ; igrp++ ) { 3648 sizes[igrp].resize( freqgrp[igrp].size() ) ; 3649 for ( uInt imem = 0 ; imem < freqgrp[igrp].size() ; imem++ ) { 3650 for ( uInt irow = 0 ; irow < iter.table().nrow() ; irow++ ) { 3651 uInt ifno = ifnoCol( irow ) ; 3652 if ( ifno == freqgrp[igrp][imem] ) { 3653 Vector<Float> spec = specCols( irow ) ; 3654 sizes[igrp][imem] = spec.nelements() ; 3655 break ; 3656 } 3657 } 3658 } 3659 } 3660 done = true ; 3679 for ( uInt igrp = 0 ; igrp < freqgrp.size() ; igrp++ ) { 3680 sizes[igrp].resize( freqgrp[igrp].size() ) ; 3681 for ( uInt imem = 0 ; imem < freqgrp[igrp].size() ; imem++ ) { 3682 for ( uInt irow = 0 ; irow < iter.table().nrow() ; irow++ ) { 3683 uInt ifno = ifnoCol( irow ) ; 3684 if ( ifno == freqgrp[igrp][imem] ) { 3685 Vector<Float> spec = specCols( irow ) ; 3686 sizes[igrp][imem] = spec.nelements() ; 3687 break ; 3688 } 3689 } 3690 } 3661 3691 } 3662 3692 // combine spectra … … 3705 3735 specColOut.put( irow, newspec ) ; 3706 3736 flagColOut.put( irow, newflag ) ; 3707 // IFNO renumbering 3737 // IFNO renumbering (renumbered as frequency group ID) 3708 3738 ifnoColOut.put( irow, igrp ) ; 3709 3739 } … … 3716 3746 uInt index = 0 ; 3717 3747 uInt pixShift = 0 ; 3748 3718 3749 while ( freqgrp[igrp][index] != gmemid[igrp] ) { 3719 3750 pixShift += sizes[igrp][index++] ; 3720 3751 } 3721 3752 for ( uInt irow = 0 ; irow < out->table().nrow() ; irow++ ) { 3722 if ( ifnoColOut( irow ) == gmemid[igrp] && !updated[igrp] ) { 3753 //if ( ifnoColOut( irow ) == gmemid[igrp] && !updated[igrp] ) { 3754 if ( ifnoColOut( irow ) == igrp && !updated[igrp] ) { 3723 3755 uInt freqidOut = freqidColOut( irow ) ; 3724 3756 //os << "freqgrp " << igrp << " freqidOut = " << freqidOut << LogIO::POST ; … … 3727 3759 double increm ; 3728 3760 out->frequencies().getEntry( refpix, refval, increm, freqidOut ) ; 3761 if (increm < 0) 3762 refpix = sizes[igrp][index] - 1 - refpix ; // reversed 3729 3763 refpix += pixShift ; 3730 out->frequencies().setEntry( refpix, refval, increm, freqidOut ) ;3764 out->frequencies().setEntry( refpix, refval, gmaxdnu[igrp], freqidOut ) ; 3731 3765 updated[igrp] = true ; 3732 3766 }
Note:
See TracChangeset
for help on using the changeset viewer.