Changeset 230
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r227 r230 956 956 const uInt nRow = in.nRow(); 957 957 958 // Get elevation column fromdata958 // Get elevation from SDMemTable data 959 959 960 960 const Table& tab = in.table(); 961 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 data973 974 962 Vector<Float> xOut = elev.getColumn(); 975 963 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 } 964 // 965 String col0("ELEVATION"); 966 String col1("FACTOR"); 967 // 968 return correctFromAsciiTable (pTabOut, in, fileName, col0, col1, methodStr, doAll, xOut); 969 } 970 971 1033 972 1034 973 … … 1238 1177 Table SDMath::readAsciiFile (const String& fileName) const 1239 1178 { 1240 String tableName("___asap_temp.tbl"); 1241 readAsciiTable (fileName, "", tableName); 1242 Table tbl(tableName); 1179 String formatString; 1180 Table tbl = readAsciiTable (formatString, Table::Memory, fileName, "", "", False); 1243 1181 return tbl; 1244 1182 } 1183 1184 1185 SDMemTable* SDMath::correctFromAsciiTable(SDMemTable* pTabOut, 1186 const SDMemTable& in, const String& fileName, 1187 const String& col0, const String& col1, 1188 const String& methodStr, Bool doAll, 1189 const Vector<Float>& xOut) 1190 { 1191 1192 // Read gain-elevation ascii file data into a Table. 1193 1194 Table tTable = readAsciiFile (fileName); 1195 // tTable.markForDelete(); 1196 // 1197 return correctFromTable (pTabOut, in, tTable, col0, col1, methodStr, doAll, xOut); 1198 } 1199 1200 SDMemTable* SDMath::correctFromTable(SDMemTable* pTabOut, const SDMemTable& in, const Table& tTable, 1201 const String& col0, const String& col1, 1202 const String& methodStr, Bool doAll, 1203 const Vector<Float>& xOut) 1204 { 1205 1206 // Get data from Table 1207 1208 ROScalarColumn<Float> geElCol(tTable, col0); 1209 ROScalarColumn<Float> geFacCol(tTable, col1); 1210 Vector<Float> xIn = geElCol.getColumn(); 1211 Vector<Float> yIn = geFacCol.getColumn(); 1212 Vector<Bool> maskIn(xIn.nelements(),True); 1213 1214 // Interpolate (and extrapolate) with desired method 1215 1216 Int method = 0; 1217 convertInterpString(method, methodStr); 1218 // 1219 Vector<Float> yOut; 1220 Vector<Bool> maskOut; 1221 InterpolateArray1D<Float,Float>::interpolate(yOut, maskOut, xOut, 1222 xIn, yIn, maskIn, method, 1223 True, True); 1224 1225 // For operations only on specified cursor location 1226 1227 IPosition start, end; 1228 getCursorLocation(start, end, in); 1229 1230 // Loop over rows and interpolate correction factor 1231 1232 const uInt axis = asap::ChanAxis; 1233 for (uInt i=0; i < in.nRow(); ++i) { 1234 1235 // Get data 1236 1237 MaskedArray<Float> dataIn(in.rowAsMaskedArray(i)); 1238 Array<Float>& valuesIn = dataIn.getRWArray(); // writable reference 1239 const Array<Bool>& maskIn = dataIn.getMask(); 1240 1241 // Apply factor 1242 1243 if (doAll) { 1244 VectorIterator<Float> itValues(valuesIn, asap::ChanAxis); 1245 while (!itValues.pastEnd()) { 1246 itValues.vector() *= yOut(i); // Writes back into dataIn 1247 // 1248 itValues.next(); 1249 } 1250 } else { 1251 Array<Float> valuesIn2 = valuesIn(start,end); 1252 valuesIn2 *= yOut(i); 1253 valuesIn(start,end) = valuesIn2; 1254 } 1255 1256 // Write out 1257 1258 SDContainer sc = in.getSDContainer(i); 1259 putDataInSDC(sc, valuesIn, maskIn); 1260 // 1261 pTabOut->putSDContainer(sc); 1262 } 1263 // 1264 return pTabOut; 1265 } 1266 -
trunk/src/SDMath.h
r227 r230 143 143 void convertInterpString(casa::Int& type, const casa::String& interp) const; 144 144 145 // Read ascii file 145 146 // Correct data from an ascii Table 147 SDMemTable* correctFromAsciiTable(SDMemTable* pTabOut, const SDMemTable& in, 148 const casa::String& fileName, 149 const casa::String& col0, const casa::String& col1, 150 const casa::String& methodStr, casa::Bool doAll, 151 const casa::Vector<casa::Float>& xOut); 152 153 // Correct data from a Table 154 SDMemTable* correctFromTable(SDMemTable* pTabOut, const SDMemTable& in, const casa::Table& tTable, 155 const casa::String& col0, const casa::String& col1, 156 const casa::String& methodStr, casa::Bool doAll, 157 const casa::Vector<casa::Float>& xOut); 158 159 // Read ascii file into a Table 146 160 147 161 casa::Table readAsciiFile (const casa::String& fileName) const;
Note:
See TracChangeset
for help on using the changeset viewer.