Ignore:
Timestamp:
07/11/12 12:29:28 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-4010

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: sdcal unit test

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Rewrote STMath::new_average based on new algorithm. To do that,
Scantable::regridChannel is re-defined.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Scantable.cpp

    r2591 r2595  
    23042304}
    23052305
     2306void Scantable::regridChannel( int nChan, double dnu, double fmin, int irow )
     2307{
     2308  Vector<Float> oldspec = specCol_( irow ) ;
     2309  Vector<uChar> oldflag = flagsCol_( irow ) ;
     2310  Vector<Float> oldtsys = tsysCol_( irow ) ;
     2311  Vector<Float> newspec( nChan, 0 ) ;
     2312  Vector<uChar> newflag( nChan, true ) ;
     2313  Vector<Float> newtsys ;
     2314  bool regridTsys = false ;
     2315  if (oldtsys.size() == oldspec.size()) {
     2316    regridTsys = true ;
     2317    newtsys.resize(nChan,false) ;
     2318    newtsys = 0 ;
     2319  }
     2320 
     2321  // regrid
     2322  vector<double> abcissa = getAbcissa( irow ) ;
     2323  int oldsize = abcissa.size() ;
     2324  double olddnu = abcissa[1] - abcissa[0] ;
     2325  //int ichan = 0 ;
     2326  double wsum = 0.0 ;
     2327  Vector<double> zi( nChan+1 ) ;
     2328  Vector<double> yi( oldsize + 1 ) ;
     2329  Block<uInt> count( nChan, 0 ) ;
     2330  yi[0] = abcissa[0] - 0.5 * olddnu ;
     2331  for ( int ii = 1 ; ii < oldsize ; ii++ )
     2332    yi[ii] = 0.5* (abcissa[ii-1] + abcissa[ii]) ;
     2333  yi[oldsize] = abcissa[oldsize-1] \
     2334    + 0.5 * (abcissa[oldsize-1] - abcissa[oldsize-2]) ;
     2335//   cout << "olddnu=" << olddnu << ", dnu=" << dnu << " (diff=" << olddnu-dnu << ")" << endl ;
     2336//   cout << "yi[0]=" << yi[0] << ", fmin=" << fmin << " (diff=" << yi[0]-fmin << ")" << endl ;
     2337//   cout << "oldsize=" << oldsize << ", nChan=" << nChan << endl ;
     2338
     2339  // do not regrid if input parameters are almost same as current
     2340  // spectral setup
     2341  double dnuDiff = abs( ( dnu - olddnu ) / olddnu ) ;
     2342  double oldfmin = min( yi[0], yi[oldsize] ) ;
     2343  double fminDiff = abs( ( fmin - oldfmin ) / oldfmin ) ;
     2344  double nChanDiff = nChan - oldsize ;
     2345  double eps = 1.0e-8 ;
     2346  if ( nChanDiff == 0 && dnuDiff < eps && fminDiff < eps )
     2347    return ;
     2348
     2349  //zi[0] = abcissa[0] - 0.5 * olddnu ;
     2350  //zi[0] = ((olddnu*dnu > 0) ? yi[0] : yi[oldsize]) ;
     2351  if ( dnu > 0 )
     2352    zi[0] = fmin - 0.5 * dnu ;
     2353  else
     2354    zi[0] = fmin + nChan * abs(dnu) ;
     2355  for ( int ii = 1 ; ii < nChan ; ii++ )
     2356    zi[ii] = zi[0] + dnu * ii ;
     2357  zi[nChan] = zi[nChan-1] + dnu ;
     2358  // Access zi and yi in ascending order
     2359  int izs = ((dnu > 0) ? 0 : nChan ) ;
     2360  int ize = ((dnu > 0) ? nChan : 0 ) ;
     2361  int izincr = ((dnu > 0) ? 1 : -1 ) ;
     2362  int ichan =  ((olddnu > 0) ? 0 : oldsize ) ;
     2363  int iye = ((olddnu > 0) ? oldsize : 0 ) ;
     2364  int iyincr = ((olddnu > 0) ? 1 : -1 ) ;
     2365  //for ( int ii = izs ; ii != ize ; ii+=izincr ){
     2366  int ii = izs ;
     2367  while (ii != ize) {
     2368    // always zl < zr
     2369    double zl = zi[ii] ;
     2370    double zr = zi[ii+izincr] ;
     2371    // Need to access smaller index for the new spec, flag, and tsys.
     2372    // Values between zi[k] and zi[k+1] should be stored in newspec[k], etc.
     2373    int i = min(ii, ii+izincr) ;
     2374    //for ( int jj = ichan ; jj != iye ; jj+=iyincr ) {
     2375    int jj = ichan ;
     2376    while (jj != iye) {
     2377      // always yl < yr
     2378      double yl = yi[jj] ;
     2379      double yr = yi[jj+iyincr] ;
     2380      // Need to access smaller index for the original spec, flag, and tsys.
     2381      // Values between yi[k] and yi[k+1] are stored in oldspec[k], etc.
     2382      int j = min(jj, jj+iyincr) ;
     2383      if ( yr <= zl ) {
     2384        jj += iyincr ;
     2385        continue ;
     2386      }
     2387      else if ( yl <= zl ) {
     2388        if ( yr < zr ) {
     2389          if (!oldflag[j]) {
     2390            newspec[i] += oldspec[j] * ( yr - zl ) ;
     2391            if (regridTsys) newtsys[i] += oldtsys[j] * ( yr - zl ) ;
     2392            wsum += ( yr - zl ) ;
     2393            count[i]++ ;
     2394          }
     2395          newflag[i] = newflag[i] && oldflag[j] ;
     2396        }
     2397        else {
     2398          if (!oldflag[j]) {
     2399            newspec[i] += oldspec[j] * abs(dnu) ;
     2400            if (regridTsys) newtsys[i] += oldtsys[j] * abs(dnu) ;
     2401            wsum += abs(dnu) ;
     2402            count[i]++ ;
     2403          }
     2404          newflag[i] = newflag[i] && oldflag[j] ;
     2405          ichan = jj ;
     2406          break ;
     2407        }
     2408      }
     2409      else if ( yl < zr ) {
     2410        if ( yr <= zr ) {
     2411          if (!oldflag[j]) {
     2412            newspec[i] += oldspec[j] * ( yr - yl ) ;
     2413            if (regridTsys) newtsys[i] += oldtsys[j] * ( yr - yl ) ;
     2414            wsum += ( yr - yl ) ;
     2415            count[i]++ ;
     2416          }
     2417          newflag[i] = newflag[i] && oldflag[j] ;
     2418        }
     2419        else {
     2420          if (!oldflag[j]) {
     2421            newspec[i] += oldspec[j] * ( zr - yl ) ;
     2422            if (regridTsys) newtsys[i] += oldtsys[j] * ( zr - yl ) ;
     2423            wsum += ( zr - yl ) ;
     2424            count[i]++ ;
     2425          }
     2426          newflag[i] = newflag[i] && oldflag[j] ;
     2427          ichan = jj ;
     2428          break ;
     2429        }
     2430      }
     2431      else {
     2432        //ichan = jj - iyincr ;
     2433        break ;
     2434      }
     2435      jj += iyincr ;
     2436    }
     2437    if ( wsum != 0.0 ) {
     2438      newspec[i] /= wsum ;
     2439      if (regridTsys) newtsys[i] /= wsum ;
     2440    }
     2441    wsum = 0.0 ;
     2442    ii += izincr ;
     2443  }
     2444
     2445  // flag out channels without data
     2446  // this is tentative since there is no specific definition
     2447  // on bit flag...
     2448  uChar noData = 1 << 7 ;
     2449  for ( Int i = 0 ; i < nChan ; i++ ) {
     2450    if ( count[i] == 0 )
     2451      newflag[i] = noData ;
     2452  }
     2453
     2454  specCol_.put( irow, newspec ) ;
     2455  flagsCol_.put( irow, newflag ) ;
     2456  if (regridTsys) tsysCol_.put( irow, newtsys );
     2457
     2458  return ;
     2459}
     2460
    23062461std::vector<float> Scantable::getWeather(int whichrow) const
    23072462{
Note: See TracChangeset for help on using the changeset viewer.