Changeset 2443 for branches


Ignore:
Timestamp:
03/23/12 18:20:50 (13 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: No

Ready for Test: No

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs:

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Test tuning ALMA calibration code.


Location:
branches/hpc33/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/hpc33/src/STMath.cpp

    r2432 r2443  
    44504450}
    44514451
     4452vector<float> STMath::getSpectrumFromTime( double reftime,
     4453                                           CountedPtr<Scantable>& s,
     4454                                           string mode )
     4455{
     4456  LogIO os( LogOrigin( "STMath", "getSpectrumFromTime", WHERE ) ) ;
     4457  vector<float> sp ;
     4458
     4459  if ( s->nrow() == 0 ) {
     4460    os << LogIO::SEVERE << "No spectra in the input scantable. Return empty spectrum." << LogIO::POST ;
     4461    return sp ;
     4462  }
     4463  else if ( s->nrow() == 1 ) {
     4464    //os << "use row " << 0 << " (scanno = " << s->getScan( 0 ) << ")" << LogIO::POST ;
     4465    return s->getSpectrum( 0 ) ;
     4466  }
     4467  else {
     4468    ROScalarColumn<Double> timeCol( s->table(), "TIME" ) ;
     4469    Vector<Double> timeVec = timeCol.getColumn() ;
     4470    vector<int> idx = getRowIdFromTime( reftime, timeVec ) ;
     4471    if ( mode == "before" ) {
     4472      int id = -1 ;
     4473      if ( idx[0] != -1 ) {
     4474        id = idx[0] ;
     4475      }
     4476      else if ( idx[1] != -1 ) {
     4477        os << LogIO::WARN << "Failed to find a scan before reftime. return a spectrum just after the reftime." << LogIO::POST ;
     4478        id = idx[1] ;
     4479      }
     4480      //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
     4481      sp = s->getSpectrum( id ) ;
     4482    }
     4483    else if ( mode == "after" ) {
     4484      int id = -1 ;
     4485      if ( idx[1] != -1 ) {
     4486        id = idx[1] ;
     4487      }
     4488      else if ( idx[0] != -1 ) {
     4489        os << LogIO::WARN << "Failed to find a scan after reftime. return a spectrum just before the reftime." << LogIO::POST ;
     4490        id = idx[1] ;
     4491      }
     4492      //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
     4493      sp = s->getSpectrum( id ) ;
     4494    }
     4495    else if ( mode == "nearest" ) {
     4496      int id = -1 ;
     4497      if ( idx[0] == -1 ) {
     4498        id = idx[1] ;
     4499      }
     4500      else if ( idx[1] == -1 ) {
     4501        id = idx[0] ;
     4502      }
     4503      else if ( idx[0] == idx[1] ) {
     4504        id = idx[0] ;
     4505      }
     4506      else {
     4507        //double t0 = getMJD( s->getTime( idx[0] ) ) ;
     4508        //double t1 = getMJD( s->getTime( idx[1] ) ) ;
     4509//         double t0 = s->getEpoch( idx[0] ).get( Unit( "d" ) ).getValue() ;
     4510//         double t1 = s->getEpoch( idx[1] ).get( Unit( "d" ) ).getValue() ;
     4511        double t0 = timeVec[idx[0]] ;
     4512        double t1 = timeVec[idx[1]] ;
     4513//         cout << "t0-t0c=" << t0-t0c << endl ;
     4514//         cout << "t1-t1c=" << t1-t1c << endl ;
     4515//         double tref = getMJD( reftime ) ;
     4516        double tref = reftime ;
     4517        if ( abs( t0 - tref ) > abs( t1 - tref ) ) {
     4518          id = idx[1] ;
     4519        }
     4520        else {
     4521          id = idx[0] ;
     4522        }
     4523      }
     4524      //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
     4525      sp = s->getSpectrum( id ) ;     
     4526    }
     4527    else if ( mode == "linear" ) {
     4528      if ( idx[0] == -1 ) {
     4529        // use after
     4530        os << LogIO::WARN << "Failed to interpolate. return a spectrum just after the reftime." << LogIO::POST ;
     4531        int id = idx[1] ;
     4532        //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
     4533        sp = s->getSpectrum( id ) ;
     4534      }
     4535      else if ( idx[1] == -1 ) {
     4536        // use before
     4537        os << LogIO::WARN << "Failed to interpolate. return a spectrum just before the reftime." << LogIO::POST ;
     4538        int id = idx[0] ;
     4539        //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
     4540        sp = s->getSpectrum( id ) ;
     4541      }
     4542      else if ( idx[0] == idx[1] ) {
     4543        // use before
     4544        //os << "No need to interporate." << LogIO::POST ;
     4545        int id = idx[0] ;
     4546        //os << "use row " << id << " (scanno = " << s->getScan( id ) << ")" << LogIO::POST ;
     4547        sp = s->getSpectrum( id ) ;
     4548      }
     4549      else {
     4550        // do interpolation
     4551        //os << "interpolate between " << idx[0] << " and " << idx[1] << " (scanno: " << s->getScan( idx[0] ) << ", " << s->getScan( idx[1] ) << ")" << LogIO::POST ;
     4552        //double t0 = getMJD( s->getTime( idx[0] ) ) ;
     4553        //double t1 = getMJD( s->getTime( idx[1] ) ) ;
     4554//         double t0 = s->getEpoch( idx[0] ).get( Unit( "d" ) ).getValue() ;
     4555//         double t1 = s->getEpoch( idx[1] ).get( Unit( "d" ) ).getValue() ;
     4556        double t0 = timeVec[idx[0]] ;
     4557        double t1 = timeVec[idx[1]] ;
     4558//         cout << "t0-t0c=" << t0-t0c << endl ;
     4559//         cout << "t1-t1c=" << t1-t1c << endl ;
     4560//         double tref = getMJD( reftime ) ;
     4561        double tref = reftime ;
     4562        vector<float> sp0 = s->getSpectrum( idx[0] ) ;
     4563        vector<float> sp1 = s->getSpectrum( idx[1] ) ;
     4564        for ( unsigned int i = 0 ; i < sp0.size() ; i++ ) {
     4565          float v = ( sp1[i] - sp0[i] ) / ( t1 - t0 ) * ( tref - t0 ) + sp0[i] ;
     4566          sp.push_back( v ) ;
     4567        }
     4568      }
     4569    }
     4570    else {
     4571      os << LogIO::SEVERE << "Unknown mode" << LogIO::POST ;
     4572    }
     4573    return sp ;
     4574  }
     4575}
     4576
    44524577double STMath::getMJD( string strtime )
    44534578{
     
    45084633  v.push_back( just_before ) ;
    45094634  v.push_back( just_after ) ;
     4635
     4636  return v ;
     4637}
     4638
     4639vector<int> STMath::getRowIdFromTime( double reftime, Vector<Double> &t )
     4640{
     4641//   double reft = reftime ;
     4642  double dtmin = 1.0e100 ;
     4643  double dtmax = -1.0e100 ;
     4644//   vector<double> dt ;
     4645  int just_before = -1 ;
     4646  int just_after = -1 ;
     4647  //cout << setprecision(24) << reft << endl ;
     4648//   ROScalarColumn<Double> timeCol( s->table(), "TIME" ) ;
     4649//   for ( int i = 0 ; i < s->nrow() ; i++ ) {
     4650//     cout << setprecision(24) << timeCol(i) << endl ;
     4651//     //dt.push_back( getMJD( s->getTime( i ) ) - reft ) ;
     4652//     dt.push_back( timeCol(i) - reft ) ;
     4653//   }
     4654  Vector<Double> dt = t - reftime ;
     4655  for ( unsigned int i = 0 ; i < dt.size() ; i++ ) {
     4656    if ( dt[i] > 0.0 ) {
     4657      // after reftime
     4658      if ( dt[i] < dtmin ) {
     4659        just_after = i ;
     4660        dtmin = dt[i] ;
     4661      }
     4662    }
     4663    else if ( dt[i] < 0.0 ) {
     4664      // before reftime
     4665      if ( dt[i] > dtmax ) {
     4666        just_before = i ;
     4667        dtmax = dt[i] ;
     4668      }
     4669    }
     4670    else {
     4671      // just a reftime
     4672      just_before = i ;
     4673      just_after = i ;
     4674      dtmax = 0 ;
     4675      dtmin = 0 ;
     4676      break ;
     4677    }
     4678  }
     4679
     4680  vector<int> v(2) ;
     4681  v[0] = just_before ;
     4682  v[1] = just_after ;
    45104683
    45114684  return v ;
     
    48335006                                            int index )
    48345007{
    4835   string reftime = on->getTime( index ) ;
     5008//   string reftime = on->getTime( index ) ;
     5009  ROTableColumn timeCol( on->table(), "TIME" ) ;
     5010  double reftime = timeCol.asdouble(index) ;
    48365011  vector<int> ii( 1, on->getIF( index ) ) ;
    48375012  vector<int> ib( 1, on->getBeam( index ) ) ;
  • branches/hpc33/src/STMath.h

    r2186 r2443  
    403403
    404404  vector<float> getSpectrumFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode = "before" ) ;
     405  vector<float> getSpectrumFromTime( double reftime, casa::CountedPtr<Scantable>& s, string mode = "before" ) ;
    405406  vector<float> getTcalFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode="before" ) ;
    406407  vector<float> getTsysFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode="before" ) ;
    407408  vector<int> getRowIdFromTime( string reftime, casa::CountedPtr<Scantable>& s ) ;
     409  vector<int> getRowIdFromTime( double reftime, casa::Vector<casa::Double>& t ) ;
    408410
    409411  // Chopper-Wheel type calibration
Note: See TracChangeset for help on using the changeset viewer.