Changeset 354 for trunk/src/SDMath.cc


Ignore:
Timestamp:
02/03/05 15:43:18 (19 years ago)
Author:
kil064
Message:

rework convertFLux stuff using new SDAttr and looking up values
where possible

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMath.cc

    r330 r354  
    5151#include <casa/Quanta/Unit.h>
    5252#include <casa/Quanta/MVEpoch.h>
    53 #include <casa/Quanta/QC.h>
    5453#include <casa/Quanta/MVTime.h>
    5554#include <casa/Utilities/Assert.h>
     
    7978#include "MathUtils.h"
    8079#include "SDDefs.h"
     80#include "SDAttr.h"
    8181#include "SDContainer.h"
    8282#include "SDMemTable.h"
     
    10611061
    10621062
    1063 SDMemTable* SDMath::convertFlux (const SDMemTable& in, Float a, Float eta, Bool doAll) const
     1063SDMemTable* SDMath::convertFlux (const SDMemTable& in, Float D, Float etaAp,
     1064                                 Float JyPerK, Bool doAll) const
    10641065//
    1065 // As it is, this function could be implemented with 'simpleOperate'
    1066 // However, I anticipate that eventually we will look the conversion
    1067 // values up in a Table and apply them in a frequency dependent way,
    1068 // so I have implemented it fully here
     1066// etaAp = aperture efficiency
     1067// D     = geometric diameter (m)
     1068// JyPerK
    10691069//
    10701070{
     
    10721072  SDMemTable* pTabOut = new SDMemTable(in, True);
    10731073
    1074 // FInd out how to convert values into Jy and K (e.g. units might be mJy or mK)
     1074// Find out how to convert values into Jy and K (e.g. units might be mJy or mK)
    10751075// Also automatically find out what we are converting to according to the
    10761076// flux unit
     
    10811081//
    10821082  Bool toKelvin = True;
    1083   Double inFac = 1.0;
     1083  Double cFac = 1.0;   
    10841084  if (fluxUnit==JY) {
    10851085     cerr << "Converting to K" << endl;
     
    10871087     Quantum<Double> t(1.0,fluxUnit);
    10881088     Quantum<Double> t2 = t.get(JY);
    1089      inFac = (t2 / t).getValue();
     1089     cFac = (t2 / t).getValue();               // value to Jy
    10901090//
    10911091     toKelvin = True;
     
    10961096     Quantum<Double> t(1.0,fluxUnit);
    10971097     Quantum<Double> t2 = t.get(K);
    1098      inFac = (t2 / t).getValue();
     1098     cFac = (t2 / t).getValue();              // value to K
    10991099//
    11001100     toKelvin = False;
     
    11051105  pTabOut->putSDHeader(sh);
    11061106
    1107 // Compute conversion factor. 'a' and 'eta' are really frequency, time and 
    1108 // telescope dependent and should be looked// up in a table
    1109 
    1110   Float factor = 2.0 * inFac * 1.0e-7 * 1.0e26 *
    1111                  QC::k.getValue(Unit(String("erg/K"))) / a / eta;
    1112   if (toKelvin) {
    1113     factor = 1.0 / factor;
    1114   }
    1115   cerr << "Applying conversion factor = " << factor << endl;
    1116 
    1117 // Generate correction vector.  Apply same factor regardless
    1118 // of beam/pol/IF.  This will need to change somewhen.
    1119 
    1120   Vector<Float> factors(in.nRow(), factor);
    1121 
    1122 // Correct
    1123 
    1124   correctFromVector (pTabOut, in, doAll, factors);
     1107// Make sure input values are converted to either Jy or K first...
     1108
     1109  Float factor = cFac;
     1110
     1111// Select method
     1112
     1113  if (JyPerK>0.0) {
     1114     factor *= JyPerK;
     1115     if (toKelvin) factor = 1.0 / JyPerK;
     1116//
     1117     cerr << "Applying supplied conversion factor = " << factor << endl;
     1118     Vector<Float> factors(in.nRow(), factor);
     1119     correctFromVector (pTabOut, in, doAll, factors);
     1120  } else if (etaAp>0.0) {
     1121     factor *= SDAttr::findJyPerKFac (etaAp, D);
     1122     if (toKelvin) {
     1123        factor = 1.0 / factor;
     1124     }
     1125//
     1126     cerr << "Applying supplied conversion factor = " << factor << endl;
     1127     Vector<Float> factors(in.nRow(), factor);
     1128     correctFromVector (pTabOut, in, doAll, factors);
     1129  } else {
     1130
     1131// OK now we must deal with automatic look up of values.
     1132// We must also deal with the fact that the factors need
     1133// to be computed per IF and may be different and may
     1134// change per integration.
     1135
     1136     cerr << "Looking up conversion factors" << endl;
     1137     convertBrightnessUnits (pTabOut, in, toKelvin, cFac, doAll);
     1138  }
    11251139//
    11261140  return pTabOut;
    11271141}
     1142
     1143
     1144
    11281145
    11291146
     
    12531270// 'private' functions
    12541271
     1272void SDMath::convertBrightnessUnits (SDMemTable* pTabOut, const SDMemTable& in,
     1273                                     Bool toKelvin, Float cFac, Bool doAll) const
     1274{
     1275
     1276// Get header
     1277
     1278   SDHeader sh = in.getSDHeader();
     1279   const uInt nChan = sh.nchan;
     1280
     1281// Get instrument
     1282
     1283   Bool throwIt = True;
     1284   Instrument inst = SDMemTable::convertInstrument (sh.antennaname, throwIt);
     1285
     1286// Get Diameter (m)
     1287
     1288   SDAttr sdAtt;
     1289
     1290// Get epoch of first row
     1291
     1292   MEpoch dateObs = in.getEpoch(0);
     1293
     1294// Generate a Vector of correction factors. One per FreqID
     1295
     1296   SDFrequencyTable sdft = in.getSDFreqTable();
     1297   Vector<uInt> freqIDs;
     1298//
     1299   Vector<Float> freqs(sdft.length());
     1300   for (uInt i=0; i<sdft.length(); i++) {
     1301      freqs(i) = (nChan/2 - sdft.referencePixel(i))*sdft.increment(i) + sdft.referenceValue(i);
     1302   }
     1303//
     1304   Vector<Float> JyPerK = sdAtt.JyPerK(inst, dateObs, freqs);
     1305   Vector<Float> factors = cFac * JyPerK;
     1306   if (toKelvin) factors = Float(1.0) / factors;
     1307
     1308// For operations only on specified cursor location
     1309
     1310   IPosition start, end;
     1311   getCursorLocation(start, end, in);
     1312   const uInt ifAxis = in.getIF();
     1313
     1314// Iteration axes
     1315
     1316   IPosition axes(asap::nAxes-1,0);
     1317   for (uInt i=0,j=0; i<asap::nAxes; i++) {
     1318      if (i!=asap::IFAxis) {
     1319         axes(j++) = i;
     1320      }
     1321   }
     1322
     1323// Loop over rows and apply correction factor
     1324
     1325   Float factor = 1.0; 
     1326   const uInt axis = asap::ChanAxis;
     1327   for (uInt i=0; i < in.nRow(); ++i) {
     1328
     1329// Get data
     1330
     1331      MaskedArray<Float> dataIn(in.rowAsMaskedArray(i));
     1332      Array<Float>& values = dataIn.getRWArray();
     1333
     1334// Get SDCOntainer
     1335
     1336      SDContainer sc = in.getSDContainer(i);
     1337
     1338// Get FreqIDs
     1339
     1340      freqIDs = sc.getFreqMap();
     1341
     1342// Now the conversion factor depends only upon frequency
     1343// So we need to iterate through by IF only giving
     1344// us BEAM/POL/CHAN cubes
     1345
     1346      if (doAll) {
     1347         ArrayIterator<Float> itIn(values, axes);
     1348         uInt ax = 0;
     1349         while (!itIn.pastEnd()) {
     1350           itIn.array() *= factors(freqIDs(ax));         // Writes back to dataIn
     1351           itIn.next();
     1352         }
     1353      } else {
     1354         MaskedArray<Float> dataIn2 = dataIn(start,end);  // reference
     1355         dataIn2 *= factors(freqIDs(ifAxis));
     1356      }
     1357
     1358// Write out
     1359
     1360      putDataInSDC(sc, dataIn.getArray(), dataIn.getMask());
     1361//
     1362      pTabOut->putSDContainer(sc);
     1363   }
     1364}
     1365
     1366
    12551367
    12561368SDMemTable* SDMath::frequencyAlign (const SDMemTable& in,
     
    18001912   }
    18011913}
    1802 
    1803 
Note: See TracChangeset for help on using the changeset viewer.