Changeset 917


Ignore:
Timestamp:
03/22/06 21:40:28 (18 years ago)
Author:
mar637
Message:

0-based re-indexing SCANNO on merge. added frequencyAlign. Compiles, but not yet tested.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STMath.cpp

    r902 r917  
    2424#include <tables/Tables/TableRow.h>
    2525#include <tables/Tables/TableVector.h>
     26#include <tables/Tables/TabVecMath.h>
    2627#include <tables/Tables/ExprNode.h>
    2728#include <tables/Tables/TableRecord.h>
     
    2930
    3031#include <lattices/Lattices/LatticeUtilities.h>
     32
     33#include <coordinates/Coordinates/SpectralCoordinate.h>
     34#include <coordinates/Coordinates/CoordinateSystem.h>
     35#include <coordinates/Coordinates/CoordinateUtil.h>
     36#include <coordinates/Coordinates/FrequencyAligner.h>
    3137
    3238#include <scimath/Mathematics/VectorKernel.h>
     
    822828  Table& tout = out->table();
    823829  ScalarColumn<uInt> freqidcol(tout,"FREQ_ID"), molidcol(tout, "MOLECULE_ID");
    824   ScalarColumn<uInt> scannocol(tout,"SCANNO"),focusidcol(tout,"FOCUS_ID");
     830  ScalarColumn<uInt> scannocol(tout,"SCANNO"), focusidcol(tout,"FOCUS_ID");
     831  // Renumber SCANNO to be 0-based
     832  uInt offset = min(scannocol.getColumn());
     833  TableVector<uInt> scannos(tout, "SCANNO");
     834  scannos -= offset;
    825835  uInt newscanno = max(scannocol.getColumn())+1;
    826836  ++it;
     
    944954  return out;
    945955}
     956
     957CountedPtr< Scantable >
     958  asap::STMath::frequencyAlign( const CountedPtr< Scantable > & in,
     959                                const std::string & refTime,
     960                                const std::string & method, bool perfreqid )
     961{
     962  CountedPtr< Scantable > out = getScantable(in, false);
     963  Table& tout = out->table();
     964  // clear ouput frequency table
     965  Table ftable = out->frequencies().table();
     966  ftable.removeRow(ftable.rowNumbers());
     967  // Get reference Epoch to time of first row or given String
     968  Unit DAY(String("d"));
     969  MEpoch::Ref epochRef(in->getTimeReference());
     970  MEpoch refEpoch;
     971  if (refTime.length()>0) {
     972    Quantum<Double> qt;
     973    if (MVTime::read(qt,refTime)) {
     974      MVEpoch mv(qt);
     975      refEpoch = MEpoch(mv, epochRef);
     976   } else {
     977      throw(AipsError("Invalid format for Epoch string"));
     978   }
     979  } else {
     980    refEpoch = in->timeCol_(0);
     981  }
     982  MPosition refPos = in->getAntennaPosition();
     983/*  ostringstream oss;
     984  oss << "Aligned at reference Epoch " << formatEpoch(refEpoch)
     985      << " in frame " << MFrequency::showType(freqSystem);
     986  pushLog(String(oss));
     987*/
     988  InterpolateArray1D<Double,Float>::InterpolationMethod interp;
     989  Int interpMethod(stringToIMethod(method));
     990  // test if user frame is different to base frame
     991  if ( in->frequencies().getFrameString(true)
     992       == in->frequencies().getFrameString(false) ) {
     993    throw(AipsError("You have not set a frequency frame different from the initial - use function set_freqframe"));
     994  }
     995  MFrequency::Types system = in->frequencies().getFrame();
     996  // set up the iterator
     997  Block<String> cols(3);
     998  // select the by constant direction
     999  cols[0] = String("SRCNAME");
     1000  cols[1] = String("BEAMNO");
     1001  // select by IF ( no of channels varies over this )
     1002  cols[2] = String("IFNO");
     1003  // handle freqid based alignment
     1004  if ( perfreqid ) {
     1005    cols.resize(4);
     1006    cols[3] = String("FREQ_ID");
     1007  }
     1008  TableIterator iter(tout, cols);
     1009  while (!iter.pastEnd()) {
     1010    Table t = iter.table();
     1011    MDirection::ROScalarColumn dirCol(t, "DIRECTION");
     1012    ScalarColumn<uInt> freqidCol(t, "FREQ_ID");
     1013    // get the SpectralCoordinate for the freqid, which we are iterating over
     1014    SpectralCoordinate sC = in->frequencies().getSpectralCoordinate(freqidCol(0));
     1015    // determine nchan from the first row. This should work as
     1016    // we are iterting over IFNO
     1017    ROArrayColumn<Float> sCol(t, "SPECTRA");
     1018    uInt nchan = sCol(0).nelements();
     1019    // we should have constant direction
     1020    FrequencyAligner<Float> fa(sC, nchan, refEpoch, dirCol(0), refPos, system);
     1021    // realign the SpectralCOordinate and put into the output Scantable
     1022    Vector<String> units(1);
     1023    units = String("Hz");
     1024    Bool linear=True;
     1025    SpectralCoordinate sc2 = fa.alignedSpectralCoordinate(linear);
     1026    sc2.setWorldAxisUnits(units);
     1027    out->frequencies().addEntry(sc2.referencePixel()[0],
     1028                                sc2.referenceValue()[0],
     1029                                sc2.increment()[0]);
     1030    // create the abcissa for IF based alignment
     1031    Vector<Double> abc;
     1032    if ( !perfreqid ) {
     1033      abc.resize(nchan);
     1034      Double w;
     1035      for (uInt i=0; i<nchan; i++) {
     1036        sC.toWorld(w,Double(i));
     1037        abc[i] = w;
     1038      }
     1039    }
     1040    // cache abcissa for same time stamps, so iterate over those
     1041    TableIterator timeiter(t, "TIME");
     1042    while ( !timeiter.pastEnd() ) {
     1043      Table tab = timeiter.table();
     1044      ArrayColumn<Float> specCol(tab, "SPECTRA");
     1045      ArrayColumn<uChar> flagCol(tab, "FLAGTRA");
     1046      MEpoch::ROScalarColumn timeCol(tab, "TIME");
     1047      // use align abcissa cache after the first row
     1048      bool first = true;
     1049      // these rows should be just be POLNO
     1050      for (int i=0; i<tab.nrow(); ++i) {
     1051        // input values
     1052        Vector<uChar> flag = flagCol(i);
     1053        Vector<Bool> mask(flag.shape());
     1054        Vector<Float> specOut;
     1055        Vector<Bool> maskOut;Vector<uChar> flagOut;
     1056        convertArray(mask, flag);
     1057        // alignment
     1058        if ( perfreqid ) {
     1059          Bool ok = fa.align(specOut, maskOut, specCol(i),
     1060                        mask, timeCol(i), !first,
     1061                        interp, False);
     1062        } else {
     1063          Bool ok = fa.align(specOut, maskOut, abc, specCol(i),
     1064                        mask, timeCol(i), !first,
     1065                        interp, False);
     1066        }
     1067        // back into scantable
     1068        flagOut.resize(maskOut.nelements());
     1069        convertArray(flagOut, maskOut);
     1070        flagCol.put(i, flagOut);
     1071        specCol.put(i, specOut);
     1072        // start ancissa caching
     1073        first = false;
     1074      }
     1075      ++timeiter;
     1076    }
     1077    // next aligner
     1078    ++iter;
     1079  }
     1080  return out;
     1081}
  • trunk/src/STMath.h

    r912 r917  
    114114    swapPolarisations(const casa::CountedPtr<Scantable>& in);
    115115
     116  casa::CountedPtr<Scantable>
     117    frequencyAlign( const casa::CountedPtr<Scantable>& in,
     118                    const std::string& refTime,
     119                    const std::string& method, bool perfreqid);
     120
    116121private:
    117122  casa::CountedPtr<Scantable>  applyToPol( const casa::CountedPtr<Scantable>& in,
Note: See TracChangeset for help on using the changeset viewer.