Changeset 354 for trunk/src/SDMath.cc
- Timestamp:
- 02/03/05 15:43:18 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r330 r354 51 51 #include <casa/Quanta/Unit.h> 52 52 #include <casa/Quanta/MVEpoch.h> 53 #include <casa/Quanta/QC.h>54 53 #include <casa/Quanta/MVTime.h> 55 54 #include <casa/Utilities/Assert.h> … … 79 78 #include "MathUtils.h" 80 79 #include "SDDefs.h" 80 #include "SDAttr.h" 81 81 #include "SDContainer.h" 82 82 #include "SDMemTable.h" … … 1061 1061 1062 1062 1063 SDMemTable* SDMath::convertFlux (const SDMemTable& in, Float a, Float eta, Bool doAll) const 1063 SDMemTable* SDMath::convertFlux (const SDMemTable& in, Float D, Float etaAp, 1064 Float JyPerK, Bool doAll) const 1064 1065 // 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 1069 1069 // 1070 1070 { … … 1072 1072 SDMemTable* pTabOut = new SDMemTable(in, True); 1073 1073 1074 // F Ind 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) 1075 1075 // Also automatically find out what we are converting to according to the 1076 1076 // flux unit … … 1081 1081 // 1082 1082 Bool toKelvin = True; 1083 Double inFac = 1.0;1083 Double cFac = 1.0; 1084 1084 if (fluxUnit==JY) { 1085 1085 cerr << "Converting to K" << endl; … … 1087 1087 Quantum<Double> t(1.0,fluxUnit); 1088 1088 Quantum<Double> t2 = t.get(JY); 1089 inFac = (t2 / t).getValue();1089 cFac = (t2 / t).getValue(); // value to Jy 1090 1090 // 1091 1091 toKelvin = True; … … 1096 1096 Quantum<Double> t(1.0,fluxUnit); 1097 1097 Quantum<Double> t2 = t.get(K); 1098 inFac = (t2 / t).getValue();1098 cFac = (t2 / t).getValue(); // value to K 1099 1099 // 1100 1100 toKelvin = False; … … 1105 1105 pTabOut->putSDHeader(sh); 1106 1106 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 } 1125 1139 // 1126 1140 return pTabOut; 1127 1141 } 1142 1143 1144 1128 1145 1129 1146 … … 1253 1270 // 'private' functions 1254 1271 1272 void 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 1255 1367 1256 1368 SDMemTable* SDMath::frequencyAlign (const SDMemTable& in, … … 1800 1912 } 1801 1913 } 1802 1803
Note: See TracChangeset
for help on using the changeset viewer.