Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r15 r38 29 29 //# $Id: 30 30 //#--------------------------------------------------------------------------- 31 #include <vector> 32 31 33 #include <aips/aips.h> 32 34 #include <aips/Utilities/String.h> 33 35 #include <aips/Arrays/IPosition.h> 34 36 #include <aips/Arrays/Array.h> 37 #include <aips/Arrays/ArrayAccessor.h> 38 #include <aips/Arrays/Slice.h> 35 39 #include <aips/Arrays/ArrayMath.h> 36 40 #include <aips/Arrays/ArrayLogical.h> … … 43 47 #include <aips/Tables/ArrayColumn.h> 44 48 49 #include <aips/Fitting.h> 50 #include <trial/Fitting/LinearFit.h> 51 #include <trial/Functionals/CompiledFunction.h> 52 #include <aips/Mathematics/AutoDiff.h> 53 #include <aips/Mathematics/AutoDiffMath.h> 54 55 #include "MathUtils.h" 45 56 #include "SDContainer.h" 46 57 #include "SDMemTable.h" … … 56 67 ROScalarColumn<String> srcn(t, "SRCNAME"); 57 68 ROScalarColumn<Double> integr(t, "INTERVAL"); 69 ROArrayColumn<uInt> freqidc(t, "FREQID"); 58 70 IPosition ip = in->rowAsMaskedArray(0).shape(); 59 71 Array<Float> outarr(ip); outarr =0.0; … … 95 107 String tstr; srcn.getScalar(0,tstr);// get sourcename of "mid" point 96 108 sc.sourcename = tstr; 109 Vector<uInt> tvec; 110 freqidc.get(0,tvec); 111 sc.putFreqMap(tvec); 112 sc.scanid = 0; 97 113 sc.putSpectrum(outarr); 98 114 sc.putFlags(outflags); … … 112 128 ROScalarColumn<Double> integr(ton, "INTERVAL"); 113 129 ROScalarColumn<String> srcn(ton, "SRCNAME"); 130 ROArrayColumn<uInt> freqidc(ton, "FREQID"); 131 114 132 MaskedArray<Float> mon(on->rowAsMaskedArray(0)); 115 133 MaskedArray<Float> moff(off->rowAsMaskedArray(0)); … … 137 155 integr.getScalar(0,tme); 138 156 sc.interval = tme; 157 Vector<uInt> tvec; 158 freqidc.get(0,tvec); 159 sc.putFreqMap(tvec); 160 sc.scanid = 0; 139 161 sc.putSpectrum(out); 140 162 sc.putFlags(outflags); … … 158 180 return CountedPtr<SDMemTable>(sdmt); 159 181 } 182 static std::vector<float> SDMath::baseline(const CountedPtr<SDMemTable>& in, 183 const std::string& fitexpr) { 184 cout << "Fitting: " << fitexpr << endl; 185 Table t = in->table(); 186 LinearFit<Float> fitter; 187 Vector<Float> y; 188 in->getSpectrum(y, 0); 189 Vector<Bool> m; 190 in->getMask(m, 0); 191 Vector<Float> x(y.nelements()); 192 indgen(x); 193 CompiledFunction<AutoDiff<Float> > fn; 194 fn.setFunction(String(fitexpr)); 195 fitter.setFunction(fn); 196 Vector<Float> out,out1; 197 out = fitter.fit(x,y,&m); 198 out1 = y; 199 fitter.residual(out1,x); 200 cout << "solution =" << out << endl; 201 std::vector<float> fitted; 202 out1.tovector(fitted); 203 return fitted; 204 } 205 206 207 static CountedPtr<SDMemTable> 208 SDMath::hanning(const CountedPtr<SDMemTable>& in) { 209 IPosition ip = in->rowAsMaskedArray(0).shape(); 210 MaskedArray<Float> marr(in->rowAsMaskedArray(0)); 211 212 Array<Float> arr = marr.getArray(); 213 Array<Bool> barr = marr.getMask(); 214 for (uInt i=0; i<in->nBeam();++i) { 215 for (uInt j=0; j<in->nIF();++j) { 216 for (uInt k=0; k<in->nPol();++k) { 217 IPosition start(4,i,j,k,0); 218 IPosition end(4,i,j,k,in->nChan()-1); 219 Array<Float> subArr(arr(start,end)); 220 Array<Bool> subMask(barr(start,end)); 221 Vector<Float> outv; 222 Vector<Bool> outm; 223 Vector<Float> v(subArr.nonDegenerate()); 224 Vector<Bool> m(subMask.nonDegenerate()); 225 ::hanning(outv,outm,v,m); 226 ArrayAccessor<Float, Axis<0> > aa0(outv); 227 ArrayAccessor<Bool, Axis<0> > ba0(outm); 228 ArrayAccessor<Bool, Axis<3> > ba(subMask); 229 for (ArrayAccessor<Float, Axis<3> > aa(subArr); aa != aa.end();++aa) { 230 (*aa) = (*aa0); 231 (*ba) = (*ba0); 232 aa0++; 233 ba0++; 234 ba++; 235 } 236 } 237 } 238 } 239 Array<uChar> outflags(barr.shape()); 240 convertArray(outflags,!barr); 241 SDContainer sc = in->getSDContainer(); 242 sc.putSpectrum(arr); 243 sc.putFlags(outflags); 244 SDMemTable* sdmt = new SDMemTable(*in,True); 245 sdmt->putSDContainer(sc); 246 return CountedPtr<SDMemTable>(sdmt); 247 } 248 160 249 /* 161 250 static Float SDMath::rms(const SDMemTable& in, uInt whichRow) { -
trunk/src/SDMath.h
r15 r38 32 32 #define _SDMATH_H_ 33 33 34 #include <string> 35 #include <vector> 34 36 #include <aips/Utilities/CountedPtr.h> 35 37 … … 46 48 Float factor); 47 49 50 static std::vector<float> baseline(const CountedPtr<SDMemTable>& in, 51 const std::string& fitexpr ); 52 static CountedPtr<SDMemTable> hanning(const CountedPtr<SDMemTable>& in); 48 53 49 54 }; 50 51 55 } // namespace 52 56
Note:
See TracChangeset
for help on using the changeset viewer.