Changeset 2727 for trunk


Ignore:
Timestamp:
01/11/13 18:48:37 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-4770, CAS-4774

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Updated STApplyCal to be able to specify interpolation method.
The method can be specified in time and frequency axes independently.
Possible options are nearest, linear (default), (natural) cubic spline,
and polynomial with arbitrary order.

Location:
trunk/src
Files:
12 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/BisectionLocator.cpp

    r2720 r2727  
    1212#include <assert.h>
    1313
    14 #include <casa/Arrays/Vector.h>
    15 #include <casa/Arrays/ArrayIO.h>
    16 #include <casa/Exceptions/Error.h>
    17 
    1814#include "BisectionLocator.h"
    19 
    20 using namespace casa;
    2115
    2216namespace asap {
     
    3933    else if (x > x_[n_-1])
    4034      return n_;
     35
     36    unsigned int jl = 0;
     37    unsigned int ju = n_;
     38    unsigned int jm;
     39    while (ju - jl > 1) {
     40      jm = (ju + jl) >> 1;
     41      if (x > x_[jm])
     42        jl = jm;
     43      else
     44        ju = jm;
     45    }
     46    return ju;
    4147  }
    4248  else {
    43     if (x > x_[0])
     49    if (x >= x_[0])
    4450      return 0;
    45     else if (x <= x_[n_-1])
     51    else if (x < x_[n_-1])
    4652      return n_;
     53
     54    unsigned int jl = 0;
     55    unsigned int ju = n_;
     56    unsigned int jm;
     57    while (ju - jl > 1) {
     58      jm = (ju + jl) >> 1;
     59      if (x < x_[jm])
     60        jl = jm;
     61      else
     62        ju = jm;
     63    }
     64    return ju;
    4765  }
    48   unsigned int jl = 0;
    49   unsigned int ju = n_;
    50   unsigned int jm;
    51 
    52   while (ju - jl > 1) {
    53     jm = (ju + jl) >> 1;
    54     if ((x >= x_[jm]) == ascending)
    55       jl = jm;
    56     else
    57       ju = jm;
    58   }
    59   return ju;
    6066}
    6167
  • trunk/src/BisectionLocator.h

    r2720 r2727  
    1212#ifndef ASAP_BISECTION_LOCATOR_H
    1313#define ASAP_BISECTION_LOCATOR_H
    14 
    15 #include <memory>
    16 #include <vector>
    17 
    18 #include <casa/aips.h>
    19 #include <casa/Arrays/Vector.h>
    20 #include <casa/Arrays/Matrix.h>
    21 #include <casa/BasicSL/String.h>
    22 #include <casa/Utilities/CountedPtr.h>
    2314
    2415#include "Locator.h"
  • trunk/src/CMakeLists.txt

    r2720 r2727  
    8282     ${SRCDIR}/Locator.cpp
    8383     ${SRCDIR}/BisectionLocator.cpp
     84     ${SRCDIR}/HuntLocator.cpp
     85     ${SRCDIR}/BufferedBisectionLocator.cpp
    8486     ${SRCDIR}/Interpolator1D.cpp
    85      ${SRCDIR}/NearestInterpolator1D.cpp )
     87     ${SRCDIR}/NearestInterpolator1D.cpp
     88     ${SRCDIR}/LinearInterpolator1D.cpp
     89     ${SRCDIR}/BufferedLinearInterpolator1D.cpp
     90     ${SRCDIR}/CubicSplineInterpolator1D.cpp
     91     ${SRCDIR}/PolynomialInterpolator1D.cpp )
    8692
    8793set( ASAP_PYSRCS
  • trunk/src/Interpolator1D.cpp

    r2720 r2727  
    1717#include "Interpolator1D.h"
    1818#include "BisectionLocator.h"
     19#include "HuntLocator.h"
    1920
    2021using namespace casa;
     
    2324
    2425Interpolator1D::Interpolator1D()
    25   : order_(0),
     26  : order_(1),
    2627    n_(0),
    2728    x_(0),
    28     y_(0)
     29    y_(0),
     30    locator_(0)
    2931{
    30   locator_ = new BisectionLocator();
    3132}
    3233
     
    4243  y_ = y;
    4344  n_ = n;
     45  createLocator();
    4446  locator_->set(x, n);
    4547}
     
    5052  x_ = x;
    5153  n_ = n;
     54  createLocator();
    5255  locator_->set(x, n);
    5356}
     
    6568  x_ = 0;
    6669  y_ = 0;
     70  if (locator_) {
     71    delete locator_;
     72    locator_ = 0;
     73  }
    6774}
    6875
     
    7784}
    7885
     86void Interpolator1D::createLocator()
     87{
     88  if (!locator_) {
     89    if (n_ > 1000)
     90      locator_ = new HuntLocator();
     91    else
     92      locator_ = new BisectionLocator();
     93  }
    7994}
     95
     96}
  • trunk/src/Interpolator1D.h

    r2720 r2727  
    1212#ifndef ASAP_INTERPOLATOR_1D_H
    1313#define ASAP_INTERPOLATOR_1D_H
    14 
    15 #include <memory>
    16 #include <vector>
    17 
    18 #include <casa/aips.h>
    19 #include <casa/Containers/Block.h>
    20 #include <casa/Arrays/Vector.h>
    21 #include <casa/Arrays/Matrix.h>
    22 #include <casa/BasicSL/String.h>
    23 #include <casa/Utilities/CountedPtr.h>
    2414
    2515#include "Locator.h"
     
    4131  void setY(float *y, unsigned int n);
    4232  void reset();
     33
     34  // currently only effective for polynomial interpolation
    4335  void setOrder(unsigned int order) {order_ = order;}
    4436
     
    4840  int locate(double x);
    4941  bool isready();
     42  void createLocator();
    5043
    5144  unsigned int order_;
  • trunk/src/Locator.cpp

    r2720 r2727  
    1212#include <assert.h>
    1313
    14 #include <casa/Arrays/Vector.h>
    15 #include <casa/Exceptions/Error.h>
    16 
    1714#include "Locator.h"
    18 
    19 using namespace casa;
    2015
    2116namespace asap {
  • trunk/src/Locator.h

    r2720 r2727  
    1212#ifndef ASAP_LOCATOR_H
    1313#define ASAP_LOCATOR_H
    14 
    15 #include <memory>
    16 #include <vector>
    17 
    18 #include <casa/aips.h>
    19 #include <casa/Arrays/Vector.h>
    20 #include <casa/Arrays/Matrix.h>
    21 #include <casa/BasicSL/String.h>
    22 #include <casa/Utilities/CountedPtr.h>
    2314
    2415namespace asap {
  • trunk/src/STApplyCal.cpp

    r2722 r2727  
    3434#include "PSAlmaCalibrator.h"
    3535#include "NearestInterpolator1D.h"
     36#include "BufferedLinearInterpolator1D.h"
     37#include "PolynomialInterpolator1D.h"
     38#include "CubicSplineInterpolator1D.h"
    3639#include <atnf/PKSIO/SrcType.h>
    3740
     
    6265  doTsys_ = False;
    6366  interp_.resize((int)STCalEnum::NumAxis);
     67  // default is linear interpolation
     68  for (unsigned int i = 0; i < interp_.size(); i++) {
     69    interp_[i] = STCalEnum::LinearInterpolation;
     70  }
    6471}
    6572
     
    125132
    126133  // interpolator
    127   interpolatorS_ = new NearestInterpolator1D();
    128   interpolatorT_ = new NearestInterpolator1D();
    129   interpolatorF_ = new NearestInterpolator1D();
     134  initInterpolator();
    130135
    131136  // select data
     
    450455}
    451456
    452 }
     457void STApplyCal::initInterpolator()
     458{
     459  int ta = (int)STCalEnum::TimeAxis;
     460  int fa = (int)STCalEnum::FrequencyAxis;
     461  int order = (order_ > 0) ? order_ : 1;
     462  switch (interp_[ta]) {
     463  case STCalEnum::NearestInterpolation:
     464    {
     465      os_ << "use NearestInterpolator in time axis" << LogIO::POST;
     466      interpolatorS_ = new NearestInterpolator1D();
     467      interpolatorT_ = new NearestInterpolator1D();
     468      break;
     469    }
     470  case STCalEnum::LinearInterpolation:
     471    {
     472      os_ << "use BufferedLinearInterpolator in time axis" << LogIO::POST;
     473      interpolatorS_ = new BufferedLinearInterpolator1D();
     474      interpolatorT_ = new BufferedLinearInterpolator1D();
     475      break;     
     476    }
     477  case STCalEnum::CubicSplineInterpolation:
     478    {
     479      os_ << "use CubicSplineInterpolator in time axis" << LogIO::POST;
     480      interpolatorS_ = new CubicSplineInterpolator1D();
     481      interpolatorT_ = new CubicSplineInterpolator1D();
     482      break;
     483    }
     484  case STCalEnum::PolynomialInterpolation:
     485    {
     486      os_ << "use PolynomialInterpolator in time axis" << LogIO::POST;
     487      if (order == 0) {
     488        interpolatorS_ = new NearestInterpolator1D();
     489        interpolatorT_ = new NearestInterpolator1D();
     490      }
     491      else {
     492        interpolatorS_ = new PolynomialInterpolator1D();
     493        interpolatorT_ = new PolynomialInterpolator1D();
     494        interpolatorS_->setOrder(order);
     495        interpolatorT_->setOrder(order);
     496      }
     497      break;
     498    }
     499  default:
     500    {
     501      os_ << "use BufferedLinearInterpolator in time axis" << LogIO::POST;
     502      interpolatorS_ = new BufferedLinearInterpolator1D();
     503      interpolatorT_ = new BufferedLinearInterpolator1D();
     504      break;     
     505    }
     506  }
     507   
     508  switch (interp_[fa]) {
     509  case STCalEnum::NearestInterpolation:
     510    {
     511      os_ << "use NearestInterpolator in frequency axis" << LogIO::POST;
     512      interpolatorF_ = new NearestInterpolator1D();
     513      break;
     514    }
     515  case STCalEnum::LinearInterpolation:
     516    {
     517      os_ << "use BufferedLinearInterpolator in frequency axis" << LogIO::POST;
     518      interpolatorF_ = new BufferedLinearInterpolator1D();
     519      break;     
     520    }
     521  case STCalEnum::CubicSplineInterpolation:
     522    {
     523      os_ << "use CubicSplineInterpolator in frequency axis" << LogIO::POST;
     524      interpolatorF_ = new CubicSplineInterpolator1D();
     525      break;
     526    }
     527  case STCalEnum::PolynomialInterpolation:
     528    {
     529      os_ << "use PolynomialInterpolator in frequency axis" << LogIO::POST;
     530      if (order == 0) {
     531        interpolatorF_ = new NearestInterpolator1D();
     532      }
     533      else {
     534        interpolatorF_ = new PolynomialInterpolator1D();
     535        interpolatorF_->setOrder(order);
     536      }
     537      break;
     538    }
     539  default:
     540    {
     541      os_ << "use LinearInterpolator in frequency axis" << LogIO::POST;
     542      interpolatorF_ = new BufferedLinearInterpolator1D();
     543      break;     
     544    }
     545  }
     546}
     547}
  • trunk/src/STApplyCal.h

    r2720 r2727  
    7373  void init();
    7474
     75  // setup interpolator
     76  void initInterpolator();
     77
    7578  // single loop element in apply()
    7679  void doapply(casa::uInt beamno, casa::uInt ifno, casa::uInt polno,
  • trunk/src/STCalEnum.h

    r2721 r2727  
    3333                          LinearInterpolation,
    3434                          PolynomialInterpolation,
    35                           CSplineInterpolation};
     35                          CubicSplineInterpolation};
    3636  enum InterpolationAxis {TimeAxis = 0,
    3737                          FrequencyAxis,
  • trunk/src/STCalSkyTable.cpp

    r2720 r2727  
    1010//
    1111//
     12#include <assert.h>
     13
    1214#include <casa/Exceptions/Error.h>
    1315#include <casa/Logging/LogIO.h>
Note: See TracChangeset for help on using the changeset viewer.