Changeset 1069 for trunk/src/STMath.cpp


Ignore:
Timestamp:
07/04/06 14:44:44 (18 years ago)
Author:
mar637
Message:

enhancement ticket #35. median scantable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STMath.cpp

    r1066 r1069  
    189189}
    190190
     191CountedPtr< Scantable >
     192  STMath::averageChannel( const CountedPtr < Scantable > & in,
     193                          const std::string & mode )
     194{
     195  // clone as this is non insitu
     196  bool insitu = insitu_;
     197  setInsitu(false);
     198  CountedPtr< Scantable > out = getScantable(in, true);
     199  setInsitu(insitu);
     200  Table& tout = out->table();
     201  ArrayColumn<Float> specColOut(tout,"SPECTRA");
     202  ArrayColumn<uChar> flagColOut(tout,"FLAGTRA");
     203  ArrayColumn<Float> tsysColOut(tout,"TSYS");
     204
     205  Block<String> cols(3);
     206  cols[0] = String("BEAMNO");
     207  cols[1] = String("IFNO");
     208  cols[2] = String("POLNO");
     209  uInt outrowCount = 0;
     210  uChar userflag = 1 << 7;
     211  TableIterator iter(in->table(), cols);
     212  while (!iter.pastEnd()) {
     213    Table subt = iter.table();
     214    ROArrayColumn<Float> specCol, tsysCol;
     215    ROArrayColumn<uChar> flagCol;
     216    specCol.attach(subt,"SPECTRA");
     217    flagCol.attach(subt,"FLAGTRA");
     218    tsysCol.attach(subt,"TSYS");
     219    tout.addRow();
     220    TableCopy::copyRows(tout, subt, outrowCount, 0, 1);
     221    Vector<Float> tmp;
     222    specCol.get(0, tmp);
     223    uInt nchan = tmp.nelements();
     224    Vector<uChar> flags = flagCol.getColumn(Slicer(Slice(0)));
     225    Vector<Float> outspec(nchan);
     226    Vector<uChar> outflag(nchan,0);
     227    Vector<Float> outtsys(1);/// @fixme when tsys is channel based
     228    for (uInt i=0; i<nchan; ++i) {
     229      Vector<Float> specs = specCol.getColumn(Slicer(Slice(i)));
     230      MaskedArray<Float> ma = maskedArray(specs,flags);
     231      outspec[i] = median(ma);
     232      if ( allEQ(ma.getMask(), False) )
     233        outflag[i] = userflag;// flag data
     234    }
     235    outtsys[0] = median(tsysCol.getColumn());
     236    specColOut.put(outrowCount, outspec);
     237    flagColOut.put(outrowCount, outflag);
     238    tsysColOut.put(outrowCount, outtsys);
     239
     240    ++outrowCount;
     241    ++iter;
     242  }
     243  return out;
     244}
    191245
    192246CountedPtr< Scantable > STMath::getScantable(const CountedPtr< Scantable >& in,
     
    331385{
    332386  bool insitu = insitu_;
     387  if ( ! on->conformant(*off) ) {
     388    throw(AipsError("'on' and 'off' scantables are not conformant."));
     389  }
    333390  setInsitu(false);
    334391  CountedPtr< Scantable > out = getScantable(on, false);
Note: See TracChangeset for help on using the changeset viewer.