Changeset 926
- Timestamp:
- 03/24/06 13:35:32 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STMath.cpp
r917 r926 60 60 61 61 CountedPtr<Scantable> 62 STMath::average( const std::vector<CountedPtr<Scantable> >& in,62 STMath::average( const std::vector<CountedPtr<Scantable> >& scantbls, 63 63 const std::vector<bool>& mask, 64 64 const std::string& weight, … … 66 66 bool alignfreq) 67 67 { 68 if ( avmode == "SCAN" && in.size() != 1 )68 if ( avmode == "SCAN" && scantbls.size() != 1 ) 69 69 throw(AipsError("Can't perform 'SCAN' averaging on multiple tables")); 70 70 WeightType wtype = stringToWeight(weight); 71 72 std::vector<CountedPtr<Scantable> >* in = const_cast<std::vector<CountedPtr<Scantable> >*>(&scantbls); 73 std::vector<CountedPtr<Scantable> > inaligned; 74 if ( alignfreq ) { 75 // take first row of first scantable as reference epoch 76 String epoch = scantbls[0]->getTime(0); 77 for (int i=0; i< scantbls.size(); ++i ) { 78 inaligned.push_back(frequencyAlign(scantbls[i], epoch)); 79 } 80 in = &inaligned; 81 } 82 71 83 // output 72 84 // clone as this is non insitu 73 85 bool insitu = insitu_; 74 86 setInsitu(false); 75 CountedPtr< Scantable > out = getScantable( in[0], true);87 CountedPtr< Scantable > out = getScantable((*in)[0], true); 76 88 setInsitu(insitu); 77 std::vector<CountedPtr<Scantable> >::const_iterator stit = in .begin();89 std::vector<CountedPtr<Scantable> >::const_iterator stit = in->begin(); 78 90 ++stit; 79 while ( stit != in .end() ) {91 while ( stit != in->end() ) { 80 92 out->appendToHistoryTable((*stit)->history()); 81 93 ++stit; … … 94 106 // set up the output table rows. These are based on the structure of the 95 107 // FIRST scantable in the vector 96 const Table& baset = in[0]->table();108 const Table& baset = (*in)[0]->table(); 97 109 98 110 Block<String> cols(3); … … 104 116 cols[3] = String("SRCNAME"); 105 117 } 106 if ( avmode == "SCAN" && in .size() == 1) {118 if ( avmode == "SCAN" && in->size() == 1) { 107 119 cols.resize(4); 108 120 cols[3] = String("SCANNO"); … … 128 140 129 141 for (uInt i=0; i < tout.nrow(); ++i) { 130 for ( int j=0; j < in .size(); ++j ) {131 const Table& tin = in[j]->table();142 for ( int j=0; j < in->size(); ++j ) { 143 const Table& tin = (*in)[j]->table(); 132 144 const TableRecord& rec = row.get(i); 133 145 ROScalarColumn<Double> tmp(tin, "TIME"); … … 270 282 ROArrayColumn<Float> outtsysCol(tout, "TSYS"); 271 283 ArrayColumn<uChar> outflagCol(tout, "FLAGTRA"); 272 273 284 for (uInt i=0; i < tout.nrow(); ++i) { 274 285 const TableRecord& rec = row.get(i); … … 303 314 outspecCol.put(i, quot.getArray()); 304 315 outflagCol.put(i, flagsFromMA(quot)); 316 } 317 // renumber scanno 318 TableIterator it(tout, "SCANNO"); 319 uInt i = 0; 320 while ( !it.pastEnd() ) { 321 Table t = it.table(); 322 TableVector<uInt> vec(t, "SCANNO"); 323 vec = i; 324 ++i; 325 ++it; 305 326 } 306 327 return out; … … 480 501 // initialize the lookup table if necessary 481 502 if ( lookup.empty() ) { 482 lookup[" NEAR"] = InterpolateArray1D<Double,Float>::nearestNeighbour;483 lookup[" LIN"] = InterpolateArray1D<Double,Float>::linear;484 lookup[" CUB"] = InterpolateArray1D<Double,Float>::cubic;485 lookup[" SPL"] = InterpolateArray1D<Double,Float>::spline;503 lookup["nearest"] = InterpolateArray1D<Double,Float>::nearestNeighbour; 504 lookup["linear"] = InterpolateArray1D<Double,Float>::linear; 505 lookup["cubic"] = InterpolateArray1D<Double,Float>::cubic; 506 lookup["spline"] = InterpolateArray1D<Double,Float>::spline; 486 507 } 487 508 … … 526 547 // Get elevation data from Scantable and convert to degrees 527 548 CountedPtr< Scantable > out = getScantable(in, false); 528 Table& tab = in->table();549 Table& tab = out->table(); 529 550 ROScalarColumn<Float> elev(tab, "ELEVATION"); 530 551 Vector<Float> x = elev.getColumn(); … … 641 662 flagCol.put(i, flagsFromMA(ma)); 642 663 if ( dotsys ) { 643 Vector<Float> tsys; 644 tsysCol.get(i, tsys); 664 Vector<Float> tsys = tsysCol(i); 645 665 tsys *= factor[i]; 646 specCol.put(i,tsys);666 tsysCol.put(i,tsys); 647 667 } 648 668 } … … 759 779 { 760 780 CountedPtr< Scantable > out = getScantable(in, false); 761 Table& tab = in->table(); 781 782 Table tab = out->table(); 762 783 ROScalarColumn<Float> elev(tab, "ELEVATION"); 763 784 ArrayColumn<Float> specCol(tab, "SPECTRA"); … … 766 787 Float zdist = Float(C::pi_2) - elev(i); 767 788 Float factor = exp(tau)/cos(zdist); 768 MaskedArray<Float> ma 789 MaskedArray<Float> ma = maskedArray(specCol(i), flagCol(i)); 769 790 ma *= factor; 770 791 specCol.put(i, ma.getArray()); … … 830 851 ScalarColumn<uInt> scannocol(tout,"SCANNO"), focusidcol(tout,"FOCUS_ID"); 831 852 // Renumber SCANNO to be 0-based 832 uInt offset = min(scannocol.getColumn());833 TableVector<uInt> scannos(tout, "SCANNO");853 Vector<uInt> scannos = scannocol.getColumn(); 854 uInt offset = min(scannos); 834 855 scannos -= offset; 835 uInt newscanno = max(scannocol.getColumn())+1; 856 scannocol.putColumn(scannos); 857 uInt newscanno = max(scannos)+1; 836 858 ++it; 837 859 while ( it != in.end() ){ … … 958 980 asap::STMath::frequencyAlign( const CountedPtr< Scantable > & in, 959 981 const std::string & refTime, 960 const std::string & method , bool perfreqid)982 const std::string & method) 961 983 { 962 984 CountedPtr< Scantable > out = getScantable(in, false); … … 994 1016 } 995 1017 MFrequency::Types system = in->frequencies().getFrame(); 1018 out->frequencies().setFrame(system); 996 1019 // set up the iterator 997 Block<String> cols( 3);998 // select theby constant direction1020 Block<String> cols(4); 1021 // select by constant direction 999 1022 cols[0] = String("SRCNAME"); 1000 1023 cols[1] = String("BEAMNO"); 1001 1024 // select by IF ( no of channels varies over this ) 1002 1025 cols[2] = String("IFNO"); 1003 // handle freqid based alignment 1004 if ( perfreqid ) { 1005 cols.resize(4); 1006 cols[3] = String("FREQ_ID"); 1007 } 1026 // select by restfrequency 1027 cols[3] = String("MOLECULE_ID"); 1008 1028 TableIterator iter(tout, cols); 1009 while ( !iter.pastEnd()) {1029 while ( !iter.pastEnd() ) { 1010 1030 Table t = iter.table(); 1011 1031 MDirection::ROScalarColumn dirCol(t, "DIRECTION"); 1012 ScalarColumn<uInt> freqidCol(t, "FREQ_ID"); 1013 // get the SpectralCoordinate for the freqid, which we are iterating over 1014 SpectralCoordinate sC = in->frequencies().getSpectralCoordinate(freqidCol(0)); 1032 TableIterator fiter(t, "FREQ_ID"); 1015 1033 // determine nchan from the first row. This should work as 1016 // we are iterting over IFNO 1034 // we are iterating over BEAMNO and IFNO // we should have constant direction 1035 1017 1036 ROArrayColumn<Float> sCol(t, "SPECTRA"); 1037 MDirection direction = dirCol(0); 1018 1038 uInt nchan = sCol(0).nelements(); 1019 // we should have constant direction 1020 FrequencyAligner<Float> fa(sC, nchan, refEpoch, dirCol(0), refPos, system); 1021 // realign the SpectralCOordinate and put into the output Scantable 1022 Vector<String> units(1); 1023 units = String("Hz"); 1024 Bool linear=True; 1025 SpectralCoordinate sc2 = fa.alignedSpectralCoordinate(linear); 1026 sc2.setWorldAxisUnits(units); 1027 out->frequencies().addEntry(sc2.referencePixel()[0], 1028 sc2.referenceValue()[0], 1029 sc2.increment()[0]); 1030 // create the abcissa for IF based alignment 1031 Vector<Double> abc; 1032 if ( !perfreqid ) { 1033 abc.resize(nchan); 1039 while ( !fiter.pastEnd() ) { 1040 Table ftab = fiter.table(); 1041 ScalarColumn<uInt> freqidCol(ftab, "FREQ_ID"); 1042 // get the SpectralCoordinate for the freqid, which we are iterating over 1043 cout << freqidCol.getColumn() << endl; 1044 SpectralCoordinate sC = in->frequencies().getSpectralCoordinate(freqidCol(0)); 1045 FrequencyAligner<Float> fa( sC, nchan, refEpoch, 1046 direction, refPos, system ); 1047 // realign the SpectralCoordinate and put into the output Scantable 1048 Vector<String> units(1); 1049 units = String("Hz"); 1050 Bool linear=True; 1051 SpectralCoordinate sc2 = fa.alignedSpectralCoordinate(linear); 1052 sc2.setWorldAxisUnits(units); 1053 out->frequencies().addEntry(sc2.referencePixel()[0], 1054 sc2.referenceValue()[0], 1055 sc2.increment()[0]); 1056 // create the "global" abcissa for alignment with same FREQ_ID 1057 Vector<Double> abc(nchan); 1034 1058 Double w; 1035 1059 for (uInt i=0; i<nchan; i++) { … … 1037 1061 abc[i] = w; 1038 1062 } 1039 } 1040 // cache abcissa for same time stamps, so iterate over those 1041 TableIterator timeiter(t, "TIME"); 1042 while ( !timeiter.pastEnd() ) { 1043 Table tab = timeiter.table(); 1044 ArrayColumn<Float> specCol(tab, "SPECTRA"); 1045 ArrayColumn<uChar> flagCol(tab, "FLAGTRA"); 1046 MEpoch::ROScalarColumn timeCol(tab, "TIME"); 1047 // use align abcissa cache after the first row 1048 bool first = true; 1049 // these rows should be just be POLNO 1050 for (int i=0; i<tab.nrow(); ++i) { 1051 // input values 1052 Vector<uChar> flag = flagCol(i); 1053 Vector<Bool> mask(flag.shape()); 1054 Vector<Float> specOut; 1055 Vector<Bool> maskOut;Vector<uChar> flagOut; 1056 convertArray(mask, flag); 1057 // alignment 1058 if ( perfreqid ) { 1059 Bool ok = fa.align(specOut, maskOut, specCol(i), 1060 mask, timeCol(i), !first, 1061 interp, False); 1062 } else { 1063 Bool ok = fa.align(specOut, maskOut, abc, specCol(i), 1064 mask, timeCol(i), !first, 1065 interp, False); 1063 // cache abcissa for same time stamps, so iterate over those 1064 TableIterator timeiter(ftab, "TIME"); 1065 while ( !timeiter.pastEnd() ) { 1066 Table tab = timeiter.table(); 1067 ArrayColumn<Float> specCol(tab, "SPECTRA"); 1068 ArrayColumn<uChar> flagCol(tab, "FLAGTRA"); 1069 MEpoch::ROScalarColumn timeCol(tab, "TIME"); 1070 // use align abcissa cache after the first row 1071 bool first = true; 1072 // these rows should be just be POLNO 1073 for (int i=0; i<tab.nrow(); ++i) { 1074 // input values 1075 Vector<uChar> flag = flagCol(i); 1076 Vector<Bool> mask(flag.shape()); 1077 Vector<Float> specOut, spec; 1078 spec = specCol(i); 1079 Vector<Bool> maskOut;Vector<uChar> flagOut; 1080 convertArray(mask, flag); 1081 // alignment 1082 Bool ok = fa.align(specOut, maskOut, abc, spec, 1083 mask, timeCol(i), !first, 1084 interp, False); 1085 // back into scantable 1086 cout << spec[spec.nelements()/2] << " --- " << specOut[specOut.nelements()/2] << endl; 1087 flagOut.resize(maskOut.nelements()); 1088 convertArray(flagOut, maskOut); 1089 flagCol.put(i, flagOut); 1090 specCol.put(i, specOut); 1091 // start abcissa caching 1092 first = false; 1066 1093 } 1067 // back into scantable 1068 flagOut.resize(maskOut.nelements()); 1069 convertArray(flagOut, maskOut); 1070 flagCol.put(i, flagOut); 1071 specCol.put(i, specOut); 1072 // start ancissa caching 1073 first = false; 1094 // next timestamp 1095 ++timeiter; 1074 1096 } 1075 ++timeiter; 1097 // nect FREQ_ID 1098 ++fiter; 1076 1099 } 1077 1100 // next aligner
Note:
See TracChangeset
for help on using the changeset viewer.