Ignore:
Timestamp:
02/25/11 16:51:50 (13 years ago)
Author:
WataruKawasaki
Message:

New Development: Yes

JIRA Issue: Yes (CAS-2373, CAS-2620)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: For Scantable::polyBaseline(), parameters and return value have been changed.

Test Programs:

Put in Release Notes: Yes

Module(s): sdbaseline, sd.linefinder

Description: (1) CAS-2373-related:

(1.1) Modified Scantable::polyBaseline() to have the row-based loop inside.

Now it fits and subtracts baseline for all rows and also output info
about the fitting result to logger and text file, while in the
previous version this method just did baseline fitting/subtraction
for one row only and had to be put inside a row-based loop at the
python side ("poly_baseline()" in scantable.py) and result output had
also to be controlled at the python side. Using a test data from NRO
45m telescope (348,000 rows, 512 channels), the processing time of
scantable.poly_baseline() has reduced from 130 minutes to 5-6 minutes.

(1.2) For accelerating the another polynomial fitting function, namely

scantable.auto_poly_baseline(), added a method
Scantable::autoPolyBaseline(). This basically does the same thing
with Scantable::polyBaseline(), but uses linefinfer also to
automatically flag the line regions.

(1.3) To make linefinder usable in Scantable class, added a method

linefinder.setdata(). This makes it possible to apply linefinder
for a float-list data given as a parameter, without setting scantable,
while it was indispensable to set scantable to use linefinger previously.

(2) CAS-2620-related:

Added Scantable::cubicSplineBaseline() and autoCubicSplineBaseline() for
fit baseline using the cubic spline function. Parameters include npiece
(number of polynomial pieces), clipthresh (clipping threshold), and
clipniter (maximum iteration number).



