Changeset 2012 for trunk/src/STLineFinder.cpp
- Timestamp:
- 02/25/11 16:51:50 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STLineFinder.cpp
r1670 r2012 925 925 itsNoiseBox = in_noise_box; 926 926 itsUseMedian = in_median; 927 928 useScantable = true; 927 929 } 928 930 … … 934 936 scan=in_scan.getCP(); 935 937 AlwaysAssert(!scan.null(),AipsError); 936 938 } 939 940 // set spectrum data to work with. this is a method to allow linefinder work 941 // without setting scantable for the purpose of using linefinder inside some 942 // method in scantable class. (Dec 22, 2010 by W.Kawasaki) 943 void STLineFinder::setData(const std::vector<float> &in_spectrum) 944 { 945 spectrum = Vector<Float>(in_spectrum); 946 useScantable = false; 937 947 } 938 948 … … 948 958 const casa::uInt &whichRow) throw(casa::AipsError) 949 959 { 950 if ( scan.null())960 if (useScantable && scan.null()) 951 961 throw AipsError("STLineFinder::findLines - a scan should be set first," 952 962 " use set_scan"); 953 963 954 uInt nchan = scan->nchan(scan->getIF(whichRow));964 uInt nchan = useScantable ? scan->nchan(scan->getIF(whichRow)) : spectrum.nelements(); 955 965 // set up mask and edge rejection 956 966 // no mask given... … … 962 972 } 963 973 if (mask.nelements()!=nchan) 964 throw AipsError("STLineFinder::findLines - in_scan and in_mask have different"965 "number of spectral channels.");974 throw AipsError("STLineFinder::findLines - in_scan and in_mask, or in_spectrum " 975 "and in_mask have different number of spectral channels."); 966 976 967 977 // taking flagged channels into account 968 vector<bool> flaggedChannels = scan->getMask(whichRow); 969 if (flaggedChannels.size()) { 978 if (useScantable) { 979 vector<bool> flaggedChannels = scan->getMask(whichRow); 980 if (flaggedChannels.size()) { 970 981 // there is a mask set for this row 971 982 if (flaggedChannels.size() != mask.nelements()) { 972 throw AipsError("STLineFinder::findLines - internal inconsistency: number of mask elements do not match the number of channels"); 983 throw AipsError("STLineFinder::findLines - internal inconsistency: number of " 984 "mask elements do not match the number of channels"); 973 985 } 974 986 for (size_t ch = 0; ch<mask.nelements(); ++ch) { 975 987 mask[ch] &= flaggedChannels[ch]; 976 988 } 989 } 977 990 } 978 991 … … 1015 1028 throw AipsError("STLineFinder::findLines - noise_box is supposed to be at least 2 elements"); 1016 1029 1017 spectrum.resize(); 1018 spectrum = Vector<Float>(scan->getSpectrum(whichRow)); 1030 if (useScantable) { 1031 spectrum.resize(); 1032 spectrum = Vector<Float>(scan->getSpectrum(whichRow)); 1033 } 1019 1034 1020 1035 lines.resize(0); // search from the scratch … … 1141 1156 { 1142 1157 try { 1143 if (scan.null()) 1144 throw AipsError("STLineFinder::getMask - a scan should be set first," 1145 " use set_scan followed by find_lines"); 1146 DebugAssert(mask.nelements()==scan->getChannels(last_row_used), AipsError); 1147 /* 1148 if (!lines.size()) 1149 throw AipsError("STLineFinder::getMask - one have to search for " 1158 if (useScantable) { 1159 if (scan.null()) 1160 throw AipsError("STLineFinder::getMask - a scan should be set first," 1161 " use set_scan followed by find_lines"); 1162 DebugAssert(mask.nelements()==scan->getChannels(last_row_used), AipsError); 1163 } 1164 /* 1165 if (!lines.size()) 1166 throw AipsError("STLineFinder::getMask - one have to search for " 1150 1167 "lines first, use find_lines"); 1151 */ 1152 std::vector<bool> res_mask(mask.nelements()); 1153 // iterator through lines 1154 std::list<std::pair<int,int> >::const_iterator cli=lines.begin(); 1155 for (int ch=0;ch<int(res_mask.size());++ch) { 1156 if (ch<edge.first || ch>=edge.second) res_mask[ch]=false; 1157 else if (!mask[ch]) res_mask[ch]=false; 1158 else { 1159 res_mask[ch]=!invert; // no line by default 1160 if (cli!=lines.end()) 1161 if (ch>=cli->first && ch<cli->second) 1162 res_mask[ch]=invert; // this is a line 1163 } 1164 if (cli!=lines.end()) 1165 if (ch>=cli->second) { 1166 ++cli; // next line in the list 1167 } 1168 } 1169 return res_mask; 1168 */ 1169 std::vector<bool> res_mask(mask.nelements()); 1170 // iterator through lines 1171 std::list<std::pair<int,int> >::const_iterator cli=lines.begin(); 1172 for (int ch=0;ch<int(res_mask.size());++ch) { 1173 if (ch<edge.first || ch>=edge.second) res_mask[ch]=false; 1174 else if (!mask[ch]) res_mask[ch]=false; 1175 else { 1176 res_mask[ch]=!invert; // no line by default 1177 if (cli!=lines.end()) 1178 if (ch>=cli->first && ch<cli->second) 1179 res_mask[ch]=invert; // this is a line 1180 } 1181 if (cli!=lines.end()) 1182 if (ch>=cli->second) 1183 ++cli; // next line in the list 1184 } 1185 return res_mask; 1170 1186 } 1171 1187 catch (const AipsError &ae) { 1172 1188 throw; 1173 1189 } 1174 1190 catch (const exception &ex) { 1175 1191 throw AipsError(String("STLineFinder::getMask - STL error: ")+ex.what()); 1176 1192 } 1177 1193 } … … 1182 1198 const throw(casa::AipsError) 1183 1199 { 1184 // convert to required abscissa units 1185 std::vector<double> vel=scan->getAbcissa(last_row_used); 1200 std::vector<double> vel; 1201 if (useScantable) { 1202 // convert to required abscissa units 1203 vel = scan->getAbcissa(last_row_used); 1204 } else { 1205 for (int i = 0; i < spectrum.nelements(); ++i) 1206 vel.push_back((double)i); 1207 } 1186 1208 std::vector<int> ranges=getLineRangesInChannels(); 1187 1209 std::vector<double> res(ranges.size()); … … 1202 1224 { 1203 1225 try { 1204 if (scan.null())1205 throw AipsError("STLineFinder::getLineRangesInChannels - a scan should be set first,"1206 " use set_scan followed by find_lines"); 1207 DebugAssert(mask.nelements()==scan->getChannels(last_row_used), AipsError);1208 1209 if (!lines.size())1210 throw AipsError("STLineFinder::getLineRangesInChannels - one have to search for " 1211 "lines first, use find_lines");1212 1213 std::vector<int> res(2*lines.size());1214 // iterator through lines & result 1215 std::list<std::pair<int,int> >::const_iterator cli=lines.begin();1216 std::vector<int>::iterator ri=res.begin();1217 for (;cli!=lines.end() && ri!=res.end();++cli,++ri) {1218 *ri=cli->first;1219 if (++ri!=res.end())1220 *ri=cli->second-1;1221 }1222 return res;1223 }1224 catch (const AipsError &ae) {1225 throw;1226 }1227 catch (const exception &ex) {1228 throw AipsError(String("STLineFinder::getLineRanges - STL error: ")+ex.what());1226 if (useScantable) { 1227 if (scan.null()) 1228 throw AipsError("STLineFinder::getLineRangesInChannels - a scan should be set first," 1229 " use set_scan followed by find_lines"); 1230 DebugAssert(mask.nelements()==scan->getChannels(last_row_used), AipsError); 1231 } 1232 1233 if (!lines.size()) 1234 throw AipsError("STLineFinder::getLineRangesInChannels - one have to search for " 1235 "lines first, use find_lines"); 1236 1237 std::vector<int> res(2*lines.size()); 1238 // iterator through lines & result 1239 std::list<std::pair<int,int> >::const_iterator cli = lines.begin(); 1240 std::vector<int>::iterator ri = res.begin(); 1241 for (; cli != lines.end() && ri != res.end(); ++cli,++ri) { 1242 *ri = cli->first; 1243 if (++ri != res.end()) 1244 *ri = cli->second - 1; 1245 } 1246 return res; 1247 } catch (const AipsError &ae) { 1248 throw; 1249 } catch (const exception &ex) { 1250 throw AipsError(String("STLineFinder::getLineRanges - STL error: ") + ex.what()); 1229 1251 } 1230 1252 }
Note: See TracChangeset
for help on using the changeset viewer.