Changeset 227


Ignore:
Timestamp:
01/19/05 19:31:46 (19 years ago)
Author:
kil064
Message:

add gain-elevation correction capability

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMath.cc

    r221 r227  
    4949#include <scimath/Mathematics/VectorKernel.h>
    5050#include <scimath/Mathematics/Convolver.h>
     51#include <scimath/Mathematics/InterpolateArray1D.h>
    5152
    5253#include <tables/Tables/Table.h>
    5354#include <tables/Tables/ScalarColumn.h>
    5455#include <tables/Tables/ArrayColumn.h>
     56#include <tables/Tables/ReadAsciiTable.h>
    5557
    5658#include <lattices/Lattices/LatticeUtilities.h>
     
    9698CountedPtr<SDMemTable> SDMath::average(const Block<CountedPtr<SDMemTable> >& in,
    9799                                       const Vector<Bool>& mask, Bool scanAv,
    98                                        const std::string& weightStr)
     100                                       const String& weightStr)
    99101//Bool alignVelocity)
    100102//
     
    327329           oldScanID = scanID;
    328330           outScanID += 1;               // Scan ID for next accumulation period
    329 
    330 }
     331        }
    331332
    332333// Accumulate
     
    948949
    949950
     951SDMemTable* SDMath::gainElevation (const SDMemTable& in, const String& fileName,
     952                                   const String& methodStr, Bool doAll)
     953{
     954  SDHeader sh = in.getSDHeader();
     955  SDMemTable* pTabOut = new SDMemTable(in, True);
     956  const uInt nRow = in.nRow();
     957
     958// Get elevation column from data
     959
     960  const Table& tab = in.table();
     961  ROScalarColumn<Float> elev(tab, "ELEVATION");
     962
     963// Read gain-elevation ascii file data into a Table.
     964
     965  Table geTable = readAsciiFile (fileName);
     966  ROScalarColumn<Float> geElCol(geTable, "ELEVATION");
     967  ROScalarColumn<Float> geFacCol(geTable, "FACTOR");
     968  Vector<Float> xIn = geElCol.getColumn();
     969  Vector<Float> yIn = geFacCol.getColumn();
     970  Vector<Bool> maskIn(xIn.nelements(),True);
     971
     972// Get elevation vector from data
     973
     974  Vector<Float> xOut = elev.getColumn();
     975  xOut *= Float(180 / C::pi);
     976
     977// Interpolate (and extrapolate) with desired method
     978
     979   Int method = 0;
     980   convertInterpString(method, methodStr);
     981//
     982   Vector<Float> yOut;
     983   Vector<Bool> maskOut;
     984   InterpolateArray1D<Float,Float>::interpolate(yOut, maskOut, xOut,
     985                                                xIn, yIn, maskIn, method,
     986                                                True, True);
     987
     988// For operations only on specified cursor location
     989
     990  IPosition start, end;
     991  getCursorLocation(start, end, in);
     992
     993// Loop over rows and interpolate correction factor
     994 
     995  const uInt axis = asap::ChanAxis;
     996  for (uInt i=0; i < in.nRow(); ++i) {
     997
     998// Get data
     999
     1000    MaskedArray<Float> dataIn(in.rowAsMaskedArray(i));
     1001    Array<Float>& valuesIn = dataIn.getRWArray();              // writable reference
     1002    const Array<Bool>& maskIn = dataIn.getMask(); 
     1003
     1004// Apply factor
     1005
     1006    if (doAll) {
     1007       VectorIterator<Float> itValues(valuesIn, asap::ChanAxis);
     1008       while (!itValues.pastEnd()) {
     1009          itValues.vector() *= yOut(i);                    // Writes back into dataIn
     1010//
     1011          itValues.next();
     1012       }
     1013    } else {
     1014       Array<Float> valuesIn2 = valuesIn(start,end);
     1015       valuesIn2 *= yOut(i);
     1016       valuesIn(start,end) = valuesIn2;
     1017    }
     1018
     1019// Write out
     1020
     1021    SDContainer sc = in.getSDContainer(i);
     1022    putDataInSDC(sc, valuesIn, maskIn);
     1023//
     1024    pTabOut->putSDContainer(sc);
     1025  }
     1026
     1027// Delete temporary gain/el Table
     1028
     1029  geTable.markForDelete();
     1030// 
     1031  return pTabOut;
     1032}
     1033
     1034
     1035
    9501036// 'private' functions
    9511037
     
    9561042                     Int scanID, Double timeStamp,
    9571043                     Double interval, const String& sourceName,
    958                      const Vector<uInt>& freqID)
     1044                     const Vector<uInt>& freqID) const
    9591045{
    9601046// Data and mask
     
    9801066                        const Array<Float>& nPts,
    9811067                        WeightType wtType, Int axis,
    982                         Int nAxesSub)
     1068                        Int nAxesSub) const
    9831069{
    9841070   IPosition pos2(nAxesSub,0);
     
    10171103                        uInt iTab, uInt iRow, uInt axis,
    10181104                        uInt nAxesSub, Bool useMask,
    1019                         WeightType wtType)
     1105                        WeightType wtType) const
    10201106{
    10211107
     
    10851171
    10861172void SDMath::getCursorLocation(IPosition& start, IPosition& end,
    1087                                const SDMemTable& in)
     1173                               const SDMemTable& in) const
    10881174{
    10891175  const uInt nDim = 4;
     
    11071193
    11081194
    1109 void SDMath::convertWeightString(WeightType& wtType, const std::string& weightStr)
     1195void SDMath::convertWeightString(WeightType& wtType, const String& weightStr) const
    11101196{
    11111197  String tStr(weightStr);
     
    11231209}
    11241210
     1211void SDMath::convertInterpString(Int& type, const String& interp) const
     1212{
     1213  String tStr(interp);
     1214  tStr.upcase();
     1215  if (tStr.contains(String("NEAR"))) {
     1216     type = InterpolateArray1D<Float,Float>::nearestNeighbour;
     1217  } else if (tStr.contains(String("LIN"))) {
     1218     type = InterpolateArray1D<Float,Float>::linear;
     1219  } else if (tStr.contains(String("CUB"))) {
     1220     type = InterpolateArray1D<Float,Float>::cubic;
     1221  } else if (tStr.contains(String("SPL"))) {
     1222     type = InterpolateArray1D<Float,Float>::spline;
     1223  } else {
     1224    throw(AipsError("Unrecognized interpolation type"));
     1225  }
     1226}
     1227
    11251228void SDMath::putDataInSDC(SDContainer& sc, const Array<Float>& data,
    1126                           const Array<Bool>& mask)
     1229                          const Array<Bool>& mask) const
    11271230{
    11281231    sc.putSpectrum(data);
     
    11321235    sc.putFlags(outflags);
    11331236}
     1237
     1238Table SDMath::readAsciiFile (const String& fileName) const
     1239{
     1240   String tableName("___asap_temp.tbl");
     1241   readAsciiTable (fileName, "", tableName);
     1242   Table tbl(tableName);
     1243   return tbl;
     1244}
  • trunk/src/SDMath.h

    r221 r227  
    3737#include <casa/Utilities/CountedPtr.h>
    3838
     39class casa::Table;
     40
    3941namespace asap {
    4042
     
    6466   casa::CountedPtr<SDMemTable>  average(const casa::Block<casa::CountedPtr<SDMemTable> >& in,
    6567                                         const casa::Vector<casa::Bool>& mask,
    66                                          casa::Bool scanAverage, const std::string& weightStr);
     68                                         casa::Bool scanAverage, const casa::String& weightStr);
    6769//                                         casa::Bool alignVelocity);
    6870
     
    8183   SDMemTable* convertFlux (const SDMemTable& in, casa::Float area,
    8284                            casa::Float eta, casa::Bool doAll);
     85
     86// Gain-elevation correction
     87   SDMemTable* gainElevation (const SDMemTable& in, const casa::String& fileName,
     88                              const casa::String& method, casa::Bool doAll);
    8389
    8490// Simple mathematical operations.  what=0 (mul) or 1 (add)
     
    104110                   const casa::Block<casa::CountedPtr<SDMemTable> >& in,
    105111                   casa::uInt iTab, casa::uInt iRow, casa::uInt axis, casa::uInt nAxesSub,
    106                    casa::Bool useMask, WeightType wtType);
     112                   casa::Bool useMask, WeightType wtType) const;
    107113
    108114// Function to fill Scan Container when averaging in time
     
    113119                casa::Int scanID, casa::Double timeStamp,
    114120                casa::Double interval, const casa::String& sourceName,
    115                 const casa::Vector<casa::uInt>& freqID);
     121                const casa::Vector<casa::uInt>& freqID) const;
    116122
    117123// Put the data and mask into the SDContainer
    118124   void putDataInSDC (SDContainer& sc, const casa::Array<casa::Float>& data,
    119                       const casa::Array<casa::Bool>& mask);
     125                      const casa::Array<casa::Bool>& mask) const;
    120126
    121127// Function to normalize data when averaging in time
     
    124130                  const casa::Array<casa::Float>& sumSq,
    125131                  const casa::Array<casa::Float>& nPts,
    126                   WeightType wtType, casa::Int axis, casa::Int nAxes);
     132                  WeightType wtType, casa::Int axis, casa::Int nAxes) const;
    127133
    128134// Function to get the current cursor location
    129135   void getCursorLocation (casa::IPosition& start, casa::IPosition& end,
    130                            const SDMemTable& in);
     136                           const SDMemTable& in) const;
    131137
    132138// Convert weight string to enum value
    133139
    134    void convertWeightString (WeightType& wt, const std::string& weightStr);
     140   void convertWeightString (WeightType& wt, const casa::String& weightStr) const;
     141
     142// Convert interpolation type string
     143   void convertInterpString(casa::Int& type, const casa::String& interp) const;
     144
     145// Read ascii file
     146
     147   casa::Table readAsciiFile (const casa::String& fileName) const;
     148                   
    135149};
    136150
  • trunk/src/SDMathWrapper.cc

    r222 r227  
    162162{
    163163  SDMath sdm;
    164   return sdm.statistic(in.getCP(), mask, which);
     164  return sdm.statistic(in.getCP(), mask, String(which));
    165165}
    166166
     
    185185}
    186186
     187
     188void SDMathWrapper::gainElevationInSitu(SDMemTableWrapper& in, const string& fileName,
     189                                        const string& method, bool doAll)
     190{
     191  SDMemTable* pIn = in.getPtr();
     192  SDMath sdm;
     193  SDMemTable* pOut = sdm.gainElevation(*pIn, String(fileName), String(method), Bool(doAll));
     194  *pIn = *pOut;
     195  delete pOut;
     196}
     197
     198
     199SDMemTableWrapper SDMathWrapper::gainElevation(const SDMemTableWrapper& in,
     200                                               const string& fileName,
     201                                               const string& method, bool doAll)
     202{
     203  const CountedPtr<SDMemTable>& pIn = in.getCP();
     204  SDMath sdm;
     205  return CountedPtr<SDMemTable>(sdm.gainElevation(*pIn, String(fileName),
     206                                                  String(method), Bool(doAll)));
     207}
     208
  • trunk/src/python_SDMath.cc

    r223 r227  
    7878      def("convertflux_insitu", &SDMathWrapper::convertFluxInSitu);
    7979//
     80      def("gainel", &SDMathWrapper::gainElevation);
     81      def("gainel_insitu", &SDMathWrapper::gainElevationInSitu);
     82//
    8083      def("average", &SDMathWrapper::average);
    8184//
Note: See TracChangeset for help on using the changeset viewer.