File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STLineFinder.cpp

    r1670 r2012  
    925925  itsNoiseBox = in_noise_box;
    926926  itsUseMedian = in_median;
     927
     928  useScantable = true;
    927929}
    928930
     
    934936  scan=in_scan.getCP();
    935937  AlwaysAssert(!scan.null(),AipsError);
    936 
     938}
     939
     940// set spectrum data to work with. this is a method to allow linefinder work
     941// without setting scantable for the purpose of using linefinder inside some
     942// method in scantable class. (Dec 22, 2010 by W.Kawasaki)
     943void STLineFinder::setData(const std::vector<float> &in_spectrum)
     944{
     945  spectrum = Vector<Float>(in_spectrum);
     946  useScantable = false;
    937947}
    938948
     
    948958                const casa::uInt &whichRow) throw(casa::AipsError)
    949959{
    950   if (scan.null())
     960  if (useScantable && scan.null())
    951961      throw AipsError("STLineFinder::findLines - a scan should be set first,"
    952962                      " use set_scan");
    953963
    954   uInt nchan = scan->nchan(scan->getIF(whichRow));
     964  uInt nchan = useScantable ? scan->nchan(scan->getIF(whichRow)) : spectrum.nelements();
    955965  // set up mask and edge rejection
    956966  // no mask given...
     
    962972  }
    963973  if (mask.nelements()!=nchan)
    964       throw AipsError("STLineFinder::findLines - in_scan and in_mask have different"
    965             "number of spectral channels.");
     974      throw AipsError("STLineFinder::findLines - in_scan and in_mask, or in_spectrum "
     975                      "and in_mask have different number of spectral channels.");
    966976
    967977  // taking flagged channels into account
    968   vector<bool> flaggedChannels = scan->getMask(whichRow);
    969   if (flaggedChannels.size()) {
     978  if (useScantable) {
     979    vector<bool> flaggedChannels = scan->getMask(whichRow);
     980    if (flaggedChannels.size()) {
    970981      // there is a mask set for this row
    971982      if (flaggedChannels.size() != mask.nelements()) {
    972           throw AipsError("STLineFinder::findLines - internal inconsistency: number of mask elements do not match the number of channels");
     983          throw AipsError("STLineFinder::findLines - internal inconsistency: number of "
     984                          "mask elements do not match the number of channels");
    973985      }
    974986      for (size_t ch = 0; ch<mask.nelements(); ++ch) {
    975987           mask[ch] &= flaggedChannels[ch];
    976988      }
     989    }
    977990  }
    978991
     
    10151028      throw AipsError("STLineFinder::findLines - noise_box is supposed to be at least 2 elements");
    10161029
    1017   spectrum.resize();
    1018   spectrum = Vector<Float>(scan->getSpectrum(whichRow));
     1030  if (useScantable) {
     1031    spectrum.resize();
     1032    spectrum = Vector<Float>(scan->getSpectrum(whichRow));
     1033  }
    10191034
    10201035  lines.resize(0); // search from the scratch
     
    11411156{
    11421157  try {
    1143        if (scan.null())
    1144            throw AipsError("STLineFinder::getMask - a scan should be set first,"
    1145                       " use set_scan followed by find_lines");
    1146        DebugAssert(mask.nelements()==scan->getChannels(last_row_used), AipsError);
    1147        /*
    1148        if (!lines.size())
    1149            throw AipsError("STLineFinder::getMask - one have to search for "
     1158    if (useScantable) {
     1159      if (scan.null())
     1160        throw AipsError("STLineFinder::getMask - a scan should be set first,"
     1161                        " use set_scan followed by find_lines");
     1162      DebugAssert(mask.nelements()==scan->getChannels(last_row_used), AipsError);
     1163    }
     1164    /*
     1165    if (!lines.size())
     1166       throw AipsError("STLineFinder::getMask - one have to search for "
    11501167                           "lines first, use find_lines");
    1151        */
    1152        std::vector<bool> res_mask(mask.nelements());
    1153        // iterator through lines
    1154        std::list<std::pair<int,int> >::const_iterator cli=lines.begin();
    1155        for (int ch=0;ch<int(res_mask.size());++ch) {
    1156             if (ch<edge.first || ch>=edge.second) res_mask[ch]=false;
    1157             else if (!mask[ch]) res_mask[ch]=false;
    1158             else {
    1159                     res_mask[ch]=!invert; // no line by default
    1160                     if (cli!=lines.end())
    1161                         if (ch>=cli->first && ch<cli->second)
    1162                              res_mask[ch]=invert; // this is a line
    1163             }
    1164             if (cli!=lines.end())
    1165                 if (ch>=cli->second) {
    1166                     ++cli; // next line in the list
    1167                 }
    1168        }
    1169        return res_mask;
     1168    */
     1169    std::vector<bool> res_mask(mask.nelements());
     1170    // iterator through lines
     1171    std::list<std::pair<int,int> >::const_iterator cli=lines.begin();
     1172    for (int ch=0;ch<int(res_mask.size());++ch) {
     1173      if (ch<edge.first || ch>=edge.second) res_mask[ch]=false;
     1174      else if (!mask[ch]) res_mask[ch]=false;
     1175      else {
     1176        res_mask[ch]=!invert; // no line by default
     1177        if (cli!=lines.end())
     1178          if (ch>=cli->first && ch<cli->second)
     1179            res_mask[ch]=invert; // this is a line
     1180      }
     1181      if (cli!=lines.end())
     1182        if (ch>=cli->second)
     1183          ++cli; // next line in the list
     1184    }
     1185    return res_mask;
    11701186  }
    11711187  catch (const AipsError &ae) {
    1172       throw;
     1188    throw;
    11731189  }
    11741190  catch (const exception &ex) {
    1175       throw AipsError(String("STLineFinder::getMask - STL error: ")+ex.what());
     1191    throw AipsError(String("STLineFinder::getMask - STL error: ")+ex.what());
    11761192  }
    11771193}
     
    11821198                             const throw(casa::AipsError)
    11831199{
    1184   // convert to required abscissa units
    1185   std::vector<double> vel=scan->getAbcissa(last_row_used);
     1200  std::vector<double> vel;
     1201  if (useScantable) {
     1202    // convert to required abscissa units
     1203    vel = scan->getAbcissa(last_row_used);
     1204  } else {
     1205    for (int i = 0; i < spectrum.nelements(); ++i)
     1206      vel.push_back((double)i);
     1207  }
    11861208  std::vector<int> ranges=getLineRangesInChannels();
    11871209  std::vector<double> res(ranges.size());
     
    12021224{
    12031225  try {
    1204        if (scan.null())
    1205            throw AipsError("STLineFinder::getLineRangesInChannels - a scan should be set first,"
    1206                       " use set_scan followed by find_lines");
    1207        DebugAssert(mask.nelements()==scan->getChannels(last_row_used), AipsError);
    1208 
    1209        if (!lines.size())
    1210            throw AipsError("STLineFinder::getLineRangesInChannels - one have to search for "
    1211                            "lines first, use find_lines");
    1212 
    1213        std::vector<int> res(2*lines.size());
    1214        // iterator through lines & result
    1215        std::list<std::pair<int,int> >::const_iterator cli=lines.begin();
    1216        std::vector<int>::iterator ri=res.begin();
    1217        for (;cli!=lines.end() && ri!=res.end();++cli,++ri) {
    1218             *ri=cli->first;
    1219             if (++ri!=res.end())
    1220                 *ri=cli->second-1;
    1221        }
    1222        return res;
    1223   }
    1224   catch (const AipsError &ae) {
    1225       throw;
    1226   }
    1227   catch (const exception &ex) {
    1228       throw AipsError(String("STLineFinder::getLineRanges - STL error: ")+ex.what());
     1226    if (useScantable) {
     1227      if (scan.null())
     1228        throw AipsError("STLineFinder::getLineRangesInChannels - a scan should be set first,"
     1229                        " use set_scan followed by find_lines");
     1230      DebugAssert(mask.nelements()==scan->getChannels(last_row_used), AipsError);
     1231    }
     1232
     1233    if (!lines.size())
     1234      throw AipsError("STLineFinder::getLineRangesInChannels - one have to search for "
     1235                      "lines first, use find_lines");
     1236
     1237    std::vector<int> res(2*lines.size());
     1238    // iterator through lines & result
     1239    std::list<std::pair<int,int> >::const_iterator cli = lines.begin();
     1240    std::vector<int>::iterator ri = res.begin();
     1241    for (; cli != lines.end() && ri != res.end(); ++cli,++ri) {
     1242      *ri = cli->first;
     1243      if (++ri != res.end())
     1244        *ri = cli->second - 1;
     1245    }
     1246    return res;
     1247  } catch (const AipsError &ae) {
     1248    throw;
     1249  } catch (const exception &ex) {
     1250    throw AipsError(String("STLineFinder::getLineRanges - STL error: ") + ex.what());
    12291251  }
    12301252}
Note: See TracChangeset for help on using the changeset viewer.