Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r294 r299 599 599 pTabOut->putSDHeader(sh); 600 600 601 602 601 // Loop over rows and bin along channel axis 603 602 … … 631 630 pTabOut->putSDContainer(sc); 632 631 } 632 return pTabOut; 633 } 634 635 SDMemTable* SDMath::resample (const SDMemTable& in, const String& methodStr, 636 Float width) const 637 // 638 // Should add the possibility of width being specified in km/s. This means 639 // that for each freqID (SpectralCoordinate) we will need to convert to an 640 // average channel width (say at the reference pixel). Then we would need 641 // to be careful to make sure each spectrum (of different freqID) 642 // is the same length. 643 // 644 { 645 Bool doVel = False; 646 647 // Interpolation method 648 649 Int interpMethod = 0; 650 convertInterpString(interpMethod, methodStr); 651 652 // Make output table 653 654 SDMemTable* pTabOut = new SDMemTable(in, True); 655 656 // Resample SpectralCoordinates (one per freqID) 657 658 const uInt nCoord = in.nCoordinates(); 659 Vector<Float> offset(1,0.0); 660 Vector<Float> factors(1,1.0/width); 661 Vector<Int> newShape; 662 for (uInt j=0; j<in.nCoordinates(); ++j) { 663 CoordinateSystem cSys; 664 cSys.addCoordinate(in.getSpectralCoordinate(j)); 665 CoordinateSystem cSys2 = cSys.subImage(offset, factors, newShape); 666 SpectralCoordinate sC = cSys2.spectralCoordinate(0); 667 // 668 pTabOut->setCoordinate(sC, j); 669 } 670 671 // Get header 672 673 SDHeader sh = in.getSDHeader(); 674 675 // Generate resampling vectors 676 677 const uInt nChanIn = sh.nchan; 678 Vector<Float> xIn(nChanIn); 679 indgen(xIn); 680 // 681 Int fac = Int(nChanIn/width); 682 Vector<Float> xOut(fac+10); // 10 to be safe - resize later 683 uInt i = 0; 684 Float x = 0.0; 685 Bool more = True; 686 while (more) { 687 xOut(i) = x; 688 // 689 i++; 690 x += width; 691 if (x>nChanIn-1) more = False; 692 } 693 const uInt nChanOut = i; 694 xOut.resize(nChanOut,True); 695 cerr << "width, shape in, out = " << width << ", " << nChanIn << ", " << nChanOut << endl; 696 // 697 IPosition shapeIn(in.rowAsMaskedArray(0).shape()); 698 sh.nchan = nChanOut; 699 pTabOut->putSDHeader(sh); 700 701 // Loop over rows and resample along channel axis 702 703 Array<Float> valuesOut; 704 Array<Bool> maskOut; 705 Array<Float> tSysOut; 706 Array<Bool> tSysMaskIn(shapeIn,True); 707 Array<Bool> tSysMaskOut; 708 for (uInt i=0; i < in.nRow(); ++i) { 709 710 // Get container 711 712 SDContainer sc = in.getSDContainer(i); 713 714 // Get data and Tsys 715 716 const Array<Float>& tSysIn = sc.getTsys(); 717 const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(i)); 718 Array<Float> valuesIn = dataIn.getArray(); 719 Array<Bool> maskIn = dataIn.getMask(); 720 721 // Interpolate data 722 723 InterpolateArray1D<Float,Float>::interpolate(valuesOut, maskOut, xOut, 724 xIn, valuesIn, maskIn, 725 interpMethod, True, True); 726 sc.resize(valuesOut.shape()); 727 putDataInSDC(sc, valuesOut, maskOut); 728 729 // Interpolate TSys 730 731 InterpolateArray1D<Float,Float>::interpolate(tSysOut, tSysMaskOut, xOut, 732 xIn, tSysIn, tSysMaskIn, 733 interpMethod, True, True); 734 sc.putTsys(tSysOut); 735 736 // Put container in output 737 738 pTabOut->putSDContainer(sc); 739 } 740 // 633 741 return pTabOut; 634 742 } … … 845 953 const casa::String& kernelType, 846 954 casa::Float width, Bool doAll) const 955 // 956 // Should smooth TSys as well 957 // 847 958 { 848 959 849 960 // Number of channels 850 961 851 const uInt chanAxis = asap::ChanAxis; // Spectral axis852 962 SDHeader sh = in.getSDHeader(); 853 963 const uInt nChan = sh.nchan; … … 895 1005 896 1006 if (doAll) { 897 uInt axis = asap::ChanAxis; 898 VectorIterator<Float> itValues(valuesIn, axis); 899 VectorIterator<Bool> itMask(maskIn, axis); 1007 VectorIterator<Float> itValues(valuesIn, asap::ChanAxis); 1008 VectorIterator<Bool> itMask(maskIn, asap::ChanAxis); 900 1009 while (!itValues.pastEnd()) { 901 1010 … … 918 1027 // Set multi-dim Vector shape 919 1028 920 shapeOut(asap::ChanAxis) = valuesIn.shape()( chanAxis);1029 shapeOut(asap::ChanAxis) = valuesIn.shape()(asap::ChanAxis); 921 1030 922 1031 // Stuff about with shapes so that we don't have conformance run-time errors -
trunk/src/SDMath.h
r294 r299 88 88 // Bin up spectra 89 89 SDMemTable* bin(const SDMemTable& in, casa::Int width) const; 90 91 // Resample spectra 92 SDMemTable* resample(const SDMemTable& in, const casa::String& method, 93 casa::Float factor) const; 90 94 91 95 // Smooth
Note:
See TracChangeset
for help on using the changeset viewer.